Debian Codegraph @

hmmer/profmark/x-fps-fasta

raw
1 #! /usr/bin/perl -w
2
3 # Do a piece of a profmark benchmark, for FASTA searches by FPS
4 # (family-pairwise-search; best E-value of all individual queries).
5 #
6 # This script is normally called by pmark_master.pl; its command line
7 # syntax is tied to pmark_master.pl.
8 #
9 # Usage: x-fasta-fps <top_builddir> <top_srcdir> <resultdir> <tblfile> <msafile> <fafile> <outfile>
10 # Example: ./x-fasta-fps /usr/local/fasta-36x2 ~/src/hmmer testdir test.tbl pmark.msa test.fa test.out
11 #
12 # SRE, Tue Apr 20 10:14:39 2010 [Janelia]
13 # SVN $Id$
14
15 BEGIN {
16 $top_builddir = shift;
17 $top_srcdir = shift;
18 $wrkdir = shift;
19 $tblfile = shift;
20 $msafile = shift;
21 $fafile = shift;
22 $outfile = shift;
23 }
24 use lib "${top_srcdir}/easel/demotic";
25 use demotic_fasta;
26
27 $fasta = "${top_builddir}/bin/fasta36";
28 $opts = "-q";
29
30 if (! -d $top_builddir) { die "didn't find BLAST build directory $top_builddir"; }
31 if (! -d $top_srcdir) { die "didn't find H3 source directory $top_srcdir"; }
32 if (! -x $fasta) { die "didn't find executable $fasta"; }
33 if (! -e $wrkdir) { die "$wrkdir doesn't exist"; }
34
35 open(OUTFILE,">$outfile") || die "failed to open $outfile";
36 open(TABLE, "$tblfile") || die "failed to open $tblfile";
37 MSA:
38 while (<TABLE>)
39 {
40 ($msaname) = split;
41
42 %seen = ();
43 %best_pval = ();
44 %best_bitscore = ();
45
46 `esl-afetch -o $wrkdir/$msaname.sto $msafile $msaname`;
47 if ($?) { print "FAILED: esl-afetch -o $wrkdir/$msaname.sto $msafile $msaname\n"; next MSA; }
48
49 # Extract a list of individual sequence names from the multiple alignment.
50 $output = `esl-seqstat -a $wrkdir/$msaname.sto | grep "^=" | awk '{print \$2}'`;
51 if ($?) { print "FAILED: esl-seqstat -a $wrkdir/$msaname.sto\n"; next MSA; }
52
53 @qnames = split(/^/,$output);
54 chop (@qnames);
55
56 # Loop over each query; blast; accumulate best pval for each target
57 foreach $qname (@qnames)
58 {
59 $output = `esl-sfetch -o $wrkdir/$msaname.query.fa $wrkdir/$msaname.sto $qname`;
60 if ($?) { print "FAILED: esl-sfetch -o $wrkdir/$msaname.query.fa $wrkdir/$msaname.sto $qname\n"; next MSA; }
61
62 if (! open(FASTA, "$fasta $opts $wrkdir/$msaname.query.fa $fafile |")) {
63 print "FAILED: $fasta $opts $wrkdir/$msaname.query.fa $fafile |\n"; next MSA;
64 }
65
66 if (! demotic_fasta::parse(\*FASTA)) {
67 print "FAILED: demotic parser for fasta output\n"; next MSA;
68 }
69
70 for ($i = 0; $i < $demotic_fasta::nhits; $i++)
71 {
72 $target = $demotic_fasta::hit_target[$i];
73 $pval = $demotic_fasta::hit_Eval[$i];
74 $bitscore = $demotic_fasta::hit_bitscore[$i];
75
76 if (! $seen{$target} || $pval < $best_pval{$target})
77 {
78 $seen{$target} = 1;
79 $best_pval{$target} = $pval;
80 $best_bitscore{$target} = $bitscore;
81 }
82 }
83 close FASTA;
84 }
85
86 # Append to the outfile.
87 foreach $target (keys(%seen))
88 {
89 printf OUTFILE "%g %.1f %s %s\n", $best_pval{$target}, $best_bitscore{$target}, $target, $msaname;
90 }
91
92 unlink "$wrkdir/$msaname.sto";
93 unlink "$wrkdir/$msaname.query.fa";
94 }
95 close TABLE;
96 close OUTFILE;