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