-
Notifications
You must be signed in to change notification settings - Fork 5
/
psortb
executable file
·136 lines (109 loc) · 4.79 KB
/
psortb
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#!/usr/bin/perl
# Perl script wrapper to run a "docker run" command which runs
# PSORTb inside the docker container.
use strict;
use Getopt::Long;
use File::Basename;
use Cwd 'abs_path';
our $docker_results_dir = "/tmp/results";
our $docker_image = "brinkmanlab/psortb_commandline:1.0.2";
sub main {
my ($seqfile, $help, $nondocker_results_dir);
my ($positive, $negative, $archaea, $xskiploc);
my ($format, $verbose, $cutoff, $exact, $version, $output, $divergent);
my @args = @ARGV;
my $extra_args = remove_unneeded_args(\@args);
GetOptions('seq|i=s' => \$seqfile, 'positive|p' => \$positive,
'archaea|a' => \$archaea, 'negative|n' => \$negative,
'x-skip-localization' => \$xskiploc,
'help|h' => \$help, 'outdir|r=s' => \$nondocker_results_dir,
'format|f=s' => \$format, 'divergent|d=f' => \$divergent,
'verbose|v' => \$verbose,
'cutoff|c=f' => \$cutoff, 'output|o=s' => \$output,
'exact|e' => \$exact, 'version' => \$version);
usage() if($help);
if ($version) {
my $cmd = "sudo docker run --rm -ti $docker_image /usr/local/psortb/bin/psort --version";
#print "cmd = $cmd\n";
system($cmd);
exit(0);
}
if (! -d $nondocker_results_dir) {
print "Please enter a valid local directory to store the PSORTb results in (-r).\n";
usage();
}
elsif (! -e $seqfile) {
print "Please enter a valid FASTA-format protein sequence file (-i).\n";
}
$seqfile = abs_path($seqfile);
$nondocker_results_dir = abs_path($nondocker_results_dir);
$nondocker_results_dir =~ s/\/$//; # remove trailing slash if present
my $seqfilename = basename($seqfile);
my $nondocker_seqfile = "$nondocker_results_dir/$seqfilename";
my $docker_seqfile = "$docker_results_dir/$seqfilename";
# copy file to mount directory (if it doesn't already exist)
my $seqfile_copied = make_file_copy($seqfile, $nondocker_seqfile);
my $cmd = "sudo docker run --rm -v $nondocker_results_dir:$docker_results_dir -e MOUNT='$nondocker_results_dir' -ti $docker_image /usr/local/psortb/bin/psort $extra_args -i $docker_seqfile";
#print "cmd = $cmd\n";
system($cmd);
# remove copied files (if they were created)
delete_file($nondocker_seqfile, $seqfile_copied);
}
sub make_file_copy {
my ($orig_file, $new_file) = @_;
my $cmd = "cp $orig_file $new_file";
system($cmd);
die "Could not copy file: $cmd: $@\n" if $@;
}
sub delete_file {
my ($file, $delete_flag) = @_;
if ($delete_flag) {
my $cmd = "rm $file";
system($cmd);
die "Could not delete file: $cmd: $@\n" if $@;
}
}
sub remove_unneeded_args {
my $args = shift;
# remove -r (non-docker results dir) because inside docker, the
# "Saving results to <-r option value>" is provided by an environment
# variable.
# Remove -i <local file> (because we need to use -i <container file>)
my @modified_arg_list;
for (my $i=0; $i<scalar(@$args); $i++) {
if (($$args[$i] eq '-r') ||
($$args[$i] eq '--outdir') ||
($$args[$i] eq '-i') ||
($$args[$i] eq '--seq')) {
$i++;
}
else {
push(@modified_arg_list, $$args[$i]);
}
}
return( join(" ", @modified_arg_list) );
}
sub usage {
$0 =~ /^.*\/(.+)/;
print("\nUsage: $1 -i <sequence file> -r <local results directory> [-n|-p|-a] [OPTIONS]\n");
print("Example command: psortb -n -i myseqs.fasta -r /tmp/psortb_results\n");
print(" --seq, -i Input sequence file path (required)\n");
print(" --positive, -p Gram positive bacteria\n");
print(" --negative, -n Gram negative bacteria\n");
print(" --archaea, -a Archaea\n");
print(" --outdir, -r Path of where to save results files.\n");
print(" --cutoff, -c Sets a cutoff value for reported results\n");
print(" --divergent, -d Sets a cutoff value for the multiple\n");
print(" localization flag\n");
print(" --format, -f Specifies sequence format (default is FASTA)\n");
print(" --exact, -e Skip SCLBLASTe (useful for batch runs of data\n");
print(" against itself in SCLBLAST)\n");
print(" --output, -o Specifies the format for the output (default is\n");
print(" 'normal'). Value can be one of: normal, terse or long\n");
print(" --verbose, -v Be verbose while running\n");
print(" --version Print the version of PSortb\n");
print(" --x-skip-localization Comma-separated list of localizations to skip\n");
print(" --help, -h Displays usage information\n\n");
exit(0);
}
main();