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

Fix get_ssm_by_regions when maf_data is provided #82

Merged
merged 3 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 18 additions & 32 deletions R/get_ssm_by_region.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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])
Expand All @@ -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)
}

Expand Down
35 changes: 23 additions & 12 deletions R/get_ssm_by_regions.R
Original file line number Diff line number Diff line change
Expand Up @@ -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(...)

Expand All @@ -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){
Expand Down Expand Up @@ -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
Expand Down
Loading