GFF/Adaptor/biofetch_oracle.pm

filter: Statementstmt 18.4% 21 / 114 Branchbran 0.0% 0 / 54 Conditioncond 0.0% 0 / 21 MC/DCmcdc 0.0% 0 / 12 Subroutinesub 40.0% 6 / 15 Podpod 42.8% 3 / 7 totaltotal 13.4% 30 / 223 CC 42 SCAR 48.6
CC
42
Cov
11%
_load_embl
342.0
segment
72.0
new
30.0
CRAP 129.4
« GFF/Adaptor/dbi/oracle.pm ↑ Summary GFF/Aggregator/alignment.pm »
1 package Bio::DB::GFF::Adaptor::biofetch_oracle;
2 1 $Bio::DB::GFF::Adaptor::biofetch_oracle::VERSION = '1.7.4';
3 #$Id$
4  
5 =head1 NAME
6  
7 Bio::DB::GFF::Adaptor::biofetch_oracle -- Cache BioFetch objects in a Bio::DB::GFF database
8  
9 =head1 SYNOPSIS
10  
11 Proof of principle. Not for production use.
12  
13 =head1 DESCRIPTION
14  
15 This adaptor is a proof-of-principle. It is used to fetch BioFetch
16 sequences into a Bio::DB::GFF database (currently uses a hard-coded
17 EMBL database) as needed. This allows the Generic Genome Browser to
18 be used as a Genbank/EMBL browser.
19  
20 =head1 AUTHOR
21  
22 Lincoln Stein E<lt>lstein@cshl.orgE<gt>.
23  
24 Copyright 2002 Cold Spring Harbor Laboratory.
25  
26 This library is free software; you can redistribute it and/or modify
27 it under the same terms as Perl itself.
28  
29 =cut
30  
31 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
32 1 ▶use Bio::DB::GFF::Util::Rearrange; # for rearrange()
Subroutine BEGIN: called CC=1 SCAR=0.0
33 1 ▶use Bio::DB::BioFetch;
Subroutine BEGIN: called CC=1 SCAR=0.0
34 1 ▶use Bio::SeqIO;
Subroutine BEGIN: called CC=1 SCAR=0.0
35  
36 1 ▶use vars qw(%default_preferred_tags);
Subroutine BEGIN: called CC=1 SCAR=0.0
37 1 ▶use base qw(Bio::DB::GFF::Adaptor::dbi::oracle);
Subroutine BEGIN: called CC=1 SCAR=0.0
38  
39 # priority for choosing names of CDS tags, higher is higher priority
40 1 %default_preferred_tags = (
41 strain => 10,
42 organism => 20,
43 protein_id => 40,
44 locus_tag => 50,
45 locus => 60,
46 gene => 70,
47 standard_name => 80,
48 );
49  
50 0 ▶sub _preferred_tags {
Subroutine _preferred_tags: not called CC=3 SCAR=24.8
51 0 my ($self, $tags) = @_;
52 0 ▶ if ($tags && (ref($tags) =~ /HASH/)){
Branch: 1 branch
BranchTrueFalseTotal
if ($tags and ref($tags) =~ /HASH/) 0 0 0
Condition0%0/3
$tags and ref($tags) =~ /HASH/
!ll&&!rl&&r
000
MC/DC0%0/2
$tags and ref($tags) =~ /HASH/
$tags ref($tags) =~ /HASH/
Truth table0%0/3
A and B
A= $tagsB= ref($tags) =~ /HASH/
ABresult
0X0
100
111
53 0 $self->{preferred_tags} = $tags;
54 }
55 0 return $self->{preferred_tags};
56 }
57  
58  
59 =head2 new
60  
61 Title : new
62 Usage : $db = Bio::DB::GFF->new(-adaptor=>'biofetch_oracle', -preferred_tags => \%preferred, @args)
63 Function: create a new adaptor
64 Returns : a Bio::DB::GFF object
65 Args : -adaptor : required. Which adaptor to use; biofetch for mysql, biofetch_oracle for Oracle
66 -preferred_tags : optional. A hash of {classname => weight,...}
67 used to determine the class and name of the feature
68 when a choice of possible feature classes is available
69 (e.g. a feature has both a 'gene' and a 'locus' tag).
70 Common defaults are provided that work well for eukaryotic
71 features (but not well for viral/prokaryotic)
72 see below for additional arguments.
73 Status : Public
74  
75 This is the constructor for the adaptor. It is called automatically
76 by Bio::DB::GFF-E<gt>new. In addition to arguments that are common among
77 all adaptors, the following class-specific arguments are recgonized:
78  
79 Argument Description
80 -------- -----------
81  
82 -dsn the DBI data source, e.g. 'dbi:mysql:ens0040'
83  
84 -user username for authentication
85  
86 -pass the password for authentication
87  
88 -proxy [['http','ftp'],'http://proxy:8080']
89  
90 -create initialize the database
91  
92 -dsn,-user and -pass indicate the local database to cache results in,
93 and as are per Bio::DB::GFF::Adaptor::dbi. The -proxy argument allows
94 you to set the biofetch web proxy, and uses the same syntax described
95 for the proxy() method of L<Bio::DB::WebDBSeqI>, except that the
96 argument must be passed as an array reference.
97  
98 =cut
99  
100 0 ▶sub new {
Subroutine new: not called CC=5 SCAR=34.0
Pod documented
101 0 my $class = shift;
102 0 my $args = shift;
103 0 my $self = $class->SUPER::new($args);
104 0 my ($preferred) = rearrange(['PREFERRED_TAGS'],$args);
105 0 ▶ $self->_preferred_tags($preferred?$preferred:\%default_preferred_tags); # if the caller sent their own preferences, then use these, otherwise use defaults.
Branch: 1 branch
BranchTrueFalseTotal
$preferred ? : 0 0 0
106  
107 0 my ($proxy) = rearrange(['PROXY'],$args);
108 0 ▶ if ($proxy) {
Branch: 1 branch
BranchTrueFalseTotal
if ($proxy) 0 0 0
109 0 ▶ my @args = ref($proxy) ? @$proxy : eval $proxy;
Branch: 1 branch
BranchTrueFalseTotal
ref $proxy ? : 0 0 0
110 0 ▶ $self->{_proxy} = \@args if @args;
Branch: 1 branch
BranchTrueFalseTotal
if @args 0 0 0
111 }
112 0 $self;
113 }
114  
115 0 ▶sub segment {
Subroutine segment: not called CC=8 SCAR=42.8
Pod documented
116 0 my $self = shift;
117 0 my @segments = $self->SUPER::segment(@_);
118  
119 0 ▶ if (!@segments) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@segments) 0 0 0
120 0 my $refclass = $self->refclass;
121  
122 0 my %args = $self->setup_segment_args(@_);
123 0 ▶ if ($args{-class} && $args{-class} =~ /$refclass/oi) {
Branch: 2 branches
BranchTrueFalseTotal
if ($args{'-class'} and $args{'-class'} =~ /$refclass/io) { } 0 0 0
elsif ($args{'-class'} and $args{'-class'} =~ /refseq|swall|embl/i) { } 0 0 0
Condition0%0/3
$args{"-class"} and $args{"-class"} =~ /$refclass/io
!ll&&!rl&&r
000
MC/DC0%0/2
$args{"-class"} and $args{"-class"} =~ /$refclass/io
$args{"-class"} $args{"-class"} =~ /$refclass/io
Truth table0%0/3
A and B
A= $args{"-class"}B= $args{"-class"} =~ /$refclass/io
ABresult
0X0
100
111
124 0 ▶ return unless $self->load_from_embl('embl'=>$args{-name});
Branch: 1 branch
BranchTrueFalseTotal
unless $self->load_from_embl("embl", $args{"-name"}) 0 0 0
125 0 @segments = $self->SUPER::segment(@_);
126 ▶ } elsif ($args{-class} && $args{-class} =~ /refseq|swall|embl/i) { #hack to get refseq names
Condition0%0/3
$args{"-class"} and $args{"-class"} =~ /refseq|swall|embl/i
!ll&&!rl&&r
000
MC/DC0%0/2
$args{"-class"} and $args{"-class"} =~ /refseq|swall|embl/i
$args{"-class"} $args{"-class"} =~ /refseq|swall|embl/i
Truth table0%0/3
A and B
A= $args{"-class"}B= $args{"-class"} =~ /refseq|swall|embl/i
ABresult
0X0
100
111
127 0 ▶ return unless $self->load_from_embl(lc($args{-class})=>$args{-name});
Branch: 1 branch
BranchTrueFalseTotal
unless $self->load_from_embl(lc $args{"-class"}, $args{"-name"}) 0 0 0
128 0 $args{-class} = $self->refclass;
129 0 @segments = $self->SUPER::segment(%args);
130 }
131 }
132  
133 0 $self->_multiple_return_args(@segments);
134 }
135  
136 # default is to return 'Sequence' as the class of all references
137 0 ▶sub refclass {
Subroutine refclass: not called CC=1 SCAR=6.9
Pod documented
138 0 my $self = shift;
139 0 my $refname = shift;
140 0 'Accession';
141 }
142  
143 0 ▶sub load_from_embl {
Subroutine load_from_embl: not called CC=5 SCAR=34.0
Pod undocumented
144 0 my $self = shift;
145 0 my $db = shift;
146 0 ▶ my $acc = shift or $self->throw('Must provide an accession ID');
Branch: 1 branch
BranchTrueFalseTotal
my $acc = shift() or $self->throw("Must provide an accession ID") 0 0 0
147  
148 0 my $biofetch;
149 0 ▶ if ($self->{_biofetch}{$db}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'_biofetch'}{$db}) { } 0 0 0
150 0 $biofetch = $self->{_biofetch}{$db};
151 } else {
152 0 $biofetch = $self->{_biofetch}{$db} = Bio::DB::BioFetch->new(-db=>$db);
153 0 $biofetch->retrieval_type('tempfile');
154 0 ▶ $biofetch->proxy(@{$self->{_proxy}}) if $self->{_proxy};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_proxy"} 0 0 0
155 }
156  
157 0 ▶ my $seq = eval {$biofetch->get_Seq_by_id($acc)} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $seq = eval { do { $biofetch->get_Seq_by_id($acc) } } or return 0 0 0
158 0 $self->_load_embl($acc,$seq);
159 0 1;
160 }
161  
162 0 ▶sub load_from_file {
Subroutine load_from_file: not called CC=2 SCAR=17.9
Pod undocumented
163 0 my $self = shift;
164 0 my $file = shift;
165  
166 0 ▶ my $format = $file =~ /\.(gb|genbank|gbk)$/i ? 'genbank' : 'embl';
Branch: 1 branch
BranchTrueFalseTotal
$file =~ /\.(gb|genbank|gbk)$/i ? : 0 0 0
167  
168 0 my $seqio = Bio::SeqIO->new( '-format' => $format, -file => $file);
169 0 my $seq = $seqio->next_seq;
170  
171 0 $self->_load_embl($seq->accession,$seq);
172 0 1;
173 }
174  
175 0 ▶sub _load_embl {
Subroutine _load_embl: not called CC=18 SCAR=58.3
176 0 my $self = shift;
177 0 my $acc = shift;
178 0 my $seq = shift;
179 0 my $refclass = $self->refclass;
180 0 my $locus = $seq->id;
181  
182 # begin loading
183 0 $self->setup_load();
184  
185 # first synthesize the entry for the top-level feature
186 0 my @aliases;
187 0 foreach ($seq->accession,$seq->get_secondary_accessions) {
188 0 ▶ next if lc($_) eq lc($acc);
Branch: 1 branch
BranchTrueFalseTotal
if lc $_ eq lc $acc 0 0 0
189 0 push @aliases,[Alias => $_];
190 }
191 $self->load_gff_line(
192 {
193 0 ref => $acc,
194 class => $refclass,
195 source => 'EMBL',
196 method => 'origin',
197 start => 1,
198 stop => $seq->length,
199 score => undef,
200 strand => '.',
201 phase => '.',
202 gclass => $self->refclass,
203 gname => $acc,
204 tstart => undef,
205 tstop => undef,
206 attributes => [[Note => $seq->desc],@aliases],
207 }
208 );
209 # now load each feature in turn
210 0 for my $feat ($seq->all_SeqFeatures) {
211 0 my $attributes = $self->get_attributes($feat);
212 0 my $name = $self->guess_name($attributes);
213  
214 0 my $location = $feat->location;
215 0 ▶ my @segments = map {[$_->start,$_->end,$_->seq_id]}
Branch: 1 branch
BranchTrueFalseTotal
$location->can('sub_Location') ? : 0 0 0
216 $location->can('sub_Location') ? $location->sub_Location : $location;
217  
218 0 ▶ my $type = $feat->primary_tag eq 'CDS' ? 'mRNA' : $feat->primary_tag;
Branch: 1 branch
BranchTrueFalseTotal
$feat->primary_tag eq 'CDS' ? : 0 0 0
219 0 ▶ my $parttype = $feat->primary_tag eq 'gene' ? 'exon' : $feat->primary_tag;
Branch: 1 branch
BranchTrueFalseTotal
$feat->primary_tag eq 'gene' ? : 0 0 0
220  
221 0 ▶ if ($feat->primary_tag =~ /^(gene|CDS)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($feat->primary_tag =~ /^(gene|CDS)$/) 0 0 0
222 0 ▶ $self->load_gff_line( {
Branch: 2 branches
BranchTrueFalseTotal
$feat->strand > 0 ? : 0 0 0
$feat->strand < 0 ? : 0 0 0
Condition0%0/4
$feat->score || undef
l!l
00
$feat->frame || '.'
l!l
00
MC/DC0%0/1
$feat->score || undef
$feat->score
MC/DC0%0/1
$feat->frame || '.'
$feat->frame
Truth table0%0/2
A
A= $feat->score
Aresult
11
00
Truth table0%0/2
A
A= $feat->frame
Aresult
11
00
223 ref => $acc,
224 class => $refclass,
225 source => 'EMBL',
226 method => $type,
227 start => $location->start,
228 stop => $location->end,
229 score => $feat->score || undef,
230 strand => $feat->strand > 0 ? '+' : ($feat->strand < 0 ? '-' : '.'),
231 phase => $feat->frame || '.',
232 gclass => $name->[0],
233 gname => $name->[1],
234 tstart => undef,
235 tstop => undef,
236 attributes => $attributes,
237 }
238 );
239 0 @$attributes = ();
240 }
241  
242 0 for my $segment (@segments) {
243  
244 0 ▶ $self->load_gff_line( {
Branch: 3 branches
BranchTrueFalseTotal
$segment->[2] eq $locus ? : 0 0 0
$feat->strand > 0 ? : 0 0 0
$feat->strand < 0 ? : 0 0 0
Condition0%0/4
$feat->score || undef
l!l
00
$feat->frame || '.'
l!l
00
MC/DC0%0/1
$feat->score || undef
$feat->score
MC/DC0%0/1
$feat->frame || '.'
$feat->frame
Truth table0%0/2
A
A= $feat->score
Aresult
11
00
Truth table0%0/2
A
A= $feat->frame
Aresult
11
00
245 ref => $segment->[2] eq $locus ? $acc : $segment->[2],
246 class => $refclass,
247 source => 'EMBL',
248 method => $parttype,
249 start => $segment->[0],
250 stop => $segment->[1],
251 score => $feat->score || undef,
252 strand => $feat->strand > 0 ? '+' : ($feat->strand < 0 ? '-' : '.'),
253 phase => $feat->frame || '.',
254 gclass => $name->[0],
255 gname => $name->[1],
256 tstart => undef,
257 tstop => undef,
258 attributes => $attributes,
259 }
260 );
261 }
262  
263 }
264  
265 # finish loading
266 0 $self->finish_load();
267  
268 # now load the DNA
269 0 $self->load_sequence_string($acc,$seq->seq);
270  
271 0 1;
272 }
273  
274 0 ▶sub get_attributes {
Subroutine get_attributes: not called CC=4 SCAR=30.0
Pod undocumented
275 0 my $self = shift;
276 0 my $seq = shift;
277  
278 0 ▶ my @tags = $seq->all_tags or return;
Branch: 1 branch
BranchTrueFalseTotal
my(@tags) = $seq->all_tags or return 0 0 0
279 0 my @result;
280 0 foreach my $tag (@tags) {
281 0 foreach my $value ($seq->each_tag_value($tag)) {
282 0 push @result,[$tag=>$value];
283 }
284 }
285 0 \@result;
286 }
287  
288 0 ▶sub guess_name {
Subroutine guess_name: not called CC=4 SCAR=30.0
Pod undocumented
289 0 my $self = shift;
290 0 my $attributes = shift;
291 # remove this fix when Lincoln fixes it properly
292 0 ▶ return ["Misc" => "Misc"] unless ($attributes); # these are arbitrary, and possibly destructive defaults
Branch: 1 branch
BranchTrueFalseTotal
unless $attributes 0 0 0
293 0 ▶ my @ordered_attributes = sort {($self->_preferred_tags->{$a->[0]} || 0) <=> ($self->_preferred_tags->{$b->[0]} || 0)} @$attributes;
Condition0%0/4
$self->_preferred_tags->{$Bio::DB::GFF::Adaptor::biofetch_oracle::a->[0]} || 0
l!l
00
$self->_preferred_tags->{$Bio::DB::GFF::Adaptor::biofetch_oracle::b->[0]} || 0
l!l
00
MC/DC0%0/1
$self->_preferred_tags->{$Bio::DB::GFF::Adaptor::biofetch_oracle::a->[0]} || 0
$self->_preferred_tags->{$Bio::DB::GFF::Adaptor::biofetch_oracle::a->[0]}
MC/DC0%0/1
$self->_preferred_tags->{$Bio::DB::GFF::Adaptor::biofetch_oracle::b->[0]} || 0
$self->_preferred_tags->{$Bio::DB::GFF::Adaptor::biofetch_oracle::b->[0]}
Truth table0%0/2
A
A= $self->_preferred_tags->{$Bio::DB::GFF::Adaptor::biofetch_oracle::a->[0]}
Aresult
11
00
Truth table0%0/2
A
A= $self->_preferred_tags->{$Bio::DB::GFF::Adaptor::biofetch_oracle::b->[0]}
Aresult
11
00
294 0 my $best = pop @ordered_attributes;
295 0 @$attributes = @ordered_attributes;
296 0 return $best;
297 }
298  
299  
300  
301 1 1;
« GFF/Adaptor/dbi/oracle.pm ↑ Summary GFF/Aggregator/alignment.pm »