forked from eastgenomics/TSO500R
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from christopher-mohr/development
Add functionality for parsing raw CNV data
- Loading branch information
Showing
9 changed files
with
205 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
#' Read in a *CopyNumberVariants.vcf file and store as an object | ||
#' | ||
#' @description Read in a *CopyNumberVariants.vcf file | ||
#' | ||
#' @param cnv_file_path a file path to a *CopyNumberVariants.vcf file | ||
#' | ||
#' @return A cnv.output object | ||
#' | ||
#' @export | ||
cnv <- function(cnv_file_path, local_app=FALSE){ | ||
new_cnv_output(cnv_file_path) | ||
} | ||
|
||
#' Constructor function for combined.cnv.output objects | ||
#' Not to be called directly | ||
#' | ||
#' @param cnv_file_path a file path to a *CopyNumberVariants.vcf file | ||
#' @param local_app specifies whether quality metrics are coming from local app | ||
#' | ||
#' @return A combined.cnv.output object | ||
new_cnv_output <- function(cnv_file_path, local_app=FALSE) { | ||
|
||
cnv_data = tibble(file = cnv_file_path) %>% | ||
mutate(data = lapply(file, parse_vcf_to_df)) %>% | ||
unnest(data) %>% | ||
mutate(sample_id = str_replace(basename(file), "_CopyNumberVariants.vcf", "")) %>% | ||
select(-file) %>% | ||
relocate(sample_id) | ||
|
||
return(structure(cnv_data, class = "combined.cnv.output")) | ||
} | ||
|
||
#' Read in a batch of *CopyNumberVariants.vcf files into a list of CNV objects | ||
#' | ||
#' @param cnv_directory a file path to a directory containing one of more *CopyNumberVariants.vcf files | ||
#' @param local_app specifies whether quality metrics are coming from local app | ||
#' | ||
#' @return A named list of combined.cnv.output objects | ||
#' | ||
#' @export | ||
read_cnv_data <- function(cnv_directory, local_app=FALSE){ | ||
cnv_files <- list.files( | ||
path = cnv_directory, | ||
pattern = "*CopyNumberVariants.vcf", | ||
full.names = TRUE | ||
) | ||
cnv_data <- map(cnv_files, cnv, local_app) %>% | ||
set_names(str_remove(basename(cnv_files), "\\.vcf$")) | ||
cnv_data | ||
} | ||
|
||
#' Read in a batch of *CopyNumberVariants.vcf files into one dataframe | ||
#' | ||
#' @param tmb_directory a file path to a directory containing one of more | ||
#' *tmb.json files | ||
#' | ||
#' @return A dataframe with the read CNV data | ||
#' | ||
#' @export | ||
summarize_cnv_data <- function(cnv_directory){ | ||
cnv_files <- list.files( | ||
path = cnv_directory, | ||
pattern = "*cnv.vcf|*CopyNumberVariants.vcf", | ||
full.names = TRUE | ||
) | ||
|
||
cnv_data = tibble(file = cnv_files) %>% | ||
mutate(data = lapply(file, parse_vcf_to_df)) %>% | ||
unnest(data) %>% | ||
mutate(sample_id = str_replace(basename(file), "_CopyNumberVariants.vcf", "")) %>% | ||
select(-file) %>% | ||
relocate(sample_id) | ||
|
||
cnv_data | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.