Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Re: comparing sequence fasta headers

by biohisham (Priest)
on Sep 17, 2014 at 13:24 UTC ( #1100925=note: print w/replies, xml ) Need Help??

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...

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1100925]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (3)
As of 2021-10-22 23:08 GMT
Find Nodes?
    Voting Booth?
    My first memorable Perl project was:

    Results (86 votes). Check out past polls.