1. 豐度數(shù)據(jù)和分組信息讀取
未處理的數(shù)據(jù)讀取,以data表示;分組信息以info表示。
In [1]:
data = read.table('phylum.taxon.Abundance.xls',header = T,sep = 't',row.names = 1) dataOut[1]:
In [2]:
info = read.table('sample_groups.xls',header = F,sep = 't',col.names = c('sample','group')) infoOut[2]:
2. 提取數(shù)據(jù)框
通過grep獲取All和Verrucomicrobia的行號
In [3]:
grep("All|Verrucomicrobia", rownames(data))Out[3]:
10 12處理后的數(shù)據(jù)以數(shù)據(jù)框df表示。- grep("All|Verrucomicrobia", rownames(data)) 用于提取非All和Verrucomicrobia的行,info$sample提取樣品列
In [4]:
df = data[-grep("All|Unassigned", rownames(data)),info$sample] dfOut[4]:
3. 求兩組的均值、方差和標準差;并計算成對樣品T檢驗P值。
In [5]:
Out[5]:df['H_mean'] = apply(df[,info[info$group=='H',1]],1,mean) df['H_var'] = apply(df[,info[info$group=='H',1]],1,var) df['H_sd'] = apply(df[,info[info$group=='H',1]],1,sd) df['L_mean'] = apply(df[,info[info$group=='L',1]],1,mean) df['L_var'] = apply(df[,info[info$group=='L',1]],1,var) df['L_sd'] = apply(df[,info[info$group=='L',1]],1,sd) df['p.value'] = apply(df,1,function(x){ t.test(as.numeric(x[info[info$group=='H',1]]),as.numeric(x[info[info$group=='L',1]]),paired = T)$p.value }) df
數(shù)據(jù)保存至文本文件phylum.taxon.Abundance.new.xls 中。
In [6]:
write.table(df,'phylum.taxon.Abundance.new.xls',sep = 't',row.names = T, col.names = NA,quote = F)
4. 提取P值顯著的數(shù)據(jù)
In [7]:
df_diff = df[df$p.value<0.05,info$sample] df_diffOut[7]:
1. 數(shù)據(jù)合并
In [8]:
df_diff = data.frame(t(df_diff),group = info$group) df_diff
Out[8]:
2. 加載R包
In [9]:
.libPaths("C:/Program Files/R/R-3.6.1/library") library(ggpubr)3. 繪圖
method包括:t.test、wilcox.test、anova、kruskal.test;本次分析采用t.test。
ggarrange可以將多個圖繪制在一張圖上,ncol=2 按照每行2張圖繪制,行不限制。
In [10]:
Out[10]:p1= ggpaired(df_diff, x="group", y="Bacteroidetes", color = "group", line.color = "gray",xlab = 'Bacteroidetes', line.size = 0.4, palette = "npg")+ stat_compare_means(method = "t.test",paired = TRUE) p2= ggpaired(df_diff, x="group", y="Proteobacteria", color = "group", line.color = "gray", xlab = 'Proteobacteria', line.size = 0.4, palette = "npg")+ stat_compare_means(method = "t.test",paired = TRUE) ggarrange(p1, p2, ncol = 2,common.legend = T)
往期相關鏈接:
1、R基礎篇
excel不熟練怎么辦,R來幫您(一)數(shù)據(jù)分類匯總;
【零基礎學繪圖】之繪制venn圖(五);2、R進階
【繪圖進階】之六種帶中心點的PCA 圖和三維PCA圖繪制(四);
【繪圖進階】之交互式可刪減分組和顯示樣品名的PCA 圖(三);
3、數(shù)據(jù)提交
3分鐘學會CHIP-seq類實驗測序數(shù)據(jù)可視化 —IGV的使用手冊;
10分鐘搞定多樣性數(shù)據(jù)提交,最快半天內(nèi)獲取登錄號,史上最全的多樣性原始數(shù)據(jù)提交教程;
20分鐘搞定GEO上傳,史上最簡單、最詳細的GEO數(shù)據(jù)上傳攻略;
4、表達譜分析
表達譜分析(二)通路富集分析和基因互作網(wǎng)絡圖繪制;如何對GEO數(shù)據(jù)進行差異分析;miRNA靶基因預測軟件__miRWalk 3.0;5、醫(yī)學數(shù)據(jù)分析
KING: 樣本親緣關系鑒定工具;【W(wǎng)GS服務升級】人工智能軟件SpliceAI助力解讀罕見和未確診疾病中的非編碼突變;隱性疾病trio家系別忽視單親二倍體現(xiàn)象——天昊數(shù)據(jù)分析助力臨床疾病診斷新添UPD(單親二倍體)可視化分析工具;【昊工具】Oh My God! 太好用了吧!疾病或表型的關鍵基因查詢數(shù)據(jù)庫,我不允許你不知道Phenolyzer;
天昊客戶服務中心
手機/微信號:18964693703