in reply to Re^3: fasta hash
in thread fasta hash
I have changed the code, but now my problem seems to be that I can only access the last line of the output outside the loops. I wonder if there's a way to store the variables inside the loop to be accessible outside. The code looks like this now.
if(@ARGV < 3){ die "Not enough arguments\n"; } $sequence=""; $fastaID; open(FILE1,"$ARGV[0]") or die "No fasta file provided in command line: + $!\n"; while ($line=<FILE1>){ chomp($line); if ($line=~/^\s*$/){ next; }elsif ($line=~/^.*$/){ $fastaID=$line; $fastahash{$fastaID}=1; } } open(FILE2,"$ARGV[2]") or die "No fasta file provided in command line: + $!\n"; while($line2=<FILE2>){ chomp($line2); if ($line2=~/^>/){ @data=split(" ",$line2); $fasta=$data[1]; $sequence=""; }else{ $sequence.=$line2; } } if (exists $fastahash{$fasta}){ print "$fastaID\t $sequence\n"; } exit;
And the output, which is just the last key value in the fastahash is
2056360013 Musacgagchagshgashcgahcgacacsasasasacsacsasasacacaasc +assacsaascascascascac
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: fasta hash
by moritz (Cardinal) on Aug 26, 2011 at 16:38 UTC | |
by morio56 (Initiate) on Aug 26, 2011 at 19:10 UTC | |
by moritz (Cardinal) on Aug 26, 2011 at 19:40 UTC | |
by Marshall (Canon) on Aug 28, 2011 at 15:32 UTC |