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

Drop unnecessary dependencies #38

Merged
merged 4 commits into from
Dec 4, 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
5 changes: 1 addition & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,9 @@ Imports:
GAMBLR.data,
ggplot2,
ggthemes,
philentropy,
readr,
stringr,
tibble,
tidyr,
workflowr
tidyr
Remotes:
morinlab/GAMBLR.data
Encoding: UTF-8
Expand Down
20 changes: 1 addition & 19 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export(get_template_wildcards)
export(get_unmatched_normals)
export(grob_wildcards)
export(handle_metadata)
export(kl_divergence)
export(maf_header)
export(normalize_expression_data)
export(rainfall_conv)
Expand All @@ -30,29 +31,10 @@ export(subset_cnstates)
export(theme_Morons)
export(trim_scale_expression)
export(vc_nonSynonymous)
export(web_initialize_gambl_site)
import(GAMBLR.data)
import(dplyr)
import(ggplot2)
import(readr)
import(stringr)
import(tibble)
import(tidyr)
import(workflowr)
importFrom(dplyr,left_join)
importFrom(ggthemes,theme_foundation)
importFrom(philentropy,KL)
importFrom(stats,end)
importFrom(stats,quantile)
importFrom(stats,start)
importFrom(stringr,str_c)
importFrom(stringr,str_extract)
importFrom(stringr,str_remove)
importFrom(stringr,str_remove_all)
importFrom(tidyr,unnest_auto)
importFrom(utils,head)
importFrom(utils,read.csv)
importFrom(utils,read.socket)
importFrom(utils,tail)
importFrom(utils,write.socket)
importFrom(utils,write.table)
22 changes: 0 additions & 22 deletions R/GAMBLR.helpers-package.R

This file was deleted.

13 changes: 10 additions & 3 deletions R/compare_coding_mutation_pattern.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#'
#' @return list
#'
#' @import dplyr
#' @export
compare_coding_mutation_pattern = function(maf_df1,maf_df2,gene){
if(missing(maf_df1) | missing(maf_df2)){
Expand All @@ -17,9 +18,9 @@ compare_coding_mutation_pattern = function(maf_df1,maf_df2,gene){
stop("Must provide the Hugo_Symbol of a single gene that is present in both maf files")
}
missense_positions1 = dplyr::filter(maf_df1,Hugo_Symbol==gene,!Variant_Classification %in% c("Silent","Splice_Site","Splice_Region"),Variant_Type=="SNP") %>%
pull(HGVSp_Short) %>% str_remove_all("p.\\w") %>% str_extract("\\d+") %>% as.numeric()
pull(HGVSp_Short) %>% gsub("p\\.\\w", "", .) %>% regmatches(., regexpr("\\d+", .)) %>% as.numeric()
missense_positions2 = dplyr::filter(maf_df2,Hugo_Symbol==gene,!Variant_Classification %in% c("Silent","Splice_Site","Splice_Region"),Variant_Type=="SNP") %>%
pull(HGVSp_Short) %>% str_remove_all("p.\\w") %>% str_extract("\\d+") %>% as.numeric()
pull(HGVSp_Short) %>% gsub("p\\.\\w", "", .) %>% regmatches(., regexpr("\\d+", .)) %>% as.numeric()
if(length(missense_positions1)==0 | length(missense_positions2)==0 ){
message(paste("no mutations for",gene,"in one or both data sets"))
return(list(kl=15))
Expand All @@ -35,6 +36,12 @@ compare_coding_mutation_pattern = function(maf_df1,maf_df2,gene){
all_counts = dplyr::select(full_df,-position) %>% t()
all_counts[1,]=all_counts[1,]/sum(all_counts[1,])
all_counts[2,]=all_counts[2,]/sum(all_counts[2,])
kl_out = KL(all_counts)

# Normalize the rows to turn counts into probabilities
P <- all_counts[1, ] / sum(all_counts[1, ])
Q <- all_counts[2, ] / sum(all_counts[2, ])

kl_out <- kl_divergence(P, Q)

return(list(df=full_df,kl=unname(kl_out)))
}
1 change: 1 addition & 0 deletions R/gene_mutation_tally.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#'
#' @return data frame
#'
#' @import dplyr
#' @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
4 changes: 2 additions & 2 deletions R/get_gambl_colours.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#'
#' @return A named vector of colour codes for lymphgen classes and pathology.
#'
#' @import dplyr stringr tidyr
#' @import dplyr tidyr
#' @export
#'
#' @examples
Expand Down Expand Up @@ -318,7 +318,7 @@ get_gambl_colours = function(classification = "all",
everything = c(everything, all_colours[[this_group]])
}
#return matching value from lowercase version of the argument if it exists
lc_class = stringr::str_to_lower(classification)
lc_class = tolower(classification)
if(return_available){
return(names(all_colours))
}
Expand Down
2 changes: 1 addition & 1 deletion R/get_template_wildcards.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ get_template_wildcards = function(parent_key,
}else{
wildcard_string = config::get(paste0(parent_key,"_wildcards"))[template_key]
}
wildcards = stringr::str_split(wildcard_string,",")
wildcards = strsplit(wildcard_string,",")
return(unlist(wildcards))
}
4 changes: 2 additions & 2 deletions R/grob_wildcards.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#'
#' @export
grob_wildcards = function(wildcarded_string){
wildcards = unlist(stringr::str_extract_all(wildcarded_string,"\\{[^\\{]+\\}"))
wildcards = stringr::str_remove_all(wildcards,"\\{") %>% stringr::str_remove_all(.,"\\}")
wildcards = unlist(regmatches(wildcarded_string, gregexpr("\\{[^\\{]+\\}", wildcarded_string)))
wildcards = gsub("\\{", "", wildcards) %>% gsub("\\}", "", .)
return(wildcards)
}
36 changes: 36 additions & 0 deletions R/kl_divergence.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#' Calculate Kullback-Leibler Divergence
#'
#' This function computes the Kullback-Leibler (KL) divergence between two
#' probability distributions, with an optional small constant (epsilon)
#' added to avoid zero probabilities, which would otherwise cause division
#' by zero or undefined logarithms.
#'
#' @param P A numeric vector representing the first probability distribution.
#' The sum of "P" should be 1, but the function will normalize it if
#' necessary.
#' @param Q A numeric vector representing the second probability distribution.
#' The sum of "Q" should be 1, but the function will normalize it if
#' necessary.
#' @param epsilon A small positive number (default = 1e-7) to be added to each
#' probability in P and Q to avoid zero probabilities. This helps to
#' prevent division by zero or log(0).
#'
#' @return float
#'
#' @examples
#' P <- c(0.1, 0.4, 0.3, 0.2)
#' Q <- c(0.2, 0.3, 0.4, 0.1)
#'
#' kl_divergence(P, Q)
#'
#' @export
kl_divergence <- function(P, Q, epsilon = 1e-7) {
P <- P + epsilon
Q <- Q + epsilon

P <- P / sum(P)
Q <- Q / sum(Q)

# KL divergence formula: sum(P * log(P / Q))
return(sum(P * log(P / Q), na.rm = TRUE))
}
2 changes: 1 addition & 1 deletion R/sanity_check_metadata.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#'
#' @return A table.
#'
#' @import tibble readr dplyr
#' @import tibble readr dplyr tidyr
#'
#'
#' @examples
Expand Down
22 changes: 0 additions & 22 deletions R/web_initialize_gambl_site.R

This file was deleted.

15 changes: 0 additions & 15 deletions man/GAMBLR.helpers-package.Rd

This file was deleted.

37 changes: 37 additions & 0 deletions man/kl_divergence.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 0 additions & 25 deletions man/web_initialize_gambl_site.Rd

This file was deleted.

Loading