Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

You can print the matching lines with a regular expression that matches only the lines you're interested in:

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

The above will also handle arbitrarily large files, as it reads one line at a time into memory.

There are many hits, but if I want the top ten only, what do i do?

I'm not sure what you mean by top ten, exactly (highest "Score"? "E Value"? Order within the file?), but a likely approach to this would be to modify the above while loop and instead of printing, place each line in a hash. My regular expression already does basic parsing of the input line into capture variables $1 through $5, so you can try something like this:

$hash{$2} = { col1 => $1, desc => $3, score => $4, E => $5 } if /.../; # Use regex above

Then, after the loop finishes, you can sort and display the results however you like. For example:

my $how_many = 10; for (sort { $hash{$b}->{score} <=> $hash{$a}->{score} } keys %hash +) { printf "%-4s %-55s %5s\n", $hash{$_}->{col1}, $hash{$_}->{desc}, $hash{$_}->{score}; last if --$how_many == 0; }

Outputs:

emb plasma membrane H+-ATPase [Oryza sativa Japonica... 213 gb hypothetical protein OsI_09609 [Oryza sativa Indi... 213 ref Os03g0100800 [Oryza sativa Japonica Group] >... 213 gb ATPase 11, plasma membrane-type [Aegilops tauschii] 208 ref PREDICTED: ATPase 7, plasma membrane-type is... 207 ref H(\+)-transporting atpase plant/fungi plasma... 207 ref PREDICTED: plasma membrane ATPase 1-like [Br... 207 ref PREDICTED: ATPase 7, plasma membrane-type is... 207 ref autoinhibited H+ ATPase [Populus trichocarpa... 206 ref PREDICTED: plasma membrane ATPase 1-like iso... 205

In reply to Re: how do i obtain blast result from the given file by rjt
in thread how do i obtain blast result from the given file by bingalee

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (5)
As of 2024-03-29 13:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found