Skip to content

Instantly share code, notes, and snippets.

@lwaldron
Last active March 22, 2018 12:20
Show Gist options
  • Save lwaldron/df1053ea409ef03da18f48afeca4048c to your computer and use it in GitHub Desktop.
Save lwaldron/df1053ea409ef03da18f48afeca4048c to your computer and use it in GitHub Desktop.
Create a small SummarizedExperiment from one dataset in curatedMetagenomicData (including ape phylogenetic tree)
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()
}
eset = curatedMetagenomicData("AsnicarF_2017.metaphlan_bugs_list.milk",
dryrun = FALSE,
counts = TRUE)[[1]]
tax.table <- makeTaxTable(rownames(eset))
if(simplifynodes){
rownames(eset) <- gsub(".+\\|", "", rownames(eset))
}
smallSE = SummarizedExperiment(assays = list(counts=exprs(eset)),
colData=pData(eset),
rowData=tax.table,
metadata=list(phylo=getMetaphlanTree(simplify=simplifynodes)))
summary(metadata(smallSE)$phylo$tip.label %in% rownames(smallSE))
summary(rownames(smallSE) %in% metadata(smallSE)$phylo$tip.label)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment