| 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 | |||
| 22 | =head1 CONTACT | ||
| 23 | |||
| 24 | Please email comments or questions to the public Ensembl | ||
| 25 | developers list at <http://lists.ensembl.org/mailman/listinfo/dev>. | ||
| 26 | |||
| 27 | Questions may also be sent to the Ensembl help desk at | ||
| 28 | <http://www.ensembl.org/Help/Contact>. | ||
| 29 | =cut | ||
| 30 | |||
| 31 | =head1 NAME | ||
| 32 | |||
| 33 | Bio::EnsEMBL::ProteinFeature | ||
| 34 | |||
| 35 | =head1 SYNOPSIS | ||
| 36 | |||
| 37 | my $feature = Bio::EnsEMBL::ProteinFeature->new( | ||
| 38 | -start => $start, | ||
| 39 | -end => $end, | ||
| 40 | -hstart => $hit_start, | ||
| 41 | -hend => $hit_end, | ||
| 42 | -hseqname => $hit_name | ||
| 43 | ); | ||
| 44 | |||
| 45 | =head1 DESCRIPTION | ||
| 46 | |||
| 47 | ProteinFeature objects represent domains or other features of interest | ||
| 48 | on a peptide sequence. | ||
| 49 | |||
| 50 | =head1 METHODS | ||
| 51 | |||
| 52 | =cut | ||
| 53 | |||
| 54 | package Bio::EnsEMBL::ProteinFeature; | ||
| 55 | $Bio::EnsEMBL::ProteinFeature::VERSION = '114.0.0_50'; # TRIAL | ||
| 56 | $Bio::EnsEMBL::ProteinFeature::VERSION = '114.0.050'; | ||
| 57 | use strict; | ||
| 58 | |||
| 59 | use Bio::EnsEMBL::FeaturePair; | ||
| 60 | use Bio::EnsEMBL::BaseAlignFeature; | ||
| 61 | use Bio::EnsEMBL::Utils::Argument qw(rearrange); | ||
| 62 | |||
| 63 | use parent qw(Bio::EnsEMBL::BaseAlignFeature); | ||
| 64 | |||
| 65 | =head2 new | ||
| 66 | |||
| 67 | Arg [IDESC] : (optional) string An interpro description | ||
| 68 | Arg [INTERPRO_AC] : (optional) string An interpro accession | ||
| 69 | Arg [TRANSLATION_ID] : (optional) integer A translation dbID | ||
| 70 | Arg [...] : named arguments to FeaturePair superclass | ||
| 71 | Example : | ||
| 72 | |||
| 73 | $pf = | ||
| 74 | Bio::EnsEMBL::ProteinFeature->new( -IDESC => $idesc, | ||
| 75 | -INTERPRO_AC => $iac, | ||
| 76 | @fp_args ); | ||
| 77 | |||
| 78 | Description: Instantiates a Bio::EnsEMBL::ProteinFeature | ||
| 79 | Returntype : Bio::EnsEMBL::FeaturePair | ||
| 80 | Exceptions : none | ||
| 81 | Caller : general | ||
| 82 | Status : Stable | ||
| 83 | |||
| 84 | =cut | ||
| 85 | |||
| 86 | |||
| 87 | sub new { | ||
| 88 | my ($proto, @args) = @_; | ||
| 89 | |||
| 90 | my $class = ref($proto) || $proto; | ||
| 91 | |||
| 92 | my $self; | ||
| 93 | my ($idesc, $ilabel, $interpro_ac, $translation_id, $external_data, $hit_description, $cigar_string, $align_type, $slice) = rearrange(['IDESC', 'ILABEL', 'INTERPRO_AC', 'TRANSLATION_ID', 'EXTERNAL_DATA', 'HDESCRIPTION', 'CIGAR_STRING', 'ALIGN_TYPE', 'SLICE'], @args); | ||
| 94 | |||
| 95 | # BaseAlignFeature expects cigar_line or features | ||
| 96 | if($cigar_string && $align_type){ | ||
| 97 | $self = $class->SUPER::new(@args); | ||
| 98 | }else{ | ||
| 99 | #call the grand parent directly | ||
| 100 | $self = $class->Bio::EnsEMBL::FeaturePair::new(@args); | ||
| 101 | } | ||
| 102 | |||
| 103 | # the strand of protein features is always 0 | ||
| 104 | $self->{'strand'} = 0; | ||
| 105 | $self->{'idesc'} = $idesc || ''; | ||
| 106 | $self->{'ilabel'} = $ilabel || ''; | ||
| 107 | $self->{'interpro_ac'} = $interpro_ac || ''; | ||
| 108 | $self->{'translation_id'} = $translation_id || ''; | ||
| 109 | $self->{'external_data'} = $external_data || ''; | ||
| 110 | $self->{'hit_description'} = $hit_description || ''; | ||
| 111 | $self->{'cigar_string'} = $cigar_string || ''; | ||
| 112 | $self->{'align_type'} = $align_type; | ||
| 113 | |||
| 114 | return $self; | ||
| 115 | } | ||
| 116 | |||
| 117 | =head2 strand | ||
| 118 | |||
| 119 | Arg [1] : Ignored | ||
| 120 | Description: Overwrites Bio::EnsEMBL::Feature->strand to not allow | ||
| 121 | : the strand to be set. | ||
| 122 | Returntype : int | ||
| 123 | Status : Stable | ||
| 124 | |||
| 125 | =cut | ||
| 126 | |||
| 127 | #do not allow the strand to be set | ||
| 128 | sub strand { | ||
| 129 | my $self = shift; | ||
| 130 | return $self->{'strand'}; | ||
| 131 | } | ||
| 132 | |||
| 133 | =head2 idesc | ||
| 134 | |||
| 135 | Arg [1] : (optional) string The interpro description | ||
| 136 | Example : print $protein_feature->idesc(); | ||
| 137 | Description: Getter/Setter for the interpro description of this protein | ||
| 138 | feature. | ||
| 139 | Returntype : string | ||
| 140 | Exceptions : none | ||
| 141 | Caller : general | ||
| 142 | Status : Stable | ||
| 143 | |||
| 144 | =cut | ||
| 145 | |||
| 146 | sub idesc { | ||
| 147 | my $self = shift; | ||
| 148 | $self->{'idesc'} = shift if (@_); | ||
| 149 | return $self->{'idesc'}; | ||
| 150 | } | ||
| 151 | |||
| 152 | =head2 ilabel | ||
| 153 | |||
| 154 | Arg [1] : (optional) string The interpro label | ||
| 155 | Example : print $protein_feature->ilabel(); | ||
| 156 | Description: Getter/Setter for the interpro label of this protein | ||
| 157 | feature. | ||
| 158 | Returntype : string | ||
| 159 | Exceptions : none | ||
| 160 | Caller : general | ||
| 161 | Status : Stable | ||
| 162 | |||
| 163 | =cut | ||
| 164 | |||
| 165 | sub ilabel { | ||
| 166 | my $self = shift; | ||
| 167 | $self->{'ilabel'} = shift if (@_); | ||
| 168 | return $self->{'ilabel'}; | ||
| 169 | } | ||
| 170 | |||
| 171 | =head2 interpro_ac | ||
| 172 | |||
| 173 | Arg [1] : (optional) string The interpro accession | ||
| 174 | Example : print $protein_feature->interpro_ac(); | ||
| 175 | Description: Getter/Setter for the interpro accession of this protein | ||
| 176 | feature. | ||
| 177 | Returntype : string | ||
| 178 | Exceptions : none | ||
| 179 | Caller : general | ||
| 180 | Status : Stable | ||
| 181 | |||
| 182 | =cut | ||
| 183 | |||
| 184 | sub interpro_ac { | ||
| 185 | my $self = shift; | ||
| 186 | $self->{'interpro_ac'} = shift if (@_); | ||
| 187 | return $self->{'interpro_ac'}; | ||
| 188 | } | ||
| 189 | |||
| 190 | =head2 translation_id | ||
| 191 | |||
| 192 | Arg [1] : (optional) integer The dbID of the translation | ||
| 193 | Example : print $protein_feature->translation_id(); | ||
| 194 | Description: Getter/Setter for the translation dbID of this protein | ||
| 195 | feature. | ||
| 196 | Returntype : string | ||
| 197 | Exceptions : none | ||
| 198 | Caller : general | ||
| 199 | Status : Stable | ||
| 200 | |||
| 201 | =cut | ||
| 202 | |||
| 203 | sub translation_id { | ||
| 204 | my $self = shift; | ||
| 205 | $self->{'translation_id'} = shift if (@_); | ||
| 206 | return $self->{'translation_id'}; | ||
| 207 | } | ||
| 208 | |||
| 209 | sub external_data { | ||
| 210 | my $self = shift; | ||
| 211 | $self->{'external_data'} = shift if (@_); | ||
| 212 | return $self->{'external_data'}; | ||
| 213 | } | ||
| 214 | |||
| 215 | |||
| 216 | =head2 summary_as_hash | ||
| 217 | |||
| 218 | Example : $protein_feature_summary = $protein_feature->summary_as_hash(); | ||
| 219 | Description : Retrieves a textual summary of this Protein feature. | ||
| 220 | Not inherited from Feature. | ||
| 221 | Returns : hashref of arrays of descriptive strings | ||
| 222 | Status : Intended for internal use | ||
| 223 | =cut | ||
| 224 | |||
| 225 | sub summary_as_hash { | ||
| 226 | my $self = shift; | ||
| 227 | my %summary; | ||
| 228 | $summary{'type'} = $self->analysis->db; | ||
| 229 | $summary{'id'} = $self->display_id; | ||
| 230 | $summary{'start'} = $self->start; | ||
| 231 | $summary{'end'} = $self->end; | ||
| 232 | $summary{'interpro'} = $self->interpro_ac; | ||
| 233 | $summary{'description'} = $self->idesc; | ||
| 234 | $summary{'hit_start'} = $self->hstart; | ||
| 235 | $summary{'hit_end'} = $self->hend; | ||
| 236 | $summary{'cigar_string'} = $self->cigar_string; | ||
| 237 | $summary{'align_type'} = $self->align_type; | ||
| 238 | $summary{'hseqname'} = $self->hseqname; | ||
| 239 | $summary{'translation_id'} = $self->translation_id; | ||
| 240 | |||
| 241 | return \%summary; | ||
| 242 | } | ||
| 243 | |||
| 244 | |||
| 245 | =head2 alignment_strings | ||
| 246 | |||
| 247 | Arg [1] : list of string $flags | ||
| 248 | Example : $pf->alignment_strings | ||
| 249 | Description: Allows to rebuild the alignment string of both the query and target sequence | ||
| 250 | using the sequence from translation object and | ||
| 251 | MD Z String for mismatching positions. Regex : [0-9]+(([A-Z]|\^[A-Z]+)[0-9]+)* (Refer: SAM/BAM specification) | ||
| 252 | eg: MD:Z:96^RHKTDSFVGLMGKRALNS0V14 | ||
| 253 | Returntype : array reference containing 2 strings | ||
| 254 | the first corresponds to seq | ||
| 255 | the second corresponds to hseq | ||
| 256 | Exceptions : none | ||
| 257 | Caller : general | ||
| 258 | Status : Stable | ||
| 259 | |||
| 260 | =cut | ||
| 261 | |||
| 262 | |||
| 263 | sub alignment_strings { | ||
| 264 | my $self = shift; | ||
| 265 | |||
| 266 | #Translations | ||
| 267 | my $transl_adaptor = $self->adaptor->db->get_TranslationAdaptor(); | ||
| 268 | my $transl_object = $transl_adaptor->fetch_by_dbID($self->translation_id); | ||
| 269 | my $seq; | ||
| 270 | if(defined $transl_object && $transl_object->isa('Bio::EnsEMBL::Translation')) { | ||
| 271 | $seq = $transl_object->transcript()->translate()->seq(); | ||
| 272 | } | ||
| 273 | |||
| 274 | if ($self->align_type eq 'mdtag') { | ||
| 275 | if(defined $seq && defined $self->cigar_string){ | ||
| 276 | return $self->_mdz_alignment_string($seq,$self->cigar_string); | ||
| 277 | }else{ | ||
| 278 | warn "sequence or cigar_line not found for " . $self->translation_id; | ||
| 279 | } | ||
| 280 | } else { | ||
| 281 | throw("alignment_strings method not implemented for " . $self->align_type); | ||
| 282 | } | ||
| 283 | return; | ||
| 284 | } | ||
| 285 | |||
| 286 | |||
| 287 | sub transform { | ||
| 288 | my $self = shift; | ||
| 289 | |||
| 290 | $self->throw( "ProteinFeature cant be transformed directly as". | ||
| 291 | " they are not on EnsEMBL coord system" ); | ||
| 292 | return; | ||
| 293 | } | ||
| 294 | |||
| 295 | |||
| 296 | =head2 _hit_unit | ||
| 297 | |||
| 298 | Arg [1] : none | ||
| 299 | Description: PRIVATE implementation of abstract superclass method. Returns | ||
| 300 | 1 as the 'unit' used for the hit sequence. | ||
| 301 | Returntype : int | ||
| 302 | Exceptions : none | ||
| 303 | Caller : Bio::EnsEMBL::BaseAlignFeature | ||
| 304 | Status : Stable | ||
| 305 | |||
| 306 | |||
| 307 | =cut | ||
| 308 | |||
| 309 | sub _hit_unit { | ||
| 310 | return 3; | ||
| 311 | } | ||
| 312 | |||
| 313 | |||
| 314 | =head2 _query_unit | ||
| 315 | |||
| 316 | Arg [1] : none | ||
| 317 | Description: PRIVATE implementation of abstract superclass method. Returns | ||
| 318 | 3 as the 'unit' used for the query sequence. | ||
| 319 | Returntype : int | ||
| 320 | Exceptions : none | ||
| 321 | Caller : Bio::EnsEMBL::BaseAlignFeature | ||
| 322 | Status : Stable | ||
| 323 | |||
| 324 | |||
| 325 | =cut | ||
| 326 | |||
| 327 | sub _query_unit { | ||
| 328 | return 3; | ||
| 329 | } | ||
| 330 | |||
| 331 | |||
| 332 | |||
| 333 | |||
| 334 | |||
| 335 | 1; |