普氏分析

目的

为了展示相同个体不同组学数据,或者不同表型数据之间的相似性关系以及之间的差异性,所以采用了普氏分析。这里展示的是如何将两组数据进行普氏分析并进行可视化

一、导入数据

1 | 微生物种水平丰度表

图一 微生物种水平丰度表

2 | 食物数据的非加权unifrac矩阵

图二 食物数据
# 食物数据

# load the food distance matrix, unweighted unifrac
food_un <- read.delim("data/diet/processed_food/dhydrt_smry_no_soy_beta/unweighted_unifrac_dhydrt.smry.no.soy.txt", row = 1) # weighted in not significant
food_dist <- as.dist(food_un)

##############taxonomy############
# load taxonomy collapsed for each person
tax <- read.delim("data/microbiome/processed_average/UN_tax_CLR_mean_norm_s.txt", row = 1) # updates from reviewer comments
# drop soylents
tax <- tax[,colnames(tax) %in% colnames(food_un)]

# make taxonomy distance matrix
tax_dist <- dist(t(tax))

###############nutrients############
# load nutrition data
nutr <- read.delim("data/diet/processed_nutr/nutr_65_smry_no_soy.txt", row = 1)

# normalize nutrition data across features (rows)
nutr_n <- sweep(nutr, 1, rowSums(nutr), "/")

# make nutrition distance matrix (euclidean)
nutr_dist <- dist(t(nutr_n))

二、进行procrustes分析并作图

1 | 首先以食物和微生物为例

# make pcoas 
pcoa_f <- as.data.frame(pcoa(food_dist)$vectors)
pcoa_t <- as.data.frame(pcoa(tax_dist)$vectors)

# procrustes
pro <- procrustes(pcoa_f, pcoa_t)
pro_test <- protest(pcoa_f, pcoa_t, perm = 999)  #普氏分析组间数据的检验

eigen <- sqrt(pro$svd$d)
percent_var <- signif(eigen/sum(eigen), 4)*100

beta_pro <- data.frame(pro$X)
trans_pro <- data.frame(pro$Yrot)
beta_pro$UserName <- rownames(beta_pro)
beta_pro$type <- "Food (Unweighted Unifrac)"
trans_pro$UserName <- rownames(trans_pro)
trans_pro$type <- "Microbiome (Aitchison's)"

colnames(trans_pro) <- colnames(beta_pro)

pval <- signif(pro_test$signif, 1)

plot <- rbind(beta_pro, trans_pro)

food_micro <- ggplot(plot) +
  geom_point(size = 2, alpha=0.75, aes(x = Axis.1, y = Axis.2, color = type)) +
  scale_color_manual(values = c("#5a2071", "#5f86b7")) +
    theme_classic() +
    geom_line(aes(x= Axis.1, y=Axis.2, group=UserName), col = "darkgrey", alpha = 0.6) +
  theme(panel.background = element_blank(),
        panel.grid.major = element_blank(),
        panel.grid.minor = element_blank(),
        legend.title = element_blank(),
        legend.text = element_text(size=9),
        legend.position = 'bottom',
        axis.text = element_text(size=4),
        axis.title = element_text(size=9),
         aspect.ratio = 1) +
  guides(color = guide_legend(ncol = 1)) +
  annotate("text", x = 0.3, y = -0.27, label = paste0("p-value=",pval), size = 2) +
  xlab(paste0("PC 1 [",percent_var[1],"%]")) +
  ylab(paste0("PC 2 [",percent_var[2],"%]")) 
  
  food_micro_leg <- get_legend(food_micro) #得到ggplot图的图例信息


food_micro + theme(legend.position = "none")

2 | 营养与微生物之间的普氏分析

# make pcoas 
pcoa_n <- as.data.frame(pcoa(nutr_dist)$vectors)
pcoa_t <- as.data.frame(pcoa(tax_dist)$vectors)

# procrustes
pro <- procrustes(pcoa_n, pcoa_t)
pro_test <- protest(pcoa_n, pcoa_t, perm = 999)

eigen <- sqrt(pro$svd$d)
percent_var <- signif(eigen/sum(eigen), 4)*100

