python-读取abi文件信息并绘制峰图

1. 引入第三方库

from Bio import SeqIO
import matplotlib.pyplot as plt

2. 写函数

def sequence(file_name):
    info_dict = {}
    # 绘图数据
    # 检查后缀
    raw = open(file_name, errors='ignore').read()
    if file_name[-3:] != 'ab1' or raw[:4] != 'ABIF':
        return "wrong file format"

    # 读取数据
    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"])

        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()

3. 导入文件

if __name__ == "__main__":
    sequence('文件')

4. 启动函数

在这里插入图片描述

评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

xiongsheng666

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值