beginner27 has asked for the wisdom of the Perl Monks concerning the following question:
Hi all,
I am dealing with a FASTA file with multiple IDs (the same ID can be repeated) and the corresponding sequence. My idea was to create an Hash with as keys the IDs, in order to have a list without repetitions, and as values an array containing the sequence/sequences of the same ID. I need that each sequence is an element of the array. My script works as long as it stores the first and the second sequence in the array, from the third the data are no longer correct...
Hope to have been clear enough! I tried everything but nothing works..and the best would be not using any modules.
Thanks
my $tot = 0; my $current_ID = 1; while ( my $line = <IN> ){ chomp( $line ); if ( $line =~ /^>/ ) { $title= $line; $tot++; }else{ $seq.= $line; shift @{$hash{$title}}; push (@{$hash{$title}}, $seq); } if ($tot > $current_ID) { $current_ID ++; push (@{$hash{$title}}, $seq); $seq = ""; } }
|
|---|