Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Separate function to read samplesheet into dataframe #22

Open
grst opened this issue May 8, 2024 · 0 comments
Open

Separate function to read samplesheet into dataframe #22

grst opened this issue May 8, 2024 · 0 comments

Comments

@grst
Copy link

grst commented May 8, 2024

Sometimes the Dragen samplesheet can contain additional columns that are relevant and are not part of the DRAGEN results.
It would be nice to have a separate function for reading in the samplesheets and return a tibble. This is already done internally by the create_dragen_samplesheet here:

TSO500R/R/write.R

Lines 119 to 141 in 0e4248e

HEADER_STRING <- '[Header]'
CHEMISTRY_STRING <- 'Chemistry'
SETTINGS_STRING <- '[Settings]'
OVERRIDE_CYCLES_STRING <- 'OverrideCycles'
DATA_STRING <- '[Data]'
# Read text file into string
samplesheet_file <- readr::read_file(samplesheet)
split_samplesheet_string <- stringr::str_split(string = samplesheet_file, pattern = "\r\n") %>% unlist()
# parse header part of provided sample sheet
start_header <- pmatch(HEADER_STRING, split_samplesheet_string) + 1
end_header <- which(grepl(CHEMISTRY_STRING, split_samplesheet_string))
header <- read.csv(text=split_samplesheet_string[start_header:end_header],header=FALSE) %>%
purrr::discard(~all(is.na(.))) %>%
pivot_wider(names_from=V1, values_from=V2)
# parse settings part of provided sample sheet
start_settings <- pmatch(SETTINGS_STRING, split_samplesheet_string) + 1
end_settings <- which(grepl(OVERRIDE_CYCLES_STRING, split_samplesheet_string))
settings <- read.csv(text=split_samplesheet_string[start_settings:end_settings],header=FALSE) %>%
purrr::discard(~all(is.na(.))) %>%
pivot_wider(names_from=V1, values_from=V2)

So it would mean refactoring that into a separate function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant