Question: Extraction Of Header Of Sequences In Fasta File
2
gravatar for Mohammad Reza Bakhtiarizadeh
9.0 years ago by
Tehran university

Hi all I have a fasta file that i want to extract just header of sequences. is there any perl code or some thing like this to do that? thanks a lot in advance

regards

perl fasta python parsing • 29k views
ADD COMMENTlink modified 9.0 years ago by Michael Dondrup48k • written 9.0 years ago by Mohammad Reza Bakhtiarizadeh290
1

By "header", you mean everything after the ">"? Or just some part of everything after the ">"? Or including the ">"? It's important to be specific since a lot of people misunderstand "header".

ADD REPLYlink written 9.0 years ago by Neilfws49k

I just want everything after the ">". and i have to say that i am not familiar with perl and i want a perl code to run. if possible help me. thanks a lot. regards

ADD REPLYlink written 9.0 years ago by Mohammad Reza Bakhtiarizadeh290

err, why don't you just post your code then?

ADD REPLYlink written 9.0 years ago by Michael Dondrup48k
12
gravatar for Frédéric Mahé
9.0 years ago by
France, Montpellier, CIRAD
Frédéric Mahé3.1k wrote:

For perl code, you can visit http://www.bioperl.org/wiki/Main_Page. If you just want to extract the headers, on a Linux/Unix system, a simple grep "^>" myfile.fasta should work.

ADD COMMENTlink written 9.0 years ago by Frédéric Mahé3.1k
11
gravatar for Michael Dondrup
9.0 years ago by
Bergen, Norway
Michael Dondrup48k wrote:

Why so complicated? ;) Only the header in a fasta file contains > so you can use grep :

grep -e ">" my.fasta

or awk to remove the >:

$ awk 'sub(/^>/, "")' 
>aksdjfljfd
aksdjfljfd
ADD COMMENTlink modified 18 months ago by _r_am32k • written 9.0 years ago by Michael Dondrup48k

Thanks so much, but i am not familiar with perl code. i need a complete code to run it. if possible guide me more. thanks again

ADD REPLYlink written 9.0 years ago by Mohammad Reza Bakhtiarizadeh290

Thanks. I fixed my problem. regards

ADD REPLYlink written 9.0 years ago by Mohammad Reza Bakhtiarizadeh290

this is not perl, it's unix ;)

ADD REPLYlink written 9.0 years ago by Michael Dondrup48k

what about i want to extract the header and their belonging sequences?

ADD REPLYlink written 6 months ago by bioinfo0
7
gravatar for Caddymob
9.0 years ago by
Caddymob980
United States
Caddymob980 wrote:

Expression in perl would be basically the same as the grep above (m/^>/).. There are easier 1-liner ways to do this, but this is a basic outline of the perl code that should be pretty readable.

#!/usr/bin/perl

open(FASTA, "<your.fa");
while(<FASTA>) {
    chomp($_);
    if ($_ =~  m/^>/ ) {
        my $header = $_;
        print "$header\n";
    }
}
ADD COMMENTlink modified 18 months ago by _r_am32k • written 9.0 years ago by Caddymob980

thanks so much. your code is ok but how can i write it in a text file. i am not familiar with perl code.

thanks

ADD REPLYlink written 9.0 years ago by Mohammad Reza Bakhtiarizadeh290

thanks so much i fixed my problem. regards

ADD REPLYlink written 9.0 years ago by Mohammad Reza Bakhtiarizadeh290
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1908 users visited in the last hour
_