-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5083546
commit fc8312b
Showing
9 changed files
with
354 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#' Get proportions of pLOH score from Allele Specific Copy Number Profile | ||
#' | ||
#' pLOH score represents the genome that displayed LOH. | ||
#' | ||
#' @inheritParams read_copynumber | ||
#' @param data a CopyNumber object or a `data.frame` containing at least | ||
#' 'chromosome', 'start', 'end', 'segVal', 'sample' these columns. | ||
#' @param rm_chrs chromosomes to be removed in calculation. Default is sex | ||
#' chromosomes (recommended). | ||
#' @references | ||
#' Steele, Christopher D., et al. "Signatures of copy number alterations in human cancer." bioRxiv (2021). | ||
#' | ||
#' @return A `data.frame` | ||
#' @export | ||
#' | ||
#' @examples | ||
#' # Load toy dataset of absolute copynumber profile | ||
#' load(system.file("extdata", "toy_segTab.RData", | ||
#' package = "sigminer", mustWork = TRUE | ||
#' )) | ||
#' | ||
#' set.seed(1234) | ||
#' segTabs$minor_cn <- sample(c(0, 1), size = nrow(segTabs), replace = TRUE) | ||
#' cn <- read_copynumber(segTabs, | ||
#' seg_cols = c("chromosome", "start", "end", "segVal"), | ||
#' genome_measure = "wg", complement = TRUE, add_loh = TRUE | ||
#' ) | ||
#' | ||
#' df <- get_pLOH_score(cn) | ||
#' df | ||
#' | ||
#' df2 <- get_pLOH_score(cn@data) | ||
#' df2 | ||
#' | ||
#' @testexamples | ||
#' expect_equal(nrow(df), 10L) | ||
#' expect_equal(nrow(df2), 10L) | ||
get_pLOH_score <- function(data, rm_chrs = c("chrX", "chrY"), genome_build = "hg19") { | ||
stopifnot(is.data.frame(data) | inherits(data, "CopyNumber") | "chrY" %in% rm_chrs) | ||
if (!is.data.frame(data)) { | ||
data <- data@data | ||
} | ||
|
||
nc_cols <- c("chromosome", "start", "end", "segVal", "minor_cn", "sample") | ||
if (!all(nc_cols %in% colnames(data))) { | ||
stop("Invalid input, it must contain columns: ", paste(nc_cols, collapse = " ")) | ||
} | ||
|
||
data <- data.table::as.data.table(data)[!chromosome %in% rm_chrs, nc_cols, with = FALSE] | ||
|
||
# Make sure the minor_cn is really minor copy | ||
data$minor_cn <- pmin(data$segVal - data$minor_cn, data$minor_cn) | ||
|
||
chr_size <- get_genome_annotation(genome_build = genome_build) | ||
chr_size <- chr_size[!chr_size$chrom %in% rm_chrs, ] | ||
chr_size <- sum(chr_size$size) | ||
|
||
data[segVal >= 1 & minor_cn == 0, list(pLOH = sum(end - start + 1L) / chr_size), by = "sample"] | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
28 changes: 28 additions & 0 deletions
28
tests/testthat/test-roxytest-testexamples-get_pLOH_score.R
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Generated by roxytest: Do not edit by hand! | ||
|
||
# File R/get_pLOH_score.R: @testexamples | ||
|
||
test_that("Function get_pLOH_score() @ L38", { | ||
|
||
# Load toy dataset of absolute copynumber profile | ||
load(system.file("extdata", "toy_segTab.RData", | ||
package = "sigminer", mustWork = TRUE | ||
)) | ||
|
||
set.seed(1234) | ||
segTabs$minor_cn <- sample(c(0, 1), size = nrow(segTabs), replace = TRUE) | ||
cn <- read_copynumber(segTabs, | ||
seg_cols = c("chromosome", "start", "end", "segVal"), | ||
genome_measure = "wg", complement = TRUE, add_loh = TRUE | ||
) | ||
|
||
df <- get_pLOH_score(cn) | ||
df | ||
|
||
df2 <- get_pLOH_score(cn@data) | ||
df2 | ||
|
||
expect_equal(nrow(df), 10L) | ||
expect_equal(nrow(df2), 10L) | ||
}) | ||
|