Codebase list barrnap / 1c9755d
Issue #15 | support STDIN Torsten Seemann 5 years ago
2 changed file(s) with 29 addition(s) and 9 deletion(s). Raw diff Collapse all Expand all
1313 - "barrnap --help"
1414 - "barrnap --citation"
1515 - "! barrnap --doesnotexist"
16 - "barrnap 2>&1 | grep 'ERROR: No input file'"
1617 - "barrnap -q --kingdom bac examples/bacteria.fna"
1718 - "barrnap -q --kingdom arc examples/bacteria.fna"
1819 - "barrnap -q --kingdom mito examples/mitochondria.fna"
2021 - "! barrnap examples/empty.fna"
2122 - "! barrnap examples/null.fna"
2223 - "barrnap -q examples/small.fna | grep 16S_rRNA"
24 - "barrnap -q < examples/small.fna | grep 16S_rRNA"
25 - "barrnap -q - < examples/small.fna | grep 16S_rRNA"
2326 - "barrnap examples/nohits.fna 2>&1 | grep 'Found 0 '"
2427 - "barrnap --threads 2 examples/small.fna"
2528 - "barrnap -q --incseq examples/small.fna | grep '^>'"
22 use warnings;
33 use List::Util qw(max);
44 use FindBin;
5 use File::Temp;
56
67 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
78 # global variables
910 my $EXE = $FindBin::RealScript;
1011 my $VERSION = "0.9-dev";
1112 my $DESC = "rapid ribosomal RNA prediction";
12 my $AUTHOR = 'Torsten Seemann <torsten.seemann@gmail.com>';
13 my $AUTHOR = 'Torsten Seemann';
1314 my $URL = 'https://github.com/tseemann/barrnap';
1415 my $DBDIR = "$FindBin::RealBin/../db";
1516 my $OPSYS = $^O;
6364 msg("Using database: $hmmdb");
6465
6566 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
67 # check if user is piping to STDIN
68 # nhmmer needs to fseek() so we make a temp fasta file
69
70 my $fasta = shift @ARGV;
71 my $tmpfh;
72 if (defined($fasta) && $fasta eq '-' or !defined($fasta) && !-t \*STDIN) {
73 $tmpfh = File::Temp->new(UNLINK=>1);
74 msg("Copying STDIN to a temporary file:", $tmpfh->filename);
75 while (<STDIN>) {
76 print $tmpfh $_;
77 }
78 $fasta = $tmpfh->filename;
79 }
80 $fasta && -r $fasta or err("No input file on command line or stdin");
81
82 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
6683 # run the external command
67
68 my $fasta = shift @ARGV;
69 $fasta && -r $fasta or err("Usage: $EXE <file.fasta>");
7084
7185 msg("Scanning $fasta for $kdom rRNA genes... please wait");
7286 my $cmd = "$NHMMER --cpu $threads -E $evalue --w_length $MAXLEN -o /dev/null --tblout /dev/stdout \Q$hmmdb\E \Q$fasta\E";
160174
161175 sub err {
162176 $quiet=0;
163 msg(@_);
177 msg("ERROR:", @_);
164178 exit(2);
165179 }
166180
178192
179193 If you use Barrnap in your work, please cite:
180194
181 Seemann T (2017)
195 Seemann T
182196 $EXE $VERSION : $DESC
183197 $URL
184198
204218 {OPT=>"quiet!", VAR=>\$quiet, DEFAULT=>0, DESC=>"No screen output"},
205219 {OPT=>"threads=i", VAR=>\$threads, DEFAULT=>1, DESC=>"Number of threads/cores/CPUs to use"},
206220 {OPT=>"lencutoff=f",VAR=>\$lencutoff, DEFAULT=>0.8, DESC=>"Proportional length threshold to label as partial"},
207 {OPT=>"reject=f",VAR=>\$reject, DEFAULT=>0.5, DESC=>"Proportional length threshold to reject prediction"},
221 {OPT=>"reject=f",VAR=>\$reject, DEFAULT=>0.25, DESC=>"Proportional length threshold to reject prediction"},
208222 {OPT=>"evalue=f",VAR=>\$evalue, DEFAULT=>1E-6, DESC=>"Similarity e-value cut-off"},
209223 {OPT=>"incseq!", VAR=>\$incseq, DEFAULT=>0, DESC=>"Include FASTA input sequences in GFF3 output"},
210224 # {OPT=>"outseq!", VAR=>\$outseq, DEFAULT=>'', DESC=>"Save hits to this FASTA file"},
211225 );
212226
213 (!@ARGV) && (usage(1));
227 # (!@ARGV) && (usage(1));
214228
215229 &GetOptions(map {$_->{OPT}, $_->{VAR}} grep { ref } @Options) || usage(1);
216230
232246
233247 print "Synopsis:\n $EXE $VERSION - $DESC\n";
234248 print "Author:\n $AUTHOR\n";
235 print "Usage:\n $EXE [options] <chromosomes.fasta>\n";
249 print "Usage:\n";
250 print " $EXE [options] chr.fa\n";
251 print " $EXE [options] < chr.fa\n";
252 print " $EXE [options] - < chr.fa\n";
236253 foreach (@Options) {
237254 if (ref) {
238255 my $def = defined($_->{DEFAULT}) ? " (default '$_->{DEFAULT}')" : "";