Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
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 imbibing at the Monastery: (5)
As of 2015-07-30 00:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (269 votes), past polls