Skip to content

Instantly share code, notes, and snippets.

@lwaldron
Last active March 22, 2018 12:23
Show Gist options
  • Save lwaldron/dc9988692b5f9bd6bdb5fc22ff26e8f9 to your computer and use it in GitHub Desktop.
Save lwaldron/dc9988692b5f9bd6bdb5fc22ff26e8f9 to your computer and use it in GitHub Desktop.
Create a big SummarizedExperiment from curatedMetagenomicData (including phylogenetic tree)
## 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