Changrong Ge wrote:
Hi guys,

Hello,

     Thanks a lot for this issue and with Anjan's help here I got the
wonderful script for my work and I post below, hopefully it would be helpful
for others--works perfectly for fasta file.
     Also thanks to others who are interested in the discussion, but I think
it takes time for me to digest those "weird" symbols-----Tack Så Mycket!!!
     Have a nice day
     Changrong



usage: perl seqComp.pl<input_fasta_file>  >  <output_file>


#! /usr/bin/perl -w
use strict;

open (S, "$ARGV[0]") || die "cannot open FASTA file to read: $!";

my %s;# a hash of arrays, to hold each line of sequence
my %seq; #a hash to hold the AA sequences.
my $key;

while (<S>){ #Read the FASTA file.
     chomp;

     if (/>/){
         s/>//;
         $key= $_;
     }else{
         push (@{$s{$key}}, $_);
     }

}

foreach my $a (keys %s){
     my $s= join("", @{$s{$a}});
     $seq{$a}=$s;
     #print("$a\t$s\n");
}

You don't need two loops for that, you could just do:

while ( <S> ) { #Read the FASTA file.
    chomp;

    if ( s/>// ) {
        $key = $_;
    }
    else {
        $seq{ $key } .= $_;
    }
}




John
--
Any intelligent fool can make things bigger and
more complex... It takes a touch of genius -
and a lot of courage to move in the opposite
direction.                   -- Albert Einstein

--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/


Reply via email to