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

bingalee has asked for the wisdom of the Perl Monks concerning the following question:

I have a file of blast results of different sequences. Some of them have "no hits found", and the others have hits. How do I obtain the lines which have the results , ignoring the initial lines.

Here"s what a file looks like

BLASTX 2.2.26 [Sep-21-2011] Reference: Altschul, Stephen F., Thomas L. Madden, Alejandro A. Schaff +er, Jinghui Zhang, Zheng Zhang, Webb Miller, and David J. Lipman (1997), "Gapped BLAST and PSI-BLAST: a new generation of protein database sear +ch programs", Nucleic Acids Res. 25:3389-3402. Query= XLOC_000039-chr1:983051-985037 (1987 letters) Database: nr 26,236,801 sequences; 9,088,244,489 total letters Searching..................................................done Score + E Sequences producing significant alignments: (bits +) Value ref|XP_002322127.1| autoinhibited H+ ATPase [Populus trichocarpa... +195 2e-93 emb|CAD29314.1| plasma membrane H+-ATPase [Oryza sativa Japonica... +213 1e-55 ref|NP_001048647.1| Os03g0100800 [Oryza sativa Japonica Group] >... +213 1e-55 gb|EEC74325.1| hypothetical protein OsI_09609 [Oryza sativa Indi... +213 1e-55 gb|EMT10609.1| ATPase 11, plasma membrane-type [Aegilops tauschii] +208 3e-54 ref|XP_002511598.1| H(\+)-transporting atpase plant/fungi plasma... +207 3e-54 ref|XP_002274074.1| PREDICTED: ATPase 7, plasma membrane-type is... +207 5e-54 ref|XP_003633895.1| PREDICTED: ATPase 7, plasma membrane-type is... +207 6e-54 gb|AAA34099.1| plasma membrane H+ ATPase, partial [Nicotiana plu... +197 8e-54 ref|XP_003562242.1| PREDICTED: plasma membrane ATPase 1-like [Br... +207 8e-54 ref|XP_002326870.1| autoinhibited H+ ATPase [Populus trichocarpa... +206 1e-53 ref|XP_003529038.1| PREDICTED: plasma membrane ATPase 1-like iso... +205 4e-53

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

here"s the code i got so far for my entire task, I managed to do the first part, but am stuck at this one

#!usr/bin/perl -w open(IN,"/home/maize/sequence-ID.txt"); open(OUT,">abc.txt"); open(OUT1,">blastresults.txt"); while($id=<IN>) { $id=~s/\n|\r//g; open(BLAST,"output/$id"); while($file=<BLAST>) { if ($file=~ m/No hits found/) { print OUT "$id \n"; } } close(BLAST); } close(IN); close(OUT); close(OUT1);

so now i've created a text file which has the names of all those files without any hits. Now i have to create another file with the names of those which have significatn hits, along with the first ten hits. Please help :(

EDIT

I figured one way of doing it,

#!usr/bin/perl -w open(IN,"/home/adithie/datasets/maize/sequence-ID.txt"); open(OUT,">lncRNA3.txt"); open(OUT1,">blastresults2.txt"); while($id=<IN>) { $id=~s/\n|\r//g; open(BLAST,"output/$id"); for($i=0;$i<16;$i++){<BLAST>;} $raw=<BLAST>; if ($raw=~ m/No hits found/) { print OUT "$id\n"; } else { <BLAST>; <BLAST>; <BLAST>; <BLAST>; $raw=<BLAST>; print OUT1 "$id\n"; $count=0; while(length($raw)>10 && $count<=10) { $count++; print OUT1 "$raw"; $raw=<BLAST>; } } close(BLAST); } close(IN); close(OUT); close(OUT1);