in reply to Searching array against hash
I feel that there should be a more efficient way
There is. Your current process is ~O(900,000*60,000) = 54 billion.
If you reverse the logic of your lookups, by reading the list file into a hash first; you can then read the fasta file line by line and lookup the headers in the hash, which results in an O( 900,000 ) process.
Try this (untested) version which should run close to 60,000 times faster:
#!/usr/bin/perl use strict; use warnings; use diagnostics; use FAlite; die "usage: $0 <fasta> <list>\n" unless @ARGV == 2; my %list; open(LIST, $ARGV[1]) or die; while (<LIST>) { next if /^#/; my ($header, $score) = split; $list{ $header } = $score; } close LIST; open(FASTA, $ARGV[0]) or die; my $fasta = new FAlite(\*FASTA); while (my $entry = $fasta->nextEntry) { if( exists $list{ $entry->def } ) { print $entry->def; print $entry->seq; } } close FASTA; __END__
With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Searching array against hash
by drhicks (Novice) on Aug 21, 2013 at 21:54 UTC | |
by davido (Cardinal) on Aug 21, 2013 at 22:10 UTC |
In Section
Seekers of Perl Wisdom