1. 輸出原序列的反向互補序列python
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行的文件,okspa
with open('probes.blast.txt') as file: for line in file: