Skip to content

Commit

Permalink
Merge pull request #78 from umccr/devtools_fixes
Browse files Browse the repository at this point in the history
Pass devtools checks
  • Loading branch information
pdiakumis authored May 7, 2024
2 parents 14c1f5e + 327f170 commit c1cda25
Show file tree
Hide file tree
Showing 20 changed files with 311 additions and 228 deletions.
3 changes: 1 addition & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ Suggests:
scales,
sigrap,
testthat (>= 3.0.0),
tibble,
tidyselect,
tibble
Roxygen: list(markdown = TRUE,
roclets = c("namespace", "rd", "roxytest::testthat_roclet"))
biocViews:
Expand Down
19 changes: 16 additions & 3 deletions R/oncokb.R
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
#' Read OncoKB
#'
#' @param x Path to something.
#'
#' @return Vector of genes.
#' @export
read_oncokb <- function(x) {
readr::read_tsv(x) |>
dplyr::filter(
`OncoKB Annotated` == "Yes"
.data$`OncoKB Annotated` == "Yes"
) |>
dplyr::pull("Hugo Symbol")
}

#' Get OncoKB Genes From Somewhere
#'
#' @param x Path to something.
#' @param oncokb_genes A tibble of something.
#' @return A vector I think.
#'
#' @export
get_oncokb_genes <- function(x, oncokb_genes) {
delimiters <- " ,&-"
Expand All @@ -16,9 +27,11 @@ get_oncokb_genes <- function(x, oncokb_genes) {
# Create regexes for each match, utilising delimiters for boundaries. Handles most cases where a gene symbol contains the '-' delimiter
purrr::map(function(n) paste0("(?<=^|", delimiter_re, ")", n, "(?=", delimiter_re, "|$)")) |>
# Loop with nm iterations through regex and gene symbols
purrr::map(function(n) stringr::str_detect(x, n) |> tibble::as_tibble_row(.name_repair="unique_quiet")) |>
purrr::map(function(n) stringr::str_detect(x, n) |> tibble::as_tibble_row(.name_repair = "unique_quiet")) |>
# Combine as tibble to access dplyr::summarise and compile list of detected OncoKB gene symbols for each effect
dplyr::bind_rows() |>
dplyr::summarise(dplyr::across(dplyr::everything(), function(v) { paste0(sort(oncokb_genes[v]), collapse=", ") })) |>
dplyr::summarise(dplyr::across(dplyr::everything(), function(v) {
paste0(sort(oncokb_genes[v]), collapse = ", ")
})) |>
unlist()
}
45 changes: 21 additions & 24 deletions R/oncoviral.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@
#' x <- system.file("extdata/virusbreakend/virusbreakend.vcf.summary.tsv", package = "gpgr")
#' (vb <- virusbreakend_summary_read(x))
#' @testexamples
#' expect_equal(colnames(vb)[ncol(vb)], "QCStatus")
#' expect_equal(colnames(vb$tab)[ncol(vb$tab)], "QC")
#'
#' @export
virusbreakend_summary_read <- function(x) {

nm <- c(
"taxid_genus" = "c",
"name_genus" = "c",
Expand Down Expand Up @@ -44,7 +43,6 @@ virusbreakend_summary_read <- function(x) {
"integrations" = "i",
"QCStatus" = "c"
)

ctypes <- paste(nm, collapse = "")
virusbreakend_summary <- readr::read_tsv(x, col_types = ctypes)

Expand All @@ -54,13 +52,13 @@ virusbreakend_summary_read <- function(x) {

virusbreakend_summary <- virusbreakend_summary |>
dplyr::select(
Virus="name_assigned",
Length="endpos",
Reads="numreads",
Coverage="coverage",
`Mean depth`="meandepth",
Intergrations="integrations",
QC="QCStatus",
Virus = "name_assigned",
Length = "endpos",
Reads = "numreads",
Coverage = "coverage",
`Mean depth` = "meandepth",
Intergrations = "integrations",
QC = "QCStatus",
)
}

Expand All @@ -71,7 +69,7 @@ virusbreakend_summary_read <- function(x) {
"Reads", "Number of reads mapped to adjusted viral reference",
"Coverage", "Percentage of viral positions with at least one read mapped",
"Mean depth", "Mean alignment depth",
"Intergrations", "Number of detected integration breakpoints",
"Integrations", "Number of detected integration breakpoints",
"QC", "QC status of viral intergrations",
)

Expand All @@ -95,29 +93,28 @@ virusbreakend_summary_read <- function(x) {
#' x <- system.file("extdata/virusbreakend/virusbreakend.vcf", package = "gpgr")
#' (vb <- virusbreakend_vcf_read(x))
#' @testexamples
#' expect_equal(colnames(vb)[ncol(vb)], "QC")
#' expect_equal(colnames(vb$tab)[ncol(vb$tab)], "QC")
#'
#' @export
virusbreakend_vcf_read <- function(x) {

d <- bedr::read.vcf(x, split.info = TRUE, verbose = FALSE)

if (nrow(d$vcf) > 0) {
virusbreakend_integrations <- tibble::as_tibble(d$vcf) |>
dplyr::select(
Contig="CHROM",
Position="POS",
"Fragment support"="BVF",
"Fragment support (unmapped)"="BUM",
"Softclip read support"="BSC",
Reference="REF",
Alt="ALT",
`Breakend ID`="ID",
`Mate ID`="MATEID",
QC="FILTER",
Contig = "CHROM",
Position = "POS",
"Fragment support" = "BVF",
"Fragment support (unmapped)" = "BUM",
"Softclip read support" = "BSC",
Reference = "REF",
Alt = "ALT",
`Breakend ID` = "ID",
`Mate ID` = "MATEID",
QC = "FILTER",
)
} else {
virusbreakend_integrations <- tibble::tibble()
virusbreakend_integrations <- tibble::tibble()
}

descr <- dplyr::tribble(
Expand Down
Loading

0 comments on commit c1cda25

Please sign in to comment.