Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re^3: how do i obtain blast result from the given file

by rjt (Curate)
on Jun 17, 2013 at 20:15 UTC ( [id://1039465]=note: print w/replies, xml ) Need Help??


in reply to Re^2: how do i obtain blast result from the given file
in thread how do i obtain blast result from the given file

In that case, just modify the initial loop to stop after ten hits:

my $how_many = 10; while (<$fh>) { if (/^(.+?)\|(.+?)\| (.+?)\s+(\d+)\s+(\d+e[+-]\d+)$/) { print; last if --$how_many == 0; } }

If that's all you want to do, you don't need the hash. Note that you can still format the output with printf: printf "%-4s %-55s %5s\n", $1, $3, $4;

You could still use the hash, as well, if you need to do further processing on the results. In that case, to preserve the order, either add an index to the hash ref for use with sort, or, simpler, push each key to an array as you find them:

my @hits; # Keys in order my $how_many = 10; while (<$fh>) { if (/^(.+?)\|(.+?)\| (.+?)\s+(\d+)\s+(\d+e[+-]\d+)$/) { $hash{$2} = { col1 => $1, desc => $3, score => $4, E => $5, key => $2 }; push @hits, $2; last if --$how_many == 0; } } # Go through the first ten hits, in order for (map { $hash{$_} } @hits) { # $_ contains the hash ref for each record printf "%-5s %-55s %5s\n", $_->{col1}, $_->{desc}, $_->{score}; }

Replies are listed 'Best First'.
Re^4: how do i obtain blast result from the given file
by bingalee (Acolyte) on Jun 18, 2013 at 19:52 UTC

    thank you :)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2024-03-19 11:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found