Python handles Fasta files, IDs and sequences on one line

Source: Internet
Author: User

#!/usr/bin/python#-*-coding:utf-8-*- " Process the Fasta file, place the ID number and sequence on one line " ImportSyswith Open (sys.argv[1]) as F:FW=open ('Out.fasta','W') Line=f.read () Line=line.replace ('\ n',"'). Replace ('>','\n>')     forAainchline:fw.write (AA) fw.close ()""">chr1|hos107.1#gene1acactcccgggccccccccccccacctttcaaaaaaaaaaaaaaaaattttccccccaaagggg>chr1|hos107.2# gene2acactcccgggccccccccccccacctttcaaaaaaaaaaaaaaaaattttc>chr1|hos107.4# gene3acactcccgggccccccccccccacctttcaaaaaaaaaaaaaaaaattttc>chr1|hos107.5# GENE4ACACTCCCGGGCCCCCCCCCCCCACCTTTCAAAAAAAAAAAAAAAAATTTTC"""""">chr1|hos107.1#gene1acactcccgggccccccccccccacctttcaaaaaaaaaaaaaaaaattttccccccaaagggg>chr1|hos107.2# gene2acactcccgggccccccccccccacctttcaaaaaaaaaaaaaaaaattttc>chr1|hos107.4# gene3acactcccgggccccccccccccacctttcaaaaaaaaaaaaaaaaattttc>chr1|hos107.5# GENE4ACACTCCCGGGCCCCCCCCCCCCACCTTTCAAAAAAAAAAAAAAAAATTTTC""" # extract target sequence F=open ('./out.fasta','R') FW=open ('Target.fasta','W')  forLineinchf.readlines ():ifLine.startswith ('>chr1|hos107.1'): Fw.write (line) F.close () fw.close ()"""You can extract a file of the specified target ID from a single-line file Out.fasta that is processed above and write it to the Target.fasta file"""#Overall idea:#first unify the Fasta file format from Test.fasta----Out.fasta#Take out the target ID sequence: out.fasta----Target.fasta

Python handles Fasta files, IDs and sequences on one line

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.