Codebase list barrnap / c4cbceb
Issue #24 | return 0 on --help Torsten Seemann 6 years ago
1 changed file(s) with 34 addition(s) and 19 deletion(s). Raw diff Collapse all Expand all
88 # global variables
99
1010 my $EXE = $FindBin::RealScript;
11 my $VERSION = "0.8";
11 my $VERSION = "0.9-dev";
1212 my $DESC = "rapid ribosomal RNA prediction";
1313 my $AUTHOR = 'Torsten Seemann <torsten.seemann@gmail.com>';
1414 my $URL = 'https://github.com/tseemann/barrnap';
2626 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2727 # command line options
2828
29 my(@Options, $quiet, $kingdom, $threads, $evalue, $lencutoff, $reject, $incseq);
29 my(@Options, $quiet, $kingdom, $threads, $evalue, $lencutoff, $reject, $incseq, $outseq);
3030 setOptions();
3131
3232 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
5757 msg("Will reject genes < $reject of expected length.");
5858
5959 my $kdom = $KINGDOM{ lc substr($kingdom,0,1) } or
60 err("I don't recognise --kingdom '$kingdom'. Try: bac arc euk mito");
60 err("I don't recognise --kingdom '$kingdom'. Try:", values(%KINGDOM) );
6161
6262 my $hmmdb = "$DBDIR/$kdom.hmm";
6363 err("Can't find database: $hmmdb") unless -r $hmmdb;
7070 $fasta && -r $fasta or err("Usage: $EXE <file.fasta>");
7171
7272 msg("Scanning $fasta for $kdom rRNA genes... please wait");
73 my $cmd = "$NHMMER --cpu $threads -E $evalue --w_length $MAXLEN -o /dev/null --tblout /dev/stdout \Q$hmmdb\E \Q$fasta\E";
73 my $cmd = "$NHMMER --cpu $threads -E $evalue --w_length $MAXLEN -o /dev/null --tblout /dev/stdout \Q$hmmdb\E \Q$fasta\E";
7474 msg("Command: $cmd");
7575 my @hits = qx($cmd 2>&1);
7676
7777 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
7878 # process the output
7979
80 my @hitseq;
8081 my @feat;
8182 HIT:
8283 foreach (@hits) {
139140 print while (<FASTA>); # `cat $fasta`
140141 }
141142
143 if ($outseq) {
144 msg("Saving hit sequences to '$outseq'");
145 open my $OUT, '>', $outseq;
146 for my $h (@hitseq) {
147 print $OUT ">",$h->[0],"\n",$h->[1],"\n";
148 }
149 close $OUT;
150 }
151
142152 #----------------------------------------------------------------------
143153
144154 sub msg {
170180
171181 If you use Barrnap in your work, please cite:
172182
173 Seemann T (2013)
183 Seemann T (2017)
174184 $EXE $VERSION : $DESC
175185 $URL
176186
192202 {OPT=>"help", VAR=>\&usage, DESC=>"This help"},
193203 {OPT=>"version", VAR=>\&version, DESC=>"Print version and exit"},
194204 {OPT=>"citation",VAR=>\&show_citation, DESC=>"Print citation for referencing $EXE"},
195 {OPT=>"kingdom=s", VAR=>\$kingdom, DEFAULT=>'bac',
196 DESC=>"Kingdom: ".join(' ', values %KINGDOM) },
205 {OPT=>"kingdom=s", VAR=>\$kingdom, DEFAULT=>'bac', DESC=>"Kingdom: ".join(' ', values %KINGDOM) },
197206 {OPT=>"quiet!", VAR=>\$quiet, DEFAULT=>0, DESC=>"No screen output"},
198207 {OPT=>"threads=i", VAR=>\$threads, DEFAULT=>8, DESC=>"Number of threads/cores/CPUs to use"},
199208 {OPT=>"lencutoff=f",VAR=>\$lencutoff, DEFAULT=>0.8, DESC=>"Proportional length threshold to label as partial"},
200209 {OPT=>"reject=f",VAR=>\$reject, DEFAULT=>0.5, DESC=>"Proportional length threshold to reject prediction"},
201210 {OPT=>"evalue=f",VAR=>\$evalue, DEFAULT=>1E-6, DESC=>"Similarity e-value cut-off"},
202211 {OPT=>"incseq!", VAR=>\$incseq, DEFAULT=>0, DESC=>"Include FASTA input sequences in GFF3 output"},
212 # {OPT=>"outseq!", VAR=>\$outseq, DEFAULT=>'', DESC=>"Save hits to this FASTA file"},
203213 );
204214
205 (!@ARGV) && (usage());
206
207 &GetOptions(map {$_->{OPT}, $_->{VAR}} grep { ref } @Options) || usage();
215 (!@ARGV) && (usage(1));
216
217 &GetOptions(map {$_->{OPT}, $_->{VAR}} grep { ref } @Options) || usage(1);
208218
209219 # Now setup default values.
210220 foreach (@Options) {
217227 #----------------------------------------------------------------------
218228
219229 sub usage {
220 print STDERR "Synopsis:\n $EXE $VERSION - $DESC\n";
221 print STDERR "Author:\n $AUTHOR\n";
222 print STDERR "Usage:\n $EXE [options] <chromosomes.fasta>\n";
230 my($exitcode) = @_;
231 $exitcode = 0 if $exitcode eq 'help'; # what gets passed by getopt func ref
232 $exitcode ||= 0;
233 select STDERR if $exitcode; # write to STDERR if exitcode is error
234
235 print "Synopsis:\n $EXE $VERSION - $DESC\n";
236 print "Author:\n $AUTHOR\n";
237 print "Usage:\n $EXE [options] <chromosomes.fasta>\n";
223238 foreach (@Options) {
224239 if (ref) {
225240 my $def = defined($_->{DEFAULT}) ? " (default '$_->{DEFAULT}')" : "";
229244 $opt =~ s/=s$/ [X]/;
230245 $opt =~ s/=i$/ [N]/;
231246 $opt =~ s/=f$/ [n.n]/;
232 printf STDERR " --%-15s %s%s\n", $opt, $_->{DESC}, $def;
247 printf " --%-15s %s%s\n", $opt, $_->{DESC}, $def;
233248 }
234249 else {
235 print STDERR "$_\n";
250 print "$_\n";
236251 }
237252 }
238 exit(1);
239 }
240
241 #----------------------------------------------------------------------
253 exit($exitcode);
254 }
255
256 #----------------------------------------------------------------------