Last active
June 11, 2022 10:45
-
-
Save lwaldron/897c6870c6082cfcf7d1eb3385aff3b2 to your computer and use it in GitHub Desktop.
Comparing assays from two different downloads
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
# installed curatedMetagenomicData from github | |
suppressPackageStartupMessages({ | |
library(curatedMetagenomicData) | |
library(dplyr) | |
}) | |
#I download the data in two ways, one select a few CRC studies and the other will multiple studies available. | |
# specific only crc studies downloaded | |
suppressMessages({ | |
tse1 <- sampleMetadata |> | |
filter(!is.na(age)) |> | |
#filter(!is.na(alcohol)) |> | |
filter(study_name %in% c("WirbelJ_2018", "VogtmannE_2016", "YuJ_2015", "ZellerG_2014", "YachidaS_2019")) |> | |
filter(body_site == "stool") |> | |
select(where(~ !all(is.na(.x)))) |> | |
returnSamples("relative_abundance", rownames = "short") | |
}) | |
tse1 | |
## large data. Multiple studies downloaded at the same time | |
suppressMessages({ | |
tse2 <- sampleMetadata |> | |
filter(!is.na(disease)) |> | |
filter(age >=18) |> | |
filter(non_westernized == "no") |> | |
filter(body_site == "stool") |> | |
select(where(~ !all(is.na(.x)))) |> | |
returnSamples("relative_abundance", rownames = "short") | |
}) | |
tse2 | |
# From the downloaded TSEs, tse1 and tse2, select specific study | |
tse1.sub <- tse1[,colData(tse1)$study_name =="WirbelJ_2018" ] | |
tse2.sub <- tse2[,colData(tse2)$study_name =="WirbelJ_2018" ] | |
rowintersect <- intersect(rownames(tse1.sub), rownames(tse2.sub)) | |
colintersect <- intersect(colnames(tse1.sub), colnames(tse2.sub)) | |
# keep same rows and columns | |
tse1.sub <- tse1.sub[rowintersect, colintersect] | |
tse2.sub <- tse2.sub[rowintersect, colintersect] | |
all.equal(assay(tse1.sub, "relative_abundance"), assay(tse2.sub, "relative_abundance")) | |
# Extract the abundances for Anaerobutyricum hallii first 5 samples. | |
data.frame(tse1.sub.A.hallii = assay(tse1.sub, "relative_abundance")["Anaerobutyricum hallii",][1:5], | |
tse2.sub.A.hallii = assay(tse2.sub, "relative_abundance")["Anaerobutyricum hallii",][1:5]) | |
devtools::session_info() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment