aprilwzh / python-

DNA-complement
0 stars 0 forks source link

python——生信练习,GC含量和碱基总个数 #8

Open aprilwzh opened 5 years ago

aprilwzh commented 5 years ago

检测文件是否存在

import os.path if os.path.isfile('9.out'): print("file exists") else: print("file not ") fw = open('9out','w')

统计碱基个数

m = 0 G = 0 with open('3.fasta') as f: for line in f: if line.startswith(">"): name = line else: n = len(line) m = m +n g = line.count('G') + line.count('C') G = G + g print(G) print(m) print(G/m)

GC含量

str((dict[ID].count('G') + dict[ID].count('C')) / len(dict[ID])