| 1 |
=pod |
| 2 |
|
| 3 |
=head1 NAME |
| 4 |
|
| 5 |
Pedigree::TwinsNode - an auxillary twins node in a pedigree |
| 6 |
|
| 7 |
=head1 SYNOPSIS |
| 8 |
|
| 9 |
use Pedigree::TwinsNode; |
| 10 |
|
| 11 |
$node = new Pedigree::TwinsNode(I<%params>); |
| 12 |
|
| 13 |
|
| 14 |
$node->DrawNode(I<$xidst>, I<$ydist>, I<$belowtextfont>, I<$abovetextfont>, |
| 15 |
I<@fieldsfornode>); |
| 16 |
|
| 17 |
$node->DrawConnections(); |
| 18 |
|
| 19 |
|
| 20 |
=head1 DESCRIPTION |
| 21 |
|
| 22 |
This package contains data about a twins node. Twins node is |
| 23 |
a special node between the parent and the twins. |
| 24 |
|
| 25 |
|
| 26 |
=cut |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
#################################################################### |
| 31 |
# Define the package # |
| 32 |
#################################################################### |
| 33 |
|
| 34 |
package Pedigree::TwinsNode; |
| 35 |
use Pedigree; |
| 36 |
use strict; |
| 37 |
our @ISA=('Pedigree::Node'); |
| 38 |
|
| 39 |
|
| 40 |
#################################################################### |
| 41 |
# new # |
| 42 |
#################################################################### |
| 43 |
|
| 44 |
=pod |
| 45 |
|
| 46 |
=over 4 |
| 47 |
|
| 48 |
=item B<new>(I<%params>); |
| 49 |
|
| 50 |
Construct a new node from the given parameters. |
| 51 |
|
| 52 |
=cut |
| 53 |
|
| 54 |
sub new { |
| 55 |
my ($class,%params)=@_; |
| 56 |
my $self=$class->SUPER::new(%params); |
| 57 |
if (!ref($self)) { # Bad node |
| 58 |
return 0; |
| 59 |
} |
| 60 |
|
| 61 |
bless ($self,$class); |
| 62 |
|
| 63 |
# After we constructed the node, we want to move the kids |
| 64 |
# from the parent node to the twins node |
| 65 |
|
| 66 |
my $selfId = $self->{'Id'}; |
| 67 |
my $parentId = $self->{'ParentId'}; |
| 68 |
foreach my $kidId (keys %{$self->{'KidIds'}}) { |
| 69 |
if ($main::DEBUG) { |
| 70 |
print STDERR |
| 71 |
"Moving $kidId from $parentId and to $selfId\n"; |
| 72 |
} |
| 73 |
delete $self->{'kids_by_parent_id'}->{$parentId}->{$kidId}; |
| 74 |
$self->{'kids_by_parent_id'}->{$selfId}->{$kidId}=1; |
| 75 |
} |
| 76 |
|
| 77 |
return $self; |
| 78 |
} |
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
#################################################################### |
| 83 |
# DrawNode # |
| 84 |
#################################################################### |
| 85 |
|
| 86 |
=pod |
| 87 |
|
| 88 |
=item B<DrawNode>(I<$xdist>, I<$ydist>, I<$belowtextfont>, I<$abovetextfont>, |
| 89 |
I<@fieldsfornode>); |
| 90 |
|
| 91 |
Output the command to draw this node. The parameters are |
| 92 |
distances between the nodes (in psunits). |
| 93 |
|
| 94 |
=cut |
| 95 |
|
| 96 |
sub DrawNode { |
| 97 |
my $self=shift; |
| 98 |
my ($xdist, $ydist, $belowtextfont, $abovetextfont, @fieldsfornode) = @_; |
| 99 |
my $result = '\rput('.($xdist*$self->GetAbsX()).", ". |
| 100 |
($ydist*$self->GetAbsY()).'){\pnode{'. |
| 101 |
$self->Id()."}}\n"; |
| 102 |
return $result; |
| 103 |
} |
| 104 |
|
| 105 |
#################################################################### |
| 106 |
# DrawConnections # |
| 107 |
#################################################################### |
| 108 |
|
| 109 |
=pod |
| 110 |
|
| 111 |
=item B<DrawConnections>(); |
| 112 |
|
| 113 |
Draw the connections from the given node to its descendants and |
| 114 |
the parent |
| 115 |
|
| 116 |
=cut |
| 117 |
|
| 118 |
sub DrawConnections { |
| 119 |
my $self = shift; |
| 120 |
my $xdist = shift; |
| 121 |
my $ydist = shift; |
| 122 |
my $Id=$self->Id(); |
| 123 |
my $parentId = $self->{'ParentId'}; |
| 124 |
my @kids = @{$self->Kids()}; |
| 125 |
my $leftKid=shift @kids; |
| 126 |
my $leftKidId=$leftKid->Id(); |
| 127 |
my $rightKid= pop @kids; |
| 128 |
my $rightKidId=$rightKid->Id(); |
| 129 |
my @opts; |
| 130 |
if ($self->Type()) { |
| 131 |
push @opts, $self->Type(); |
| 132 |
} |
| 133 |
foreach my $kid (@kids) { |
| 134 |
push @opts, "addtwin=".$kid->Id(); |
| 135 |
} |
| 136 |
my $result = '\pstTwins['; |
| 137 |
if (scalar @opts) { |
| 138 |
$result .= join (", ",@opts); |
| 139 |
} |
| 140 |
$result .= ']{'.$parentId.'}{'. |
| 141 |
$Id.'}{'.$leftKidId.'}{'.$rightKidId.'}'."\n"; |
| 142 |
return $result; |
| 143 |
} |
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
#################################################################### |
| 149 |
# THE END # |
| 150 |
#################################################################### |
| 151 |
|
| 152 |
=pod |
| 153 |
|
| 154 |
=back |
| 155 |
|
| 156 |
=head1 ENVIRONMENT |
| 157 |
|
| 158 |
The calling program should define B<$main::DEBUG> and set it to 0 |
| 159 |
or 1. |
| 160 |
|
| 161 |
=head1 SEE ALSO |
| 162 |
|
| 163 |
pedigree(1), Pedigree(3) |
| 164 |
|
| 165 |
=head1 AUTHOR |
| 166 |
|
| 167 |
Boris Veytsman, Leila Akhmadeeva, 2007 |
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
=cut |
| 172 |
|
| 173 |
1; |