1. 输出原序列的反向互补序列

in1 = open("brca1.fasta", "r")
out1 = open("re_brca1.fasta", "w") raw = in1.readlines()
# 序列信息暂时不想改
out1.write(raw[0])
s = raw[1].split("\n")[0]
# 原序列中存在小写,先统一改为大写
s = s.upper()
# 不指定替换次数,所以全部替换
s.replace('G', 'C')
s.replace('C', 'G')
s.replace('A', 'T')
s.replace('T', 'A')
# 逆序输出,再加个换行符:)
out1.write(s[::-1]+"\n") out1.close()
in1.close()

2. 读取大量数据:试了2millions行的文件,ok

with open('probes.blast.txt') as file:
for line in file:

  

05-11 20:44