Last active
March 22, 2018 12:23
-
-
Save lwaldron/dc9988692b5f9bd6bdb5fc22ff26e8f9 to your computer and use it in GitHub Desktop.
Create a big SummarizedExperiment from curatedMetagenomicData (including phylogenetic tree)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## A big SE | |
library(curatedMetagenomicData) | |
library(SummarizedExperiment) | |
library(tidyr) | |
library(ape) | |
simplifynodes <- TRUE | |
makeTaxTable <- function(fullnames){ | |
taxonomic.ranks <- c("Kingdom", "Phylum", "Class", "Order", | |
"Family", "Genus", "Species", "Strain") | |
fullnames %>% | |
gsub("[a-z]__", "", .) %>% | |
data_frame() %>% | |
separate(., ".", taxonomic.ranks, | |
sep = "\\|", fill = "right") %>% | |
as.matrix() | |
} | |
esl = curatedMetagenomicData("*metaphlan*", counts=TRUE, dryrun = FALSE) | |
eset = mergeData(esl) | |
tax.table <- makeTaxTable(rownames(eset)) | |
if(simplifynodes){ | |
rownames(eset) <- gsub(".+\\|", "", rownames(eset)) | |
} | |
phy.tree <- getMetaphlanTree(simplify = simplifynodes) | |
bigSE <- SummarizedExperiment(assays = list(counts = exprs(eset)), | |
colData = pData(eset), | |
rowData = tax.table, | |
metadata=list(phylo=phy.tree)) | |
summary(metadata(bigSE)$phylo$tip.label %in% rownames(bigSE)) | |
summary(rownames(bigSE) %in% metadata(bigSE)$phylo$tip.label) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment