| 1 | # GenPerl module | ||
| 2 | # | ||
| 3 | |||
| 4 | # POD documentation - main docs before the code | ||
| 5 | |||
| 6 | =head1 NAME | ||
| 7 | |||
| 8 | Genetics::StudyVariable | ||
| 9 | |||
| 10 | =head1 SYNOPSIS | ||
| 11 | |||
| 12 | $sv = new Genetics::StudyVariable(name => 'EA Aff Stat', | ||
| 13 | importID => 445, | ||
| 14 | dateCreated => $today, | ||
| 15 | Keywords => [ {name => "Test Data", | ||
| 16 | dataType => "Boolean", | ||
| 17 | value => 1}, | ||
| 18 | ], | ||
| 19 | description => "EA Trait Locus", | ||
| 20 | category => "AffectionStatus", | ||
| 21 | format => "Code", | ||
| 22 | isXLinked => 0, | ||
| 23 | Codes => [ {code => 0, | ||
| 24 | description => "Unknown EA Status"}, | ||
| 25 | {code => 1, | ||
| 26 | description => "EA Unaffected"}, | ||
| 27 | {code => 2, | ||
| 28 | description => "EA Affected"}, | ||
| 29 | ], | ||
| 30 | AffStatDef => {name => 'EA', | ||
| 31 | diseaseAlleleFreq => 0.001, | ||
| 32 | pen11 => 0.0, | ||
| 33 | pen12 => 0.0, | ||
| 34 | pen22 => 1.0, | ||
| 35 | AffStatElements => [ {code => 0, | ||
| 36 | type => "Unknown", | ||
| 37 | formula => "'EA Aff Stat' = 0"}, | ||
| 38 | {code => 1, | ||
| 39 | type => "Unaffected", | ||
| 40 | formula => "'EA Aff Stat' = 1"}, | ||
| 41 | {code => 2, | ||
| 42 | type => "Affected", | ||
| 43 | formula => "'EA Aff Stat' = 2"}, | ||
| 44 | ], | ||
| 45 | }, | ||
| 46 | LCDef => {name => 'EA Default LC', | ||
| 47 | LiabilityClasses => [ {code => 0, | ||
| 48 | description => "Unknown Age", | ||
| 49 | pen11 => 0.0, | ||
| 50 | pen12 => 0.0, | ||
| 51 | pen22 => 1.0, | ||
| 52 | formula => "'Age' = ''"}, | ||
| 53 | {code => 1, | ||
| 54 | description => "Age less than 40", | ||
| 55 | pen11 => 0.0, | ||
| 56 | pen12 => 0.2, | ||
| 57 | pen22 => 1.0, | ||
| 58 | formula => "'Age' < 40"}, | ||
| 59 | {code => 2, | ||
| 60 | description => "Age less than 50", | ||
| 61 | pen11 => 0.0, | ||
| 62 | pen12 => 0.3, | ||
| 63 | pen22 => 1.0, | ||
| 64 | formula => "'Age' < 50"}, | ||
| 65 | {code => 3, | ||
| 66 | description => "Age grater than or equal to 60", | ||
| 67 | pen11 => 0.0, | ||
| 68 | pen12 => 0.4, | ||
| 69 | pen22 => 1.0, | ||
| 70 | formula => "'Age' >= 60"}, | ||
| 71 | ], | ||
| 72 | }, | ||
| 73 | ) ; | ||
| 74 | |||
| 75 | See the GenPerl Tutorial for more information. | ||
| 76 | |||
| 77 | =head1 DESCRIPTION | ||
| 78 | |||
| 79 | StudyVariable objects represent definitions of physical traits, affection | ||
| 80 | status loci, environmental exposure, or drug treatments. | ||
| 81 | |||
| 82 | =head1 LICENSE | ||
| 83 | |||
| 84 | This program is free software; you can redistribute it and/or modify | ||
| 85 | it under the terms of the GNU General Public License as published by | ||
| 86 | the Free Software Foundation; either version 2 of the License, or | ||
| 87 | (at your option) any later version. | ||
| 88 | |||
| 89 | This program is distributed in the hope that it will be useful, | ||
| 90 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 91 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 92 | GNU General Public License for more details. | ||
| 93 | |||
| 94 | You should have received a copy of the GNU General Public License | ||
| 95 | along with this program; if not, write to the Free Software | ||
| 96 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
| 97 | |||
| 98 | =head1 FEEDBACK | ||
| 99 | |||
| 100 | Currently, all feedback should be sent directly to the author. | ||
| 101 | |||
| 102 | =head1 AUTHOR - Steve Mathias | ||
| 103 | |||
| 104 | Email: mathias@genomica.com | ||
| 105 | |||
| 106 | Phone: (720) 565-4029 | ||
| 107 | |||
| 108 | Address: Genomica Corporation | ||
| 109 | 1745 38th Street | ||
| 110 | Boulder, CO 80301 | ||
| 111 | |||
| 112 | =head1 DETAILS | ||
| 113 | |||
| 114 | The rest of the documentation describes each of the object variables and | ||
| 115 | methods. The names of internal variables and methods are preceded with an | ||
| 116 | underscore (_). | ||
| 117 | |||
| 118 | =cut | ||
| 119 | |||
| 120 | ################## | ||
| 121 | # # | ||
| 122 | # Begin the code # | ||
| 123 | # # | ||
| 124 | ################## | ||
| 125 | |||
| 126 | package Genetics::StudyVariable ; | ||
| 127 | |||
| 128 | BEGIN { | ||
| 129 | $ID = "Genetics::StudyVariable" ; | ||
| 130 | #$DEBUG = $main::DEBUG ; | ||
| 131 | $DEBUG = 0 ; | ||
| 132 | $DEBUG and warn "Debugging in $ID is on" ; | ||
| 133 | } | ||
| 134 | |||
| 135 | =head1 Imported Packages | ||
| 136 | |||
| 137 | Genetics::Object Superclass | ||
| 138 | strict Just to be anal | ||
| 139 | vars Global variables | ||
| 140 | |||
| 141 | =cut | ||
| 142 | |||
| 143 | use Genetics::Object ; | ||
| 144 | use strict ; | ||
| 145 | use vars qw(@ISA $ID $DEBUG @ATTRS @REQD_ATTRS %DEFAULTS) ; | ||
| 146 | |||
| 147 | require 5.004 ; | ||
| 148 | |||
| 149 | @ISA = qw(Genetics::Object) ; | ||
| 150 | |||
| 151 | @ATTRS = qw(description category format isXLinked lowerBound upperBound | ||
| 152 | Codes AffStatDef LCDef) ; | ||
| 153 | |||
| 154 | @REQD_ATTRS = qw(category format isXLinked) ; | ||
| 155 | |||
| 156 | %DEFAULTS = (category => "Trait", | ||
| 157 | isXLinked => 0 | ||
| 158 | ) ; | ||
| 159 | |||
| 160 | |||
| 161 | =head1 Public methods | ||
| 162 | |||
| 163 | printXML Print an XML representation of the object | ||
| 164 | |||
| 165 | =cut | ||
| 166 | |||
| 167 | =head2 printXML | ||
| 168 | |||
| 169 | Function : Print an XML representation of the object. | ||
| 170 | Argument : A Genetics::StudyVariable object and the XML::Writer object being | ||
| 171 | used to generate the XML. | ||
| 172 | Returns : String | ||
| 173 | Scope : Public Instance Method | ||
| 174 | Comments : Calls Genetics::Object->printGeneralXML to generate XML elements | ||
| 175 | common to all Genetics::Object objects. | ||
| 176 | |||
| 177 | =cut | ||
| 178 | |||
| 179 | sub printXML { | ||
| 180 | my($self, $writer) = @_ ; | ||
| 181 | my($class, $value, $hashPtr, $hashPtr2) ; | ||
| 182 | |||
| 183 | $class = ref $self ; | ||
| 184 | $class =~ s/.*::// ; | ||
| 185 | |||
| 186 | ## Common Attributes/Elements | ||
| 187 | $self->printGeneralXML($writer) ; | ||
| 188 | |||
| 189 | ## StudyVariable Elements | ||
| 190 | # Format | ||
| 191 | $writer->dataElement('Format', $self->field('format')) ; | ||
| 192 | # Category | ||
| 193 | $writer->dataElement('Category', $self->field('category')) ; | ||
| 194 | # IsXLinked | ||
| 195 | $writer->dataElement('IsXLinked', $self->field('isXLinked')) ; | ||
| 196 | # Description | ||
| 197 | if (defined ($value = $self->field('description'))) { | ||
| 198 | $writer->dataElement('Description', $value) ; | ||
| 199 | } | ||
| 200 | # LowerBound | ||
| 201 | if (defined ($value = $self->field('lowerBound'))) { | ||
| 202 | $writer->dataElement('LowerBound', $value) ; | ||
| 203 | } | ||
| 204 | # UpperBound | ||
| 205 | if (defined ($value = $self->field('upperBound'))) { | ||
| 206 | $writer->dataElement('UpperBound', $value) ; | ||
| 207 | } | ||
| 208 | # DecimalPlaces | ||
| 209 | if (defined ($value = $self->field('decimalPlaces'))) { | ||
| 210 | $writer->dataElement('DecimalPlaces', $value) ; | ||
| 211 | } | ||
| 212 | # PtAssayMethodTemplate | ||
| 213 | |||
| 214 | |||
| 215 | $writer->endTag($class) ; | ||
| 216 | |||
| 217 | return(1) ; | ||
| 218 | } | ||
| 219 | |||
| 220 | =head2 asHTML | ||
| 221 | |||
| 222 | Function : Generate an HTML representation of the object. | ||
| 223 | Argument : A Genetics::StudyVariable object and a scalar containing the | ||
| 224 | name of the GenPerl database in which the object is stored. | ||
| 225 | Returns : Scalar containing the HTML text. | ||
| 226 | Scope : Public Instance Method | ||
| 227 | Comments : Calls Genetics::Object->_generalHTMLParam to generate HTML | ||
| 228 | elements common to all Genetics::Object objects. An | ||
| 229 | HTML::Template object is used to actually generate the HTML. | ||
| 230 | |||
| 231 | =cut | ||
| 232 | |||
| 233 | sub asHTML { | ||
| 234 | my($self, $db) = @_ ; | ||
| 235 | my $tmpl = new HTML::Template(filename => "/home/slm/work/GenPerl/templates/studyvar.tmpl") ; | ||
| 236 | my(%param, $codeListPtr, $codePtr, @codes, $asdPtr, ) ; | ||
| 237 | |||
| 238 | %param = (DB => $db) ; # DB is the database the object is in. It is used | ||
| 239 | # to conscruct URL links to associated objects | ||
| 240 | |||
| 241 | # Object data | ||
| 242 | $self->_generalHTMLParam(\%param) ; | ||
| 243 | |||
| 244 | # Study Variable data | ||
| 245 | $param{CATEGORY} = $self->category() ; | ||
| 246 | $param{FORMAT} = $self->format() ; | ||
| 247 | $param{ISXLINKED} = $self->isXLinked() ; | ||
| 248 | $self->description() and $param{DESC} = $self->description() ; | ||
| 249 | $self->lowerBound() and $param{LBOUND} = $self->lowerBound() ; | ||
| 250 | $self->upperBound() and $param{UBOUND} = $self->upperBound() ; | ||
| 251 | if ($self->format() eq "Code") { | ||
| 252 | $codeListPtr = $self->Codes() ; | ||
| 253 | if ($self->category() eq "StaticLiabilityClass") { | ||
| 254 | # Need to get penetrance values and include them with the codes | ||
| 255 | $param{SLC} = 1 ; | ||
| 256 | $param{LCCODES} = $codeListPtr ; | ||
| 257 | } else { | ||
| 258 | foreach $codePtr (@$codeListPtr) { | ||
| 259 | push @codes, "$$codePtr{code} ($$codePtr{description})" ; | ||
| 260 | } | ||
| 261 | $param{CODES} = join("<br>", @codes) ; | ||
| 262 | } | ||
| 263 | } | ||
| 264 | if ($self->category() eq "StaticAffectionStatus") { | ||
| 265 | $param{ASD} = 1 ; | ||
| 266 | $asdPtr = $self->AffStatDef() ; | ||
| 267 | $param{DISFREQ} = $$asdPtr{diseaseAlleleFreq} ; | ||
| 268 | $param{PEN11} = $$asdPtr{pen11} ; | ||
| 269 | $param{PEN12} = $$asdPtr{pen12} ; | ||
| 270 | $param{PEN22} = $$asdPtr{pen22} ; | ||
| 271 | if ($self->isXLinked()) { | ||
| 272 | $param{MALEPEN1} = $$asdPtr{malePen1} ; | ||
| 273 | $param{MALEPEN2} = $$asdPtr{malePen2} ; | ||
| 274 | } | ||
| 275 | } | ||
| 276 | |||
| 277 | $tmpl->param( %param ) ; | ||
| 278 | |||
| 279 | return $tmpl->output() ; | ||
| 280 | } | ||
| 281 | |||
| 282 | 1; | ||
| 283 |