Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

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;

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://975474]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (6)
As of 2017-03-30 13:33 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (359 votes). Check out past polls.