-
Notifications
You must be signed in to change notification settings - Fork 0
/
perform_sequence_search.pl
executable file
·90 lines (75 loc) · 2.1 KB
/
perform_sequence_search.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/perl
## Pombert Lab, 2022
my $name = 'perform_sequence_search.pl';
my $version = '0.0.2';
my $updated = '2022-07-22';
use strict;
use warnings;
use Getopt::Long qw(GetOptions);
use File::Path qw(make_path);
my $usage = <<"EXIT";
OPTIONS
-f (--faa) .faa files from genome
-u (--uni) UniProt FASTA directory
-t (--threads) Threads [Default: 4]
-e (--eval) E-value cutoff [Default: 1e-10]
-o (--outdir) Output directory [Default: SEQUENCE_SEARCH]
EXIT
die "\n".$usage."\n\n" unless @ARGV;
my @subs;
my $queries;
my $threads = 4;
my $eval = "1e-10";
my $outdir = "SEQUENCE_SEARCH";
GetOptions(
'f|faa=s{1,}' => \@subs,
'u|uni=s' => \$queries,
't|threads=s' => \$threads,
'e|eval=s' => \$eval,
'o|outdir=s' => \$outdir,
);
my $results_dir = $outdir."/"."RESULTS";
my @dirs = ($outdir,$results_dir);
foreach my $dir (@dirs){
unless(-d $dir){
make_path($dir,{mode=>0755}) or die "Unable to create directory $dir: $!\n";
}
}
unless (-f $outdir."/DB.dmnd"){
system("diamond makedb --in @subs --db $outdir/DB");
}
opendir(DIR,$queries) or die "Unable to access directory $queries: $!\n";
foreach my $item (readdir(DIR)){
unless (-d $queries."/".$item){
my ($accession) = $item =~ /(\w+)\.fasta$/;
unless (-f $results_dir."/".$accession.".diamond.6"){
system("
diamond \\
blastp \\
--threads $threads \\
--db $outdir/DB \\
--out $results_dir/$accession.diamond.6 \\
--outfmt 6\\
--query $queries/$item \\
--evalue $eval \\
1>/dev/null 2>$outdir/diamond.errors
")
}
}
}
open OUT, ">", $outdir."/All_sequence_results.tsv" or die "Unable to access file $outdir/All_sequence_results.tsv: $!\n";
opendir(DIR,$results_dir) or die "Unable to access directory $results_dir: $!\n";
foreach my $item (readdir(DIR)){
unless(-d $results_dir."/".$item){
my ($accession) = $item =~ /(\w+).diamond.6/;
open IN, "<", $results_dir."/".$item or die "Unable to access file $results_dir/$item: $!\n";
print OUT "## $accession\n";
while (my $line = <IN>){
chomp($line);
my @data = split("\t",$line);
shift(@data);
print OUT join("\t",@data)."\n";
}
print OUT "\n";
}
}