Skip to content

Commit

Permalink
Add get_pLOH_score
Browse files Browse the repository at this point in the history
  • Loading branch information
ShixiangWang committed Aug 25, 2021
1 parent 5083546 commit fc8312b
Show file tree
Hide file tree
Showing 9 changed files with 354 additions and 0 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export(get_genome_annotation)
export(get_group_comparison)
export(get_groups)
export(get_intersect_size)
export(get_pLOH_score)
export(get_shannon_diversity_index)
export(get_sig_cancer_type_index)
export(get_sig_db)
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# sigminer 2.0.5

- Added function `get_pLOH_score()` for representing the genome that displayed LOH.
- Added function `read_copynumber_ascat()` for reading ASCAT result ASCAT object in `.rds` format.
- Added function `get_intersect_size()` for getting overlap size between intervals.
- Added option to `get_Aneuploidy_score()` to remove short arms of chr13/14/15/21/22 from calculation.
Expand Down
61 changes: 61 additions & 0 deletions R/get_pLOH_score.R
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"]
}


1 change: 1 addition & 0 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ reference:
- transform_seg_table
- get_cn_ploidy
- get_Aneuploidy_score
- get_pLOH_score
- scoring
- show_cn_profile
- show_cn_circos
Expand Down
1 change: 1 addition & 0 deletions docs/news/index.html

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

209 changes: 209 additions & 0 deletions docs/reference/get_pLOH_score.html

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

6 changes: 6 additions & 0 deletions docs/reference/index.html

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

46 changes: 46 additions & 0 deletions man/get_pLOH_score.Rd

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

28 changes: 28 additions & 0 deletions tests/testthat/test-roxytest-testexamples-get_pLOH_score.R
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)
})

0 comments on commit fc8312b

Please sign in to comment.