Skip to content

Commit

Permalink
Merge pull request #77 from bigomics/fix-ensembl-dotversion
Browse files Browse the repository at this point in the history
Fix ensembl dotversion
  • Loading branch information
ivokwee authored Dec 22, 2023
2 parents 5ba90ab + cab576e commit 8780482
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,11 @@ export(ngs.fitContrastsWithAllMethods)
export(ngs.fitContrastsWithEDGER)
export(ngs.fitContrastsWithLIMMA)
export(ngs.fitContrastsWithTTEST)
export(ngs.getGeneAnnot)
export(ngs.getGeneAnnotation)
export(ngs.getGeneAnnotation_DEPRECATED)
export(ngs.save)
export(ngs.tximportSalmon)
export(nmfImpute)
export(normalizeCounts)
export(normalizeRLE)
Expand Down
1 change: 0 additions & 1 deletion R/pgx-compute.R
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ pgx.createPGX <- function(counts,
message("[createPGX] input: dim(samples) = ", paste(dim(samples), collapse = "x"))
message("[createPGX] input: dim(contrasts) = ", paste(dim(contrasts), collapse = "x"))


## convert old-style contrast matrix to sample-wise labeled contrasts
contrasts <- playbase::contrasts.convertToLabelMatrix(contrasts, samples)

Expand Down
31 changes: 24 additions & 7 deletions R/pgx-ensembl.R
Original file line number Diff line number Diff line change
Expand Up @@ -446,22 +446,27 @@ pgx.gene_table <- function(pgx, organism) {
#' @export
detect_probe_DEPRECATED <- function(probes, organism) {
# Get org database
if (organism == "Human") {
if (tolower(organism) == "human") {
org_db <- org.Hs.eg.db::org.Hs.eg.db
} else if (organism == "Mouse") {
} else if (tolower(organism) == "mouse") {
org_db <- org.Mm.eg.db::org.Mm.eg.db
} else if (organism == "Rat") {
} else if (tolower(organism) == "rat") {
org_db <- org.Rn.eg.db::org.Rn.eg.db
}

# Probe types
keytypes <- c(
"ENSEMBL", "ENSEMBLTRANS", "SYMBOL",
"REFSEQ", "UNIPROT", "ACCNUM"
"ENSEMBL", "ENSEMBLTRANS", "SYMBOL", "REFSEQ", "UNIPROT", "ACCNUM"
)
key_matches <- vector("character", length(keytypes))
## key_matches <- vector("character", length(keytypes))
key_matches <- rep( 0L, length(keytypes))
names(key_matches) <- keytypes

## discard version numbers if ENSEMBL
if(mean(grepl("^ENS",probes)) > 0.8) {
probes <- sub("[.][0-9]+", "", probes)
}

# Subset probes if too many
if (length(probes) > 100) {
probes <- probes[as.integer(seq(1, length(probes), 100))]
Expand Down Expand Up @@ -516,7 +521,8 @@ detect_probe_DEPRECATED <- function(probes, organism) {
#' }
#' @export
ngs.getGeneAnnotation_DEPRECATED <- function(probes, probe_type, organism) {
# Get org database and columns request

# Get org database and columns request
if (organism == "Human") {
org_db <- org.Hs.eg.db::org.Hs.eg.db
cols_req <- c("SYMBOL", "GENENAME", "CHR", "CHRLOC", "MAP", "GENETYPE")
Expand All @@ -528,6 +534,12 @@ ngs.getGeneAnnotation_DEPRECATED <- function(probes, probe_type, organism) {
cols_req <- c("SYMBOL", "GENENAME", "CHR", "CHRLOC", "GENETYPE")
}

## discard version numbers if ENSEMBL
orig.probes <- probes
if(mean(grepl("^ENS",probes)) > 0.8) {
probes <- sub("[.][0-9]+", "", probes)
}

# Call for annotation table
suppressWarnings(d <- AnnotationDbi::select(org_db,
keys = probes,
Expand All @@ -544,6 +556,11 @@ ngs.getGeneAnnotation_DEPRECATED <- function(probes, probe_type, organism) {
d$MAP <- d$CHR
}

## if ENSEMBL get original probe names with version
if(probe_type == "ENSEMBL") {
d$ENSEMBL <- orig.probes[match(d$ENSEMBL, probes)]
}

# Rename cols, add extra cols, reorder cols and rows
if (probe_type == "SYMBOL") {
d[, feature := SYMBOL]
Expand Down

0 comments on commit 8780482

Please sign in to comment.