Debian Codegraph @

profmark/x-fps-diamond

raw
1 #! /usr/bin/perl -w
2
3 # Do a piece of a profmark benchmark, for DIAMOND 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-ncbiblast+-fps <top_builddir> <top_srcdir> <resultdir> <tblfile> <msafile> <fafile> <outfile>
10 # Example: ./x-ncbiblast+-fps /usr/local/ncbi-blast-2.2.21+ ~/src/hmmer/trunk testdir test.tbl pmark.msa test.fa test.out
11 #
12 # SRE, Tue Mar 8 09:12:11 2011
13 # SVN $Id$
14
15
16 BEGIN {
17 $top_builddir = shift;
18 $top_srcdir = shift;
19 $wrkdir = shift;
20 $tblfile = shift;
21 $msafile = shift;
22 $fafile = shift;
23 $outfile = shift;
24 }
25 use lib "${top_srcdir}/easel/demotic";
26 use demotic_blast;
27
28
29 $diamond = "${top_builddir}/diamond";
30 $blastopts = "--threads 1 --max-target-seqs 9999 --outfmt 6 sseqid bitscore evalue";
31
32 if (! -d $top_builddir) { die "didn't find DIAMOND build directory $top_builddir"; }
33 if (! -d $top_srcdir) { die "didn't find H3 source directory $top_srcdir"; }
34 if (! -x $diamond) { die "didn't find executable $diamond"; }
35 if (! -e $wrkdir) { die "$wrkdir doesn't exist"; }
36
37 open(OUTFILE,">$outfile") || die "failed to open $outfile";
38 open(TABLE, "$tblfile") || die "failed to open $tblfile";
39 MSA:
40 while (<TABLE>)
41 {
42 ($msaname) = split;
43
44 %seen = ();
45 %best_pval = ();
46 %best_bitscore = ();
47
48
49
50 `esl-afetch -o $wrkdir/$msaname.sto $msafile $msaname`;
51 if ($?) { print "FAILED: esl-afetch -o $wrkdir/$msaname.sto $msafile $msaname\n"; next MSA; }
52
53 # Extract a list of individual sequence names from the multiple alignment.
54 $output = `esl-seqstat -a $wrkdir/$msaname.sto | grep "^=" | awk '{print \$2}'`;
55 if ($?) { print "FAILED: esl-seqstat -a $wrkdir/$msaname.sto\n"; next MSA; }
56
57 @qnames = split(/^/,$output);
58 chop (@qnames);
59
60
61 # Loop over each query; blast; accumulate best pval for each target
62 foreach $qname (@qnames)
63 {
64
65 $output = `esl-sfetch -o $wrkdir/$msaname.query.fa $wrkdir/$msaname.sto $qname`;
66 if ($?) { print "FAILED: esl-sfetch -o $wrkdir/$msaname.query.fa $wrkdir/$msaname.sto $qname\n"; next MSA; }
67
68 if (! open(BLASTP, "$diamond blastp --db $fafile --query $wrkdir/$msaname.query.fa $blastopts |")) {
69 print "FAILED: $diamond blastp --db $fafile --query $wrkdir/$msaname.query.fa $blastopts |\n"; next MSA;
70 }
71
72
73 if (! demotic_blast::parse_diamond(\*BLASTP)) {
74 print "FAILED: demotic parser for diamond output\n"; next MSA;
75 }
76
77 for ($i = 0; $i < $demotic_blast::nhits; $i++)
78 {
79 $target = $demotic_blast::hit_target[$i];
80 $pval = $demotic_blast::hit_Eval[$i];
81 $bitscore = $demotic_blast::hit_bitscore[$i];
82
83 if (! $seen{$target} || $pval < $best_pval{$target})
84 {
85 $seen{$target} = 1;
86 $best_pval{$target} = $pval;
87 $best_bitscore{$target} = $bitscore;
88
89 }
90 }
91
92 close BLASTP;
93 }
94
95 # Append to the outfile.
96
97 foreach $target (keys(%seen))
98 {
99 printf OUTFILE "%g %.1f %s %s\n", $best_pval{$target}, $best_bitscore{$target}, $target, $msaname;
100 }
101
102
103 unlink "$wrkdir/$msaname.sto";
104 unlink "$wrkdir/$msaname.query.fa";
105 }
106 close TABLE;
107 close OUTFILE;