3 Copyright [1999-2015] Wellcome Trust Sanger Institute and the EMBL-European Bioinformatics Institute
4 Copyright [2016-2024] EMBL-European Bioinformatics Institute
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
42 # For a known Gene, find the reference alternative allele
43 my $aag = $aag_adaptor->fetch_Group_by_dbID($gene->dbID);
44 my $reference_gene = $aag->get_representative_Gene;
46 # Get a list of AltAlleleGroups
47 my $list = $aag_adaptor->fetch_all_Groups_by_type(
'HAS_CODING_POTENTIAL');
48 $list = $aag_adaptor->fetch_all_Groups();
50 while ($aag = shift @$list) {
52 # Do your important things ...
55 # Creating and editing an AltAlleleGroup
57 my %type_flags = (
'IS_MOST_COMMON_ALLELE' =>
'1',
'AUTOMATICALLY_ASSIGNED' =>
'1');
60 -MEMBERS => [ [$gene_id,\%type_flags ] ],
63 $aag->add_member($gene_id,\%type_flags);
65 my $dbID = $aag_adaptor->store($aag);
70 Alt allele groups keep track of which alleles are tied to a particular
Gene
71 They allow related genes to be located. This
class allows fetching of both
72 IDs and fully fledged
Gene objects.
74 AltAlleleGroup members are assigned types to differentiate them by their
75 origin. These types are set as flags, allowing you to select the union of
76 types as well as by individual ones.
78 No flags set denotes a situation of no information.
79 Valid flags are as follows:
81 'IS_MOST_COMMON_ALLELE',
82 'IN_CORRECTED_ASSEMBLY',
83 'HAS_CODING_POTENTIAL',
84 'IN_ARTIFICIALLY_DUPLICATED_ASSEMBLY',
86 'HAS_SAME_UNDERLYING_DNA_SEQUENCE',
87 'IN_BROKEN_ASSEMBLY_REGION',
89 'SAME_AS_REPRESENTATIVE',
90 'SAME_AS_ANOTHER_ALLELE',
92 'AUTOMATICALLY_ASSIGNED'
100 # IS_REPRESENTATIVE => 1,
101 # IS_MOST_COMMON_ALLELE => 2,
102 # IN_CORRECTED_ASSEMBLY => 3,
103 # HAS_CODING_POTENTIAL => 4,
104 # IN_ARTIFICIALLY_DUPLICATED_ASSEMBLY => 5,
105 # IN_SYNTENIC_REGION => 6,
106 # HAS_SAME_UNDERLYING_DNA_SEQUENCE => 7,
107 # IN_BROKEN_ASSEMBLY_REGION => 8,
108 # IS_VALID_ALTERNATE => 9,
109 # SAME_AS_REPRESENTATIVE => 10,
110 # SAME_AS_ANOTHER_ALLELE => 11,
111 # MANUALLY_ASSIGNED => 12,
112 # AUTOMATICALLY_ASSIGNED => 13,
124 Arg [-MEMBERS]: A list reference of [gene_id,type_flags]
125 : gene_id is a dbID for
Gene (consistent only within one release)
126 : type_flags is a hash ref of attributes for this member
128 -MEMBERS => [ [1,{$type} ], [2,{$other_type}],[3,{$type}],
130 Description: Creates a
new alt-allele group
object
140 my $class = ref($caller) || $caller;
141 my $self = $class->SUPER::new(@_);
142 my ( $list ) = rearrange( [
'MEMBERS'], @_ );
144 $self->{
'MEMBERS'} = $list || [];
152 Arg [2] : Type List, used
for assigning type flags of
this member, see Description above
153 Description : Adds a record of one
new member to the AltAlleleGroup. Once a
154 change is made,
this must be persisted to the database with
155 AltAlleleGroupAdaptor->store or ->update
156 Example : $aag->add_member(1040032,$types_hash);
157 $aaga->update($aag); # updating the whole group is necessary.
161 my ($self, $gene_id,$type_hash) = @_;
162 if(!$self->contains_member($gene_id)) {
163 push(@{$self->{MEMBERS}}, [$gene_id, {}]);
164 $self->set_attribs($gene_id, $type_hash);
169 =head2 get_all_members_with_type
171 Arg [1] : String The type to search members by
172 Description : Loops through the
internal members array returning all
173 attributes of the same type as what has been specified
174 Example : my $members = $aag->get_all_members_with_type(
'IS_VALID_ALTERNATE');
178 sub get_all_members_with_type {
182 my @filtered_members;
183 my $members = $self->{
'MEMBERS'};
184 foreach my $member (@$members) {
185 if (exists($member->[1]->{$type})) {
186 push @filtered_members,$member;
189 return \@filtered_members;
194 Arg [1] : Int gene
id to record attributes against
195 Description : Returns all known attributes of the given gene
id. Attributes
196 are returned as a HashRef but is a copy of the interally
198 Returntype : HashRef copy of all the given
id's attributes
199 Example : $aag->attribs(10, 'IS_VALID_ALTERNATE
');
200 $aag->attribs(10, [ 'IS_VALID_ALTERNATE
' ]);
201 $aag->attribs(10, {IS_VALID_ALTERNATE => 1});
206 my ($self, $gene_id) = @_;
207 assert_integer($gene_id, 'gene_id
');
208 foreach my $member (@{$self->{MEMBERS}}) {
209 if($member->[0] == $gene_id) {
210 my $attribs = $member->[1];
211 return { %{$attribs} }; # make a copy. never leak
219 Arg [1] : Int gene id to set attributes against
220 Arg [2] : ArrayRef/HashRef/Scalar The attribute you wish to record
221 Description : Adds the given type to the specified gene id in this group. You
222 can specify the type using an ArrayRef, HashRef or a single scalar
223 Example : $aag->attribs(10, 'IS_VALID_ALTERNATE
');
224 $aag->attribs(10, [ 'IS_VALID_ALTERNATE
' ]);
225 $aag->attribs(10, {IS_VALID_ALTERNATE => 1});
230 my ($self, $gene_id, $attribs) = @_;
231 assert_integer($gene_id, 'gene_id
');
232 my $current_attribs = $self->attribs($gene_id);
233 if(check_ref($attribs, 'ARRAY
')) {
235 $current_attribs->{uc($_)} = 1 for @{$attribs};
237 elsif(check_ref($attribs, 'HASH
')) {
238 #loop through the keys adding them in
239 foreach my $key (keys %{$attribs}) {
240 $current_attribs->{uc($key)} = 1;
243 #Simple scalar value so just add it in
245 $current_attribs->{uc($attribs)} = 1;
247 foreach my $member (@{$self->{MEMBERS}}) {
248 if($member->[0] == $gene_id) {
249 $member->[1] = $current_attribs;
255 =head2 remove_attribs
257 Arg [1] : Int gene id to retrieve attributes against
258 Arg [2] : ArrayRef/HashRef/Scalar The attribute you wish to remove
259 Description : Removes the given type from this group against the specified
261 Example : $aag->remove_attribs(10, 'IS_VALID_ALTERNATE
');
262 $aag->remove_attribs(10, [ 'IS_VALID_ALTERNATE
' ]);
263 $aag->remove_attribs(10, {IS_VALID_ALTERNATE => 1});
268 my ($self, $gene_id, $attribs) = @_;
269 assert_integer($gene_id, 'gene_id
');
271 if(check_ref($attribs, 'ARRAY
')) {
272 @to_remove = map { uc($_) } @{$attribs};
274 elsif(check_ref($attribs, 'HASH
')) {
275 @to_remove = map { uc($_) } keys %{$attribs};
277 #Simple scalar value so just add it in
279 @to_remove = uc($attribs);
281 foreach my $member (@{$self->{MEMBERS}}) {
282 if($member->[0] == $gene_id) {
283 my $current_attribs = $member->[1];
284 delete $current_attribs->{$_} for @to_remove;
292 Arg [1] : Int gene id to retrieve attributes against
293 Arg [2] : ArrayRef/HashRef/Scalar The attribute you wish to remove
294 Description : Removes the given member from this group. Any changes
295 must be persisted back to the database via update() or
296 store() methods in Bio::EnsEMBL::DBSQL::AltAlleleGroupAdaptor.
297 Example : $aag->remove_member(10);
302 my ($self, $gene_id) = @_;
303 assert_integer($gene_id, 'gene_id
');
304 my $members = $self->{MEMBERS};
305 my $size = scalar(@{$members});
306 for(my $i = 0; $i < $size; $i++) {
307 my $current_id = $members->[$i]->[0];
308 #If this was the ID then splice it out of the array and exit
309 if($current_id == $gene_id) {
310 splice(@{$members}, $i, 1);
317 =head2 contains_member
319 Arg [1] : Int gene id to retrieve attributes against
320 Description : Searches through the members list looking for the
321 specified gene id. Returns true if it was found
323 Returntype : Boolean indicating if the given gene id is held in this group
324 Example : $aag->contains_member(10);
328 sub contains_member {
329 my ($self, $gene_id) = @_;
330 assert_integer($gene_id, 'gene_id
');
331 foreach my $member (@{$self->{MEMBERS}}) {
332 if($member->[0] == $gene_id) {
339 =head2 remove_all_members
341 Description : Remove members from this object, but NOT the database. See
342 AltAlleleGroupAdaptor->remove() to remove the group from the
346 sub remove_all_members {
348 $self->{'MEMBERS
'} = [];
354 Arg[1] : Optional - set a new representative Gene id for the group
355 Description : Reports or sets the representative Gene for this AltAlleleGroup
356 If you wish to remove the representative status of all genes without
357 setting a new one, see unset_rep_Gene_id
358 Returntype : Integer or undef if none set
364 my $list = $self->{'MEMBERS
'};
367 foreach my $allele (@$list) {
368 my ($gene_id,$type) = @$allele;
369 if (exists($type->{IS_REPRESENTATIVE}) && !defined($new_id) ) {
374 unless ($gene_id == $new_id) {delete($allele->[1]->{IS_REPRESENTATIVE})}
376 $allele->[1]->{IS_REPRESENTATIVE} = 1;
383 $self->{'MEMBERS
'} = $list;
385 } elsif ($new_id && !$change) {
386 my $db_id = $self->dbID() || 'unknown
';
387 throw("Requested representative gene ID was not set because it is not in this AltAlleleGroup, ID $db_id");
390 warning("No representative allele currently set for this AltAlleleGroup");
395 =head2 unset_rep_Gene_id
397 Description : Removes the representative Gene flag from this AltAlleleGroup.
398 This action is not possible through rep_Gene_id due to
399 validation of inputs.
403 sub unset_rep_Gene_id {
405 my $list = $self->{'MEMBERS
'};
407 foreach my $allele (@$list) {
408 delete($allele->[1]->{IS_REPRESENTATIVE});
410 $self->{'MEMBERS
'} = $list;
414 =head2 get_all_Gene_ids
416 Arg[1] : Boolean - Do not include representative gene in list of ids.
417 Arg[2] : ArrayRef - Can contain dbIDs or Gene objects to exclude from the returned list
418 Description : fetches all the Gene dbIDs within the allele group. It can also
419 be used to list those ids that are not the representative Gene.
420 Returntype : ArrayRef of gene dbIDs
424 sub get_all_Gene_ids {
426 my $all_but_rep = shift;
427 my $excluded_genes = shift;
428 my $list = $self->{'MEMBERS
'};
431 if($excluded_genes) {
432 assert_ref($excluded_genes, 'ARRAY
', 'excluded genes
');
433 foreach my $gene (@{$excluded_genes}) {
434 my $gene_id = (ref($gene)) ? $gene->dbID() : $gene;
435 $gene_exclusions{$gene_id} = $gene_id;
441 foreach my $allele (@$list) {
442 my ($gene_id,$type) = @$allele;
443 if ($all_but_rep && $type->{IS_REPRESENTATIVE}) {next;}
444 if(exists $gene_exclusions{$gene_id}) { next; }
445 push @gene_ids,$gene_id;
447 return [sort {$a <=> $b} @gene_ids];
450 =head2 get_representative_Gene
452 Description : Used to fetch a Gene object which has been marked as the
453 representative Gene for this alt allele group.
454 Returntype : Bio::EnsEMBL::Gene object which is the representative gene
459 sub get_representative_Gene {
461 my $ga = $self->adaptor->db->get_GeneAdaptor;
463 return $ga->fetch_by_dbID($self->rep_Gene_id);
468 Arg[1] : Boolean - Do not include representative gene in list of ids.
469 Arg[2] : ArrayRef - Can contain dbIDs or Gene objects to exclude from the returned list
470 Description : Fetches all the Gene objects within the allele group. It can also
471 be used to list those Genes that are not the representative Gene.
472 Returntype : ArrayRef of Bio::EnsEMBL::Gene objects
478 my ($self, $all_but_rep, $excluded_genes) = @_;
479 my $gene_ids = $self->get_all_Gene_ids($all_but_rep, $excluded_genes);
480 return $self->adaptor()->db()->get_GeneAdaptor()->fetch_all_by_dbID_list($gene_ids);
484 =head2 get_all_Genes_types
486 Arg[1] : Boolean - Do not include representative gene in list of ids.
487 Arg[2] : ArrayRef - Can contain dbIDs or Gene objects to exclude from the returned list
488 Description : Fetches all the Gene objects within the allele group and their
489 associcated attributes. It can also be used to list those
490 Genes that are not the representative Gene.
491 Returntype : ArrayRef. 2 dimensional holding [Bio::EnsEMBL::Gene, {attribute_hash}]
495 sub get_all_Genes_types {
496 my ($self, $all_but_rep, $excluded_genes) = @_;
497 my $gene_ids = $self->get_all_Gene_ids($all_but_rep, $excluded_genes);
498 my $ga = $self->adaptor()->db()->get_GeneAdaptor();
500 my $members = $self->{MEMBERS};
501 foreach my $allele (@{$members}) {
502 my ($gene_id,$attribs) = @$allele;
503 if ($all_but_rep && $attribs->{IS_REPRESENTATIVE}) {next;}
504 my $gene = $ga->fetch_by_dbID($gene_id);
505 my %attribs_copy = %{$attribs};
506 push(@output, [$gene, \%attribs_copy])
513 Description : Returns the current size of this group in members
514 Returntype : Int the size of the current alt allele group
520 my $list = $self->{'MEMBERS
'};
521 return scalar(@$list);
525 =head2 get_all_members
527 Description : Retrieves all of the information about all members. Be aware
528 that this emits the interal data structure so direct modification
529 should be done with caution.
530 Returntype : ArrayRef of id and type list: [gene_id,type]
531 Caller : AltAlleleGroupAdaptor->store
535 sub get_all_members {
537 my $members = $self->{'MEMBERS
'};