-
Notifications
You must be signed in to change notification settings - Fork 263
Expand file tree
/
Copy path2StatPlot.sh
More file actions
626 lines (506 loc) · 22.7 KB
/
2StatPlot.sh
File metadata and controls
626 lines (506 loc) · 22.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
[TOC]
# 2EasyMetagenome Visualization (2易宏基因组统计与可视化)
# Authors(作者): Yong-Xin Liu(刘永鑫), Defeng Bai(白德凤), Tong Chen(陈同) et al.
# Version(版本): 1.25, 2026/1/22
# Operation System(操作系统): Linux Ubuntu 22.04+ / CentOS 7.7+
# Homepage(主页): https://github.com/YongxinLiu/EasyMetagenome
# Cititon(引文): Bai, et al. 2025. EasyMetagenome: A User‐Friendly and Flexible Pipeline for Shotgun Metagenomic Analysis in Microbiome Research. iMeta 4: e70001. https://doi.org/10.1002/imt2.70001
# Set work directory(设置工作目录)
wd=/d/Download/github/EasyMetagenome/result
sd=/d/Download/github/EasyMicrobiome/script
PATH=$PATH:$sd/../win:$sd
cd $wd
## MetaPhlAn4 taxonomic composition (物种组成)
### Alpha diversity (α多样性)
# index calculation (多样性指数计算)
sed -i '/^#/d' metaphlan4/taxonomy.tsv
Rscript ${sd}/metaphlan4_alpha.R -h
Rscript $sd/metaphlan4_alpha.R \
-i metaphlan4/taxonomy.tsv \
-g metadata.txt \
-t 7 \
-o metaphlan4/alpha
# Plot alpha diversity boxplot (绘制多样性指数箱线图)
# result: metaphlan4/boxplot_{richness/shannon/shannon/invsimpson/Pielou_evenness}.pdf, sig using different letter a/b/c
Rscript $sd/alpha_boxplot.R -h
head -n1 metaphlan4/alpha.txt
Rscript $sd/alpha_boxplot.R \
-i metaphlan4/alpha.txt \
-a shannon \
-d metadata.txt \
-n Group \
-o metaphlan4/ \
-w 89 -e 59
# 5 Alpha diversity boxplot
for i in `head -n1 metaphlan4/alpha.txt|cut -f 2-`;do
Rscript $sd/alpha_boxplot.R -i metaphlan4/alpha.txt -a ${i} \
-d metadata.txt -n Group -w 89 -e 59 \
-o metaphlan4/
done
# Alpha diversity boxplot with pvalue
# result: p_boxplot_${alpha_diversity}.pdf
Rscript $sd/alpha_boxplot_new.R \
-i metaphlan4/alpha.txt \
-a shannon \
-d metadata.txt \
-n Group \
-o metaphlan4/ \
-w 49 -e 79
# 5 Alpha diversity boxplot
for i in `head -n1 metaphlan4/alpha.txt|cut -f 2-`;do
Rscript $sd/alpha_boxplot_new.R -i metaphlan4/alpha.txt -a ${i} \
-d metadata.txt -n Group -w 49 -e 79 \
-o metaphlan4/
done
# Venn diagram (维恩图)
# Filter abundance > 0.5 in each sample 筛选每个样本>0.5%的分类单元,包括界门纲目科属种
awk 'BEGIN{OFS=FS="\t"}{if(FNR==1) {for(i=2;i<=NF;i++) a[i]=$i;} \
else {for(i=2;i<=NF;i++) if($i>0.5) print $1, a[i];}}' \
metaphlan4/taxonomy.tsv > metaphlan4/taxonomy_high.tsv
wc -l metaphlan4/taxonomy_high.tsv
# EVenn (https://www.bic.ac.cn/test/venn/#/) supports 6 groups and real-time viewing of element intersections (支持实时查看元素交集)
# Ref:Yang, Tong Chen, Yong-Xin Liu, Luqi Huang. 2024. Visualizing set relationships: EVenn's comprehensive approach to Venn diagrams. iMeta 3: e184. https://doi.org/10.1002/imt2.184
# script support 2-5 group: -f input, -a/b/c/d/g group, -w/u width and length, -p output filename
# 本地2-5组比较:-f输入文件,-a/b/c/d/g分组名,-w/u为宽高英寸,-p输出文件名后缀
bash ${sd}/sp_vennDiagram.sh -f metaphlan4/taxonomy_high.tsv \
-a C1 -b C2 -c Y1 -d Y2 -g Y3 \
-w 4 -u 4 \
-p C1_C2_Y1_Y2_Y3
# Group mean (求均值再两组比较)
Rscript ${sd}/otu_mean.R --input metaphlan4/taxonomy.tsv \
--metadata metadata.txt \
--group Group --thre 0 \
--scale F --all TRUE --type mean \
--output metaphlan4/group_mean.txt
# Filter abundance > 0.5 in each group (筛选每个组>0.5%的分类单元,包括界门纲目科属种)
awk 'BEGIN{OFS=FS="\t"}{if(FNR==1) {for(i=2;i<=NF;i++) a[i]=$i;} \
else {for(i=2;i<=NF;i++) if($i>0.5) print $1, a[i];}}' \
metaphlan4/group_mean.txt > metaphlan4/group_high.tsv
bash ${sd}/sp_vennDiagram.sh -f metaphlan4/group_high.tsv \
-a Centenarians -b Young -c All \
-w 8 -u 6 \
-p Centenarians_Young_All
### Beta diversity (β多样性)
# Distance calculation (距离计算)
# -t taxonomy level: 1 kingdom; 2 phylum; 3 order; 4 class; 5 family; 6 genus; 7 species
# -m distance type:"bray", "euclidean", "jaccard", "manhattan" etc.
# e.g. Claculate level 7 (species) in bray-curtis distance
Rscript ${sd}/metaphlan4_beta.R -h
Rscript $sd/metaphlan4_beta.R \
-i metaphlan4/taxonomy.tsv \
-g metadata.txt \
-t 7 \
-m bray \
-o metaphlan4/beta
# Beta diversity in Principal Coordinates Analysis (PCoA)
# input distance matrix, group name, width/height in mm, stat in beta_pcoa_stat.txt
Rscript $sd/beta_pcoa.R \
--input metaphlan4/beta_bray.txt \
--design metadata.txt \
--group Group \
--width 89 --height 59 \
--output metaphlan4/pcoa.bray_curtis.pdf
### Taxonomic composition (物种组成)
# Heatmap (热图)
# -h: Show help (显示脚本帮助)
Rscript ${sd}/metaphlan_hclust_heatmap.R -h
# stat (显示脚本帮助)
csvtk -t stat metaphlan4/taxonomy.spf
# Taxonomy level: Order, Top n taxa to plot heatmap (指定分类级、取前n种绘制热图)
# Order Top 20, Family Top 25, Genus Top 30
tax=Order
n=25
# -i: input metaphlan4 result in spf format
# -t: taxa in Kingdom/Phylum/Class/Order/Family/Genus/Species/Strain (界门纲目科属种株),推荐门,目,属
# -o: output figure in pdf, data in txt, default name Heatmap+($tax).pdf/txt
Rscript $sd/metaphlan_hclust_heatmap.R \
-i metaphlan4/taxonomy.spf \
-t ${tax} -n ${n} \
-w 183 -e 118 \
-o metaphlan4/heatmap${tax}
# Boxplot (箱线图)
for tax in Phylum Family Genus Species; do
Rscript $sd/metaphlan_boxplot.R \
-i metaphlan4/taxonomy.spf \
-t ${tax} \
-n ${n} \
-o metaphlan4/boxplot_${tax};done
# Compare group boxplot *_compare.pdf (组间比较箱线图)
for tax in Phylum Family Genus Species; do
Rscript $sd/metaphlan4_boxplot_compare.R \
-i metaphlan4/taxonomy.spf \
-t ${tax} \
-n 30 \
-o metaphlan4/boxplot_${tax};done
# Plot stackplot (绘制不同分类层级堆叠柱状图)
# Prepare file (准备每个分类层级的文件)
bash ${sd}/stack_data_prepare.sh
for tax in Phylum Genus Species; do
Rscript ${sd}/tax_stackplot.R \
--input metaphlan4/${tax}.txt --design metadata.txt \
--group Group --output metaphlan4/${tax}.stackplot \
--legend 10 --width 120 --height 70; done
# Sorted stackplot (排序分面堆叠柱状图)
for tax in Phylum Genus Species; do
Rscript ${sd}/tax_stackplot_order.R \
--input metaphlan4/${tax}.txt --design metadata.txt \
--group Group --output metaphlan4/${tax}.stackplot \
--legend 10 --width 120 --height 70; done
### Different compare (差异比较)
## STAMP
# If you encounter errors or no results, lower the threshold and p-value.
# The example sample size is small cause no significant, change it to P<0.1.
# 如果遇见报错无结果调低threshold和pvalue值,此处样本少无显著改为P<0.1
# Set compared groups, using '-' as seperate
compare="Centenarians-Young"
Rscript ${sd}/compare_stamp.R \
--input metaphlan4/Genus.txt --metadata metadata.txt \
--group Group --compare ${compare} --threshold 0.01 \
--method "t.test" --pvalue 0.1 --fdr "none" \
--width 300 --height 150 \
--output metaphlan4/stamp_${compare}
### MaAsLin2差异物种分析火山图
# 同样适用于功能通路差异分析
Rscript ${sd}/compare_MaAsLin2.R \
--i metaphlan4/Species.txt \
--m metadata.txt \
--o metaphlan4/
# 根据差异分析结果绘制火山图
Rscript ${sd}/compare_valcano.R \
--i metaphlan4/MaAsLin2_overall_difference.csv \
--d metaphlan4/MaAsLin2_enriched_depleted.csv \
--o metaphlan4/
## HUMAnN4 functional composition (功能组成)
### Clustering heatmap (分组聚类热图)
bash $sd/sp_pheatmap.sh
cut -f 1,3 metadata.txt > group.txt
# -f输入文件,-H水平聚类,u/v图片宽/高,-P添加行注释文件,-Q添加列注释
# 水平标准化,-d row,可选column
bash $sd/sp_pheatmap.sh \
-f humann4/path_relab_unstratified.tsv \
-H 'TRUE' -u 20 -v 50 \
-Q group.txt -d row
# 结果为 输入文件名+pheamap.r/pdf,代码和图片
## Kraken2 Taxonomic composition (物种组成)
### Alpha diversity (多样性)
# 提取种级别注释并抽平至最小测序量,计算6种alpha多样性指数
# 查看帮助
Rscript $sd/kraken2alpha.R -h
# -d指定最小样本量,默认0为最小值,抽平文件tax_norm.txt,alpha多样性tax_alpha.txt
Rscript $sd/kraken2alpha.R \
--input kraken2/tax_count.mpa \
--depth 0 \
--species kraken2/tax_count.txt \
--normalize kraken2/tax_count.norm \
--output kraken2/tax_count.alpha
kraken2/tax_count.txt
sed -i 's/\r//' kraken2/tax_count.*
# 绘制Alpha多样性指数,结果为输入文件+类型richness/chao1/ACE/shannon/simpson/invsimpson
# Rscript $sd/alpha_boxplot.R -h # 查看参数
Rscript $sd/alpha_boxplot.R \
-i kraken2/tax_count.alpha \
-a shannon \
-d metadata.txt \
-n Group \
-o kraken2/ \
-w 89 -e 59
# 批量计算6种指数的箱线图+统计
for i in richness chao1 ACE shannon simpson invsimpson;do
Rscript $sd/alpha_boxplot.R -i kraken2/tax_count.alpha -a ${i} \
-d metadata.txt -n Group -w 89 -e 59 \
-o kraken2/
done
### Taxonomic composition (物种组成)
# 转换为metaphalan spf格式,分隔符为下划线“__”
awk 'BEGIN{OFS=FS="\t"}{delete a; a["k"]="unclassified";a["p"]="unclassified";a["c"]="unclassified";a["o"]="unclassified";a["f"]="unclassified";a["g"]="unclassified";a["s"]="unclassified"; \
split($1,x,"|");for(i in x){split(x[i],b,"__");a[b[1]]=b[2];} \
print a["k"],a["p"],a["c"],a["o"],a["f"],a["g"],a["s"],$0;}' \
kraken2/tax_count.txt > temp.txt
cut -f 1-7,9- temp.txt > kraken2/tax_count.spf
sed -i '1 s/unclassified\tunclassified\tunclassified\tunclassified\tunclassified\tunclassified\tunclassified/Kingdom\tPhylum\tClass\tOrder\tFamily\tGenus\tSpecies/' \
kraken2/tax_count.spf
# 绘制热图,可选域、门、纲、目、科、属、种(Domain Phylum Class Order Family Genus Species)
# 单个运行
tax=Genus
Rscript $sd/metaphlan_hclust_heatmap.R \
-i kraken2/tax_count.spf \
-t ${tax} \
-n 25 \
-w 118 -e 118 \
-o kraken2/heatmap_${tax}
# 批量运行
for tax in Phylum Family Genus Species; do
Rscript $sd/metaphlan_hclust_heatmap.R \
-i kraken2/tax_count.spf \
-t ${tax} \
-n 10 \
-w 118 -e 118 \
-o kraken2/heatmap_${tax};done
### Taxonomic distribution boxplot (物种分布箱线图)
# 绘制属水平Top30箱线图
Rscript $sd/metaphlan_boxplot.R \
-i kraken2/tax_count.spf \
-t Genus \
-n 30 \
-o kraken2/boxplot_Genus
# 绘制门水平Top10箱线图
Rscript $sd/metaphlan_boxplot.R \
-i kraken2/tax_count.spf \
-t Phylum \
-n 10 -w 6 -e 4 \
-o kraken2/boxplot_Phylum
# Batch other taxonomic level (批量绘制不同层级箱线图)
for tax in Class Order Family Species; do
Rscript $sd/metaphlan_boxplot.R \
-i kraken2/tax_count.spf \
-t ${tax} \
-n 30 \
-o kraken2/boxplot_${tax};done
## Braken2: Kraken2 taxonomic abundance reestimate (物种丰度重估)
### Alpha diversity (多样性)
# 提取种级别注释并抽平至最小测序量,计算6种alpha多样性指数
# 查看帮助
Rscript $sd/otutab_rare.R -h
# -d指定最小样本量,默认0为最小值,抽平文件tax_norm.txt,alpha多样性tax_alpha.
tax=S
Rscript $sd/otutab_rare.R \
--input kraken2/bracken.${tax}.txt \
--depth 0 --seed 1 \
--normalize kraken2/bracken.${tax}.norm \
--output kraken2/bracken.${tax}.alpha
# 批量
for tax in D P G S; do
Rscript $sd/otutab_rare.R \
--input kraken2/bracken.${tax}.0.2 \
--depth 0 --seed 1 \
--normalize kraken2/bracken.${tax}.norm \
--output kraken2/bracken.${tax}.alpha;done
# 绘制Alpha多样性指数,结果为输入文件+类型richness/chao1/ACE/shannon/simpson/invsimpson
# Rscript $sd/alpha_boxplot.R -h # 查看参数
Rscript $sd/alpha_boxplot.R \
-i kraken2/bracken.${tax}.alpha \
-a richness \
-d metadata.txt \
-n Group \
-o kraken2/${tax} \
-w 89 -e 59
# 批量运行
for tax in S; do
for i in richness chao1 ACE shannon simpson invsimpson; do
mkdir -p kraken2/${tax}/alpha/
Rscript $sd/alpha_boxplot.R \
-i kraken2/bracken.${tax}.alpha \
-a ${i} \
-d metadata.txt \
-n Group \
-o kraken2/${tax}/alpha/ \
-w 89 -e 59; done
done
mv alpha_boxplot_TukeyHSD.txt kraken2/${tax}_bracken_alpha
## Beta diversity (β多样性)
# Beta多样性距离矩阵计算
# Mac 用不了面对的 usearch,使用在线平台 https://www.bic.ac.cn/BIC
mkdir -p kraken2/beta/
$sd/../win/usearch -beta_div kraken2/bracken.${tax}.norm \
-filename_prefix kraken2/beta/
# PCoA分析输入文件,选择分组,输出文件,图片尺寸mm,统计见beta_pcoa_stat.txt
# 可选距离有 bray_curtis, euclidean, jaccard, manhattan
dis=bray_curtis
Rscript $sd/beta_pcoa.R \
--input kraken2/beta/${dis}.txt \
--design metadata.txt \
--group Group \
--width 89 --height 59 \
--output kraken2/pcoa.${dis}.pdf
# 批量运行
for tax in S; do
mkdir -p kraken2/${tax}/beta/
$sd/../win/usearch -beta_div kraken2/bracken.${tax}.norm \
-filename_prefix kraken2/${tax}/beta/
for dis in bray_curtis euclidean jaccard manhatten; do
Rscript $sd/beta_pcoa.R \
--input kraken2/${tax}/beta/${dis}.txt \
--design metadata.txt \
--group Group \
--width 89 --height 59 \
--output kraken2/${tax}/beta/pcoa.${dis}.pdf; done
mv beta_pcoa_stat.txt kraken2/${tax}/beta/;done
### 堆叠柱状图
```
# 以门(P)/种(S)水平为例,结果包括output.sample/group.pdf两个文件
tax=P
Rscript ${sd}/tax_stackplot.R \
--input kraken2/bracken.${tax}.txt --design metadata.txt \
--group Group --output kraken2/bracken.${tax}.stackplot \
--legend 10 --width 89 --height 59
# 批量运行
for tax in D G P S; do
Rscript ${sd}/tax_stackplot.R \
--input kraken2/bracken.${tax}.0.01-H --design metadata.txt \
--group Group --output kraken2/bracken.${tax}.stackplot \
--legend 10 --width 120 --height 70; done
```
### STAMP图
```
compare="Normal-Cancer"
tax=S
Rscript ${sd}/compare_stamp.R \
--input kraken2/bracken.${tax}.0.01-H --metadata metadata.txt \
--group Group --compare ${compare} --threshold 0.1 \
--method "t.test" --pvalue 0.1 --fdr "none" \
--width 100 --height 200 \
--output kraken2/stamp_${compare}
```
## 基因组进化树注释table2itol
```
cd ../binning/result/itol/
## 方案1. 分类彩带、数值热图、种标签
# -a 找不到输入列将终止运行(默认不执行)-c 将整数列转换为factor或具有小数点的数字,-t 偏离提示标签时转换ID列,-w 颜色带,区域宽度等, -D输出目录,-i OTU列名,-l 种标签替换ID
Rscript ${sd}/table2itol.R -a -c double -D plan1 -i ID -l Species -t %s -w 0.5 annotation.txt
# 生成注释文件中每列为单独一个文件
## 方案2. 数值柱形图,树门背景色,属标签
Rscript ${sd}/table2itol.R -a -d -c none -D plan2 -b Phylum -i ID -l Genus -t %s -w 0.5 annotation.txt
## 方案3.分类彩带、整数为柱、小数为热图
Rscript ${sd}/table2itol.R -c keep -D plan3 -i ID -t %s annotation.txt
## 方案4. 将整数转化成因子生成注释文件
Rscript ${sd}/table2itol.R -a -c factor -D plan4 -i ID -l Genus -t %s -w 0 annotation.txt
```
## MAGs分析
### MAGs与样本稀疏曲线
```
cd ${wd}
cd ..
Rscript ${sd}/MAG_sample_rare.R \
--input binning/result/coverm/abundance.tsv \
--taxonomy binning/result/coverm/taxonomy_MAG.txt \
--output binning/result/coverm/
```
### MAGs不同功能数据库注释结果比较UpSet图
```
Rscript ${sd}/MAG_protiens_UpSet.R \
--i result/eggnog/data_venn1.txt \
--o result/eggnog/
## 单个功能数据库分组比较(COGs, KEGG, ECs, GOs), 这里以COGs注释结果作为示例
# 分组比较UpSet图
Rscript ${sd}/common_upset.R \
--i result/eggnog/data_venn2.txt \
--o result/eggnog/
# 提取交集并绘制交集组成饼图
Rscript ${sd}/upset_intersection_composition.R \
--input result/eggnog/data_venn2.txt \
--composition result/eggnog/COGs_data.txt \
--output result/eggnog/
```
### MAGs功能通路桑基图
```
Rscript ${sd}/function_sankey.R \
--i result/humann3/data_sankey.txt \
--o result/humann3/
```
### MAGs完整性和污染率关系图
```
bash ${sd}/merged_tax.sh
sed 's/ /_/g' result/checkm2/taxonomy_merge.txt > result/checkm2/taxonomy_merge2.txt
Rscript ${sd}/MAG_quality_taxonomy.R \
--i result/checkm2/taxonomy_merge2.txt \
--o result/checkm2/
```
### MAGs系统发育分析树状图
```
# 肠道微生物样本示例
Rscript ${sd}/phylogenetic_tree.R \
--input result/gtdb_95/tax.unrooted4.tree \
--annotation result/gtdb_95/annotation4.txt \
--output result/gtdb_95/
# 环境样本示例
Rscript ${sd}/phylogenetic_tree_env.R \
--input result/gtdb_95/tax.unrooted2.tree \
--annotation result/gtdb_95/annotation3.txt \
--output result/gtdb_95/
Rscript ${sd}/phylogenetic_tree_env.R \
--input result/gtdb_95/tax.unrooted4.tree \
--annotation result/gtdb_95/annotation4.txt \
--output result/gtdb_95/
```
### MAGs耐药基因丰度热图
```
Rscript ${sd}/functional_gene_heatmap.R \
--input binning/temp/ARG2/ARG_final.txt \
--group binning/temp/ARG2/group_ARG.txt \
--output binning/temp/
```
### 单菌基因组注释和绘图
# 注释:https://bakta.computational.bio/submit
# 注释和绘图:https://proksee.ca
### 宏基因组数据泛基因组分析绘图
# 绘图: https://anvi-server.org/
# 附录
## windows换行符处理
```
# 查看行尾是否有^M
cat -A $sd/metaphlan_hclust_heatmap.R | head
# 转换Windows为Linux换行符
dos2unix $sd/metaphlan_hclust_heatmap.R
```
## 表格合并
# 按末列注释,必须名叫KO
Rscript $sd/mat_gene2ko.R \
-i temp/dbcan2/gene_fam.count \
-o dbcan2/fam_merge.count
## CoverM result mean
# 按组求均值,需要metadata中有3列且每个组有多个样本
Rscript ${db}/EasyMicrobiome/script/otu_mean.R --input result/coverm/abundance.tsv \
--metadata result/metadata.txt \
--group Group --thre 0 \
--scale TRUE --zoom 100 --all TRUE --type mean \
--output result/coverm/group_mean.txt
# https://www.bic.ac.cn/ImageGP/ 直接选择热图可视化
## 附录
### SparCC NetWork (物种稀疏相关网络分析)
Rscript ${sd}/SparCC_data_processing.R \
--input metaphlan4/Species.txt \
--group metadata.txt \
--output metaphlan4/
# Python需要在Linux下用conda环境运行,整合到1Pipeline中
## SparCC相关性(Correlation)和显著性(p value)计算
# 以下命令行需在linux环境中运行
git clone https://github.com/JCSzamosi/SparCC3.git
cd SparCC3
mkdir -p data
cp result12/metaphlan4/Cancer_sparcc.txt SparCC3/data/
cp result12/metaphlan4/Normal_sparcc.txt SparCC3/data/
# Step 1 - Compute correlations
python SparCC.py data/Cancer_sparcc.txt -i 20 \
--cor_file=example/basis_corr/sxtr_sparcc_Cancer.tsv \
> example/basis_corr/sxtr_sparcc_Cancer.log
# Step 2 - Compute bootstraps
# 此处测试节省时间设置为100,建议设置为1000
mkdir -p example/pvals_cancer
python MakeBootstraps.py data/Cancer_sparcc.txt \
-n 100 -t bootstrap_#.txt \
-p example/pvals_cancer/ >> sxtr_sparcc_Cancer.log
# Step 3 - Compute p-values
# 如果上面设置1000,这里99更改为999
for n in {0..99}; do python SparCC.py example/pvals_cancer/bootstrap_${n}.txt -i 20 \
--cor_file=example/pvals_cancer/bootstrap_cor_${n}.txt >> sxtr_sparcc_Cancer.log; done
# 如果最开始设置1000,这里100更改为1000
python PseudoPvals.py example/basis_corr/sxtr_sparcc_Cancer.tsv example/pvals_cancer/bootstrap_cor_#.txt 100 \
-o example/pvals_cancer/pvals.two_sided_cancer.txt \
-t two_sided >> sxtr_sparcc_cancer.log
# step 4 - Rename file
mv example/pvals_cancer/pvals.two_sided_cancer.txt sxtr_pvals_cancer.two_sided.tsv
mv example/basis_corr/sxtr_sparcc_Cancer.tsv sxtr_cov_mat_Cancer.tsv
## 可视化
Rscript ${sd}/SparCC_visualization.R \
--Correlation result12/metaphlan4/sxtr_cov_mat_Cancer.tsv \
--Pvalue result12/metaphlan4/sxtr_pvals_cancer.two_sided.tsv \
--output result12/metaphlan4/
### graphlan_plot (物种组成)
# Graphlan输入文件获取
# Add heatmap as an example, if need to plot bar use "--type bar" instead
Rscript ${sd}/graphlan_plot.R -h
Rscript ${sd}/graphlan_plot.R \
--input metaphlan4/taxonomy.spf \
--design metadata.txt \
--type heatmap \
--output metaphlan4/graphlan