hw6/blast_get_target_seq.pl
use Bio::Tools::BPlite;
if (! $ARGV[0])
{
print "What is the query file for the blast? ";
chomp ($inFile = <STDIN>);
}
else
{
$inFile = $ARGV[0];
}
if (! $ARGV[1])
{
print "What is the blast file? ";
chomp ($blastFile = <STDIN>);
}
else
{
$blastFile = $ARGV[1];
}
if (! $ARGV[2])
{
print "where does the target file go? ";
chomp ($outFile = <STDIN>);
}
else
{
$outFile = $ARGV[2];
}
print "Wait, it's processing your data...\n";
`blastall -p blastp -d /cluster/db0/Data/nr -i $inFile -o $blastFile`;
$report = new Bio::Tools::BPlite(-file=>"$blastFile");
$i = 0;
open(FH, ">$outFile") || die "Can not write to $outFile\n";
while(my $sbjct = $report->nextSbjct) {
if ($i < 10) {
$targetName = $sbjct->name;
$targetAcc = "";
if ($targetName =~ /^[a-z]+?\|\|([a-z0-9_.-]+)?\s.*/i) {
$targetAcc = $1;
}
elsif ($targetName =~ /^[a-z]+?\|([a-z0-9_.-]+)?\|.*/i) {
$targetAcc = $1;
}
if ($targetAcc ne "") {
$fastaSeq = `fastacmd -d nr -s $targetAcc`;
print FH $fastaSeq;
$i++;
}
}
}
print "Done\n";
close (FH) || die "Can not close $outFile\n";