diff --git a/R/get_ssm_by_region.R b/R/get_ssm_by_region.R index 287087a..505fa2a 100644 --- a/R/get_ssm_by_region.R +++ b/R/get_ssm_by_region.R @@ -65,36 +65,26 @@ get_ssm_by_region = function(these_sample_ids = NULL, #check if any invalid parameters are provided check_excess_params(...) - + + #get samples with the dedicated helper function + metadata = id_ease(these_samples_metadata = these_samples_metadata, + these_sample_ids = these_sample_ids, + verbose = verbose, + this_seq_type = this_seq_type) + + sample_ids = metadata$sample_id + #return SSMs based on the selected projection if(missing(maf_data)){ - #get samples with the dedicated helper function - metadata = id_ease(these_samples_metadata = these_samples_metadata, - these_sample_ids = these_sample_ids, - verbose = verbose, - this_seq_type = this_seq_type) - - sample_ids = metadata$sample_id - - #get valid projections - valid_projections = grep("meta", names(GAMBLR.data::sample_data), value = TRUE, invert = TRUE) - - if(projection %in% valid_projections){ - this_maf = GAMBLR.data::sample_data[[projection]]$maf %>% - dplyr::filter(Tumor_Sample_Barcode %in% sample_ids) %>% - dplyr::filter((tolower(!!sym("Pipeline")) == mode)) - this_maf <- bind_rows( - this_maf, - GAMBLR.data::sample_data[[projection]]$ashm %>% - dplyr::filter(Tumor_Sample_Barcode %in% sample_ids) %>% - dplyr::filter((tolower(!!sym("Pipeline")) == mode)) - ) - }else{ - stop(paste("please provide a valid projection. The following are available:", - paste(valid_projections,collapse=", "))) - } + this_maf = GAMBLR.data::sample_data[[projection]]$maf %>% + dplyr::filter(Tumor_Sample_Barcode %in% sample_ids) %>% + dplyr::filter((tolower(!!sym("Pipeline")) == mode)) + this_maf <- GAMBLR.data::sample_data[[projection]]$ashm %>% + dplyr::filter(Tumor_Sample_Barcode %in% sample_ids) %>% + dplyr::filter((tolower(!!sym("Pipeline")) == mode)) %>% + bind_rows(this_maf, .) }else{ - this_maf = maf_data + this_maf = dplyr::filter(maf_data, Tumor_Sample_Barcode %in% sample_ids) } # Optionally return variants from a particular study @@ -112,10 +102,6 @@ get_ssm_by_region = function(these_sample_ids = NULL, region = gsub(",", "", region) split_chunks = unlist(strsplit(region, ":")) - if(projection == "grch37"){ - region = stringr::str_replace(region, "chr", "") - } - chromosome = split_chunks[1] startend = unlist(strsplit(split_chunks[2], "-")) qstart = as.numeric(startend[1]) @@ -127,7 +113,7 @@ get_ssm_by_region = function(these_sample_ids = NULL, region = paste0(chromosome, ":", qstart, "-", qend) } - if(projection =="grch37"){ + if(projection == "grch37"){ chromosome = gsub("chr", "", chromosome) } diff --git a/R/get_ssm_by_regions.R b/R/get_ssm_by_regions.R index 58a5c52..b9dbcef 100644 --- a/R/get_ssm_by_regions.R +++ b/R/get_ssm_by_regions.R @@ -52,7 +52,16 @@ get_ssm_by_regions = function(these_sample_ids = NULL, projection = "grch37", verbose = FALSE, ...){ - + + # check provided projection + # first, get valid projections + valid_projections = grep("meta", names(GAMBLR.data::sample_data), + value = TRUE, invert = TRUE) + if(! projection %in% valid_projections){ + stop("Please provide a valid projection. The following are available: ", + paste(valid_projections, collapse=", "), ".") + } + #check if any invalid parameters are provided check_excess_params(...) @@ -73,16 +82,17 @@ get_ssm_by_regions = function(these_sample_ids = NULL, if(verbose){ print(regions) } - + + #get samples with the dedicated helper function + metadata = id_ease(these_samples_metadata = these_samples_metadata, + these_sample_ids = these_sample_ids, + verbose = verbose, + this_seq_type = this_seq_type) + if(missing(maf_data)){ #warn/notify the user what version of this function they are using message("Using the bundled SSM calls (.maf) calls in GAMBLR.data...") - #get samples with the dedicated helper function - metadata = id_ease(these_samples_metadata = these_samples_metadata, - these_sample_ids = these_sample_ids, - verbose = verbose, - this_seq_type = this_seq_type) if(missing(this_study)){ region_mafs = lapply( regions, function(x){ @@ -117,11 +127,12 @@ get_ssm_by_regions = function(these_sample_ids = NULL, } }else{ region_mafs = lapply(regions, function(x){get_ssm_by_region(region = x, - maf_data = maf_data, - streamlined = streamlined, - projection = projection, - verbose = FALSE, #force to FALSE, suppressing noisy output - ...)}) + maf_data = maf_data, + these_samples_metadata = metadata, + this_seq_type = this_seq_type, + streamlined = streamlined, + projection = projection, + verbose = FALSE)}) } #deal with region names