Last active
March 22, 2018 12:20
-
-
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)
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
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