Skip to content

Commit

Permalink
improving documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
elena-buscaroli committed Jun 19, 2024
1 parent 7521742 commit f66387c
Show file tree
Hide file tree
Showing 17 changed files with 350 additions and 16 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
^pkgdown$
^codecov\.yml$
^\.github$
^vignettes/articles$
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Version: 0.1.0
Author: Azad Sadr
Maintainer: Azad Sadr <[email protected]>
Authors@R: c(
person("Elena", "Buscaroli", role=c("aut", "cre"), email="[email protected]"),
person("Azad", "Sadr", role=c("aut", "cre"), email="[email protected]"),
person("Giulio", "Caravagna", role=c("aut"), email="[email protected]")
)
Expand Down
5 changes: 5 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,21 @@ S3method(print,basilica_obj)
export(configure_environment)
export(fit)
export(fit_clustering)
export(get_denovo_signames)
export(get_fixed_signames)
export(get_input)
export(get_signames)
export(have_loaded_env)
export(have_python_deps)
export(load_conda_env)
export(merge_clusters)
export(plot_data)
export(plot_exposures)
export(plot_scores)
export(plot_signatures)
export(plot_similarity_reference)
export(print.basilica_obj)
export(refine_denovo_signatures)
export(which_conda_env)
import(ggplot2)
importFrom(cli,cli_abort)
Expand Down
22 changes: 22 additions & 0 deletions R/getters.R
Original file line number Diff line number Diff line change
@@ -1,17 +1,39 @@
# Signatures #####
## names ####

#' Get signatures names
#'
#' @param x basilica object.
#' @param types List of variant types to retrieve signames for.
#'
#' @return list of signature names with names equal to `types`.
#' @export
get_signames = function(x, types=get_types(x)) {
lapply(types, function(t)
get_signatures(x, types=t, matrix=TRUE)[[t]] %>% rownames()) %>%
setNames(types)
}

#' Get reference signatures names
#'
#' @param x basilica object.
#' @param types List of variant types to retrieve signames for.
#'
#' @return list of reference signature names with names equal to `types`.
#' @export
get_fixed_signames = function(x, types=get_types(x)) {
lapply(types, function(t)
get_fixed_signatures(x, types=t, matrix=TRUE)[[t]] %>% rownames()) %>%
setNames(types)
}

