| 1 | # GenPerl module | ||
| 2 | # | ||
| 3 | |||
| 4 | # POD documentation - main docs before the code | ||
| 5 | |||
| 6 | =head1 NAME | ||
| 7 | |||
| 8 | Genetics::Kindred | ||
| 9 | |||
| 10 | =head1 SYNOPSIS | ||
| 11 | |||
| 12 | $kindred = new Genetics::Kindred(name => 'JXPed2', | ||
| 13 | importID => 45, | ||
| 14 | dateCreated => $today, | ||
| 15 | comment => "Litt et. al. (1994)", | ||
| 16 | Keywords => [ {name => "Test Data", | ||
| 17 | dataType => "Boolean", | ||
| 18 | value => 1}, | ||
| 19 | {name => "Disease", | ||
| 20 | dataType => "String", | ||
| 21 | value => "Episodic Ataxia"} ], | ||
| 22 | NameAliases => [ {name => "Ped20", | ||
| 23 | contactName => "J.P. Morgan"}, ], | ||
| 24 | Subjects => [ {name => "EAPed20.1", importID => 42}, | ||
| 25 | {name => "EAPed20.1000", importID => 43}, | ||
| 26 | {name => "EAPed20.1001", importID => 44}, | ||
| 27 | ], | ||
| 28 | ) ; | ||
| 29 | |||
| 30 | See the GenPerl Tutorial for more information. | ||
| 31 | |||
| 32 | =head1 DESCRIPTION | ||
| 33 | |||
| 34 | Kindred objects represent groups of related individuals. | ||
| 35 | |||
| 36 | =head1 LICENSE | ||
| 37 | |||
| 38 | This program is free software; you can redistribute it and/or modify | ||
| 39 | it under the terms of the GNU General Public License as published by | ||
| 40 | the Free Software Foundation; either version 2 of the License, or | ||
| 41 | (at your option) any later version. | ||
| 42 | |||
| 43 | This program is distributed in the hope that it will be useful, | ||
| 44 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 45 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 46 | GNU General Public License for more details. | ||
| 47 | |||
| 48 | You should have received a copy of the GNU General Public License | ||
| 49 | along with this program; if not, write to the Free Software | ||
| 50 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
| 51 | |||
| 52 | =head1 FEEDBACK | ||
| 53 | |||
| 54 | Currently, all feedback should be sent directly to the author. | ||
| 55 | |||
| 56 | =head1 AUTHOR - Steve Mathias | ||
| 57 | |||
| 58 | Email: mathias@genomica.com | ||
| 59 | |||
| 60 | Phone: (720) 565-4029 | ||
| 61 | |||
| 62 | Address: Genomica Corporation | ||
| 63 | 1745 38th Street | ||
| 64 | Boulder, CO 80301 | ||
| 65 | |||
| 66 | =head1 DETAILS | ||
| 67 | |||
| 68 | The rest of the documentation describes each of the object variables and | ||
| 69 | methods. The names of internal variables and methods are preceded with an | ||
| 70 | underscore (_). | ||
| 71 | |||
| 72 | =cut | ||
| 73 | |||
| 74 | ################## | ||
| 75 | # # | ||
| 76 | # Begin the code # | ||
| 77 | # # | ||
| 78 | ################## | ||
| 79 | |||
| 80 | package Genetics::Kindred ; | ||
| 81 | |||
| 82 | BEGIN { | ||
| 83 | $ID = "Genetics::Kindred" ; | ||
| 84 | #$DEBUG = $main::DEBUG ; | ||
| 85 | $DEBUG = 0 ; | ||
| 86 | $DEBUG and warn "Debugging in $ID is on" ; | ||
| 87 | } | ||
| 88 | |||
| 89 | =head1 Imported Packages | ||
| 90 | |||
| 91 | Genetics::Object Superclass | ||
| 92 | strict Just to be anal | ||
| 93 | vars Global variables | ||
| 94 | |||
| 95 | =cut | ||
| 96 | |||
| 97 | use Genetics::Object ; | ||
| 98 | use strict ; | ||
| 99 | use vars qw(@ISA $ID $DEBUG @ATTRS @REQD_ATTRS %DEFAULTS) ; | ||
| 100 | |||
| 101 | require 5.004 ; | ||
| 102 | |||
| 103 | @ISA = qw(Genetics::Object) ; | ||
| 104 | |||
| 105 | @ATTRS = qw(isDerived DerivedFrom Subjects) ; | ||
| 106 | |||
| 107 | @REQD_ATTRS = qw(isDerived) ; | ||
| 108 | |||
| 109 | %DEFAULTS = (isDerived => 0) ; | ||
| 110 | |||
| 111 | |||
| 112 | =head1 Public methods | ||
| 113 | |||
| 114 | printXML Print an XML representation of the object | ||
| 115 | |||
| 116 | =cut | ||
| 117 | |||
| 118 | =head2 printXML | ||
| 119 | |||
| 120 | Function : Print an XML representation of the object. | ||
| 121 | Argument : A Genetics::Subject object and the XML::Writer object being used | ||
| 122 | to generate the XML. | ||
| 123 | Returns : N/A | ||
| 124 | Scope : Public Instance Method | ||
| 125 | Comments : Calls Genetics::Object->printGeneralXML to generate XML elements | ||
| 126 | common to all Genetics::Object objects. | ||
| 127 | |||
| 128 | =cut | ||
| 129 | |||
| 130 | sub printXML { | ||
| 131 | my($self, $writer) = @_ ; | ||
| 132 | my($class, $value, $listPtr, $hashPtr) ; | ||
| 133 | |||
| 134 | $class = ref $self ; | ||
| 135 | $class =~ s/.*::// ; | ||
| 136 | |||
| 137 | ## Common Attributes/Elements | ||
| 138 | $self->printGeneralXML($writer) ; | ||
| 139 | |||
| 140 | ## Kindred Elements | ||
| 141 | # Subject | ||
| 142 | if (defined ($listPtr = $self->field('Subjects'))) { | ||
| 143 | foreach $hashPtr (@$listPtr) { | ||
| 144 | $writer->startTag('SubjectRef') ; | ||
| 145 | defined $$hashPtr{name} and $$hashPtr{name} ne "" and | ||
| 146 | $writer->dataElement('Name', $$hashPtr{name}) ; | ||
| 147 | $writer->dataElement('ID', $$hashPtr{id}) ; | ||
| 148 | $writer->endTag('SubjectRef') ; | ||
| 149 | } | ||
| 150 | } | ||
| 151 | |||
| 152 | $writer->endTag($class) ; | ||
| 153 | |||
| 154 | return(1) ; | ||
| 155 | } | ||
| 156 | |||
| 157 | =head2 asHTML | ||
| 158 | |||
| 159 | Function : Generate an HTML representation of the object. | ||
| 160 | Argument : A Genetics::Kindred object and a scalar containing the name of | ||
| 161 | the GenPerl database in which the object is stored. | ||
| 162 | Returns : Scalar containing the HTML text. | ||
| 163 | Scope : Public Instance Method | ||
| 164 | Comments : Calls Genetics::Object->_generalHTMLParam to generate HTML | ||
| 165 | elements common to all Genetics::Object objects. An | ||
| 166 | HTML::Template object is used to actually generate the HTML. | ||
| 167 | |||
| 168 | =cut | ||
| 169 | |||
| 170 | sub asHTML { | ||
| 171 | my($self, $db) = @_ ; | ||
| 172 | my $tmpl = new HTML::Template(filename => "/home/slm/work/GenPerl/templates/kindred.tmpl") ; | ||
| 173 | my(%param, $isDerived, $subjListPtr) ; | ||
| 174 | |||
| 175 | %param = (DB => $db) ; # DB is the database the object is in. It is used | ||
| 176 | # to conscruct URL links to associated objects | ||
| 177 | |||
| 178 | # Object data | ||
| 179 | $self->_generalHTMLParam(\%param) ; | ||
| 180 | |||
| 181 | # Kindred data | ||
| 182 | $param{ISDERIVED} = $self->isDerived() ; | ||
| 183 | # $self->isDerived() ? $param{ISDERIVED} = "Yes" | ||
| 184 | # : $param{ISDERIVED} = "No" ; | ||
| 185 | if ($self->DerivedFrom()) { | ||
| 186 | $param{PARENT} = $self->DerivedFrom->{name} ; | ||
| 187 | $param{PARENTID} = $self->DerivedFrom->{id} ; | ||
| 188 | } | ||
| 189 | $subjListPtr = $self->Subjects() ; | ||
| 190 | # add a db key/value to each subjPtr so that functional URLs linking to | ||
| 191 | # Subjects can be constructed | ||
| 192 | grep { $_->{db} = $db } @$subjListPtr ; | ||
| 193 | $param{SUBJECTS} = $subjListPtr ; | ||
| 194 | |||
| 195 | $tmpl->param( %param ) ; | ||
| 196 | |||
| 197 | return $tmpl->output() ; | ||
| 198 | } | ||
| 199 | |||
| 200 | 1; | ||
| 201 |