| 1 | # GenPerl module | ||
| 2 | # | ||
| 3 | |||
| 4 | # POD documentation - main docs before the code | ||
| 5 | |||
| 6 | =head1 NAME | ||
| 7 | |||
| 8 | Genetics::Subject | ||
| 9 | |||
| 10 | =head1 SYNOPSIS | ||
| 11 | |||
| 12 | $subject = new Genetics::Subject(name => 'JXPed1-1', | ||
| 13 | importID => 12, | ||
| 14 | dateCreated => $today, | ||
| 15 | NameAliases => [ {name => "jb2002", | ||
| 16 | contactName => "Gregor Mendel"} | ||
| 17 | ], | ||
| 18 | Contact => {name => "J.P. Morgan, II", | ||
| 19 | comment => "Referring physican"}, | ||
| 20 | DBXReferences => [ {accessionNumber => "abc123", | ||
| 21 | databaseName => "Clinical Land", | ||
| 22 | schemaName => "Master", | ||
| 23 | comment => "Internal Clinical DB"} | ||
| 24 | ], | ||
| 25 | Keywords => [ {name => "Study Population", | ||
| 26 | dataType => "String", | ||
| 27 | description => "Internal study identifier.", | ||
| 28 | value => "Test"}, | ||
| 29 | {name => "Foo", | ||
| 30 | dataType => "String", | ||
| 31 | description => "Crap", | ||
| 32 | value => "Bar"}, | ||
| 33 | {name => "Test Data", | ||
| 34 | dataType => "Boolean", | ||
| 35 | value => 1}, | ||
| 36 | ], | ||
| 37 | gender => "Male", | ||
| 38 | dateOfBirth => "1937-08-18", | ||
| 39 | dateOfDeath => "1997-02-15", | ||
| 40 | isProband => 1, | ||
| 41 | Mother => {name => "JXPed1-2", importID => 32}, | ||
| 42 | Father => {name => "JXPed1-3", importID => 22}, | ||
| 43 | Kindred => {name => "JXPed1", importID => 264}, | ||
| 44 | Organism => {genusSpecies => "Homo sapiens"}, | ||
| 45 | ) ; | ||
| 46 | |||
| 47 | See the GenPerl Tutorial for more information. | ||
| 48 | |||
| 49 | =head1 DESCRIPTION | ||
| 50 | |||
| 51 | Subject objects represent the individuals in genetic studies. | ||
| 52 | |||
| 53 | =head1 LICENSE | ||
| 54 | |||
| 55 | This program is free software; you can redistribute it and/or modify | ||
| 56 | it under the terms of the GNU General Public License as published by | ||
| 57 | the Free Software Foundation; either version 2 of the License, or | ||
| 58 | (at your option) any later version. | ||
| 59 | |||
| 60 | This program is distributed in the hope that it will be useful, | ||
| 61 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 62 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 63 | GNU General Public License for more details. | ||
| 64 | |||
| 65 | You should have received a copy of the GNU General Public License | ||
| 66 | along with this program; if not, write to the Free Software | ||
| 67 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
| 68 | |||
| 69 | =head1 FEEDBACK | ||
| 70 | |||
| 71 | Currently, all feedback should be sent directly to the author. | ||
| 72 | |||
| 73 | =head1 AUTHOR - Steve Mathias | ||
| 74 | |||
| 75 | Email: mathias@genomica.com | ||
| 76 | |||
| 77 | Phone: (720) 565-4029 | ||
| 78 | |||
| 79 | Address: Genomica Corporation | ||
| 80 | 1745 38th Street | ||
| 81 | Boulder, CO 80301 | ||
| 82 | |||
| 83 | =head1 DETAILS | ||
| 84 | |||
| 85 | The rest of the documentation describes each of the object variables and | ||
| 86 | methods. The names of internal variables and methods are preceded with an | ||
| 87 | underscore (_). | ||
| 88 | |||
| 89 | =cut | ||
| 90 | |||
| 91 | ################## | ||
| 92 | # # | ||
| 93 | # Begin the code # | ||
| 94 | # # | ||
| 95 | ################## | ||
| 96 | |||
| 97 | package Genetics::Subject ; | ||
| 98 | |||
| 99 | BEGIN { | ||
| 100 | $ID = "Genetics::Subject" ; | ||
| 101 | #$DEBUG = $main::DEBUG ; | ||
| 102 | $DEBUG = 0 ; | ||
| 103 | $DEBUG and warn "Debugging in $ID is on" ; | ||
| 104 | } | ||
| 105 | |||
| 106 | =head1 Imported Packages | ||
| 107 | |||
| 108 | Genetics::Object Superclass | ||
| 109 | strict Just to be anal | ||
| 110 | vars Global variables | ||
| 111 | |||
| 112 | =cut | ||
| 113 | |||
| 114 | use Genetics::Object ; | ||
| 115 | use strict ; | ||
| 116 | use vars qw(@ISA $ID $DEBUG @ATTRS @REQD_ATTRS %DEFAULTS) ; | ||
| 117 | |||
| 118 | require 5.004 ; | ||
| 119 | |||
| 120 | @ISA = qw(Genetics::Object) ; | ||
| 121 | |||
| 122 | @ATTRS = qw(gender dateOfBirth dateOfDeath isProband | ||
| 123 | Mother Father Kindred Organism Haplotypes) ; | ||
| 124 | |||
| 125 | @REQD_ATTRS = qw(gender) ; | ||
| 126 | |||
| 127 | %DEFAULTS = (isProband => 0) ; | ||
| 128 | |||
| 129 | |||
| 130 | =head1 Public methods | ||
| 131 | |||
| 132 | =head2 hasParents | ||
| 133 | |||
| 134 | Function : Find out if a Subject has parents. | ||
| 135 | Argument : N/A | ||
| 136 | Returns : 1 if a Subject has both a Mother and Father, 0 otherwise. | ||
| 137 | Scope : Public | ||
| 138 | Comments : Only checks for references in the Mother and Father fields; | ||
| 139 | does not check whether or not these references point to valid | ||
| 140 | Subjects. | ||
| 141 | |||
| 142 | =cut | ||
| 143 | |||
| 144 | sub hasParents { | ||
| 145 | my($self) = @_ ; | ||
| 146 | my($hasMom, $hasDad, $momPtr, $dadPtr) ; | ||
| 147 | |||
| 148 | #$self->print() ; | ||
| 149 | $hasMom = $hasDad = 0 ; | ||
| 150 | $momPtr = $self->field("Mother") ; | ||
| 151 | $dadPtr = $self->field("Father") ; | ||
| 152 | defined($momPtr) and $momPtr ne "" and $hasMom = 1 ; | ||
| 153 | defined($dadPtr) and $dadPtr ne "" and $hasDad = 1 ; | ||
| 154 | |||
| 155 | if ($hasMom and $hasDad) { | ||
| 156 | return(1) ; | ||
| 157 | } else { | ||
| 158 | return(0) ; | ||
| 159 | } | ||
| 160 | |||
| 161 | } | ||
| 162 | |||
| 163 | =head2 getMotherName | ||
| 164 | |||
| 165 | Function : Get a Subject's Mother's name. | ||
| 166 | Argument : N/A | ||
| 167 | Returns : String | ||
| 168 | Scope : Public | ||
| 169 | Comments : | ||
| 170 | |||
| 171 | =cut | ||
| 172 | |||
| 173 | sub getMotherName { | ||
| 174 | my($self) = @_ ; | ||
| 175 | my($momPtr) ; | ||
| 176 | |||
| 177 | $momPtr = $self->field("Mother") ; | ||
| 178 | if ( defined($momPtr) and $momPtr ne "" ) { | ||
| 179 | return($$momPtr{name}) ; | ||
| 180 | } else { | ||
| 181 | return(undef) ; | ||
| 182 | } | ||
| 183 | } | ||
| 184 | |||
| 185 | =head2 getFatherName | ||
| 186 | |||
| 187 | Function : Get a Subject's Father's name. | ||
| 188 | Argument : N/A | ||
| 189 | Returns : String | ||
| 190 | Scope : Public | ||
| 191 | Comments : | ||
| 192 | |||
| 193 | =cut | ||
| 194 | |||
| 195 | sub getFatherName { | ||
| 196 | my($self) = @_ ; | ||
| 197 | my($dadPtr) ; | ||
| 198 | |||
| 199 | $dadPtr = $self->field("Father") ; | ||
| 200 | if ( defined($dadPtr) and $dadPtr ne "" ) { | ||
| 201 | return($$dadPtr{name}) ; | ||
| 202 | } else { | ||
| 203 | return(undef) ; | ||
| 204 | } | ||
| 205 | } | ||
| 206 | |||
| 207 | =head2 printXML | ||
| 208 | |||
| 209 | Function : Print an XML representation of the object. | ||
| 210 | Argument : A Genetics::Subject object and the XML::Writer object being used | ||
| 211 | to generate the XML. | ||
| 212 | Returns : N/A | ||
| 213 | Scope : Public Instance Method | ||
| 214 | Comments : Calls Genetics::Object->printGeneralXML to generate XML elements | ||
| 215 | common to all Genetics::Object objects. | ||
| 216 | |||
| 217 | =cut | ||
| 218 | |||
| 219 | sub printXML { | ||
| 220 | my($self, $writer) = @_ ; | ||
| 221 | my($class, $value, $hashPtr) ; | ||
| 222 | |||
| 223 | $class = ref $self ; | ||
| 224 | $class =~ s/.*::// ; | ||
| 225 | |||
| 226 | ## Common Attributes/Elements | ||
| 227 | $self->printGeneralXML($writer) ; | ||
| 228 | |||
| 229 | ## Subject Elements | ||
| 230 | # Sex | ||
| 231 | $writer->dataElement('Sex', $self->field('sex')) ; | ||
| 232 | # Organism | ||
| 233 | if (defined ($hashPtr = $self->field('Organism'))) { | ||
| 234 | $writer->startTag('Organism') ; | ||
| 235 | $writer->dataElement('Genus', $$hashPtr{genus}) ; | ||
| 236 | $writer->dataElement('Species', $$hashPtr{species}) ; | ||
| 237 | $writer->endTag('Organism') ; | ||
| 238 | } | ||
| 239 | # DateOfBirth | ||
| 240 | if (defined ($value = $self->field('dateOfBirth'))) { | ||
| 241 | $writer->dataElement('DateOfBirth', $value) ; | ||
| 242 | } | ||
| 243 | # DateOfDeath | ||
| 244 | if (defined ($value = $self->field('dateOfDeath'))) { | ||
| 245 | $writer->dataElement('DateOfDeath', $value) ; | ||
| 246 | } | ||
| 247 | # Father | ||
| 248 | if (defined ($hashPtr = $self->field('FatherName'))) { | ||
| 249 | $writer->startTag('Father') ; | ||
| 250 | $writer->startTag('SubjectRef') ; | ||
| 251 | $writer->dataElement('Name', $$hashPtr{name}) ; | ||
| 252 | $writer->dataElement('ID', $$hashPtr{id}) ; | ||
| 253 | $writer->endTag('SubjectRef') ; | ||
| 254 | $writer->endTag('Father') ; | ||
| 255 | } | ||
| 256 | # Mother | ||
| 257 | if (defined ($hashPtr = $self->field('Mother'))) { | ||
| 258 | $writer->startTag('Mother') ; | ||
| 259 | $writer->startTag('SubjectRef') ; | ||
| 260 | $writer->dataElement('Name', $$hashPtr{name}) ; | ||
| 261 | $writer->dataElement('ID', $$hashPtr{id}) ; | ||
| 262 | $writer->endTag('SubjectRef') ; | ||
| 263 | $writer->endTag('Mother') ; | ||
| 264 | } | ||
| 265 | # Kindred | ||
| 266 | if (defined ($hashPtr = $self->field('Kindred'))) { | ||
| 267 | $writer->startTag('KindredRef') ; | ||
| 268 | $writer->dataElement('Name', $$hashPtr{name}) ; | ||
| 269 | $writer->dataElement('ID', $$hashPtr{id}) ; | ||
| 270 | $writer->endTag('KindredRef') ; | ||
| 271 | } | ||
| 272 | |||
| 273 | $writer->endTag($class) ; | ||
| 274 | |||
| 275 | return(1) ; | ||
| 276 | } | ||
| 277 | |||
| 278 | =head2 asHTML | ||
| 279 | |||
| 280 | Function : Generate an HTML representation of the object. | ||
| 281 | Argument : A Genetics::Subject object and a scalar containing the name of | ||
| 282 | the GenPerl database in which the object is stored. | ||
| 283 | Returns : Scalar containing the HTML text. | ||
| 284 | Scope : Public Instance Method | ||
| 285 | Comments : Calls Genetics::Object->_generalHTMLParam to generate HTML | ||
| 286 | elements common to all Genetics::Object objects. An | ||
| 287 | HTML::Template object is used to actually generate the HTML. | ||
| 288 | |||
| 289 | =cut | ||
| 290 | |||
| 291 | sub asHTML { | ||
| 292 | my($self, $db) = @_ ; | ||
| 293 | my $tmpl = new HTML::Template(filename => "/home/slm/work/GenPerl/templates/subject.tmpl") ; | ||
| 294 | my(%param, $orgPtr) ; | ||
| 295 | |||
| 296 | %param = (DB => $db) ; # DB is the database the object is in. It is used | ||
| 297 | # to conscruct URL links to associated objects | ||
| 298 | |||
| 299 | # Object data | ||
| 300 | $self->_generalHTMLParam(\%param) ; | ||
| 301 | |||
| 302 | # Subject data | ||
| 303 | if ($orgPtr = $self->Organism()) { | ||
| 304 | $param{ORG} = $$orgPtr{genusSpecies} ; | ||
| 305 | } | ||
| 306 | $self->gender() and $param{GENDER} = $self->gender() ; | ||
| 307 | $self->dateOfBirth() and $param{DATEOFBIRTH} = $self->dateOfBirth() ; | ||
| 308 | $self->dateOfDeath() and $param{DATEOFDEATH} = $self->dateOfDeath() ; | ||
| 309 | $self->isProband() and $param{ISPROBAND} = $self->isProband() ; | ||
| 310 | if ($self->Mother()) { | ||
| 311 | $param{MOTHER} = $self->Mother->{name} ; | ||
| 312 | $param{MOTHERID} = $self->Mother->{id} ; | ||
| 313 | } | ||
| 314 | if ($self->Father()) { | ||
| 315 | $param{FATHER} = $self->Father->{name} ; | ||
| 316 | $param{FATHERID} = $self->Father->{id} ; | ||
| 317 | } | ||
| 318 | if ($self->Kindred()) { | ||
| 319 | $param{KINDRED} = $self->Kindred->{name} ; | ||
| 320 | $param{KINDREDID} = $self->Kindred->{id} ; | ||
| 321 | } | ||
| 322 | |||
| 323 | $tmpl->param( %param ) ; | ||
| 324 | |||
| 325 | return $tmpl->output() ; | ||
| 326 | } | ||
| 327 | |||
| 328 | 1; | ||
| 329 |