-
Notifications
You must be signed in to change notification settings - Fork 0
/
Pedigree.pm
420 lines (318 loc) · 10.6 KB
/
Pedigree.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
# $Id$
#
# BioPerl module for Bio::Pedigree
#
# Cared for by Jason Stajich <jason@chg.mc.duke.edu>
#
# Copyright Jason Stajich
#
# You may distribute this module under the same terms as perl itself
# POD documentation - main docs before the code
=head1 NAME
Bio::Pedigree - This is the toplevel object which contains references
to the Markers genotyped for a set of families, and the families for
which there are results.
=head1 SYNOPSIS
use Bio::Pedigree;
use Bio::Pedigree::PedIO;
# get a Bio::Pedigree object somehow (PedIO system typically)
my $pedio = new Bio::Pedigree::PedIO(-format => 'xml');
my $pedigree = $pedio->read_pedigree(-pedfile => 'pedigree_example.xml');
print "date is ", $pedigree->date, "\n";
print "comment is ", $pedigree->comment ,"\n";
print "markers are :\n";
foreach my $markername ( $pedigree->each_Marker('name') ) {
print "$markername\n";
}
foreach my $group ( $pedigree->each_Group ) {
print "group name is ", $group->center_groupid, "\n";
foreach my $person ( $pedigree->each_Person ) {
print $person->personid, " ", $person->gender, "\n";
}
}
=head1 DESCRIPTION
This object is the toplevel object which contains all the Groups and
Marker objects that are part of a pedigree set. More than one
Family/Group can be contained within a pedigree which may be counter
to the name 'PEDIGREE' which implies all the components within this
object are part of the same lineage. In this implementation a
Pedigree is a container for the list of Markers (and their order) as
well as the list of Groups (or Families) which have individuals with
Marker genotypes.
=head1 FEEDBACK
=head2 Mailing Lists
User feedback is an integral part of the evolution of this and other
Bioperl modules. Send your comments and suggestions preferably to
the Bioperl mailing list. Your participation is much appreciated.
bioperl-l@bioperl.org - General discussion
http://bioperl.org/MailList.shtml - About the mailing lists
=head2 Reporting Bugs
Report bugs to the Bioperl bug tracking system to help us keep track
of the bugs and their resolution. Bug reports can be submitted via
email or the web:
bioperl-bugs@bioperl.org
http://bioperl.org/bioperl-bugs/
=head1 AUTHOR - Jason Stajich
Email jason@chg.mc.duke.edu
Describe contact details here
=head1 APPENDIX
The rest of the documentation details each of the object methods.
Internal methods are usually preceded with a _
=cut
# Let the code begin...
package Bio::Pedigree;
use vars qw(@ISA);
use strict;
use Bio::Root::RootI;
use Tie::IxHash;
use Bio::Pedigree::Group;
use Bio::Pedigree::Marker;
use POSIX;
@ISA = qw(Bio::Root::RootI );
=head2 new
Title : new
Usage : my $pedigree = new Bio::Pedigree();
Function: creates a new Pedigree object for storing Group and Marker
information
Returns : Bio::Pedigree object
Args : All fields are required unless specified as optional
-groups => (optional) array ref of groups to initialize Pedigree
object with
-markers => (optional) array ref of markers to initialize Pedigree
object with
=cut
sub new {
my($class,@args) = @_;
my $self = $class->SUPER::new(@args);
$self->{'_groups'} = {};
$self->{'_markers'} = {};
# allows elements to be retrieved in order they were inserted
tie %{$self->{'_groups'}}, "Tie::IxHash";
tie %{$self->{'_markers'}}, "Tie::IxHash";
my ($groups, $markers, $date,$comment) = $self->_rearrange([qw(GROUPS
MARKERS
DATE
COMMENT)], @args);
if( defined $groups ) {
if( ref($groups) !~ /array/i ) {
$self->throw("Trying to initialize Bio::Pedigree object with groups ($groups) which is not an array reference");
} else {
foreach my $group ( @$groups ) {
$self->add_Group($group);
}
}
}
if( defined $markers ) {
if( ref($markers) !~ /array/i ) {
$self->throw("Trying to initialize Bio::Pedigree object with markers ($markers) which is not an array reference");
} else {
foreach my $marker ( @$markers ) {
$self->add_Marker($marker);
}
}
}
$date && $self->date($date);
$comment && $self->comment($comment);
return $self;
}
=head2 add_Group
Title : add_Group
Usage : my $count = $pedigree->add_Group($group);
Function: Adds a group to the Pedigree object
Returns : count of number of groups contained
Args : Bio::Pedigree::GroupI object
=cut
sub add_Group{
my ($self,$group) = @_;
return 0 if( ! $group );
if( !ref($group) || ! $group->isa('Bio::Pedigree::GroupI') ) {
$self->warn("Trying to add a group with data $group which is not a Bio::Pedigree::GroupI object");
}
# force to uppercase just in case
$self->{'_groups'}->{uc $group->center_groupid} = $group;
return keys %{$self->{'_groups'}};
}
=head2 remove_Group
Title : remove_Group
Usage : my $boolean = $pedigree->remove_Group("$center $groupid");
Function: Removes a group from the list of stored groups in this pedigree
Returns : boolean of success
Args : - either Bio::Pedigree::GroupI object or
string "$center $groupid"
=cut
sub remove_Group{
my ($self,$val) = @_;
if( ref($val) && $val->isa('Bio::Pedigree::GroupI') ) {
$val = $val->center_groupid;
}
$val = uc $val;
return 0 if( ! $self->{'_groups'}->{$val} );
delete $self->{'_groups'}->{$val};
return 1;
}
=head2 each_Group
Title : each_Group
Usage : my (@groups) = $pedigree->each_Group;
Function: returns the groups - in order
Returns : @array of strings or Bio::Pedigree::GroupI objects
Args : (optional) - if the string 'id' is passed in will
only return each group\'s center & ids
rather than the whole Bio::Pedigree::GroupI object
=cut
sub each_Group{
my ($self, $type) = @_;
return ( defined $type && $type eq 'id' ) ? keys %{$self->{'_groups'}} :
values %{$self->{'_groups'}};
}
=head2 get_Group
Title : get_Group
Usage : my $group = $pedigree->get_Group("$center $groupid");
Function: returns the group stored for a specific center and groupid
Returns : Bio::Pedigree::GroupI object or undef if no group exists for
that name
Args : name of group (center groupid)
=cut
sub get_Group{
my ($self,$name) = @_;
return $self->{'_groups'}->{uc $name};
}
=head2 num_of_groups
Title : num_of_groups
Usage : my $count = $pedigree->num_of_groups;
Function: Returns the number of groups in this Pedigree object
Returns : integer
Args : none
=cut
sub num_of_groups{
my ($self) = @_;
return scalar keys %{$self->{'_groups'}};
}
=head2 add_Marker
Title : add_Marker
Usage : my $count = $pedigree->add_Marker($marker);
Function: Adds a new Marker to the Pedigree
Returns : count of number of markers stored in pedigree
Args : Bio::Pedigree::MarkerI object
=cut
sub add_Marker{
my ($self,$marker,$overwrite) = @_;
return 0 if( ! $marker );
if( !ref($marker) || ! $marker->isa('Bio::Pedigree::MarkerI') ) {
$self->warn("Trying to add a marker with data $marker which is not a Bio::Pedigree::MarkerI object");
}
if( $self->{'_markers'}->{uc $marker->name} && ! $overwrite) {
$self->warn("Marker " . uc $marker->name . " already exists");
} else {
$self->{'_markers'}->{uc $marker->name} = $marker;
}
return scalar keys %{$self->{'_markers'}};
}
=head2 remove_Marker
Title : remove_Marker
Usage : my $status = $pedigree->remove_Marker($markername);
Function: Removes a marker from the Pedigree object
Returns : boolean of status
Args : Either marker name (string) or reference to Bio::Pedigree::MarkerI object
=cut
sub remove_Marker{
my ($self,$val) = @_;
if( ref($val) && $val->isa('Bio::Pedigree::MarkerI') ) {
$val = $val->name;
}
return 0 unless ( defined $self->{'_markers'}->{$val} );
delete $self->{'_markers'}->{$val};
return 1;
}
=head2 each_Marker
Title : each_Marker
Usage : my @markers = $pedigree->each_Marker;
Function: Returns a list of Markers or marker names stored
in the Pedigree object
Returns : @array of Bio::Pedigree::MarkerI object or marker name strings
Args : (optional) if the string 'name' is passed in will only return
the names of markers contained rather than the
actual Bio::Pedigree::MarkerI objects
=cut
sub each_Marker{
my ($self,$name) = @_;
return ( defined $name && $name eq 'name' ) ?
keys %{$self->{'_markers'}} :
values %{$self->{'_markers'}};
}
=head2 get_Marker
Title : get_Marker
Usage : my $marker = $pedigree->get_Marker($name);
Function:
Example :
Returns :
Args :
=cut
sub get_Marker {
my ($self,$name) = @_;
return $self->{'_markers'}->{uc $name};
}
=head2 num_of_markers
Title : num_of_markers
Usage : my $count = $pedigree->num_of_markers;
Function: Returns the number of markers in this Pedigree object
Returns : integer
Args : none
=cut
sub num_of_markers{
my ($self) = @_;
return scalar keys %{$self->{'_markers'}};
}
=head2 Additional Data fields
=head2 date
Title : date
Usage : $obj->date($newval)
Function: stores date created information
Returns : value of date
Args : newvalue (optional)
=cut
sub date{
my ($obj,$value) = @_;
if( defined $value || ! defined $obj->{'_date'}) {
$value = &POSIX::strftime("%Y/%M/%d",localtime(time))
unless defined $value;
$obj->{'_date'} = $value;
}
return $obj->{'_date'};
}
=head2 comment
Title : comment
Usage : $obj->comment($newval)
Function: stores pedigree comment information
Returns : value of comment
Args : newvalue (optional)
=cut
sub comment{
my ($obj,$value) = @_;
if( defined $value ) {
$obj->{'_comment'} = $value;
}
return $obj->{'_comment'} || '';
}
=head2 Algorithms and toplevel data access
=head2 calculate_all_relationships
Title : calculate_all_relationships
Usage : $pedigree->calculate_all_relationships
Function: Convience function -
calculates all the relationships by calling
calculate_relationships on each Group object
Returns : count of number of relationships updated
Args : Type of warning to use 'warnOnError', 'failOnError', or
do not report warnings.
See also L<Bio::Pedigree::Group>
=cut
sub calculate_all_relationships {
my ($self,$warningtype) = @_;
my $count = 0;
foreach my $group ( $self->each_Group ) {
$count += $group->calculate_relationships($warningtype);
}
return $count;
}
# change the group order
# change the marker order
1;