This is a test version of Biostars. For the public version, visit https://www.biostars.org.
change the name of fasta files

Dear all.

I have a big Fasta file with complicated name of the sequence as:

>scaffold:ChrPicBel3.0.1:JH584390.1:1:2133925:1 scaffold JH584390.1
GAAATGCTCTTTTCTTCATTTAACCTTATATTTAATACACCTTTTAAATGTTTCTCAATT
TTTTTATTCTTTAATAATATGACAAACTAGACCTTTAAAATCATCTCTCCTTCCTAAATC

I just want to keep the last letter as the name as:

>JH584390.1
GAAATGCTCTTTTCTTCATTTAACCTTATATTTAATACACCTTTTAAATGTTTCTCAATT
TTTTTATTCTTTAATAATATGACAAACTAGACCTTTAAAATCATCTCTCCTTCCTAAATC

Please give me some suggestion. thanks

ZQ

genome

You might want to look into using Biopython. See these pages:
http://www.bioinformatics.org/bradstuff/bp/tut/Tutorial002.html
http://biopython.org/wiki/SeqIO
http://biopython.org/DIST/docs/tutorial/Tutorial.html#htoc11
http://biopython.org/DIST/docs/api/Bio.SeqIO-module.html

It just so happens that I've posted some code examples using this package for fasta parsing here and here which might be helpful to get started; you might want to modify the record.id value with .split() (example) or a regular expression of some sort (docs here and here) and append the output to a new fasta file.

2 answers

This has been asked may be more than 20 times on biostars. You could check the previous posts.

Anyways:

awk '{ if ( $0 ~ /^>/ ) { print ">"$NF } else { print } }'  in.fasta > out.fasta

Hi dear Goutham Atla,

Very nice script. you are a bash scripting expert!

Thank you

Dear Goutham Atla, Hi.

Is there any bioawk script for this purpose ? (I have search a little but I did not find any thing)

Dear wu.zhiqiang.1020, Hi.

maybe this code can help: awk -F" " '{print $NF}' big-header.fasta > short-header.fasta

and be sure you have checked the results

~ Best

This does not help. You will miss the > part of header.

thanks for the tips of this, we can change based on this thanks

Log in to answer this question.