CheckM
CheckM在前文已经提过了,是一款评估宏基因组分箱质量的软件。目前我使用MetaBAT2这款软件已经对我的数据进行了一次分箱,现在利用CheckM进行质量评估。目前阶段,我主要想看Completeness和Contamination两个指标。
CheckM结果存储
我找了一下CheckM的结果存储,发现了这个文件/PATH/TO/checkm_results/storage/bin_stats_ext.tsv
,里面存储的信息还是我想要的用的
可以发现,每一行都是一个bin的信息,由bin的id和信息组成,bin的信息是由一个类似于python里字典的形式存储的。接下来就是要把这个信息提取出来,变成我们常用的txt表格的形式,方便后续的整理。
代码
#!/bin/python3
'''
This program is designed to process CheckM output file (e.g. bin_stats_ext.tsv) to easy-to-read text format (.txt)
Usage: python3 checkm_summary.py <inputfile> <outputfile>
Written by: Emmett Peng
'''
import json
import sys
with open(sys.argv[1] ,'r') as f:
Load = {}
for line in f:
line = line.replace('\'','\"')
line = line.split('\t')
line[0] = 'bin_' + line[0].replace('.bin.', '_')
#print(line[0])
#line[0]:Bin Id; line[1]:Bin information
#exec(f"line[0] = json.loads(line[1])")
Load[line[0]] = json.loads(line[1])
#print(Load)
#print(text)
with open(sys.argv[2], 'w+') as output:
output.write('Bin Id\tMarker Lineage\tGenomes\tMarkers\tMarker Sets\t0\t1\t2\t3\t4\t5+\tCompleteness\tContamination\tGC\tGC std\tGenome Size\tAmbiguous Bases\tScaffolds\tContigs\tTranslation Table\tPredicted Genes\n')
for key in Load:
output.write(key + '\t')
output.write(Load[key]['marker lineage'] + '\t')
output.write(str(Load[key]['# genomes']) + '\t')
output.write(str(Load[key]['# markers']) + '\t')
output.write(str(Load[key]['# marker sets']) + '\t')
output.write(str(Load[key]['0']) + '\t')
output.write(str(Load[key]['1']) + '\t')
output.write(str(Load[key]['2']) + '\t')
output.write(str(Load[key]['3']) + '\t')
output.write(str(Load[key]['4']) + '\t')
output.write(str(Load[key]['5+']) + '\t')
output.write(str(Load[key]['Completeness']) + '\t')
output.write(str(Load[key]['Contamination']) + '\t')
output.write(str(Load[key]['GC']) + '\t')
output.write(str(Load[key]['GC std']) + '\t')
output.write(str(Load[key]['Genome size']) + '\t')
output.write(str(Load[key]['# ambiguous bases']) + '\t')
output.write(str(Load[key]['# scaffolds']) + '\t')
output.write(str(Load[key]['# contigs']) + '\t')
output.write(str(Load[key]['Translation table']) + '\t')
output.write(str(Load[key]['# predicted genes']) + '\t')
output.write('\n')
这里主要是利用的json.loads()
函数读取后面这一片信息为python里的字典格式,必须注意要将所有单引号都换成双引号,因为json库函数在这里仅识别双引号为字符串信息。
代码存储在我的Github主页。
结果预览
运行结果可以放在Notepad++或Excel里打开查看,就是我们想到的比较易于检查和统计的形式了。