-
Notifications
You must be signed in to change notification settings - Fork 7
/
simple_blast.pl
62 lines (50 loc) · 1.82 KB
/
simple_blast.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/perl -w
###I can't remember makeblastdb and blast paramters all the time
###Therefore develop this script for simple blast
use Getopt::Std;
getopts "i:d:p:c:e:o:f:n:";
if ((!defined $opt_i)|| (!defined $opt_d) || (!defined $opt_p)) {
die "************************************************************************
Usage: perl simple_blast.pl -i query.fasta -d database -p blastn
-h : help and usage.
-i : query.fasta
-d : database.fasta
-p : program, could be blastn, blastp or blastx
-c : cpu (default 4)
-e : evalue (default 1e-3)
-o : output (default: blast.out)
-f : output format (default 6);
-n : number of alignment (default all)
************************************************************************\n";
}else{
print "************************************************************************\n";
print "Version demo\n";
print "Copyright to Tanger, tanger.zhang\@gmail.com\n";
print "RUNNING...\n";
print "************************************************************************\n";
}
my $database = $opt_d;
my $query = $opt_i;
my $program = $opt_p;
my $cpu = (defined $opt_c)?$opt_c:4;
my $evalue = (defined $opt_e)?$opt_e:1e-3;
my $output = (defined $opt_o)?$opt_o:"blast.out";
my $outfmt = (defined $opt_f)?$opt_f:6;
my $num_aln = (defined $opt_n)?$opt_n:0;
my $dbtype;
if($program eq "blastn"){
$dbtype = "nucl";
}else{
$dbtype = "prot";
}
$files = `ls *`;
print "\n\nWill overwrite dbname\n" if($files =~ /dbname/);
$cmd = "makeblastdb -in ".$database." -dbtype ".$dbtype." -out dbname";
print "$cmd\n";
system($cmd);
$cmd = $program." -query ".$query." -db dbname -out $output -evalue ".$evalue." -outfmt ".$outfmt." -num_threads ".$cpu;
if($num_aln != 0){
$cmd .= " -num_alignments ".$num_aln;
}
print "\n\n$cmd\n";
system($cmd);