Skip to content

Commit

Permalink
Merge pull request #115 from morinlab/cmattsson-dev
Browse files Browse the repository at this point in the history
Fancy Plots + QoL Updates
  • Loading branch information
mattssca authored Aug 11, 2022
2 parents 2cc0568 + 8cf2ec2 commit 5a07fbf
Show file tree
Hide file tree
Showing 10 changed files with 305 additions and 158 deletions.
52 changes: 32 additions & 20 deletions R/utilities.R
Original file line number Diff line number Diff line change
Expand Up @@ -937,6 +937,7 @@ test_glue = function(placeholder="INSERTED"){
#' @param sample_table A data frame with sample_id as the first column.
#' @param write_to_file Boolean statement that outputs tsv file if TRUE, default is FALSE.
#' @param join_with_full_metadata Join with all columns of meta data, default is FALSE.
#' @param these_samples_metadata Optional argument to use a user specified metadata df, overwrites get_gambl_metadata in join_with_full_metadata.
#' @param case_set Optional short name for a pre-defined set of cases.
#' @param sbs_manipulation Optional variable for transforming sbs values (e.g log, scale).
#' @param seq_type_filter Filtering criteria, default is genomes.
Expand All @@ -952,6 +953,7 @@ test_glue = function(placeholder="INSERTED"){
collate_results = function(sample_table,
write_to_file = FALSE,
join_with_full_metadata = FALSE,
these_samples_metadata,
case_set,
sbs_manipulation = "",
seq_type_filter = "genome",
Expand All @@ -976,15 +978,15 @@ collate_results = function(sample_table,
}else{
message("Slow option: not using cached result. I suggest from_cache = TRUE whenever possible")
#edit this function and add a new function to load any additional results into the main summary table
sample_table = collate_ssm_results(sample_table = sample_table,seq_type_filter=seq_type_filter)
sample_table = collate_sv_results(sample_table = sample_table,seq_type_filter=seq_type_filter)
sample_table = collate_curated_sv_results(sample_table = sample_table,seq_type_filter=seq_type_filter)
sample_table = collate_ashm_results(sample_table = sample_table,seq_type_filter=seq_type_filter)
sample_table = collate_nfkbiz_results(sample_table = sample_table,seq_type_filter=seq_type_filter)
sample_table = collate_csr_results(sample_table = sample_table,seq_type_filter=seq_type_filter)
sample_table = collate_ancestry(sample_table = sample_table,seq_type_filter=seq_type_filter)
sample_table = collate_sbs_results(sample_table = sample_table, sbs_manipulation = sbs_manipulation,seq_type_filter=seq_type_filter)
sample_table = collate_qc_results(sample_table = sample_table,seq_type_filter = seq_type_filter)
sample_table = collate_ssm_results(sample_table = sample_table, seq_type_filter = seq_type_filter)
sample_table = collate_sv_results(sample_table = sample_table, seq_type_filter = seq_type_filter)
sample_table = collate_curated_sv_results(sample_table = sample_table, seq_type_filter = seq_type_filter)
sample_table = collate_ashm_results(sample_table = sample_table, seq_type_filter = seq_type_filter)
sample_table = collate_nfkbiz_results(sample_table = sample_table, seq_type_filter = seq_type_filter)
sample_table = collate_csr_results(sample_table = sample_table, seq_type_filter = seq_type_filter)
sample_table = collate_ancestry(sample_table = sample_table, seq_type_filter = seq_type_filter)
sample_table = collate_sbs_results(sample_table = sample_table, sbs_manipulation = sbs_manipulation, seq_type_filter = seq_type_filter)
sample_table = collate_qc_results(sample_table = sample_table, seq_type_filter = seq_type_filter)
}
if(write_to_file){
output_file = config::get("table_flatfiles")$derived
Expand All @@ -995,17 +997,23 @@ collate_results = function(sample_table,
}
#convenience columns bringing together related information
if(join_with_full_metadata){
full_meta = get_gambl_metadata(seq_type_filter = seq_type_filter)
full_table = left_join(full_meta, sample_table)
full_table = full_table %>%
mutate("MYC_SV_any" = case_when(ashm_MYC > 3 ~ "POS", manta_MYC_sv == "POS" ~ "POS", ICGC_MYC_sv == "POS" ~ "POS", myc_ba == "POS" ~ "POS", TRUE ~ "NEG"))
if(!missing(these_samples_metadata)){
meta_data = these_samples_metadata
}else{
meta_data = get_gambl_metadata(seq_type_filter = seq_type_filter)
}

full_table = left_join(meta_data, sample_table)

full_table = full_table %>%
mutate("BCL2_SV_any" = case_when(ashm_BCL2 > 3 ~ "POS", manta_BCL2_sv == "POS" ~ "POS", ICGC_BCL2_sv == "POS" ~ "POS", bcl2_ba == "POS" ~ "POS", TRUE ~ "NEG"))
full_table = full_table %>%
mutate("MYC_SV_any" = case_when(ashm_MYC > 3 ~ "POS", manta_MYC_sv == "POS" ~ "POS", ICGC_MYC_sv == "POS" ~ "POS", myc_ba == "POS" ~ "POS", TRUE ~ "NEG"))

full_table =full_table %>%
mutate("DoubleHitBCL2" = ifelse(BCL2_SV_any == "POS" & MYC_SV_any == "POS", "Yes", "No"))
return(full_table)
full_table = full_table %>%
mutate("BCL2_SV_any" = case_when(ashm_BCL2 > 3 ~ "POS", manta_BCL2_sv == "POS" ~ "POS", ICGC_BCL2_sv == "POS" ~ "POS", bcl2_ba == "POS" ~ "POS", TRUE ~ "NEG"))

full_table = full_table %>%
mutate("DoubleHitBCL2" = ifelse(BCL2_SV_any == "POS" & MYC_SV_any == "POS", "Yes", "No"))
return(full_table)
}
return(sample_table)
}
Expand Down Expand Up @@ -3198,6 +3206,7 @@ adjust_ploidy = function(this_seg,
#' Helper function called by fancy_multisample_ideo, for sub-setting copy number information based on segments avaialble in cn data
#'
#' @param cn_segments DF with copy number segments, usually retrieved from get_sample_cn_segments.
#' @param include_2 Optional parameter for including or ommit CN state == 2.
#' @param samplen Numeric value that annotates the sample order.
#'
#' @return Nothing.
Expand All @@ -3207,13 +3216,16 @@ adjust_ploidy = function(this_seg,
#' subset_cnstates(cn_segments = cn_states, samplen = 1)
#'
subset_cnstates = function(cn_segments,
include_2 = FALSE,
samplen){

#transform CN states > 6 = 6 (to reflect the current copy number palette in gamblr)
cn_segments$CN[cn_segments$CN > 6] = 6

#filter out CN == 2
cn_segments = subset(cn_segments, CN != 2)
if(!include_2){
cn_segments = subset(cn_segments, CN != 2)
}

#update CN annotations (if present in cn_segment data).
cn_segments$CN = paste0("cn_", cn_segments$CN , "_sample", samplen)
Expand Down Expand Up @@ -3400,7 +3412,7 @@ cnvKompare = function(patient_id,
concordant_cytobands =
for_output %>%
# output-specific
select(ID, cb.chromosome, cb.start, cb.end, name, score) %>%
select(ID, cb.chromosome, cb.start, cb.end, name, score, log.ratio) %>%
dplyr::filter(name %in% names(overall_concordance[overall_concordance == "YES"]))

output$concordant_cytobands = concordant_cytobands
Expand Down
Loading

0 comments on commit 5a07fbf

Please # to comment.