File Coverage

blib/lib/OBO/APO/APO_ID_Set.pm
Criterion Covered Total %
statement 22 36 61.1
branch 1 8 12.5
condition n/a
subroutine 6 7 85.7
pod 2 2 100.0
total 31 53 58.4


line stmt bran cond sub pod time code
1             # $Id: APO_ID_Set.pm 2010-11-29 erick.antezana $
2             #
3             # Module : APO_ID_Set.pm
4             # Purpose : A set of APO id's.
5             # License : Copyright (c) 2006-2014 by Erick Antezana. All rights reserved.
6             # This program is free software; you can redistribute it and/or
7             # modify it under the same terms as Perl itself.
8             # Contact : Erick Antezana
9             #
10              
11             package OBO::APO::APO_ID_Set;
12              
13              
14             =head1 NAME
15              
16             OBO::APO::APO_ID_Set - An implementation of a set of OBO::APO::APO_ID objects.
17              
18             =head1 SYNOPSIS
19              
20             use OBO::APO::APO_ID_Set;
21              
22             use OBO::APO::APO_ID;
23              
24              
25             $apo_id_set = OBO::APO::APO_ID_Set->new();
26              
27             $id = OBO::APO::APO_ID->new();
28              
29             $size = $apo_id_set->size();
30              
31             if ($apo_id_set->add($id)) { ... }
32              
33             $new_id = $apo_id_set->get_new_id("APO", "C");
34              
35             $other_id = $apo_id_set->get_new_id("APO", "Ca");
36              
37             =head1 DESCRIPTION
38              
39             The OBO::APO::APO_ID_Set class implements a Cell-Cycle Ontology identifiers set.
40              
41             =head1 AUTHOR
42              
43             Erick Antezana, Eerick.antezana -@- gmail.comE
44              
45             =head1 COPYRIGHT AND LICENSE
46              
47             Copyright (c) 2006-2014 by Erick Antezana
48              
49             This library is free software; you can redistribute it and/or modify
50             it under the same terms as Perl itself, either Perl version 5.8.7 or,
51             at your option, any later version of Perl 5 you may have available.
52              
53             =cut
54              
55             our @ISA = qw(OBO::XO::OBO_ID_Set);
56 2     2   4848 use OBO::XO::OBO_ID_Set;
  2         4  
  2         68  
57 2     2   776 use OBO::APO::APO_ID;
  2         4  
  2         44  
58              
59 2     2   10 use strict;
  2         2  
  2         43  
60 2     2   7 use warnings;
  2         15  
  2         53  
61 2     2   9 use Carp;
  2         2  
  2         551  
62              
63             =head2 add_as_string
64              
65             Usage - $set->add_as_string($id)
66             Returns - the added id (OBO::APO::APO_ID)
67             Args - the APO id (string) to be added
68             Function - adds an APO_ID to this set
69            
70             =cut
71              
72             sub add_as_string () {
73 19     19 1 21 my ($self, $id_as_string) = @_;
74 19         17 my $result;
75 19 50       26 if ($id_as_string) {
76 19         36 my $new_obo_id_obj = OBO::APO::APO_ID->new();
77 19         35 $new_obo_id_obj->id_as_string($id_as_string);
78 19         35 $result = $self->add($new_obo_id_obj);
79             }
80 19         34 return $result;
81             }
82              
83             =head2 get_new_id
84              
85             Usage - $set->get_new_id($local_idspace, $subnamespace)
86             Returns - a new APO id (string)
87             Args - none
88             Function - returns a new APO ID as string and adds this id to the set
89            
90             =cut
91              
92             sub get_new_id {
93 0     0 1   my ($self, $local_idspace, $subnamespace) = @_;
94 0           my $new_apo_id = OBO::APO::APO_ID->new();
95 0 0         confess "The idspace is invalid: ", $local_idspace if ($local_idspace !~ /[A-Z][A-Z][A-Z]/);
96 0           $new_apo_id->idspace($local_idspace);
97 0 0         confess "The subnamespace is invalid: ", $subnamespace if ($subnamespace !~ /[A-Z][a-z]?/);
98 0           $new_apo_id->subnamespace($subnamespace);
99             # get the last 'localID'
100 0 0         if ($self->is_empty()){
101 0           $new_apo_id->localID("0000001");
102             } else {
103 0           my @arr = sort {$a cmp $b} keys %{$self->{MAP}};
  0            
  0            
104 0           $new_apo_id->localID( $self->{MAP}->{$arr[$#arr]}->localID() );
105             }
106 0           while (!defined ($self -> add( $new_apo_id = $new_apo_id->next_id() ))) {}
107 0           return $new_apo_id->id_as_string ();
108             }
109              
110             1;