python 中实现切除fastq文件序列的前后若干碱基

2022/8/16 1:23:47

本文主要是介绍python 中实现切除fastq文件序列的前后若干碱基,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

 

001、

[email protected]:/home/test# ls
a.fastq  test.py
[email protected]:/home/test# cat test.py                 ## 测试程序
#!/usr/bin/python
in_file = open("a.fastq", "r")
out_file = open("result.txt", "w")
dict1 = {}

idx = 0
for i in in_file:
    idx += 1
    i = i.strip()
    if idx % 4 == 1:
        key = i
        dict1[key] = []
    elif idx % 4 == 2:
        dict1[key].append(i[1:-3])             ## 切除序列的第1个碱基和最后的三个碱基
    else:
        dict1[key].append(i)
for i,j in dict1.items():
    out_file.write(i + "\n")
    for k in j:
        out_file.write(k + "\n")

in_file.close()
out_file.close()
[email protected]:/home/test# cat a.fastq                        ## 测试fastq文件
@DJB775P1:248:D0MDGACXX:7:1202:12362:49613
TGCTTACTCTGCGTTGATACCACTGCTTAGATCGGAAGAGCACACGTCTGAA
+
JJJJJIIJJJJJJHIHHHGHFFFFFFCEEEEEDBD?DDDDDDBDDDABDDCA
@DJB775P1:248:D0MDGACXX:7:1202:12782:49716
CTCTGCGTTGATACCACTGCTTACTCTGCGTTGATACCACTGCTTAGATCGG
+
IIIIIIIIIIIIIIIHHHHHHFFFFFFEECCCCBCECCCCCCCCCCCCCCCC
[email protected]:/home/test# python test.py                      ## 执行程序
[email protected]:/home/test# ls
a.fastq  result.txt  test.py
[email protected]:/home/test# cat result.txt                      ## 程序运行结果
@DJB775P1:248:D0MDGACXX:7:1202:12362:49613
GCTTACTCTGCGTTGATACCACTGCTTAGATCGGAAGAGCACACGTCT
+
JJJJJIIJJJJJJHIHHHGHFFFFFFCEEEEEDBD?DDDDDDBDDDABDDCA
@DJB775P1:248:D0MDGACXX:7:1202:12782:49716
TCTGCGTTGATACCACTGCTTACTCTGCGTTGATACCACTGCTTAGAT
+
IIIIIIIIIIIIIIIHHHHHHFFFFFFEECCCCBCECCCCCCCCCCCCCCCC

 

参考:https://www.jianshu.com/p/5ee54bea4cb0

 



这篇关于python 中实现切除fastq文件序列的前后若干碱基的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程