How to change name of species in FASTA file with BioPython
1
0
Entering edit mode
5.4 years ago

Hi I am trying to figure out a basic script to edit the names of the species in my FASTA file. I need the final product of the names to look like this:

>Homo_sapiens (FTO_NP_001073901) 
>Pan_troglodytes (FTO_XP_510968) 
>Nomascus_leucogenys (FTO_XP_003263101) 
>Pongo_abelii (FTO_NP_001126250)
FASTA PYTHON BioPython • 1.6k views
ADD COMMENT
0
Entering edit mode

Hello and welcome to biostars Daphnia3000 ,

your post is missing important information. How does your input looks like? What have tried and where did you get stuck?

fin swimmer

ADD REPLY
0
Entering edit mode

As finswimmer mentioned, the minimum we need is an example of your input so we know what manipulations are needed to create your desired output.

ADD REPLY
1
Entering edit mode
5.4 years ago
gb ★ 2.2k

Like others also said, we need more info to give the exact answer but I will still give it a try. I assume you have BioPython working, you can use something like this:

from Bio import SeqIO
with open("input.fa", "rU") as handle, open("output.fa", "a") as output:
    for record in SeqIO.parse(handle, "fasta"):
        newHeader = "create your new header here, maybe split() will help"
        output.write(">"+newHeader+"\n")
        output.write(str(record.seq)+"\n")
ADD COMMENT

Login before adding your answer.

Traffic: 2640 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6