Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

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]
[Corion]: Mhrrrr. Some project made changes to a report I ingest. I tell them "the format of the new rows is bad". They change it, without understanding/ knowing what other systems might act on this suffix. While it now works for me, I'm not really happy with ...
[Corion]: ... their approach to changing things and waiting who screams at them.

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (10)
As of 2017-07-24 14:08 GMT
Find Nodes?
    Voting Booth?
    I came, I saw, I ...

    Results (354 votes). Check out past polls.