EnsEMBL/DBSQL/TranscriptSupportingFeatureAdaptor.pm untested

filter: Statementstmt 0.0% 0 / 94 Branchbran 0.0% 0 / 28 Conditioncond 0.0% 0 / 6 Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 136 CC 15 SCAR 40.6
CC
15
Cov
0%
fetch_all_by_Transcript
72.0
store
72.0
BEGIN
2.0
CRAP 58.0
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::TranscriptSupportingFeatureAdaptor - Retrieves
34 supporting features from the database.
35  
36 =head1 SYNOPSIS
37  
38 $supporting_feature_adaptor =
39 $database_adaptor->get_TranscriptSupportingFeatureAdaptor;
40  
41 @supporting_feats =
42 @{ $supporting_feat_adaptor->fetch_all_by_Transcript($transcript) };
43  
44 =head1 METHODS
45  
46 =cut
47  
48 package Bio::EnsEMBL::DBSQL::TranscriptSupportingFeatureAdaptor;
49 $Bio::EnsEMBL::DBSQL::TranscriptSupportingFeatureAdaptor::VERSION = '114.0.0_50'; # TRIAL
50 $Bio::EnsEMBL::DBSQL::TranscriptSupportingFeatureAdaptor::VERSION = '114.0.050';
51 use strict;
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_Transcript
64  
65 Arg [1] : Bio::EnsEMBL::Transcript $transcript
66 The transcript to fetch supporting features for
67 Arg [2] : String (optional)
68 Feature type to filter upon (either 'dna_align_feature' or 'protein_align_feature')
69 Example : @sfs = @{$supporting_feat_adaptor->fetch_all_by_Transcript($transcript)};
70 @sfs = @{$supporting_feat_adaptor->fetch_all_by_Transcript($transcript, $feature_type)};
71 Description: Retrieves supporting features (evidence) for a given transcript.
72 Returntype : list of Bio::EnsEMBL::BaseAlignFeatures in the same coordinate
73 system as the $transcript argument
74 Exceptions : warning if $transcript is not in the database (i.e. dbID not defined)
75 throw if a retrieved or requested supporting feature is of unknown type
76 Caller : Bio::EnsEMBL::Transcript
77 Status : Stable
78  
79 =cut
80  
81 sub fetch_all_by_Transcript {
82 my ( $self, $transcript, $feature_type ) = @_;
83  
84 my $out = [];
85 my $out_feature_type = {};
86  
87 unless($transcript->dbID) {
88 warning("Cannot retrieve evidence for transcript without dbID");
89 return [];
90 }
91
92 if(defined $feature_type && $feature_type !~ /(dna)|(protein)_align_feature/) {
93 throw("feature type must be dna_align_feature or protein_align_feature");
94 }
95  
96 my $sth = $self->prepare("SELECT tsf.feature_type, tsf.feature_id
97 FROM transcript_supporting_feature tsf
98 WHERE transcript_id = ?");
99  
100  
101 $sth->bind_param(1,$transcript->dbID,SQL_INTEGER);
102 $sth->execute();
103  
104 my $prot_adp = $self->db->get_ProteinAlignFeatureAdaptor;
105 my $dna_adp = $self->db->get_DnaAlignFeatureAdaptor;
106  
107 my $feature;
108 while(my ($type, $feature_id) = $sth->fetchrow){
109 if ($type eq 'protein_align_feature') {
110 $feature = $prot_adp-> fetch_by_dbID($feature_id);
111 }
112 elsif($type eq 'dna_align_feature') {
113 $feature = $dna_adp-> fetch_by_dbID($feature_id);
114 } else {
115 warning("Unknown feature type [$type]\n");
116 }
117
118 if(!$feature) {
119 warning("Supporting feature $type $feature_id does not exist in DB");
120 } else {
121 my $new_feature = $feature->transfer($transcript->slice());
122
123 push @{$out_feature_type->{$type}}, $new_feature if ($new_feature);
124 }
125 }
126
127 $sth->finish();
128
129 if(defined $feature_type){
130 return $out_feature_type->{$feature_type};
131 }else{
132 while(my ($feature_type, $new_features) = each(%$out_feature_type)){
133 push @$out, @{$new_features};
134 }
135
136 }
137
138 return $out;
139 }
140  
141  
142  
143 =head2 store
144 Arg [2] : Int $transID
145 The dbID of an EnsEMBL transcript to associate with supporting
146 features
147 Arg [1] : Ref to array of Bio::EnsEMBL::BaseAlignFeature (the support)
148 Example : $dbea->store($transcript_id, \@features);
149 Description: Stores a set of alignment features and associates an EnsEMBL transcript
150 with them
151 Returntype : none
152 Exceptions : thrown when invalid dbID is passed to this method
153 Caller : TranscriptAdaptor
154 Status : Stable
155  
156 =cut
157  
158 sub store {
159 my ( $self, $tran_dbID, $aln_objs ) = @_;
160  
161 my $pep_check_sql =
162 "SELECT protein_align_feature_id " .
163 "FROM protein_align_feature " .
164 "WHERE seq_region_id = ? " .
165 "AND seq_region_start = ? " .
166 "AND seq_region_end = ? " .
167 "AND seq_region_strand = ? " .
168 "AND hit_name = ? " .
169 "AND hit_start = ? " .
170 "AND hit_end = ? " .
171 "AND analysis_id = ? " .
172 "AND cigar_line = ? " .
173 "AND hcoverage = ? ";
174  
175 my $dna_check_sql =
176 "SELECT dna_align_feature_id " .
177 "FROM dna_align_feature " .
178 "WHERE seq_region_id = ? " .
179 "AND seq_region_start = ? " .
180 "AND seq_region_end = ? " .
181 "AND seq_region_strand = ? " .
182 "AND hit_name = ? " .
183 "AND hit_start = ? " .
184 "AND hit_end = ? " .
185 "AND analysis_id = ? " .
186 "AND cigar_line = ? " .
187 "AND hcoverage = ? " .
188 "AND hit_strand = ? ";
189  
190 my $assoc_check_sql =
191 "SELECT * " .
192 "FROM transcript_supporting_feature " .
193 "WHERE transcript_id = $tran_dbID " .
194 "AND feature_type = ? " .
195 "AND feature_id = ? ";
196  
197 my $assoc_write_sql = "INSERT into transcript_supporting_feature " .
198 "(transcript_id, feature_id, feature_type) " .
199 "values(?, ?, ?)";
200  
201 my $pep_check_sth = $self->prepare($pep_check_sql);
202 my $dna_check_sth = $self->prepare($dna_check_sql);
203 my $assoc_check_sth = $self->prepare($assoc_check_sql);
204 my $sf_sth = $self->prepare($assoc_write_sql);
205  
206 my $dna_adaptor = $self->db->get_DnaAlignFeatureAdaptor();
207 my $pep_adaptor = $self->db->get_ProteinAlignFeatureAdaptor();
208  
209 foreach my $f (@$aln_objs) {
210 # check that the feature is in toplevel coords
211  
212 if($f->slice->start != 1 || $f->slice->strand != 1) {
213 #move feature onto a slice of the entire seq_region
214 my $tls = $self->db->get_sliceAdaptor->fetch_by_region($f->slice->coord_system->name(),
215 $f->slice->seq_region_name(),
216 undef, #start
217 undef, #end
218 undef, #strand
219 $f->slice->coord_system->version());
220 $f = $f->transfer($tls);
221  
222 if(!$f) {
223 throw('Could not transfer Feature to slice of ' .
224 'entire seq_region prior to storing');
225 }
226 }
227  
228 if(!$f->isa("Bio::EnsEMBL::BaseAlignFeature")){
229 throw("$f must be an align feature otherwise" .
230 "it can't be stored");
231 }
232
233 my ($sf_dbID, $type, $adap, $check_sth);
234
235 my @check_args = ($self->db->get_SliceAdaptor->get_seq_region_id($f->slice),
236 $f->start,
237 $f->end,
238 $f->strand,
239 $f->hseqname,
240 $f->hstart,
241 $f->hend,
242 $f->analysis->dbID,
243 $f->cigar_string,
244 $f->hcoverage);
245
246 if($f->isa("Bio::EnsEMBL::DnaDnaAlignFeature")){
247 $adap = $dna_adaptor;
248 $check_sth = $dna_check_sth;
249 $type = 'dna_align_feature';
250 push @check_args, $f->hstrand;
251 } elsif($f->isa("Bio::EnsEMBL::DnaPepAlignFeature")){
252 $adap = $pep_adaptor;
253 $check_sth = $pep_check_sth;
254 $type = 'protein_align_feature';
255 } else {
256 warning("Supporting feature of unknown type. Skipping : [$f]\n");
257 next;
258 }
259  
260 $check_sth->execute(@check_args);
261 $sf_dbID = $check_sth->fetchrow_array;
262
263 if (not $sf_dbID) {
264
265 $adap->store($f);
266 $sf_dbID = $f->dbID;
267 }
268  
269 # now check association
270 $assoc_check_sth->execute($type,
271 $sf_dbID);
272 if (not $assoc_check_sth->fetchrow_array) {
273 $sf_sth->bind_param(1, $tran_dbID, SQL_INTEGER);
274 $sf_sth->bind_param(2, $sf_dbID, SQL_INTEGER);
275 $sf_sth->bind_param(3, $type, SQL_VARCHAR);
276 $sf_sth->execute();
277 }
278 }
279  
280 $dna_check_sth->finish;
281 $pep_check_sth->finish;
282 $assoc_check_sth->finish;
283 $sf_sth->finish;
284
285 }
286  
287  
288 1;
289