comparison variant_effect_predictor/Bio/EnsEMBL/Compara/Subset.pm @ 0:21066c0abaf5 draft

Uploaded
author willmclaren
date Fri, 03 Aug 2012 10:04:48 -0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:21066c0abaf5
1 # $Id: Subset.pm,v 1.10 2012/05/10 14:19:20 mm14 Exp $
2 #
3 # Module to handle family members
4 #
5 # Cared for by Abel Ureta-Vidal <abel@ebi.ac.uk>
6 #
7 # Copyright Abel Ureta-Vidal
8 #
9 # You may distribute this module under the same terms as perl itself
10
11 # POD documentation - main docs before the code
12
13 =head1 NAME
14
15 Subset - DESCRIPTION of Object
16
17 =head1 SYNOPSIS
18
19 =head1 DESCRIPTION
20
21 =head1 CONTACT
22
23 Jessica Severin <jessica@ebi.ac.uk>
24
25 =head1 APPENDIX
26
27 The rest of the documentation details each of the object methods. Internal methods are usually preceded with a _
28
29 =cut
30
31 package Bio::EnsEMBL::Compara::Subset;
32
33 use strict;
34 use Bio::Species;
35 use Bio::EnsEMBL::Utils::Exception;
36 use Bio::EnsEMBL::Utils::Argument;
37
38 use Data::Dumper;
39
40 sub new {
41 my ($class, @args) = @_;
42 my $self = {};
43
44 bless $self,$class;
45
46 if (scalar @args) {
47 #do this explicitly.
48 my ($dbid, $description, $adaptor) = rearrange([qw(DBID NAME ADAPTOR)], @args);
49
50 $self->dbID($dbid) if($dbid);
51 $self->description($description) if($description);
52 $self->adaptor($adaptor) if($adaptor);
53
54 $self->{'_member_id_list'} = [];
55 }
56
57 return $self;
58 }
59
60 =head2 new_fast
61
62 Arg [1] : hash reference $hashref
63 Example : none
64 Description: This is an ultra fast constructor which requires knowledge of
65 the objects internals to be used.
66 Returntype :
67 Exceptions : none
68 Caller :
69
70 =cut
71
72 sub new_fast {
73 my ($class, $hashref) = @_;
74
75 return bless $hashref, $class;
76 }
77
78 =head2 adaptor
79
80 Title : adaptor
81 Usage :
82 Function: give the adaptor if known
83 Example :
84 Returns :
85 Args :
86
87
88 =cut
89
90 sub adaptor {
91 my ($self, $value) = @_;
92
93 if (defined $value) {
94 $self->{'_adaptor'} = $value;
95 }
96
97 return $self->{'_adaptor'};
98 }
99
100
101 =head2 dbID
102
103 Arg [1] : int $dbID (optional)
104 Example :
105 Description:
106 Returntype :
107 Exceptions :
108 Caller :
109
110 =cut
111
112 sub dbID {
113 my $self = shift;
114 $self->{'_dbID'} = shift if(@_);
115 return $self->{'_dbID'};
116 }
117
118 =head2 description
119
120 Arg [1] : string $description (optional)
121 Example :
122 Description:
123 Returntype : string
124 Exceptions :
125 Caller :
126
127 =cut
128
129 sub description {
130 my $self = shift;
131 $self->{'_description'} = shift if(@_);
132 return $self->{'_description'};
133 }
134
135 =head2 dump_loc
136
137 Arg [1] : string $dump_loc (optional)
138 Example :
139 Description:
140 Returntype : string
141 Exceptions :
142 Caller :
143
144 =cut
145
146 sub dump_loc {
147 my $self = shift;
148 $self->{'_dump_loc'} = shift if(@_);
149 return $self->{'_dump_loc'};
150 }
151
152 =head2 add_member_id
153
154 Arg [1] : $member_id
155 Example : my $count = $subset->add_member_id($member_id);
156 Description : Add a new member_id to the subset object and
157 returns the number of member_ids already in the object
158 Returntype : A scalar with the number of member_ids in the object
159 Exceptions :
160 Caller :
161
162 =cut
163
164 sub add_member_id {
165 my $self = shift;
166 my $count=0;
167
168 if(@_) {
169 my $member_id = shift;
170 $count = push @{$self->{'_member_id_list'}}, $member_id;
171 #print("added $count element to list\n");
172
173 if(defined($self->adaptor)) {
174 $self->adaptor->store_link($self, $member_id);
175 }
176 }
177 return $count
178 }
179
180
181 =head2 add_member
182
183 Arg [1] : A Bio::EnsEMBL::Compara::Member
184 Example : my $count = $subset->add_member($member);
185 Description : Add a new Bio::EnsEMBL::Compara::Member to the subset object
186 and returns the number of members already in the object.
187 It also adds the member_id to the object.
188 ReturnType : A scalar with the number of members in the object
189 Exceptions :
190 Caller :
191
192 =cut
193
194 sub add_member {
195 my ($self, $member) = @_;
196
197 unless(defined($member) and $member->isa('Bio::EnsEMBL::Compara::Member')) {
198 throw(
199 "gene arg must be a [Bio::EnsEMBL::Compara::Member] ".
200 "not a [$member]");
201 }
202
203 return $self->add_member_id($member->dbID);
204 }
205
206 sub member_id_list {
207 my $self = shift;
208
209 return $self->{'_member_id_list'};
210 }
211
212 sub count {
213 my $self = shift;
214
215 return $#{$self->member_id_list()} + 1;
216 }
217
218
219 # FIXME There should be a function to print a FASTA file
220 #sub output_to_fasta
221
222 1;