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

Major updates #34

Merged
merged 11 commits into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from 10 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
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
10 changes: 10 additions & 0 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.
#'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should say "nothing" for the return or (better yet) make functions like this one return the "full path to the file that was written"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, added this to this function and other similar functions that were writing files

#' @return file
#'
#' @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 Down
13 changes: 13 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 file
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see earlier comment regarding what to return

#'
#' @export
cache_output = function(result_df,
function_name,
Expand Down
2 changes: 1 addition & 1 deletion R/calculate_tmb.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#' maf1,
#' regions_bed = grch37_ashm_regions
#' )
#' #' calculate_tmb(
#' calculate_tmb(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The title of this function should probably be "calculate tumour mutation burden", to be more intuitive and self-explanatory

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks - Updated the title!

#' 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
10 changes: 10 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.
rdmorin marked this conversation as resolved.
Show resolved Hide resolved
#'
#' @description TODO.
#'
#' @param from_file TODO.
#' @param to_file TODO.
#' @param force TODO.
#'
#' @return file
#'
#' @export
copy_no_clobber = function(from_file,
to_file,
Expand Down
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
Loading