beta_pro <- data.frame(pro$X)
trans_pro <- data.frame(pro$Yrot)
beta_pro$UserName <- rownames(beta_pro)
beta_pro$type <- "Nutrient (Euclidean)"
trans_pro$UserName <- rownames(trans_pro)
trans_pro$type <- "Microbiome (Aitchison's)"

colnames(trans_pro) <- colnames(beta_pro)

pval <- signif(pro_test$signif, 1)

plot <- rbind(beta_pro, trans_pro)

nutr_micro <- ggplot(plot) +
  geom_point(size = 2, alpha=0.75, aes(x = Axis.1, y = Axis.2, color = type)) +
  scale_color_manual(values = c("#5f86b7", "#2bbaa7")) +
    theme_classic() +
    geom_line(aes(x= Axis.1, y=Axis.2, group=UserName), col = "darkgrey", alpha = 0.6) +
  theme(panel.background = element_blank(),
        panel.grid.major = element_blank(),
        panel.grid.minor = element_blank(),
        legend.title = element_blank(),
        legend.text = element_text(size=9),
        legend.position = 'bottom',
        axis.text = element_text(size=4),
        axis.title = element_text(size=9),
         aspect.ratio = 1) +
  guides(color = guide_legend(ncol = 1)) +
  annotate("text", x = 0.01, y = -0.19, label = paste0("p-value=",pval), size = 2) +
  xlab(paste0("PC 1 [",percent_var[1],"%]")) +
  ylab(paste0("PC 2 [",percent_var[2],"%]")) 

nutr_micro + theme(legend.position = "none")

nutr_micro_leg <- get_legend(nutr_micro)

3 | 谷物类数据和微生物数据(欧几里得距离)

# Import the beta diversity table from grains_beta (weighted or unweighted)
food_beta <- read.table(file="data/diet/fiber/grains_data/grains_beta/unweighted_unifrac_grains_fiber.txt")

food_dist <- as.dist(food_beta)
# refer this code to make a pcoa you will have to fix naming and play with the data structure of the dataframe called plot to get this to work.

# Import the beta diversity table for taxonomy
taxa_beta <- read.table(file="data/microbiome/processed_average/UN_tax_beta/euclidean_UN_taxonomy_clr_s.txt")

tax_dist <- as.dist(taxa_beta)

# make pcoas 
pcoa_f <- as.data.frame(pcoa(food_dist)$vectors)
pcoa_t <- as.data.frame(pcoa(tax_dist)$vectors)

# procrustes
pro <- procrustes(pcoa_f, pcoa_t)
pro_test <- protest(pcoa_f, pcoa_t, perm = 999)

eigen <- sqrt(pro$svd$d)
percent_var <- signif(eigen/sum(eigen), 4)*100

beta_pro <- data.frame(pro$X)
trans_pro <- data.frame(pro$Yrot)
beta_pro$UserName <- rownames(beta_pro)
beta_pro$type <- "Grain Fiber (Unweighted Unifrac)"
trans_pro$UserName <- rownames(trans_pro)
trans_pro$type <- "Microbiome (Aitchison's)"

colnames(trans_pro) <- colnames(beta_pro)

pval <- signif(pro_test$signif)

plot <- rbind(beta_pro, trans_pro)

grain_micro <- ggplot(plot) +
  geom_point(size = 2, alpha=0.75, aes(x = Axis.1, y = Axis.2, color = type)) +
  scale_color_manual(values = c("#fe9700", "#5f86b7")) +
    theme_classic() +
    geom_line(aes(x= Axis.1, y=Axis.2, group=UserName), col = "darkgrey", alpha = 0.6) +
  theme(panel.background = element_blank(),
        panel.grid.major = element_blank(),
        panel.grid.minor = element_blank(),
        legend.title = element_blank(),
        legend.text = element_text(size=9),
        legend.position = 'bottom',
        axis.text = element_text(size=4),
        axis.title = element_text(size=9),
         aspect.ratio = 1) +
  guides(color = guide_legend(ncol = 1)) +
  annotate("text", x = 0.05, y = -0.27, label = paste0("p-value=",pval), size = 2) +
  xlab(paste0("PC 1 [",percent_var[1],"%]")) +
  ylab(paste0("PC 2 [",percent_var[2],"%]")) 

grain_micro + theme(legend.position = "none")

grain_leg <- get_legend(grain_micro)

