script/or.pl untested

filter: Statementstmt 0.0% 0 / 122 Branchbran 0.0% 0 / 52 Conditioncond 0.0% 0 / 78 MC/DCmcdc 0.0% 0 / 43 Subroutinesub 0.0% 0 / 10 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 307 CC 12 SCAR 34.5
CC
12
Cov
0%
fasta_filter
56.0
hmm_disc
42.0
BEGIN
2.0
CRAP 31.4
1 #!/usr/local/bin/perl
2 # $Revision: 2.0 $
3 # $Date: 2016/06/15 $
4 # $Id: or.pl $
5 # $Author: Michael Bekaert $
6 #
7 # Olfactory Receptor family Assigner (ORA) [bioperl module]
8 # Copyright 2007-2016 Bekaert M <michael.bekaert@stir.ac.uk>
9 #
10 # This program is free software: you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation, either version 3 of the License, or
13 # (at your option) any later version.
14 #
15 # This program is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
19 #
20 # You should have received a copy of the GNU General Public License
21 # along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #
23 use strict;
24 use warnings;
25 use Getopt::Long;
26 use File::Basename qw/ dirname /;
27 use Cwd qw/ abs_path /;
28 use Bio::Seq;
29 use Bio::SeqIO;
30 use Bio::ORA;
31  
32 #----------------------------------------------------------
33 my $VERSION = '2.0';
34  
35 #----------------------------------------------------------
36 sub hmm_disc
37 {
38 my (
39 $seq, $name, $id, $translate, $evalue,
40 $format, $detail, $aug, $hmm, $filter,
41 $frag, $subset, $organism
42 ) = @_;
43 my $chrom;
44 if (defined $name) { $chrom = $name . q{_} . $id; }
45 elsif (defined $seq->display_id) { $chrom = $seq->display_id; }
46 else { $chrom = 'noname_' . $id; }
47 $seq->display_id($chrom);
48 my $ora_obj = Bio::ORA->new($seq, $translate, $aug, $hmm);
49 $ora_obj->{'_frag'} = $frag if (defined $frag);
50  
51 if (
52 $ora_obj->find($evalue)
53 && (
54 !(defined $filter)
55 || ( (defined $filter)
56 && (substr($ora_obj->{'_hmmor'}[1], 2) == $filter))
57 )
58 )
59 {
60  
61 if (defined $subset)
62 {
63 my $out =
64 Bio::SeqIO->new('-format' => 'fasta', '-file' => ">>$subset");
65 $out->write_seq($seq);
66 }
67 $ora_obj->show($format, $detail, $organism);
68 }
69 return $ora_obj->{'_verbose'};
70 }
71  
72 sub fasta_filter
73 {
74 my (
75 $seq, $ref, $id, $translate, $evalue,
76 $format, $detail, $aug, $hmm, $filter,
77 $frag, $subset, $organism
78 ) = @_;
79 my $mess = '* FASTA search for ' . $seq->display_id . "\n";
80 my @hits = Bio::ORA->getHits($seq, 1, $ref);
81 if ($#hits >= 0)
82 {
83 for (my $i = 0 ; $i <= $#hits ; $i++)
84 {
85 my ($hitstrand, $hitstart, $hitend) = split m/\|/, $hits[$i];
86 my $seqstart = $hitstart - 250;
87 $seqstart = 1 if ($seqstart < 1);
88 my $seqend = $hitend + 250;
89 $seqend = $seq->length() if ($seqend > $seq->length());
90 my $seq_or = Bio::Seq->new(
91 -seq => $seq->subseq($seqstart, $seqend),
92 -alphabet => 'dna',
93 -id => $seq->display_id . ":$seqstart-$seqend"
94 );
95 my $ora_obj = Bio::ORA->new($seq_or, $translate, $aug, $hmm);
96 $ora_obj->{'_frag'} = $frag if (defined $frag);
97  
98 if (
99 $ora_obj->find($evalue, $hitstrand, $seqstart, $seqend)
100 && (
101 !(defined $filter)
102 || ( (defined $filter)
103 && (substr($ora_obj->{'_hmmor'}[1], 2) == $filter))
104 )
105 )
106 {
107  
108 if (defined $subset)
109 {
110 my $out =
111 Bio::SeqIO->new('-format' => 'fasta',
112 '-file' => ">>$subset");
113 $out->write_seq($seq_or);
114 }
115 $ora_obj->show($format, $detail, $organism);
116 }
117 $mess .= q{ } . $ora_obj->{'_verbose'};
118 }
119 }
120 else { $mess = '* No FASTA hit for ' . $seq->display_id . "\n"; }
121 return $mess;
122 }
123  
124 #------------------------ Main ----------------------------
125 my (
126 $infile, $translate, $name, $filter, $subset,
127 $aug, $frag, $resume, $organism
128 );
129 my ($evalue, $contigs, $verbose, $detail, $format, $out, $hmm, $ref) = (
130 1e-10, 0, 0, 0, 'fasta', 1,
131 abs_path(dirname(abs_path($0)) . '/or.hmm'),
132 abs_path(dirname(abs_path($0)) . '/or.fasta')
133 );
134 GetOptions(
135 'sequence:s' => \$infile,
136 'hmmfile:s' => \$hmm,
137 'fastafile:s' => \$ref,
138 'organism:s' => \$organism,
139 'c!' => \$contigs,
140 'a!' => \$aug,
141 'format:s' => \$format,
142 'expect:f' => \$evalue,
143 'name:s' => \$name,
144 'table:i' => \$translate,
145 'filter:i' => \$filter,
146 'sub:s' => \$subset,
147 'resume:s' => \$resume,
148 'd!' => \$detail,
149 'v!' => \$verbose,
150 'size:i' => \$frag
151 );
152 $format = lc $format;
153 if (
154 (defined $infile)
155 && (-r $infile)
156 && (defined $hmm)
157 && (-r $hmm)
158 && (defined $hmm)
159 && (-r $hmm)
160 && ( !(defined $translate)
161 || ((defined $translate) && ($translate =~ m/([1-9]|1[1-6]|2[12])/)))
162 && (!(defined $filter) || ((defined $filter) && ($filter =~ m/^\d+$/)))
163 && ($format =~ m/^fasta|genbank|csv|tsv|xml|tbl$/)
164 )
165 {
166 $translate = 1 unless (defined $translate);
167 print {*STDERR}
168 "\n..:: Olfactory Receptor Assigner (ORA) v$VERSION ::..\n\n"
169 if ($verbose);
170 if ($contigs)
171 {
172 $out--;
173 my $id = 0;
174 my @prehits = Bio::ORA->fastScan($infile, $ref);
175 if (
176 ($#prehits >= 0)
177 && (my $inseq =
178 Bio::SeqIO->new('-file' => "<$infile", '-format' => 'fasta'))
179 )
180 {
181 print {*STDERR} $#prehits, " Informative contigs\n" if ($verbose);
182 my $myresume = shift @prehits;
183 while (my $seq = $inseq->next_seq)
184 {
185 my $mess;
186 next
187 if (!(defined $myresume) || ($myresume ne $seq->display_id));
188 $myresume = shift @prehits;
189 next
190 if ( (defined $resume)
191 && !$id
192 && ($resume ne $seq->display_id));
193 $id++;
194 if (length($seq->seq()) > 2500)
195 {
196 $mess = fasta_filter(
197 $seq, $ref, $id, $translate,
198 $evalue, $format, $detail, $aug,
199 $hmm, $filter, $frag, $subset,
200 $organism
201 );
202 }
203 else
204 {
205 $mess = hmm_disc(
206 $seq, $name, $id,
207 $translate, $evalue, $format,
208 $detail, $aug, $hmm,
209 $filter, $frag, $subset,
210 $organism
211 );
212 }
213 print {*STDERR} $mess if ($verbose && defined $mess);
214 }
215 }
216 }
217 elsif (my $inseq =
218 Bio::SeqIO->new('-file' => "<$infile", '-format' => 'fasta'))
219 {
220 $out--;
221 my $id = 0;
222 while (my $seq = $inseq->next_seq)
223 {
224 my $mess;
225 next
226 if ((defined $resume) && !$id && ($resume ne $seq->display_id));
227 $id++;
228 if (length($seq->seq()) > 2500)
229 {
230 $mess = fasta_filter(
231 $seq, $ref, $id,
232 $translate, $evalue, $format,
233 $detail, $aug, $hmm,
234 $filter, $frag, $subset,
235 $organism
236 );
237 }
238 else
239 {
240 $mess = hmm_disc(
241 $seq, $name, $id, $translate,
242 $evalue, $format, $detail, $aug,
243 $hmm, $filter, $frag, $subset,
244 $organism
245 );
246 }
247 print {*STDERR} $mess if ($verbose && defined $mess);
248 }
249 }
250 else { print {*STDERR} "FATAL: Incorrect file format.\n"; }
251 print {*STDERR} "\n" if ($verbose);
252 }
253 else
254 {
255 print {*STDERR}
256 "\n..:: Olfactory Receptor Assigner (ORA) v$VERSION ::..\n\nFATAL: Incorrect arguments.\nUsage: or.pl [-options] --sequence=<sequence fasta file>\n\nOptions\n -a\n Force the use of alternative start codons, according to the current genetic code.\n Otherwise, ATG is the only initiation codon allow.\n --expect\n Set the E-value threshold. This setting specifies the statistical significance\n threshold for reporting matches against database sequences. [Default $evalue].\n --format\n Available output format [Default $format]:\n fasta (FASTA format)\n csv (Comma-separated values)\n genbank (GenBank format)\n tsv (Direct output for R)\n tbl (GenBank TBL format)\n -c\n When using a large number of contigs (e.g. newly sequenced genome), proceed to an\n initial FASTA search to identify the contigs where to run the actual ORA search.\n --filter\n Show ONLY the selected family number.\n --sub\n Extract the sequences of the Fasta hits.\n --name\n Overwrite the sequence name by the provided one. Otherwise the program will use the\n sequence name from as input.\n --table\n Force a genetic code to be used for the translation of the query. [Default 1]\n --size\n Filter fragments over the specified size as functional.\n -d\n Print all sequence details.\n\nAdvance options\n --resume\n Resume the search from given sequence name.\n --hmmfile\n Provide alternative HMM profiles.\n [Default $hmm]\n --fastafile\n Provide alternative reference OR sequences (fasta format).\n [Default $ref]\n -v\n Print more possibly useful stuff, such as the individual scores for each sequence.\n\n";
257 $out++;
258 }
259 exit $out;