#::!/usr/bin/python3#-*-coding:utf-8-*- # calculate the content of each amino acid in the Fasta file ImportSysargs=SYS.ARGVF=open (Args[1],'R') FW=open ('OUT.txt','W') Line=f.read () txt="'. Join (Line.split ('\ n') [1:])#can get the amino acid sequence#A dictionary of each amino acid and content is constructed##注意collections模块中Counter的用法 fromCollectionsImportcounterdict=counter (TXT) #counter directly back to the dictionary#the Write method of a file can only be written to a string#Therefore, the dictionary should be transformed into a string pattern;JSON module Importjsonstrdict=json.dumps (dict) fw.writelines (strdict) fw.writelines ('\ n') fw.writelines (str (SUM (dict.values () ))) Fw.writelines ('\ n')#calculates the percentage of the specified amino acid" "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 ()
Python Text Processing---Calculate the number of different amino acids in the Fasta file