Skip to content

Commit

Permalink
Merge pull request #34 from morinlab/kdreval-helpers-setup
Browse files Browse the repository at this point in the history
Major updates
  • Loading branch information
Kdreval authored Mar 15, 2024
2 parents 94920fd + 8839fc1 commit 9bcc4fe
Show file tree
Hide file tree
Showing 53 changed files with 1,046 additions and 188 deletions.
49 changes: 49 additions & 0 deletions .github/workflows/build_check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: GAMBLR.helpers build check

on:
pull_request:
branches: [master]


jobs:
build:
runs-on: ubuntu-latest
defaults:
run:
shell: bash -el {0}
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
R_KEEP_PKG_SOURCE: yes

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Setup Conda
uses: actions/setup-python@v2
with:
python-version: 3.11

- name: Create conda environment
uses: conda-incubator/setup-miniconda@v2
with:
activate-environment: r
channels: conda-forge,defaults
python-version: 3.11
auto-activate-base: false
environment-file: envs/r.yaml

- name: Build package
run:
Rscript -e "devtools::install()"

- name: Check package
run:
Rscript -e "devtools::check(vignettes = FALSE, args = '--no-examples')"

- name: Upload check results
if: failure()
uses: actions/upload-artifact@main
with:
name: ${{ runner.os }}-r${{ matrix.config.r }}-results
path: check
1 change: 0 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ Imports:
ggthemes,
philentropy,
readr,
reshape2,
stringr,
tibble,
tidyr,
Expand Down
2 changes: 0 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ export(maf_header)
export(normalize_expression_data)
export(rainfall_conv)
export(required_cols)
export(review_hotspots)
export(sanity_check_metadata)
export(socketWrite)
export(standardize_chr_prefix)
Expand All @@ -44,7 +43,6 @@ import(workflowr)
importFrom(dplyr,left_join)
importFrom(ggthemes,theme_foundation)
importFrom(philentropy,KL)
importFrom(reshape2,melt)
importFrom(stats,end)
importFrom(stats,quantile)
importFrom(stats,start)
Expand Down
1 change: 0 additions & 1 deletion R/GAMBLR.helpers-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
## usethis namespace: start
#' @importFrom dplyr left_join
#' @importFrom philentropy KL
#' @importFrom reshape2 melt
#' @importFrom stats end
#' @importFrom stats quantile
#' @importFrom stats start
Expand Down
14 changes: 12 additions & 2 deletions R/bins_to_bedgraph.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
#' @title Bins to bed graph.
#'
#' @description This function will generate bed file.
#'
#' @param bin_df Data frame with bins.
#' @param min_value Minimum value to retain the bin.
#' @param filename Path to a local file on drive to save the resulting file.
#'
#' @return full path to the file that was written
#'
#' @export
bins_to_bedgraph = function(bin_df,min_value = 3,filename = "test.bed"){
bed_cols = dplyr::select(bin_df,1,2,3,smoothed_ratio)
Expand All @@ -7,8 +17,8 @@ bins_to_bedgraph = function(bin_df,min_value = 3,filename = "test.bed"){
bed_cols = mutate(bed_cols,chr = paste0("chr",chr))
}
bed_cols = dplyr::filter(bed_cols,value > min_value)
this = dplyr::filter(chr1p,bin_start==27985000)
this = dplyr::filter(chr1p,bin_start==27985000)
bed_cols = mutate(bed_cols,end=format(end, scientific=F),start=format(start, scientific=F))
write.table(bed_cols,row.names=F,col.names=F,quote=F,sep="\t",file=filename)

return(filename)
}
14 changes: 14 additions & 0 deletions R/cache_output.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
#' @title Cache output.
#'
#' @description TODO.
#'
#' @param result_df TODO.
#' @param function_name TODO.
#' @param clobber_mode TODO.
#' @param get_existing TODO.
#' @param function_params TODO.
#' @param additional_details TODO.
#'
#' @return full path to the file that was written
#'
#' @export
cache_output = function(result_df,
function_name,
Expand Down Expand Up @@ -31,4 +44,5 @@ cache_output = function(result_df,

message(paste("creating/overwriting",cache_file_name))
write_tsv(result_df,file=cache_file_name)
return(cache_file_name)
}
4 changes: 2 additions & 2 deletions R/calculate_tmb.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#' @title Return TMB counts.
#' @title Calculate tumour mutation burden.
#'
#' @description This function implements tumor mutation burden calculation.
#' TODO: add more details.
Expand Down Expand Up @@ -31,7 +31,7 @@
#' maf1,
#' regions_bed = grch37_ashm_regions
#' )
#' #' calculate_tmb(
#' calculate_tmb(
#' maf1,
#' regions_bed = grch37_ashm_regions,
#' subset_to_nonSyn = FALSE
Expand Down
8 changes: 4 additions & 4 deletions R/check_config_value.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
#' @description Check the existence of a specific config key.
#' The function will notify the user and end the program if no such key exists.
#'
#' @details INTERNAL FUNCTION for checking the existence of a config value, not meant for out-of-package usage.
#' @details INTERNAL FUNCTION for checking the existence of a config value,
#' not meant for out-of-package usage.
#'
#' @param config_key key from config, prefixed with config::get()
#'
#' @return A string with the path to a file specified in the config or nothing (if config key is NULL).
#' @return A string with the path to a file specified in the config or nothing
#' (if config key is NULL).
#'
#' @noRd
#'
#' @examples
#' check_config_value(config::get("resources")$blacklist$template)
#'
Expand Down
10 changes: 10 additions & 0 deletions R/check_file_details.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
#' @title Check file details
#'
#' @description When relative path to a file is given, this function will
#' automatically generate it's full path using the project_base config value
#' and check for existence of the file at the full path. Can operate on vector
#' of several relative paths.
#'
#' @param relative_paths Vector of relative paths.
#' @return Boolean
#'
#' @export
check_file_details = function(relative_paths){
not_found = c()
Expand Down
10 changes: 10 additions & 0 deletions R/compare_coding_mutation_pattern.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
#' @title Compare pattern of coding mutations.
#'
#' @description TODO.
#'
#' @param maf_df1 TODO.
#' @param maf_df2 TODO.
#' @param gene TODO.
#'
#' @return list
#'
#' @export
compare_coding_mutation_pattern = function(maf_df1,maf_df2,gene){
if(missing(maf_df1) | missing(maf_df2)){
Expand Down
11 changes: 11 additions & 0 deletions R/copy_no_clobber.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
#' @title Copy not clobber.
#'
#' @description TODO.
#'
#' @param from_file TODO.
#' @param to_file TODO.
#' @param force TODO.
#'
#' @return full path to the file that was written
#'
#' @export
copy_no_clobber = function(from_file,
to_file,
Expand All @@ -9,4 +19,5 @@ copy_no_clobber = function(from_file,
if(force){
file.copy(from_file,to_file)
}
return(to_file)
}
19 changes: 19 additions & 0 deletions R/gene_mutation_tally.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
#' @title Tally coding mutations load.
#'
#' @description Calculate the number of coding mutations per grouping. Silent
#' variants are excluded from this calculation. The incoming maf may contain
#' non-coding variants, which will be excluded from tallying.
#'
#' @param maf_df Data frame of simple somatic mutations in maf format. Required
#' parameter.
#' @param these_samples_metadata Data frame with metadata. Must contain sample
#' identifiers in the `sample_id` column and column that will be used
#' to calulate the mutation load. All other columns are ignored. Required
#' parameter.
#' @param these_genes Vector of hugo symbols for genes to be considered for the
#' tallying of mutations. Required parameter.
#' @param grouping_variable Column in the metadata that will be used as grouping
#' variable. By default, the `cohort` is used.
#'
#' @return data frame
#'
#' @export
gene_mutation_tally = function(maf_df,these_samples_metadata,these_genes,grouping_variable="cohort"){
meta = dplyr::select(these_samples_metadata,sample_id,{{grouping_variable}})
Expand Down
9 changes: 9 additions & 0 deletions R/get_template_wildcards.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
#' @title Get template wildcards.
#'
#' @description TODO.
#'
#' @param parent_key TODO.
#' @param template_key TODO.
#'
#' @return list
#'
#' @export
get_template_wildcards = function(parent_key,
template_key){
Expand Down
36 changes: 30 additions & 6 deletions R/get_unmatched_normals.R
Original file line number Diff line number Diff line change
@@ -1,9 +1,33 @@
#helper function to get the unmatched normals from the main config
#' @title Get unmatched normals.
#'
#' @description Helper function to get the unmatched normals from the main
#' config.
#'
#' @param seq_type_filter Seq type key from config for which to return the
#' unmatched normals for.
#'
#' @return data frame
#'
#' @import dplyr tidyr tibble
#' @export
get_unmatched_normals = function(seq_type_filter){
a = check_config_value(config::get("unmatched_normal_ids"))
df = melt(a,value.name="normal_sample_id") %>%
rename(c("genome_build"="L3","seq_type"="L2","unix_group"="L1")) %>%
dplyr::filter(seq_type == seq_type_filter)
return(df)
a <- check_config_value(config::get("unmatched_normal_ids"))
df <- a %>%
as.data.frame(
check.names = FALSE
) %>%
t %>%
as.data.frame() %>%
tibble::rownames_to_column("rownames") %>%
tidyr::separate(
rownames,
into = c("unix_group", "seq_type", "genome_build"),
sep = "\\."
) %>%
dplyr::select(
"normal_sample_id" = "V1",
genome_build, seq_type, unix_group
) %>%
dplyr::filter(seq_type == seq_type_filter)
return(df)
}
9 changes: 8 additions & 1 deletion R/grob_wildcards.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
#Helper functions not for export
#' @title Glob wildcards.
#'
#' @description Helper function to extract wildcard values from a string.
#'
#' @param wildcarded_string String containing wildcards inside the {} notations.
#'
#' @return vector
#'
#' @export
grob_wildcards = function(wildcarded_string){
wildcards = unlist(stringr::str_extract_all(wildcarded_string,"\\{[^\\{]+\\}"))
Expand Down
2 changes: 0 additions & 2 deletions R/handle_metadata.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
#'
#' @import GAMBLR.data dplyr
#'
#' @noRd
#'
#' @export
handle_metadata = function(this_seq_type = "genome") {
if ("GAMBLR.data" %in% installed.packages()) {
Expand Down
Loading

0 comments on commit 9bcc4fe

Please sign in to comment.