#!/usr/local/bin/perl5 -w

# usage: pull_hits hits_file 

( ($hits_file = shift @ARGV) &&
  ($cutoff    = shift @ARGV) ) ||
    die "usage: pull_hits hits_file cutoff (e.g. 1.0e-5)\n";

$/ = "\/\/\n";

open(HITS, "<$hits_file") ||
    die "could not open file";

while (defined($rec = <HITS>))
{
    @lines = split( "\n", $rec);

    undef $id;

    for ($i = 0; $i < @lines; $i++)
    {
        if ($lines[$i] =~ /Query:\s+(\S+)\s/)
        {
            $id = $1;
        }

        if ( ($lines[$i] =~ /^Parsed for domains/) && 
             ($lines[$i+1] =~ /^Model\s+/) )
        {
            $i += 3;

            while ($lines[$i] !~ /^\s*$/)
            {
                if ($lines[$i] =~ /^(\S+)\s+\d+\/\d+\s+(\d+)\s+(\d+).+\s(\S+)$/)
                {
                    if ($4 <= $cutoff)
                    {
                        print "$id\t$1\t$2\t$3\t$4\n";
                    }
                }
                $i++;
            }
        }
    } 
}

__END__


hmmpfam - search a single seq against HMM database
HMMER 2.1.1 (Dec 1998)
Copyright (C) 1992-1998 Washington University School of Medicine
HMMER is freely distributed under the GNU General Public License (GPL).
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
HMM file:                 Pfam
Sequence file:            Temp/wit_orfs.1.fasta
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Query:  RAA00005  Aquifex_aeolicus_832738_832340 (133 aa)

Scores for sequence family classification (score includes all domains):
Model      Description                                  Score    E-value  N 
--------   -----------                                  -----    ------- ---
flg_bb_rod Flagella basal body rod proteins              27.5    2.2e-05   1

Parsed for domains:
Model      Domain  seq-f seq-t    hmm-f hmm-t      score  E-value
--------   ------- ----- -----    ----- -----      -----  -------
flg_bb_rod   1/1       7    31 ..     1    25 [.    27.5  2.2e-05

Alignments of top-scoring domains:
flg_bb_rod: domain 1 of 1, from 7 to 31: score 27.5, E = 2.2e-05
                   *->LytavsALnaqqtrldvianNiANa<-*
                      L++ +s++ aq++r++++a+N+AN+   
    RAA00005     7    LDISASGMYAQRIRMNTVASNLANY    31   

//
