Skip to content
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ Suggests:
impute,
knitr,
magrittr,
miRNAmeConverter,
org.Hs.eg.db,
RColorBrewer,
readr,
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export(trimColData)
export(uniformBuilds)
import(methods)
importFrom(BiocBaseUtils,checkInstalled)
importFrom(BiocBaseUtils,isCharacter)
importFrom(BiocBaseUtils,isScalarCharacter)
importFrom(BiocBaseUtils,isScalarNumber)
importFrom(BiocBaseUtils,lifeCycle)
Expand Down
57 changes: 43 additions & 14 deletions R/simplifyTCGA.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#' @importFrom GenomicFeatures genes
#' @importFrom GenomeInfoDb keepStandardChromosomes seqlevelsStyle
#' seqlevelsStyle<-
#' @importFrom BiocBaseUtils isScalarCharacter
#' @importFrom BiocBaseUtils isScalarCharacter isCharacter
NULL

.checkHas <-
Expand Down Expand Up @@ -30,17 +30,23 @@ NULL

.convertTo <- function(x, which, FUN, keep, unmap) {
for (i in which(which)) {
lookup <- FUN(rownames(x[[i]]))
assay <- x[[i]]
lookup <- FUN(rownames(assay))
ranges <- lookup[["mapped"]]
rse <- x[[i]][names(ranges), ]
rowidx <- mcols(ranges)[["rowIdx"]]
rowidx <- Filter(Negate(is.na), rowidx)
if (!is.null(rowidx) && length(rowidx))
rse <- `rownames<-`(assay[rowidx, ], names(ranges))
else
rse <- assay[names(ranges), ]
# rowData not merged with mcols of RHS in `rowRanges<-` method
mcols(ranges) <-
S4Vectors::DataFrame(rowData(rse), S4Vectors::mcols(ranges))
SummarizedExperiment::rowRanges(rse) <- ranges
x <- c(x, setNames(S4Vectors::List(rse),
paste0(names(x)[i], "_ranged")))
if (length(lookup[["unmapped"]]) && unmap) {
se <- x[[i]][lookup[["unmapped"]], ]
se <- assay[lookup[["unmapped"]], ]
x <- c(x, setNames(S4Vectors::List(se),
paste0(names(x)[i], "_unranged")))
}
Expand All @@ -67,6 +73,25 @@ NULL
res
}

#' @name hidden-helpers
#' @keywords internal
.makeMiRNAListRanges <- function(x, gn) {
checkInstalled("miRNAmeConverter")
nc <- miRNAmeConverter::MiRNANameConverter()
mirna_version <-
miRNAmeConverter::assessVersion(nc, names(gn))[1L, "version"]
trout <- miRNAmeConverter::translateMiRNAName(
nc, x, versions = mirna_version
)
new_x <- trout[[paste0("v", mirna_version, ".0")]]
res <- list(unmapped = setdiff(x, trout[["input"]]))
rowIdx <- match(tolower(trout[["input"]]), tolower(x))
gn <- gn[match(new_x, names(gn))]
mcols(gn)[["rowIdx"]] <- rowIdx
res[["mapped"]] <- gn
res
}

.getGN <- function(gen) {
stopifnot(isScalarCharacter(gen))

Expand All @@ -92,9 +117,9 @@ NULL
#' @rdname hidden-helpers
#' @keywords internal
.getRangesOfMir <- function(x) {
stopifnot(isScalarCharacter(x))
stopifnot(isCharacter(x))

mirnas_gr <- .get_hsa_gff3(x)
mirnas_gr <- .get_hsa_gff3("hg19")

miR <- mirnas_gr[
mcols(mirnas_gr)[["type"]] %in% c("miRNA", "microRNA", "tRNA")
Expand All @@ -103,7 +128,7 @@ NULL
seqlevelsStyle(miR) <- "NCBI"

names(miR) <- mcols(miR)[["Name"]]
.makeListRanges(x, miR)
.makeMiRNAListRanges(x, miR)
}

#' @rdname hidden-helpers
Expand Down Expand Up @@ -209,9 +234,7 @@ NULL
#' [`RangedSummarizedExperiment`][SummarizedExperiment::RangedSummarizedExperiment-class]
#' objects
#'
#' @author L. Waldron
#'
#' @md
#' @author L. Waldron, M. Ramos
#'
#' @examples
#'
Expand Down Expand Up @@ -275,10 +298,16 @@ symbolsToRanges <- function(obj, keep.assay = FALSE, unmapped = TRUE) {
#'
#' @export
mirToRanges <- function(obj, keep.assay = FALSE, unmapped = TRUE) {
lifeCycle(
package = "TCGAutils",
cycle = "defunct",
title = "simplifyTCGA"
checkInstalled("Bioc.gff")

can.fix <- .isFixable(mae = obj, pattern = "^hsa")

.convertTo(
x = obj,
which = can.fix,
FUN = .getRangesOfMir,
keep = keep.assay,
unmap = unmapped
)
}

Expand Down
2 changes: 1 addition & 1 deletion R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
gff_lines <- readLines(file, n = 50)
genome_line <- grepv("genome-build-id", gff_lines)
gnm <- strsplit(genome_line, ":\\s+")[[1L]] |>
tail(n = 1L) |>
utils::tail(n = 1L) |>
trimws()
if (!length(gnm))
NA_character_
Expand Down
3 changes: 3 additions & 0 deletions man/hidden-helpers.Rd

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

2 changes: 1 addition & 1 deletion man/simplifyTCGA.Rd

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

Loading