EnsEMBL/DBSQL/TranscriptSupportingFeatureAdaptor.pm untested

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