From 5f76a73f05dc41b9f45cfca5fe9d64ae1be32f93 Mon Sep 17 00:00:00 2001 From: Chai Bandlamudi Date: Sat, 6 Jun 2020 19:12:31 -0400 Subject: [PATCH] adding hisens purity to facets-qc output. also compile_cohort_annotations now includes manual review info --- DESCRIPTION | 2 +- R/compile_cohort_annotations.R | 29 ++++++++++++++++++++++++++++- R/generate_genomic_annotations.R | 10 ++++++++-- R/global.R | 1 + example_facets_preview.json | 2 +- 5 files changed, 39 insertions(+), 5 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 6f7d485..607fbf9 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: facetsPreview Title: Review and refit FACETS runs -Version: 2.1.2 +Version: 2.1.4 Authors@R: person("First", "Last", email = "first.last@example.com", role = c("aut", "cre")) Description: Review and refit FACETS runs biocViews: diff --git a/R/compile_cohort_annotations.R b/R/compile_cohort_annotations.R index ccf27b6..a4752d4 100755 --- a/R/compile_cohort_annotations.R +++ b/R/compile_cohort_annotations.R @@ -42,8 +42,9 @@ compile_cohort_annotations <- function(samples_to_annotate, output_prefix, ncore ## read from facets_qc.txt qc_file = paste0(sample_path, '/facets_qc.txt') + review_file = paste0(sample_path, '/facets_review.manifest') - if (!file.exists(qc_file)) { return() } + if (!file.exists(qc_file)| !file.exists(review_file)) { return() } qc_runs = fread(qc_file) %>% filter(fit_name != 'Not selected') @@ -58,6 +59,32 @@ compile_cohort_annotations <- function(samples_to_annotate, output_prefix, ncore fit = qc_runs %>% head(n=1) } + reviews <- + fread(review_file) %>% + filter(fit_name == fit$fit_name) %>% + arrange(desc(date_reviewed)) %>% + select(fit_name, review_notes, reviewed_by, date_reviewed, use_only_purity_run, use_edited_cncf, reviewer_set_purity) %>% + head(n=1) + + fit <- + fit %>% + left_join(reviews) + + #### + #### update purity and ploidy based on reviews; + #### + fit <- + fit %>% + rowwise %>% + mutate(purity = ifelse(!is.na(reviewer_set_purity) & reviewer_set_purity != '', + reviewer_set_purity, + ifelse(!is.na(use_only_purity_run) & use_only_purity_run, + purity_run_Purity, + hisens_run_Purity))) %>% + mutate(ploidy = ifelse(!is.na(use_only_purity_run) & use_only_purity_run, + purity_run_Ploidy, + hisens_run_Ploidy)) + return (fit) }, .parallel = parallelize) ) diff --git a/R/generate_genomic_annotations.R b/R/generate_genomic_annotations.R index e188889..eee1c55 100755 --- a/R/generate_genomic_annotations.R +++ b/R/generate_genomic_annotations.R @@ -106,8 +106,14 @@ generate_genomic_annotations = function(sample_id, sample_path, config_file, reg write.table(qc, paste0(prefix, '.qc.txt'), quote=F, row.names=F, sep='\t') # Write gene level // use hisensitivity run - gene_level = facetsSuite::gene_level_changes(hisens_output, 'hg19') %>% - add_column(sample = sample_id, .before = 1) + + if (r$use_only_purity_run) { + gene_level = facetsSuite::gene_level_changes(purity_output, 'hg19', 'em') + } else { + gene_level = facetsSuite::gene_level_changes(hisens_output, 'hg19', 'em') + } + gene_level = gene_level %>% add_column(sample = sample_id, .before = 1) + write.table(gene_level, paste0(prefix, '.gene_level.txt'), quote=F, row.names=F, sep='\t') # Write arm level // use purity run diff --git a/R/global.R b/R/global.R index f872288..27c589f 100755 --- a/R/global.R +++ b/R/global.R @@ -231,6 +231,7 @@ metadata_init <- function(sample_id, sample_path, progress = NULL, update_qc_fil hisens_run_snp_nbhd = get0("hisens_snp.nbhd", ifnotfound = NA), hisens_run_ndepth = get0("hisens_ndepth", ifnotfound = NA), hisens_run_hisens = round_down(get0("hisens_hisens", ifnotfound = NA)), + hisens_run_Purity = round_down(get0("hisens_Purity", ifnotfound = NA)), hisens_run_Ploidy = round_down(get0("hisens_Ploidy", ifnotfound = NA)), hisens_run_dipLogR = round_down(get0("hisens_dipLogR", ifnotfound = NA)), diff --git a/example_facets_preview.json b/example_facets_preview.json index b72704c..34cf965 100755 --- a/example_facets_preview.json +++ b/example_facets_preview.json @@ -30,7 +30,7 @@ ], "verify_sshfs_mount" : "juno", "r_script_path" : "/opt/common/CentOS_7-dev/bin/Rscript", - "facets_suite_lib": "/juno/work/ccs/shared/software/R_libs/facetsSuite/2.0.5/", + "facets_suite_lib": "/juno/work/ccs/shared/software/R_libs/facetsSuite/2.0.6/", "facets_suite_run_wrapper": "/juno/work/ccs/shared/software/R_libs/facetsSuite/2.0.4/run-facets-wrapper.R", "facets_qc_script": "/juno/work/ccs/bandlamc/git/facets-preview/facets_qc/v1.0/facets_fit_qc.R" }