From ca297a4166189b6575baa983b4d1f5cd273a7e0c Mon Sep 17 00:00:00 2001 From: zitoa Date: Thu, 24 Oct 2024 11:40:01 +0200 Subject: [PATCH 1/3] Retrieve chr map for mouse genes --- R/pgx-annot.R | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/R/pgx-annot.R b/R/pgx-annot.R index 92d0f84d..db73b40c 100644 --- a/R/pgx-annot.R +++ b/R/pgx-annot.R @@ -233,6 +233,10 @@ getGeneAnnotation.ANNOTHUB <- function( cols <- c("SYMBOL", "GENENAME", "GENETYPE", "MAP") cols <- intersect(cols, AnnotationDbi::keytypes(orgdb)) + if(organism == "Mus musculus") { + cols <- c(cols, "ENTREZID") + } + cat("get gene annotation columns:", cols, "\n") message("retrieving annotation for ", length(probes), " ", probe_type, " features...") @@ -245,6 +249,22 @@ getGeneAnnotation.ANNOTHUB <- function( ) )) + ## Attempt to retrieve chr map via org.Mm.egCHRLOC + if(organism == "Mus musculus") { + library(org.Mm.eg.db) + chrloc <- org.Mm.egCHRLOC + mapped_genes <- as.list(chrloc[mappedkeys(chrloc)]) + cm <- intersect(as.character(annot$ENTREZID), names(mapped_genes)) + mapped_genes <- mapped_genes[cm] + locs <- unlist(lapply(mapped_genes, function(x) names(x[1]))) + jj <- match(names(locs), annot$ENTREZID) + annot$MAP <- NA + annot$MAP[jj] <- unname(locs) + cls <- colnames(annot) + cls <- cls[which(!cls %in% "ENTREZID")] + annot <- annot[, cls, drop = FALSE] + } + # some organisms do not provide symbol but rather gene name (e.g. yeast) if (!"SYMBOL" %in% colnames(annot)) { annot$SYMBOL <- annot$GENENAME From f0e10a654d66e74051aa65d1c2be6698b801cf55 Mon Sep 17 00:00:00 2001 From: Ivo Kwee Date: Thu, 24 Oct 2024 22:24:18 +0200 Subject: [PATCH 2/3] add alternative --- R/pgx-annot.R | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/R/pgx-annot.R b/R/pgx-annot.R index db73b40c..2988a314 100644 --- a/R/pgx-annot.R +++ b/R/pgx-annot.R @@ -234,7 +234,7 @@ getGeneAnnotation.ANNOTHUB <- function( cols <- intersect(cols, AnnotationDbi::keytypes(orgdb)) if(organism == "Mus musculus") { - cols <- c(cols, "ENTREZID") + cols <- unique(c(cols, "ENTREZID")) } cat("get gene annotation columns:", cols, "\n") @@ -253,6 +253,7 @@ getGeneAnnotation.ANNOTHUB <- function( if(organism == "Mus musculus") { library(org.Mm.eg.db) chrloc <- org.Mm.egCHRLOC + mapped_genes <- as.list(chrloc[mappedkeys(chrloc)]) cm <- intersect(as.character(annot$ENTREZID), names(mapped_genes)) mapped_genes <- mapped_genes[cm] @@ -260,8 +261,11 @@ getGeneAnnotation.ANNOTHUB <- function( jj <- match(names(locs), annot$ENTREZID) annot$MAP <- NA annot$MAP[jj] <- unname(locs) - cls <- colnames(annot) - cls <- cls[which(!cls %in% "ENTREZID")] + ## chr <- mget( probes, envir=org.Mm.egCHRLOC, ifnotfound=NA ) + ## chr <- unlist(sapply(chr, function(x) names(x)[1])) + ## jj <- match(annot$ENTREZID, names(chr)) + ## annot$MAP <- chr[jj] + cls <- setdiff(colnames(annot), "ENTREZID") annot <- annot[, cls, drop = FALSE] } From 2a135f84fb9f4da967c079e2642ef4c2aff39c69 Mon Sep 17 00:00:00 2001 From: zitoa Date: Fri, 25 Oct 2024 09:48:59 +0200 Subject: [PATCH 3/3] Added chr map data for Rattus norvegicus --- R/pgx-annot.R | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/R/pgx-annot.R b/R/pgx-annot.R index 2988a314..79cb7c89 100644 --- a/R/pgx-annot.R +++ b/R/pgx-annot.R @@ -233,7 +233,7 @@ getGeneAnnotation.ANNOTHUB <- function( cols <- c("SYMBOL", "GENENAME", "GENETYPE", "MAP") cols <- intersect(cols, AnnotationDbi::keytypes(orgdb)) - if(organism == "Mus musculus") { + if (organism %in% c("Mus musculus", "Rattus norvegicus")) { cols <- unique(c(cols, "ENTREZID")) } @@ -249,11 +249,16 @@ getGeneAnnotation.ANNOTHUB <- function( ) )) - ## Attempt to retrieve chr map via org.Mm.egCHRLOC - if(organism == "Mus musculus") { - library(org.Mm.eg.db) - chrloc <- org.Mm.egCHRLOC - + ## Attempt to retrieve chr map via org.Mm.egCHRLOC / org.Rn.egCHRLOC. + if (organism %in% c("Mus musculus", "Rattus norvegicus")) { + if (organism == "Mus musculus") { + library(org.Mm.eg.db) + chrloc <- org.Mm.egCHRLOC + } + if (organism == "Rattus norvegicus") { + library(org.Rn.eg.db) + chrloc <- org.Rn.egCHRLOC + } mapped_genes <- as.list(chrloc[mappedkeys(chrloc)]) cm <- intersect(as.character(annot$ENTREZID), names(mapped_genes)) mapped_genes <- mapped_genes[cm] @@ -261,10 +266,6 @@ getGeneAnnotation.ANNOTHUB <- function( jj <- match(names(locs), annot$ENTREZID) annot$MAP <- NA annot$MAP[jj] <- unname(locs) - ## chr <- mget( probes, envir=org.Mm.egCHRLOC, ifnotfound=NA ) - ## chr <- unlist(sapply(chr, function(x) names(x)[1])) - ## jj <- match(annot$ENTREZID, names(chr)) - ## annot$MAP <- chr[jj] cls <- setdiff(colnames(annot), "ENTREZID") annot <- annot[, cls, drop = FALSE] }