Python Text Processing---Calculate the number of different amino acids in the Fasta file

Source: Internet
Author: User

#::!/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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.