| 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::Biotype | ||
| 34 | |||
| 35 | =head1 SYNOPSIS | ||
| 36 | |||
| 37 | my $biotype = new Bio::EnsEMBL::Biotype( | ||
| 38 | -name => 'new_biotype, | ||
| 39 | -object_type => 'gene', | ||
| 40 | -biotype_group => 'a_biotype_group', | ||
| 41 | -so_acc => 'SO::1234567', | ||
| 42 | -description => 'New biotype' | ||
| 43 | ); | ||
| 44 | |||
| 45 | my $name = $biotype->name(); | ||
| 46 | my $biotype_group = $biotype->biotype_group(); | ||
| 47 | my $so_acc = $biotype->so_acc(); | ||
| 48 | |||
| 49 | =head1 DESCRIPTION | ||
| 50 | |||
| 51 | This is the Biotype object class. | ||
| 52 | Gene and Transcript objects used to have a biotype() method that returned the biotype name | ||
| 53 | (the biotype field in the gene and transcript tables). | ||
| 54 | From e93 a new biotype table was added. However because of legacy code using direct sql | ||
| 55 | queries on the biotype column of gene and transcript tables, that column that contains the | ||
| 56 | biotype name was not replaced by biotype_id containing a foreign key to the new biotype table. | ||
| 57 | Gene and Transcripts can still link to a Biotype through the key (name, object_type). | ||
| 58 | |||
| 59 | =head1 METHODS | ||
| 60 | |||
| 61 | =cut | ||
| 62 | |||
| 63 | |||
| 64 | package Bio::EnsEMBL::Biotype; | ||
| 65 | $Bio::EnsEMBL::Biotype::VERSION = '114.0.0'; | ||
| 66 | use strict; | ||
| 67 | use warnings; | ||
| 68 | |||
| 69 | use Bio::EnsEMBL::Storable; | ||
| 70 | use Bio::EnsEMBL::Utils::Exception qw(throw deprecate warning); | ||
| 71 | use Bio::EnsEMBL::Utils::Scalar qw(check_ref assert_ref); | ||
| 72 | use Bio::EnsEMBL::Utils::Argument qw(rearrange); | ||
| 73 | use Scalar::Util qw(weaken isweak); | ||
| 74 | |||
| 75 | use parent qw(Bio::EnsEMBL::Storable); | ||
| 76 | |||
| 77 | =head2 new | ||
| 78 | |||
| 79 | Arg [-BIOTYPE_ID] : | ||
| 80 | int - dbID of the biotype | ||
| 81 | Arg [-NAME] : | ||
| 82 | string - the name of the biotype (for ensembl) | ||
| 83 | Arg [-OBJECT_TYPE] : | ||
| 84 | string - the object type this biotype applies to (gene or transcript) | ||
| 85 | Arg [-BIOTYPE_GROUP] : | ||
| 86 | string - the name of the biotype group (for ensembl) | ||
| 87 | Arg [-SO_ACC] : | ||
| 88 | string - the Sequence Ontology accession of this biotype | ||
| 89 | Arg [-SO_TERM] : | ||
| 90 | string - the Sequence Ontology term for the SO accession of this biotype | ||
| 91 | Arg [-DESCRIPTION] : | ||
| 92 | string - the biotype description | ||
| 93 | Arg [-DB_TYPE] : | ||
| 94 | string - the database type for this biotype | ||
| 95 | Arg [-ATTRIB_TYPE_ID] : | ||
| 96 | int - attrib_type_id | ||
| 97 | |||
| 98 | Example : $biotype = Bio::EnsEMBL::Biotype->new(...); | ||
| 99 | Description: Creates a new biotype object | ||
| 100 | Returntype : Bio::EnsEMBL::Biotype | ||
| 101 | Exceptions : none | ||
| 102 | |||
| 103 | =cut | ||
| 104 | |||
| 105 | sub new { | ||
| 106 | my ( $caller, @args ) = @_; | ||
| 107 | |||
| 108 | my $class = ref($caller) || $caller; | ||
| 109 | |||
| 110 | my $self = $class->SUPER::new(); | ||
| 111 | |||
| 112 | my($dbID, $name, $object_type, $biotype_group, $so_acc, $so_term, $description, $db_type, $attrib_type_id) = | ||
| 113 | rearrange([qw(BIOTYPE_ID NAME OBJECT_TYPE BIOTYPE_GROUP SO_ACC SO_TERM DESCRIPTION DB_TYPE ATTRIB_TYPE_ID)], @args); | ||
| 114 | |||
| 115 | $self->{'dbID'} = $dbID; | ||
| 116 | $self->{'name'} = $name; | ||
| 117 | $self->{'object_type'} = $object_type; | ||
| 118 | $self->{'biotype_group'} = $biotype_group; | ||
| 119 | $self->{'so_acc'} = $so_acc; | ||
| 120 | $self->{'so_term'} = $so_term; | ||
| 121 | $self->{'description'} = $description; | ||
| 122 | $self->{'db_type'} = $db_type; | ||
| 123 | $self->{'attrib_type_id'} = $attrib_type_id; | ||
| 124 | |||
| 125 | return $self; | ||
| 126 | } | ||
| 127 | |||
| 128 | =head2 new_fast | ||
| 129 | |||
| 130 | Arg [1] : hashref to be blessed | ||
| 131 | Description: Construct a new Bio::EnsEMBL::Biotype using the hashref. | ||
| 132 | Exceptions : none | ||
| 133 | Returntype : Bio::EnsEMBL::Biotype | ||
| 134 | |||
| 135 | =cut | ||
| 136 | |||
| 137 | |||
| 138 | sub new_fast { | ||
| 139 | my ( $class, $hashref ) = @_; | ||
| 140 | |||
| 141 | my $self = bless $hashref, $class; | ||
| 142 | |||
| 143 | if ( !isweak($self->{adaptor}) ) { | ||
| 144 | weaken($self->{adaptor}) | ||
| 145 | } | ||
| 146 | |||
| 147 | return $self; | ||
| 148 | } | ||
| 149 | |||
| 150 | =head2 name | ||
| 151 | |||
| 152 | Arg [1] : (optional) string $name | ||
| 153 | The name of this biotype according to ensembl. | ||
| 154 | Example : $name = $biotype->name() | ||
| 155 | Description: Getter/Setter for the name of this biotype. | ||
| 156 | Returntype : string | ||
| 157 | Exceptions : none | ||
| 158 | |||
| 159 | =cut | ||
| 160 | |||
| 161 | sub name { | ||
| 162 | my ( $self, $name ) = @_; | ||
| 163 | |||
| 164 | if ( defined($name) ) { | ||
| 165 | $self->{'name'} = $name; | ||
| 166 | } | ||
| 167 | |||
| 168 | return $self->{'name'}; | ||
| 169 | } | ||
| 170 | |||
| 171 | =head2 biotype_group | ||
| 172 | |||
| 173 | Arg [1] : (optional) string $biotype_group | ||
| 174 | Example : $biotype_group = $biotype->biotype_group(); | ||
| 175 | Description: Getter/Setter for the biotype_group of this biotype. | ||
| 176 | Biotype groups are used internally at ensembl pipelines | ||
| 177 | and consist on few defined categories. | ||
| 178 | Returntype : string | ||
| 179 | Exceptions : none | ||
| 180 | Caller : general | ||
| 181 | Status : Stable | ||
| 182 | |||
| 183 | =cut | ||
| 184 | |||
| 185 | sub biotype_group { | ||
| 186 | my ( $self, $biotype_group ) = @_; | ||
| 187 | |||
| 188 | if ( defined($biotype_group) ) { | ||
| 189 | $self->{'biotype_group'} = $biotype_group; | ||
| 190 | } | ||
| 191 | |||
| 192 | return $self->{'biotype_group'}; | ||
| 193 | } | ||
| 194 | |||
| 195 | =head2 so_acc | ||
| 196 | |||
| 197 | Arg [1] : (optional) string $so_acc | ||
| 198 | Example : $feat->so_acc(); | ||
| 199 | Description: Getter/Setter for the Sequence Ontology accession of this biotype. | ||
| 200 | It must be a SO like accession. | ||
| 201 | Returntype : string | ||
| 202 | Exceptions : thrown if an invalid so_acc argument is passed | ||
| 203 | |||
| 204 | =cut | ||
| 205 | |||
| 206 | sub so_acc { | ||
| 207 | my ( $self, $so_acc ) = @_; | ||
| 208 | |||
| 209 | if ( defined($so_acc) ) { | ||
| 210 | # throw an error if setting something that does not look like an SO acc | ||
| 211 | unless ( $so_acc =~ m/\ASO:\d+\z/x ) { | ||
| 212 | throw("so_acc must be a Sequence Ontology accession. '$so_acc' does not look like one.") | ||
| 213 | } | ||
| 214 | |||
| 215 | $self->{'so_acc'} = $so_acc; | ||
| 216 | } | ||
| 217 | |||
| 218 | return $self->{'so_acc'}; | ||
| 219 | } | ||
| 220 | |||
| 221 | =head2 so_term | ||
| 222 | |||
| 223 | Arg [1] : (optional) string $so_term | ||
| 224 | Example : $feat->so_term(); | ||
| 225 | Description: Getter/Setter for the Sequence Ontology term of this biotype. | ||
| 226 | Returntype : string | ||
| 227 | Exceptions : none | ||
| 228 | |||
| 229 | =cut | ||
| 230 | |||
| 231 | sub so_term { | ||
| 232 | my ( $self, $so_term ) = @_; | ||
| 233 | |||
| 234 | if ( defined($so_term) ) { | ||
| 235 | $self->{'so_term'} = $so_term; | ||
| 236 | } | ||
| 237 | |||
| 238 | return $self->{'so_term'}; | ||
| 239 | } | ||
| 240 | |||
| 241 | =head2 object_type | ||
| 242 | |||
| 243 | Arg [1] : (optional) string $object_type | ||
| 244 | Example : $object_type = $biotype->object_type(); | ||
| 245 | Description: Getter/Setter for the object_type of this biotype. | ||
| 246 | Biotypes can be assigned to either genes or transcripts, | ||
| 247 | object_type refers to which of them. | ||
| 248 | Returntype : string | ||
| 249 | Exceptions : thrown if an invalid object_type argument is passed (not gene or transcript) | ||
| 250 | |||
| 251 | =cut | ||
| 252 | |||
| 253 | sub object_type { | ||
| 254 | my ( $self, $object_type ) = @_; | ||
| 255 | |||
| 256 | if ( defined($object_type) ) { | ||
| 257 | $object_type = lc $object_type; | ||
| 258 | # throw an error if setting something that does not look like an SO acc | ||
| 259 | unless ( $object_type eq 'gene' || $object_type eq 'transcript' ) { | ||
| 260 | throw("object_type must be gene or transcript. Got '$object_type'.") | ||
| 261 | } | ||
| 262 | |||
| 263 | $self->{'object_type'} = $object_type; | ||
| 264 | } | ||
| 265 | |||
| 266 | return $self->{'object_type'}; | ||
| 267 | } | ||
| 268 | |||
| 269 | 1; |