#' Get denovo signatures names
#'
#' @param x basilica object.
#' @param types List of variant types to retrieve signames for.
#'
#' @return list of de novo signature names with names equal to `types`.
#' @export
get_denovo_signames = function(x, types=get_types(x)) {
lapply(types, function(t)
get_denovo_signatures(x, types=t, matrix=TRUE)[[t]] %>% rownames()) %>%
Expand Down
24 changes: 19 additions & 5 deletions R/plot_QC.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,30 @@ plot_gradient_norms = function(x, types=get_types(x)) {



plot_scores = function(x, types=get_types(x)) {
#' Plot model selection scores
#'
#' @description
#' Function to plot the model selection scores for NMF on each variant type and clustering.
#' Reported scores are BIC and negative log-likelihood.
#'
#' @param x basilica object.
#' @param types List of variant types to visualize.
#' @param remove_outliers Logical. If `TRUE`, outliers in each score will be removed.
#'
#' @return ggplot2 object.
#' @export
plot_scores = function(x, types=get_types(x), remove_outliers=FALSE) {
scores = get_scores(x) %>%
dplyr::group_by(score_id, parname, type) %>%
dplyr::mutate(is.min=score==min(score),
label=replace(is.min, is.min==T, "Best fit"),
label=replace(label, label==F | score_id=="likelihood", NA)) %>%
label=replace(label, label==F | score_id=="likelihood", NA))

dplyr::group_by(score_id, parname, type) %>%
dplyr::mutate(is.outlier=score %in% boxplot.stats(score)$out) %>%
dplyr::filter(!is.outlier)
if (remove_outliers)
scores = scores %>%
dplyr::group_by(score_id, parname, type) %>%
dplyr::mutate(is.outlier=score %in% boxplot.stats(score)$out) %>%
dplyr::filter(!is.outlier)

scores_nmf = scores %>%
dplyr::filter(parname == "K") %>%
Expand Down
14 changes: 14 additions & 0 deletions R/utils_refine.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
#' De novo signatures refinement.
#'
#' @description
#' Function to refine the inferred de novo signatures.
#' The function performs a linear combination between de novo and reference
#' signatures. If a de novo signature can be explained as a linear combination
#' of one or more reference signatures, it will be removed and its exposures
#' will be distributed among the similar signatures.
#'
#' @param x basilica object.
#' @param types List of variant types to perform de novo refinement on.
#'
#' @return basilica object.
#' @export
refine_denovo_signatures = function(x, types=get_types(x)) {

alternatives = get_alternatives(x) %>% dplyr::filter(type %in% types)
Expand Down
5 changes: 5 additions & 0 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,15 @@ reference:
contents:
- fit
- fit_clustering
- refine_denovo_signatures

- title: Getters
desc: Utility functions to extract attributes.
contents:
- get_input
- get_signames
- get_fixed_signames
- get_denovo_signames

- title: Plotting functions
desc: Plotting functions available in the package
Expand All @@ -27,6 +31,7 @@ reference:
- merge_clusters
- plot_fit
- plot_similarity_reference
- plot_scores

- title: S3 objects
desc: Print and plot S3 functions
Expand Down
19 changes: 19 additions & 0 deletions man/get_denovo_signames.Rd

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

19 changes: 19 additions & 0 deletions man/get_fixed_signames.Rd

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

19 changes: 19 additions & 0 deletions man/get_signames.Rd

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

16 changes: 5 additions & 11 deletions man/plot_exposures.Rd

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

22 changes: 22 additions & 0 deletions man/plot_scores.Rd

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

23 changes: 23 additions & 0 deletions man/refine_denovo_signatures.Rd

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

33 changes: 33 additions & 0 deletions nobuild/test_basilica.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ devtools::load_all("~/GitHub/simbasilica/")
load_deps()
devtools::load_all("~/GitHub/basilica/")


## SIMULATED ####
counts = get_input(example_dataset, matrix=T)
reference_cat = list("SBS"=COSMIC_sbs_filt, "DBS"=COSMIC_dbs)
max_K = sapply(get_signames(example_dataset), length) %>% max()
Expand All @@ -17,3 +19,34 @@ x_refined_cluster %>% merge_clusters() %>% plot_exposures()
example_dataset %>% plot_signatures()
x_refined_cluster %>% merge_clusters() %>% plot_signatures()






## REAL ####
x = readRDS("~/Google Drive/My Drive/work/basilica_shared/fit_27052024/fit_wcat.Breast.Rds")
for (tid in get_types(x)) {
alt_t = x$nmf[[tid]]$pyro$alternatives

x$nmf[[tid]]$pyro$alternatives = alt_t %>%
dplyr::rowwise() %>%
dplyr::mutate(seed=pyro_fit[[1]]$seed,
pyro_fit=list(pyro_fit[[1]])) %>%
dplyr::ungroup()
}

x$clustering$pyro$alternatives = x$clustering$pyro$alternatives %>%
dplyr::rowwise() %>%
dplyr::mutate(seed=pyro_fit[[1]]$pyro$seed,
pyro_fit=list(pyro_fit[[1]])) %>%
dplyr::ungroup()

x_refined = refine_denovo_signatures(x, types="SBS")

saveRDS(x_refined, "~/Desktop/fit_wcat.Breast_refined.Rds")

x %>% plot_signatures()

cls_list = x %>% plot_cluster_scores()
x %>% plot_cls_score_heatmap()
2 changes: 2 additions & 0 deletions vignettes/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.html
*.R
Loading

0 comments on commit f66387c

Please sign in to comment.