3 See the NOTICE file distributed with
this work
for additional information
4 regarding copyright ownership.
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
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.
23 Please email comments or questions to the
public Ensembl
24 developers list at <http:
26 Questions may also be sent to the Ensembl help desk at
34 Adaptor
for ProteinAlignFeatures
39 $registry->get_adaptor(
'Human',
'Core',
'ProteinAlignFeature' );
43 $pafa->store(@features);
50 package Bio::EnsEMBL::DBSQL::ProteinAlignFeatureAdaptor;
64 Example : $protein_align_feature_adaptor->store(@feats);
65 Description: stores a list of ProteinAlignFeatures in the database
67 Exceptions :
throw if any of the provided features cannot be stored
69 * The feature does not have an associated
Slice
70 * The feature does not have an associated analysis
71 * The
Slice the feature is associated with is on a seq_region
72 unknown to
this database
73 A warning is given
if:
74 * The feature has already been stored in
this db
82 my ($self, @feats) = @_;
84 throw(
"Must call store with features")
if( scalar(@feats) == 0 );
86 my @tabs = $self->_tables;
87 my ($tablename) = @{$tabs[0]};
90 my $slice_adaptor = $db->get_SliceAdaptor();
91 my $analysis_adaptor = $db->get_AnalysisAdaptor();
93 my $sth = $self->prepare(
94 "INSERT INTO $tablename (seq_region_id, seq_region_start, seq_region_end,
95 seq_region_strand, hit_start, hit_end,
97 analysis_id, score, evalue, perc_ident, external_db_id, hcoverage, align_type)
98 VALUES (?,?,?,?,?,?,?,?,?,?, ?, ?, ?, ?,?)");
100 FEATURE:
foreach my $feat ( @feats ) {
101 if( !ref $feat || !$feat->isa(
"Bio::EnsEMBL::DnaPepAlignFeature") ) {
102 throw(
"feature must be a Bio::EnsEMBL::DnaPepAlignFeature,"
103 .
" not a [".ref($feat).
"].");
106 if($feat->is_stored($db)) {
107 warning(
"PepDnaAlignFeature [".$feat->dbID.
"] is already stored" .
108 " in this database.");
112 #sanity check the hstart and hend
113 my $hstart = $feat->hstart();
114 my $hend = $feat->hend();
115 $self->_check_start_end_strand($hstart,$hend,1,$feat->hslice);
117 my $cigar_string = $feat->cigar_string();
119 $cigar_string = $feat->length() .
'M';
120 warning(
"DnaPepAlignFeature does not define a cigar_string.\n" .
121 "Assuming ungapped block with cigar_string=$cigar_string\n");
124 my $hseqname = $feat->hseqname();
126 throw(
"DnaPepAlignFeature must define an hseqname.");
129 if(!defined($feat->analysis)) {
130 throw(
"An analysis must be attached to the features to be stored.");
133 #store the analysis if it has not been stored yet
134 if(!$feat->analysis->is_stored($db)) {
135 $analysis_adaptor->store($feat->analysis());
138 my $slice = $feat->slice();
139 if(!defined($slice) || !($slice->isa(
"Bio::EnsEMBL::Slice") or $slice->isa(
'Bio::EnsEMBL::LRGSlice')) ) {
140 throw(
"A slice must be attached to the features to be stored.");
143 my $original = $feat;
145 ($feat, $seq_region_id) = $self->_pre_store($feat);
147 $sth->bind_param(1,$seq_region_id,SQL_INTEGER);
148 $sth->bind_param(2,$feat->start,SQL_INTEGER);
149 $sth->bind_param(3,$feat->end,SQL_INTEGER);
150 $sth->bind_param(4,$feat->strand,SQL_TINYINT);
151 $sth->bind_param(5,$feat->hstart,SQL_INTEGER);
152 $sth->bind_param(6,$feat->hend,SQL_INTEGER);
153 $sth->bind_param(7,$feat->hseqname,SQL_VARCHAR);
154 $sth->bind_param(8,$feat->cigar_string,SQL_LONGVARCHAR);
155 $sth->bind_param(9,$feat->analysis->dbID,SQL_INTEGER);
156 $sth->bind_param(10,$feat->score,SQL_DOUBLE);
157 $sth->bind_param(11,$feat->p_value,SQL_DOUBLE);
158 $sth->bind_param(12,$feat->percent_id,SQL_REAL);
159 $sth->bind_param(13,$feat->external_db_id,SQL_INTEGER);
160 $sth->bind_param(14,$feat->hcoverage,SQL_DOUBLE);
161 $sth->bind_param(15,$feat->align_type,SQL_VARCHAR);
164 my $dbId = $self->last_insert_id(
"${tablename}_id", undef, $tablename);
165 $original->dbID($dbId);
166 $original->adaptor($self);
173 =head2 _objs_from_sth
175 Arg [1] : DBI statement handle $sth
176 an exectuted DBI statement handle generated by selecting
177 the columns specified by _columns() from the table specified
179 Example : @dna_dna_align_feats = $self->_obj_from_hashref
180 Description: PROTECTED implementation of superclass abstract method.
181 Creates DnaDnaAlignFeature objects from a DBI hashref
182 Returntype : listref of
Bio::
EnsEMBL::ProteinAlignFeatures
184 Caller :
Bio::
EnsEMBL::BaseFeatureAdaptor::generic_fetch
190 my ($self, $sth, $mapper, $dest_slice) = @_;
193 # This code is ugly because an attempt has been made to remove as many
194 # function calls as possible for speed purposes. Thus many caches and
195 # a fair bit of gymnastics is used.
198 my $sa = $self->db()->get_SliceAdaptor();
199 my $aa = $self->db()->get_AnalysisAdaptor();
208 $protein_align_feature_id, $seq_region_id, $seq_region_start,
209 $seq_region_end, $analysis_id, $seq_region_strand,
210 $hit_start, $hit_end, $hit_name,
211 $cigar_line, $evalue, $perc_ident,
212 $score, $external_db_id, $hcoverage, $align_type,
213 $external_db_name, $external_display_db_name );
215 $sth->bind_columns(\(
216 $protein_align_feature_id, $seq_region_id, $seq_region_start,
217 $seq_region_end, $analysis_id, $seq_region_strand,
218 $hit_start, $hit_end, $hit_name,
219 $cigar_line, $evalue, $perc_ident,
220 $score, $external_db_id, $hcoverage, $align_type,
221 $external_db_name, $external_display_db_name ));
223 my $dest_slice_start;
225 my $dest_slice_strand;
226 my $dest_slice_length;
228 my $dest_slice_sr_name;
229 my $dest_slice_sr_id;
233 $dest_slice_start = $dest_slice->start();
234 $dest_slice_end = $dest_slice->end();
235 $dest_slice_strand = $dest_slice->strand();
236 $dest_slice_length = $dest_slice->length();
237 $dest_slice_cs = $dest_slice->coord_system();
238 $dest_slice_sr_name = $dest_slice->seq_region_name();
239 $dest_slice_sr_id = $dest_slice->get_seq_region_id();
240 $asma = $self->db->get_AssemblyMapperAdaptor();
243 FEATURE:
while($sth->fetch()) {
245 #get the analysis object
246 my $analysis = $analysis_hash{$analysis_id} ||= $aa->fetch_by_dbID($analysis_id);
247 $analysis_hash{$analysis_id} = $analysis;
249 #need to get the internal_seq_region, if present
250 $seq_region_id = $self->get_seq_region_id_internal($seq_region_id);
251 my $slice = $slice_hash{
"ID:".$seq_region_id};
254 $slice = $sa->fetch_by_seq_region_id($seq_region_id);
255 $slice_hash{
"ID:".$seq_region_id} = $slice;
256 $sr_name_hash{$seq_region_id} = $slice->seq_region_name();
257 $sr_cs_hash{$seq_region_id} = $slice->coord_system();
260 #obtain a mapper if none was defined, but a dest_seq_region was
261 if(!$mapper && $dest_slice && !$dest_slice_cs->equals($slice->coord_system)) {
262 $mapper = $asma->fetch_by_CoordSystems($dest_slice_cs, $slice->coord_system);
265 my $sr_name = $sr_name_hash{$seq_region_id};
266 my $sr_cs = $sr_cs_hash{$seq_region_id};
269 # remap the feature coordinates to another coord system
270 # if a mapper was provided
275 if (defined $dest_slice && $mapper->isa(
'Bio::EnsEMBL::ChainedAssemblyMapper') ) {
276 ($seq_region_id, $seq_region_start, $seq_region_end, $seq_region_strand) =
277 $mapper->map($sr_name, $seq_region_start, $seq_region_end, $seq_region_strand, $sr_cs, 1, $dest_slice);
280 ($seq_region_id, $seq_region_start, $seq_region_end, $seq_region_strand) =
281 $mapper->fastmap($sr_name, $seq_region_start, $seq_region_end, $seq_region_strand, $sr_cs);
284 #skip features that map to gaps or coord system boundaries
285 next FEATURE
if (!defined($seq_region_id));
287 #get a slice in the coord system we just mapped to
288 $slice = $slice_hash{
"ID:".$seq_region_id} ||= $sa->fetch_by_seq_region_id($seq_region_id);
292 # If a destination slice was provided convert the coords.
294 if (defined($dest_slice)) {
295 my $seq_region_len = $dest_slice->seq_region_length();
297 if ( $dest_slice_strand == 1 ) {
298 $seq_region_start = $seq_region_start - $dest_slice_start + 1;
299 $seq_region_end = $seq_region_end - $dest_slice_start + 1;
301 if ( $dest_slice->is_circular ) {
302 # Handle circular chromosomes.
304 if ( $seq_region_start > $seq_region_end ) {
305 # Looking at a feature overlapping the chromosome origin.
307 if ( $seq_region_end > $dest_slice_start ) {
308 # Looking at the region in the beginning of the chromosome
309 $seq_region_start -= $seq_region_len;
311 if ( $seq_region_end < 0 ) {
312 $seq_region_end += $seq_region_len;
315 if ($dest_slice_start > $dest_slice_end && $seq_region_end < 0) {
316 # Looking at the region overlapping the chromosome
317 # origin and a feature which is at the beginning of the
319 $seq_region_start += $seq_region_len;
320 $seq_region_end += $seq_region_len;
326 my $start = $dest_slice_end - $seq_region_end + 1;
327 my $end = $dest_slice_end - $seq_region_start + 1;
329 if ($dest_slice->is_circular()) {
331 if ($dest_slice_start > $dest_slice_end) {
332 # slice spans origin or replication
334 if ($seq_region_start >= $dest_slice_start) {
335 $end += $seq_region_len;
336 $start += $seq_region_len
if $seq_region_end > $dest_slice_start;
338 } elsif ($seq_region_start <= $dest_slice_end) {
340 } elsif ($seq_region_end >= $dest_slice_start) {
341 $start += $seq_region_len;
342 $end += $seq_region_len;
344 } elsif ($seq_region_end <= $dest_slice_end) {
345 $end += $seq_region_len
if $end < 0;
347 } elsif ($seq_region_start > $seq_region_end) {
348 $end += $seq_region_len;
353 if ($seq_region_start <= $dest_slice_end and $seq_region_end >= $dest_slice_start) {
355 } elsif ($seq_region_start > $seq_region_end) {
356 if ($seq_region_start <= $dest_slice_end) {
357 $start -= $seq_region_len;
358 } elsif ($seq_region_end >= $dest_slice_start) {
359 $end += $seq_region_len;
365 $seq_region_start = $start;
366 $seq_region_end = $end;
367 $seq_region_strand *= -1;
369 } ## end
else [
if ( $dest_slice_strand...)]
371 # Throw away features off the end of the requested slice or on
372 # different seq_region.
373 if ($seq_region_end < 1
374 || $seq_region_start > $dest_slice_length
375 || ($dest_slice_sr_id != $seq_region_id)) {
378 $slice = $dest_slice;
381 # Finally, create the new ProteinAlignFeature.
384 $self->_create_feature_fast(
385 'Bio::EnsEMBL::DnaPepAlignFeature', {
387 'start' => $seq_region_start,
388 'end' => $seq_region_end,
389 'strand' => $seq_region_strand,
390 'hseqname' => $hit_name,
391 'hstart' => $hit_start,
393 'hstrand' => 1, # dna_pep_align features
394 # are always hstrand 1
396 'p_value' => $evalue,
397 'percent_id' => $perc_ident,
398 'cigar_string' => $cigar_line,
399 'analysis' => $analysis,
401 'dbID' => $protein_align_feature_id,
402 'external_db_id' => $external_db_id,
403 'hcoverage' => $hcoverage,
404 'align_type' => $align_type,
405 'dbname' => $external_db_name,
406 'db_display_name' => $external_display_db_name
419 return ([
'protein_align_feature',
'paf'], [
'external_db',
'exdb']);
426 #warning _objs_from_hashref method depends on ordering of this list
427 return qw( paf.protein_align_feature_id
432 paf.seq_region_strand
444 exdb.db_display_name);
448 return ([
'external_db',
"exdb.external_db_id = paf.external_db_id"]);
454 Example : @feature_ids = @{$protein_align_feature_adaptor->list_dbIDs()};
455 Description: Gets an array of
internal ids
for all protein align
456 features in the current db
457 Arg[1] : <optional>
int. not 0
for the ids to be sorted by the seq_region.
458 Returntype : listref of ints
466 my ($self,$ordered) = @_;
468 return $self->_list_dbIDs(
"protein_align_feature", undef, $ordered);