ensembl-hive  2.7.0
BiotypeAdaptor.pm
Go to the documentation of this file.
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::BiotypeAdaptor - An adaptor which performs database
34  interaction relating to the storage and retrieval of Biotypes
35 
36 =head1 SYNOPSIS
37 
38  my $biotype = $db_adaptor->fetch_by_name_object_type('protein_coding', 'gene');
39 
40 =head1 DESCRIPTION
41 
42  This adaptor provides a means to retrieve and store information related
43  to Biotypes. Primarily this involves the retrieval or storage of
44  Bio::EnsEMBL::Biotype objects from a database.
45 
46  See Bio::EnsEMBL::Biotype for details of the Biotype class.
47 
48 =head1 METHODS
49 
50 =cut
51 
52 package Bio::EnsEMBL::DBSQL::BiotypeAdaptor;
53 
55 use Bio::EnsEMBL::Utils::Exception qw(throw deprecate warning);
57 
58 use strict;
59 use warnings;
60 
62 
63 =head2 _tables
64 
65  Arg [1] : none
66  Description: PROTECTED implementation of superclass abstract method.
67  Returns the names, aliases of the tables to use for queries.
68  Returntype : list of arrays of strings
69  Exceptions : none
70 
71 =cut
72 
73 sub _tables {
74  my $self = shift;
75 
76  return (['biotype', 'b']);
77 }
78 
79 =head2 _columns
80 
81  Arg [1] : none
82  Example : none
83  Description: PROTECTED implementation of superclass abstract method.
84  Returns a list of columns to use for queries.
85  Returntype : list of strings
86  Exceptions : none
87 
88 =cut
89 
90 sub _columns {
91  my $self = shift;
92 
93  return ('b.biotype_id', 'b.name', 'b.object_type', 'b.db_type', 'b.attrib_type_id', 'b.description', 'b.biotype_group', 'b.so_acc', 'b.so_term');
94 }
95 
96 =head2 _objs_from_sth
97 
98  Arg [1] : StatementHandle $sth
99  Example : none
100  Description: PROTECTED implementation of abstract superclass method.
101  responsible for the creation of ProteinFeatures
102  Returntype : arrayref of Bio::EnsEMBL::Biotype objects
103  Exceptions : none
104 
105 =cut
106 
107 sub _objs_from_sth {
108  my ($self, $sth) = @_;
109 
110  my ($dbID, $name, $object_type, $db_type, $attrib_type_id, $description, $biotype_group, $so_acc, $so_term);
111 
112  $sth->bind_columns(\$dbID, \$name, \$object_type, \$db_type, \$attrib_type_id, \$description, \$biotype_group, \$so_acc, \$so_term);
113 
114  my @biotypes;
115 
116  while($sth->fetch()) {
117  push( @biotypes,
118  my $feat = Bio::EnsEMBL::Biotype->new_fast( {
119  'dbID' => $dbID,
120  'name' => $name,
121  'object_type' => $object_type,
122  'db_type' => $db_type,
123  'attrib_type_id' => $attrib_type_id,
124  'description' => $description,
125  'biotype_group' => $biotype_group,
126  'so_acc' => $so_acc,
127  'so_term' => $so_term,
128  } )
129  );
130  }
131 
132  return \@biotypes;
133 }
134 
135 
136 =head2 fetch_by_name_object_type
137 
138  Arg [1] : String $name
139  The name of the biotype to retrieve
140  Arg [2] : String $object_type
141  The object type of the biotype to retrieve (gene or transcript)
142  Example : $biotype = $biotype_adaptor->fetch_by_name_object_type('mRNA', 'gene');
143  Description: Retrieves a biotype object from the database via its combined key (name, object_type).
144  If the Biotype requested does not exist in the database, a new Biotype object is
145  created with the provided name and object_type to be returned.
146  Returntype : Bio::EnsEMBL::Biotype
147  Exceptions : none
148 
149 =cut
150 
151 sub fetch_by_name_object_type {
152  my ($self, $name, $object_type) = @_;
153 
154  my $biotype;
155 
156  # biotype table implemented on schema_version 93
157  if ($self->schema_version > 92) {
158  my $constraint = "b.name = ? AND b.object_type = ?";
159  $self->bind_param_generic_fetch($name, SQL_VARCHAR);
160  $self->bind_param_generic_fetch($object_type, SQL_VARCHAR);
161  $biotype = shift @{$self->generic_fetch($constraint)};
162  }
163 
164  # If request biotype does not exist in the table
165  # create a new biotype object containing name and object_type only
166  # this is required by genebuild in pipelines
167  if (!defined $biotype) {
168  $biotype = Bio::EnsEMBL::Biotype->new(
169  -NAME => $name,
170  -OBJECT_TYPE => $object_type,
171  )
172  }
173 
174  return $biotype;
175 }
176 
177 =head2 fetch_all_by_object_type
178 
179  Arg [1] : String $object_type
180  The object_type of the biotypes to retrieve (gene or transcript).
181  Example : $biotypes = $biotype_adaptor->fetch_all_by_object_type('gene');
182  Description: Retrieves an array reference of biotype objects from the database.
183  Returntype : arrayref of Bio::EnsEMBL::Biotype objects or empty arrayref
184  Warning : If empty arrayref is to be returned
185  Exceptions : none
186 
187 =cut
188 
189 sub fetch_all_by_object_type {
190  my ($self, $object_type) = @_;
191 
192  my $constraint = "b.object_type = ?";
193  $self->bind_param_generic_fetch($object_type, SQL_VARCHAR);
194  my @biotypes = @{$self->generic_fetch($constraint)};
195 
196  if ( !@biotypes ) {
197  warning("No objects retrieved. Check if object_type '$object_type' is correct.")
198  }
199 
200  return \@biotypes;
201 }
202 
203 =head2 fetch_all_by_name
204 
205  Arg [1] : String $name
206  The name of the biotype to retrieve
207  Arg [2] : (optional) String $object_type
208  The object_type of the biotypes to retrieve (gene or transcript).
209  Example : $biotypes = $biotype_adaptor->fetch_all_by_name('lincRNA');
210  Description: Retrieves an array reference of biotype objects from the database.
211  Returntype : arrayref of Bio::EnsEMBL::Biotype objects or empty arrayref
212  Warning : If empty arrayref is to be returned
213  Exceptions : none
214 
215 =cut
216 
217 sub fetch_all_by_name{
218  my ($self, $name, $object_type) = @_;
219 
220  my $constraint = "b.name = ?";
221  $self->bind_param_generic_fetch($name, SQL_VARCHAR);
222  if (defined $object_type) {
223  $constraint .= "AND b.object_type = ?";
224  $self->bind_param_generic_fetch($object_type, SQL_VARCHAR);
225  }
226  my @biotypes = @{$self->generic_fetch($constraint)};
227 
228  if ( !@biotypes ) {
229  warning("No objects retrieved. Check if name '$name' is correct.")
230  }
231 
232  return \@biotypes;
233 }
234 
235 =head2 fetch_all_by_group_object_db_type
236 
237  Arg [1] : String $biotype_group
238  The group of the biotypes to retrieve
239  Arg [2] : String $object_type
240  The object type of the biotypes to retrieve (gene or transcript)
241  Arg [3] : (optional) String $db_type
242  The db_type of the biotypes to retrieve. If not provided defaults to 'core'.
243  Example : $biotype = $biotype_adaptor->fetch_all_by_group_object_db_type('coding', 'gene');
244  Description: Retrieves an array reference of biotype objects from the database of the provided
245  biotype_group and object_type and core db_type.
246  Returntype : arrayref of Bio::EnsEMBL::Biotype objects or empty arrayref
247  Warning : If empty arrayref is to be returned
248  Exceptions : none
249 
250 =cut
251 
252 sub fetch_all_by_group_object_db_type {
253  my ($self, $biotype_group, $object_type, $db_type) = @_;
254 
255  $db_type //= 'core';
256  $db_type = '%' . $db_type . '%';
257 
258  my $constraint = "b.biotype_group = ? AND b.db_type LIKE ? ";
259  $self->bind_param_generic_fetch($biotype_group, SQL_VARCHAR);
260  $self->bind_param_generic_fetch($db_type, SQL_VARCHAR);
261  if (defined $object_type) {
262  $constraint .= " AND b.object_type = ?";
263  $self->bind_param_generic_fetch($object_type, SQL_VARCHAR);
264  }
265  my @biotypes = @{$self->generic_fetch($constraint)};
266 
267  if ( !@biotypes ) {
268  warning("No objects retrieved. Check if object_type '$object_type' is correct.")
269  }
270 
271  return \@biotypes;
272 }
273 
274 1;
transcript
public transcript()
Bio::EnsEMBL::Biotype
Definition: Biotype.pm:35
Bio::EnsEMBL::Biotype::new
public Bio::EnsEMBL::Biotype new()
Bio::EnsEMBL::DBSQL::StatementHandle
Definition: StatementHandle.pm:21
Bio::EnsEMBL::DBSQL::BaseAdaptor
Definition: BaseAdaptor.pm:71
Bio::EnsEMBL::DBSQL::BiotypeAdaptor
Definition: BiotypeAdaptor.pm:22
Bio::EnsEMBL::DBSQL::BiotypeAdaptor::fetch_by_name_object_type
public Bio::EnsEMBL::Biotype fetch_by_name_object_type()
Bio::EnsEMBL::Utils::Exception
Definition: Exception.pm:68