本文属于存档性质,因为我后面用c#另外写了一版abi文件的读取工具。
下面data 9~12 分属于哪个字母,看的是FWO_1,不改了,懒
from Bio import SeqIO
import matplotlib.pyplot as plt
import sys
def drawGraph(file_name):
seq = ""
# 一些需要的信息
# SIGN是什么??
info_dict = {
}
# 绘图数据
data_a = []
data_c = []
data_g = []
data_t = []
qs = [] # quality scores
anno = {
}
letter_anno = {
}
abif_raw = {
}
# 检查后缀
raw = open(file_name, errors='ignore').read()
if file_name[-3:] != 'ab1' or raw[:4] != 'ABIF':
return "wrong file format"
#try:
# 读取数据
for record in SeqIO.parse(file_name, "abi"):
info_dict["seq"] = record.seq
info_dict["name"] = record.id
anno = record.annotations
letter_anno = record.letter_annotations
abif_raw = anno["abif_raw"]
# 信息
info_dict["date"] = anno["run_start"] + " to " + anno["run_finish"]
#info_dict["lane"] = anno["LANE1"]
info_dict["spac"] = "{:.2f}".format(abif_raw["SPAC1"]) # 保留两位小数
info_dict["dyep"] = abif_raw["PDMF2"].decode('utf-8')
info_dict["mach"] = abif_raw["MCHN1"].decode('utf-8')
info_dict["modl"] = anno["machine_model"].decode('utf-8') # bytes转str
info_dict["bcal"] = abif_raw["SPAC2"].decode('utf-8')
info_dict["ver1"] = abif_raw["SVER1"].decode('utf-8')
info_dict["ver2"] = abif_raw["SVER2"].decode('utf-8')
# 绘制折线的数据
data_g = list(abif_raw["DATA9"])
data_a = list(abif_raw["DATA10"])
data_t = list(abif_raw["DATA11"])
data_c = list(abif_raw["DATA12"])
# quality scores
qs = letter_anno["phred_quality"]
# 打印测试
#for k,v in info_dict.items():
# print(k + " : " + v)
#print("qs:")
#print(qs)
#print("g-data:")
#print(data_g)
# 绘制图像
plt.figure()
ticks = [int(i) for i in range(len(data_g))]
plt.plot(ticks, data_a, c='green')
plt.plot(ticks, data_c, c='purple')
plt.plot(ticks, data_g, c='gray')
plt.plot(ticks, data_t, c='red')
plt.show()
if __name__ == "__main__":
drawGraph(sys.argv[1])