EnsEMBL/DBSQL/SupportingFeatureAdaptor.pm untested

filter: Statementstmt 0.0% 0 / 84 Branchbran 0.0% 0 / 24 Conditioncond 0.0% 0 / 3 Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 119 CC 13 SCAR 38.4
CC
13
Cov
0%
store
72.0
fetch_all_by_Exon
42.0
BEGIN
2.0
CRAP 46.4
1 =head1 LICENSE
2  
3 See the NOTICE file distributed with this work for additional information
4 regarding copyright ownership.
5  
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
9  
10 http://www.apache.org/licenses/LICENSE-2.0
11  
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an "AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 See the License for the specific language governing permissions and
16 limitations under the License.
17  
18 =cut
19  
20  
21 =head1 CONTACT
22  
23 Please email comments or questions to the public Ensembl
24 developers list at <http://lists.ensembl.org/mailman/listinfo/dev>.
25  
26 Questions may also be sent to the Ensembl help desk at
27 <http://www.ensembl.org/Help/Contact>.
28  
29 =cut
30  
31 =head1 NAME
32  
33 Bio::EnsEMBL::DBSQL::SupportingFeatureAdaptor - Retrieves supporting
34 features from the database.
35  
36 =head1 SYNOPSIS
37  
38 my $sfa =
39 $registry->get_adaptor( 'Human', 'Core', 'SupportingFeature' );
40  
41 my @supporting_feats = @{ $sfa->fetch_all_by_Exon($exon) };
42  
43 =head1 METHODS
44  
45 =cut
46  
47 package Bio::EnsEMBL::DBSQL::SupportingFeatureAdaptor;
48 $Bio::EnsEMBL::DBSQL::SupportingFeatureAdaptor::VERSION = '114.0.0_50'; # TRIAL
49 $Bio::EnsEMBL::DBSQL::SupportingFeatureAdaptor::VERSION = '114.0.050';
50 use strict;
51  
52 use Bio::EnsEMBL::DBSQL::BaseAdaptor;
53  
54 use Bio::EnsEMBL::Utils::Exception qw(throw warning);
55  
56 use vars qw(@ISA);
57  
58 #inherits from BaseAdaptor
59 @ISA = qw(Bio::EnsEMBL::DBSQL::BaseAdaptor);
60  
61  
62  
63 =head2 fetch_all_by_Exon
64  
65 Arg [1] : Bio::EnsEMBL::Exon $exon
66 The exon to fetch supporting features.
67 Example : @sfs =
68 @{ $supporting_feat_adaptor->fetch_all_by_Exon($exon) };
69 Description: Retrieves supporting features (evidence) for a given
70 exon.
71 Returntype : List of Bio::EnsEMBL::BaseAlignFeatures in the same
72 coordinate system as the $exon argument
73 Exceptions : Warning if $exon is not in the database (i.e. dbID
74 not defined).
75 Throw if a retrieved supporting feature is of unknown
76 type.
77 Caller : Bio::EnsEMBL::Exon
78 Status : Stable
79  
80 =cut
81  
82 sub fetch_all_by_Exon {
83 my ( $self, $exon ) = @_;
84  
85 my $out = [];
86  
87 unless($exon->dbID) {
88 warning("Cannot retrieve evidence for exon without dbID");
89 return [];
90 }
91  
92 my $sth = $self->prepare("SELECT sf.feature_type, sf.feature_id
93 FROM supporting_feature sf
94 WHERE exon_id = ?");
95  
96 $sth->bind_param(1,$exon->dbID,SQL_INTEGER);
97 $sth->execute();
98  
99 my $prot_adp = $self->db->get_ProteinAlignFeatureAdaptor;
100 my $dna_adp = $self->db->get_DnaAlignFeatureAdaptor;
101  
102 my $feature;
103 while(my ($type, $feature_id) = $sth->fetchrow){
104 if($type eq 'protein_align_feature'){
105 $feature = $prot_adp->fetch_by_dbID($feature_id);
106 } elsif($type eq 'dna_align_feature'){
107 $feature = $dna_adp->fetch_by_dbID($feature_id);
108 } else {
109 warning("Unknown feature type [$type]\n");
110 }
111  
112 if(!$feature) {
113 warning("Supporting feature $type $feature_id does not exist in DB");
114 } else {
115 my $new_feature = $feature->transfer($exon->slice());
116 push @$out, $new_feature if( $new_feature );
117 }
118 }
119  
120 $sth->finish();
121  
122 return $out;
123 }
124  
125 =head2 store
126  
127 Arg [1] : Int $exonsID
128 The dbID of an EnsEMBL exon to associate with
129 supporting features.
130 Arg [2] : Ref to array of Bio::EnsEMBL::BaseAlignFeature
131 (the support)
132 Example : $sfa->store($exon_id, \@features);
133 Description: Stores a set of alignment features and associates an
134 EnsEMBL exon with them
135 Returntype : none
136 Exceptions : thrown when invalid dbID is passed to this method
137 Caller : TranscriptAdaptor
138 Status : Stable
139  
140 =cut
141  
142 sub store {
143 my ( $self, $exon_dbID, $aln_objs ) = @_;
144  
145 my $pep_check_sql =
146 "SELECT protein_align_feature_id " .
147 "FROM protein_align_feature " .
148 "WHERE seq_region_id = ? " .
149 "AND seq_region_start = ? " .
150 "AND seq_region_end = ? " .
151 "AND seq_region_strand = ? " .
152 "AND hit_name = ? " .
153 "AND hit_start = ? " .
154 "AND hit_end = ? " .
155 "AND analysis_id = ? " .
156 "AND cigar_line = ? ";
157  
158 my $dna_check_sql =
159 "SELECT dna_align_feature_id " .
160 "FROM dna_align_feature " .
161 "WHERE seq_region_id = ? " .
162 "AND seq_region_start = ? " .
163 "AND seq_region_end = ? " .
164 "AND seq_region_strand = ? " .
165 "AND hit_name = ? " .
166 "AND hit_start = ? " .
167 "AND hit_end = ? " .
168 "AND analysis_id = ? " .
169 "AND cigar_line = ? " .
170 "AND hit_strand = ? ";
171  
172 my $assoc_check_sql =
173 "SELECT * " .
174 "FROM supporting_feature " .
175 "WHERE exon_id = $exon_dbID " .
176 "AND feature_type = ? " .
177 "AND feature_id = ? ";
178  
179 my $assoc_write_sql = "INSERT into supporting_feature " .
180 "(exon_id, feature_id, feature_type) " .
181 "values(?, ?, ?)";
182  
183 my $pep_check_sth = $self->prepare($pep_check_sql);
184 my $dna_check_sth = $self->prepare($dna_check_sql);
185 my $assoc_check_sth = $self->prepare($assoc_check_sql);
186 my $sf_sth = $self->prepare($assoc_write_sql);
187  
188 my $dna_adaptor = $self->db->get_DnaAlignFeatureAdaptor();
189 my $pep_adaptor = $self->db->get_ProteinAlignFeatureAdaptor();
190  
191 foreach my $f (@$aln_objs) {
192 # check that the feature is in toplevel coords
193  
194 if($f->slice->start != 1 || $f->slice->strand != 1) {
195 #move feature onto a slice of the entire seq_region
196 my $tls = $self->db->get_sliceAdaptor->fetch_by_region($f->slice->coord_system->name(),
197 $f->slice->seq_region_name(),
198 undef, #start
199 undef, #end
200 undef, #strand
201 $f->slice->coord_system->version());
202 $f = $f->transfer($tls);
203  
204 if(!$f) {
205 throw('Could not transfer Feature to slice of ' .
206 'entire seq_region prior to storing');
207 }
208 }
209  
210 if(!$f->isa("Bio::EnsEMBL::BaseAlignFeature")){
211 throw("$f must be an align feature otherwise" .
212 "it can't be stored");
213 }
214
215 my ($sf_dbID, $type, $adap, $check_sth);
216
217 my @check_args = ($self->db->get_SliceAdaptor->get_seq_region_id($f->slice),
218 $f->start,
219 $f->end,
220 $f->strand,
221 $f->hseqname,
222 $f->hstart,
223 $f->hend,
224 $f->analysis->dbID,
225 $f->cigar_string);
226  
227 if($f->isa("Bio::EnsEMBL::DnaDnaAlignFeature")){
228 $adap = $dna_adaptor;
229 $check_sth = $dna_check_sth;
230 $type = 'dna_align_feature';
231 push @check_args, $f->hstrand;
232 } elsif($f->isa("Bio::EnsEMBL::DnaPepAlignFeature")){
233 $adap = $pep_adaptor;
234 $check_sth = $pep_check_sth;
235 $type = 'protein_align_feature';
236 } else {
237 warning("Supporting feature of unknown type. Skipping : [$f]\n");
238 next;
239 }
240  
241 $check_sth->execute(@check_args);
242 $sf_dbID = $check_sth->fetchrow_array;
243 if (not $sf_dbID) {
244 $adap->store($f);
245 $sf_dbID = $f->dbID;
246 }
247  
248 # now check association
249 $assoc_check_sth->execute($type,
250 $sf_dbID);
251 if (not $assoc_check_sth->fetchrow_array) {
252 $sf_sth->bind_param(1, $exon_dbID, SQL_INTEGER);
253 $sf_sth->bind_param(2, $sf_dbID, SQL_INTEGER);
254 $sf_sth->bind_param(3, $type, SQL_VARCHAR);
255 $sf_sth->execute();
256 }
257 }
258  
259 $dna_check_sth->finish;
260 $pep_check_sth->finish;
261 $assoc_check_sth->finish;
262 $sf_sth->finish;
263
264 }
265  
266  
267  
268 1;
269