4 | 水果数据和微生物数据

# Import the beta diversity table from fruit_beta (weighted or unweighted)
food_beta <- read.table(file="data/diet/fiber/fruit_data/fruit_beta/unweighted_unifrac_fruit_fiber.txt")

food_dist <- as.dist(food_beta)

# make pcoas 
pcoa_f <- as.data.frame(pcoa(food_dist)$vectors)
pcoa_t <- as.data.frame(pcoa(tax_dist)$vectors)

# procrustes
pro <- procrustes(pcoa_f, pcoa_t)
pro_test <- protest(pcoa_f, pcoa_t, perm = 999)

eigen <- sqrt(pro$svd$d)
percent_var <- signif(eigen/sum(eigen), 4)*100

beta_pro <- data.frame(pro$X)
trans_pro <- data.frame(pro$Yrot)
beta_pro$UserName <- rownames(beta_pro)
beta_pro$type <- "Fruit Fiber (Unweighted Unifrac)"
trans_pro$UserName <- rownames(trans_pro)
trans_pro$type <- "Microbiome (CLR-Euclidean)"

colnames(trans_pro) <- colnames(beta_pro)

pval <- signif(pro_test$signif, 3)

plot <- rbind(beta_pro, trans_pro)

fruit_micro <- ggplot(plot) +
    geom_point(size = 2, alpha=0.75, aes(x = Axis.1, y = Axis.2, color = type)) +
  scale_color_manual(values = c("#CBD13E", "#5f86b7")) +
    theme_classic() +
    geom_line(aes(x= Axis.1, y=Axis.2, group=UserName), col = "darkgrey", alpha = 0.6) +
  theme(panel.background = element_blank(),
        panel.grid.major = element_blank(),
        panel.grid.minor = element_blank(),
        legend.title = element_blank(),
        legend.text = element_text(size=9),
        legend.position = 'bottom',
        axis.text = element_text(size=4),
        axis.title = element_text(size=9),
         aspect.ratio = 1) +
  guides(color = guide_legend(ncol = 1)) +
  annotate("text", x = 0.33, y = -0.33, label = paste0("p-value=",pval), size = 2) +
  xlab(paste0("PC 1 [",percent_var[1],"%]")) +
  ylab(paste0("PC 2 [",percent_var[2],"%]")) 

fruit_micro + theme(legend.position = "none")

fruit_leg <- get_legend(fruit_micro)

# 合并四个图

plotC_H <- plot_grid(  food_micro + theme(legend.position = "none"), 
          nutr_micro + theme(legend.position = "none"), 
          grain_micro + theme(legend.position = "none"), 
          fruit_micro + theme(legend.position = "none"), 
          ncol = 2, 
          align = "h", 
          labels = c("E", "F", "G", "H"))

save_plot("Figure2E_H.pdf", plotC_H, base_width = 3.5, base_height = 3.5)

5 | 出图,大功告成


图三 普氏分析图

参考文章

[1] https://www.cell.com/cell-host-microbe/fulltext/S1931-3128(19)30250-1

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 194,491评论 5 459
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 81,856评论 2 371
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 141,745评论 0 319
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 52,196评论 1 263
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 61,073评论 4 355
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 46,112评论 1 272
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 36,531评论 3 381
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 35,215评论 0 253
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 39,485评论 1 290
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 34,578评论 2 309
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 36,356评论 1 326
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 32,215评论 3 312
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 37,583评论 3 299
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 28,898评论 0 17
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 30,174评论 1 250
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 41,497评论 2 341
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 40,697评论 2 335

推荐阅读更多精彩内容

  • Swift1> Swift和OC的区别1.1> Swift没有地址/指针的概念1.2> 泛型1.3> 类型严谨 对...
    cosWriter阅读 11,067评论 1 32
  • “不少于800字!”是我少年求学时最大的梦魇。其实从牙牙学语,我们便开始使用语言,可真正围绕一个主题,有逻辑、有系...
    色yp阅读 437评论 0 5
  • 长夜风暖月始亏。望窗楹,怀心思,辗转寥语无眠。可怜,可怜,孤枕身热腿寒。 鸦躁星沉日吐晖。梦萦萦,襟湿湿,慨怨路遥...
    悦竹弄藻阅读 647评论 0 5