#::!/usr/bin/python3
#-*- coding:utf-8 -*-
#计算fasta文件中各个氨基酸的含量

import sys
args=sys.argv

f=open(args[1], 'r')
fw=open('out.txt', 'w')

line=f.read()
txt=''.join(line.split('\n')[1:])       #可以得到氨基酸序列


#构建了各个氨基酸和含量的字典
##注意collections模块中Counter的用法
from collections import Counter
dict=Counter(txt)       #Counter直接返回字典


#文件的write方法只能写入字符串,
#因此要先将字典转变为字符串模式;json模块
import json
strdict=json.dumps(dict)
fw.writelines(strdict)
fw.writelines('\n')
fw.writelines(str(sum(dict.values())))
fw.writelines('\n')


#计算指定氨基酸的百分比
'''
for index  in dict.keys():
    if index==args[2]:
        rate=str(dict[index]/sum(dict.values()))
        fw.writelines('\n')
        fw.writelines(rate)
        fw.writelines('\n')
'''

f.close()
fw.close()

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-04
  • 2021-09-12
  • 2021-07-03
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-02
  • 2022-12-23
相关资源
相似解决方案