Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: replace FASTA sequence headers

by jwkrahn (Monsignor)
on Jun 10, 2012 at 19:34 UTC ( #975474=note: print w/ replies, xml ) Need Help??


in reply to replace FASTA sequence headers

It sounds like you want something like this:

use strict; use warnings; @ARGV == 2 or die "usage: $0 <multifasta file> <header replacement fil +e>\n"; my ( $fasta_file, $header_file ) = @ARGV; my $destination = $fasta_file . '_headers-replaced.fasta'; open IN2, '<', $header_file or die "Can't read from tab-delimited head +er replacement file $header_file: $!\n"; my %head_seqs; while ( <IN2> ) { chomp; my ( $old, $new ) = split /\t/; $head_seqs{ $old } = $new; } close IN2; open IN1, '<', $fasta_file or die "Can't read from multifasta file wit +h alternating lines of headers and sequences $fasta_file: $!\n"; open OUT, '>', $destination or die "Can't write to file $destination: +$!\n"; while ( <IN1> ) { if ( /^>(.+)$/ && exists $head_seqs{ $1 } ) { $_ = ">$head_seqs{ $1 }\n"; } print OUT $_; } close IN1; close OUT;


Comment on Re: replace FASTA sequence headers
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://975474]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2014-07-26 14:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (177 votes), past polls