http://qs321.pair.com?node_id=1100925


in reply to comparing sequence fasta headers

Hello Pasan and welcome to the Monastery.

Of course your code will print "match found" because that is what you are telling it to do. Dump the content of $fastaH1 through Data::Dumper to see how your hash looks like. My piece of advice is that if you are reading from a Bio::SeqIO object then you got to write your output through a Bio::SeqIO object as well. That way you will save yourself from a lot of the unexpected Bio::* behaviors.

other things I noticed in your code is that your open statement doesn't capture failure. Alsoe, if you're using a Bio::SeqIO then you don't need to explicitly import all the parent modules.

use strict; #a good habit to start your prog use warnings; use Bio::SeqIO; #load your codes.txt into an array open(my $fh, "<","codes.txt") or die("could not open codes.txt $!"); # +a more proper way to opening files my @codes=<$fh>; #slurping codes.txt into an array my $obj=Bio::SeqIO->new( #Bio::SeqIO for input -file=>"fasta.fa", -format=>"fasta" ); my $out_obj=Bio::SeqIO->new( #Bio::SeqIO for output -file=>">matching.fa", -format=>"fasta" ); while(my $seq=$obj->next_seq){ foreach my $element (@codes){ chomp $element; if($seq->id=~/$element*?/gi){ #regular-expression based mat +ching $out_obj->write_seq($seq); #output written to matching.fa } } }

David R. Gergen said "We know that second terms have historically been marred by hubris and by scandal." and I am a two y.o. monk today :D, June,12th, 2011...