| 1 | # GenPerl module | ||
| 2 | # | ||
| 3 | |||
| 4 | # POD documentation - main docs before the code | ||
| 5 | |||
| 6 | =head1 NAME | ||
| 7 | |||
| 8 | Genetics::Genotype | ||
| 9 | |||
| 10 | =head1 SYNOPSIS | ||
| 11 | |||
| 12 | $gt = new Genetics::Genotype(name => '1-D12S91', | ||
| 13 | importID => 13, | ||
| 14 | dateCreated => $today, | ||
| 15 | Keywords => [ {name => "Test Data", | ||
| 16 | dataType => "Boolean", | ||
| 17 | value => 1}, | ||
| 18 | ], | ||
| 19 | isActive => 1, | ||
| 20 | icResult => "Pass", | ||
| 21 | dateCollected => "1993-11-13", | ||
| 22 | Subject => {name => "EAPed20.1", importID => 12}, | ||
| 23 | Marker => {name => "D12S91", importID => 1}, | ||
| 24 | AssayAttrs => [ {name => "lab", | ||
| 25 | dataType=> "string", | ||
| 26 | value => "Lab 6"}, | ||
| 27 | {name => "machineID", | ||
| 28 | dataType => "String", | ||
| 29 | value => "ABC1234"} | ||
| 30 | ], | ||
| 31 | AlleleCalls => [ {alleleName => 3, | ||
| 32 | alleleType => "Code", | ||
| 33 | phase => "Maternal", | ||
| 34 | AssayAttrs => [ {name => "peakHeight", | ||
| 35 | dataType => "Number", | ||
| 36 | value => 367} ] | ||
| 37 | }, | ||
| 38 | {alleleName => 1, | ||
| 39 | alleleType => "Code", | ||
| 40 | phase => "Paternal", | ||
| 41 | AssayAttrs => [ {name => "peakHeight", | ||
| 42 | dataType => "Number", | ||
| 43 | value => 435} ] | ||
| 44 | }, | ||
| 45 | ] | ||
| 46 | ) ; | ||
| 47 | |||
| 48 | See the GenPerl Tutorial for more information. | ||
| 49 | |||
| 50 | =head1 DESCRIPTION | ||
| 51 | |||
| 52 | A Perl class encapsulating data associated with GNOM Genotype objects. | ||
| 53 | Genotype objects represent the experimentally determined set of alleles | ||
| 54 | that an individual has at a genetic marker. | ||
| 55 | |||
| 56 | =head1 LICENSE | ||
| 57 | |||
| 58 | This program is free software; you can redistribute it and/or modify | ||
| 59 | it under the terms of the GNU General Public License as published by | ||
| 60 | the Free Software Foundation; either version 2 of the License, or | ||
| 61 | (at your option) any later version. | ||
| 62 | |||
| 63 | This program is distributed in the hope that it will be useful, | ||
| 64 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 65 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 66 | GNU General Public License for more details. | ||
| 67 | |||
| 68 | You should have received a copy of the GNU General Public License | ||
| 69 | along with this program; if not, write to the Free Software | ||
| 70 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
| 71 | |||
| 72 | =head1 FEEDBACK | ||
| 73 | |||
| 74 | Currently, all feedback should be sent directly to the author. | ||
| 75 | |||
| 76 | =head1 AUTHOR - Steve Mathias | ||
| 77 | |||
| 78 | Email: mathias@genomica.com | ||
| 79 | |||
| 80 | Phone: (720) 565-4029 | ||
| 81 | |||
| 82 | Address: Genomica Corporation | ||
| 83 | 1745 38th Street | ||
| 84 | Boulder, CO 80301 | ||
| 85 | |||
| 86 | =head1 DETAILS | ||
| 87 | |||
| 88 | The rest of the documentation describes each of the object variables and | ||
| 89 | methods. The names of internal variables and methods are preceded with an | ||
| 90 | underscore (_). | ||
| 91 | |||
| 92 | =cut | ||
| 93 | |||
| 94 | ################## | ||
| 95 | # # | ||
| 96 | # Begin the code # | ||
| 97 | # # | ||
| 98 | ################## | ||
| 99 | |||
| 100 | package Genetics::Genotype ; | ||
| 101 | |||
| 102 | BEGIN { | ||
| 103 | $ID = "Genetics::Genotype" ; | ||
| 104 | #$DEBUG = $main::DEBUG ; | ||
| 105 | $DEBUG = 0 ; | ||
| 106 | $DEBUG and warn "Debugging in $ID is on" ; | ||
| 107 | } | ||
| 108 | |||
| 109 | =head1 Imported Packages | ||
| 110 | |||
| 111 | Genetics::Object Superclass | ||
| 112 | strict Just to be anal | ||
| 113 | vars Global variables | ||
| 114 | |||
| 115 | =cut | ||
| 116 | |||
| 117 | use Genetics::Object ; | ||
| 118 | use strict ; | ||
| 119 | use vars qw(@ISA) ; | ||
| 120 | |||
| 121 | require 5.004 ; | ||
| 122 | |||
| 123 | @ISA = qw(Genetics::Object) ; | ||
| 124 | |||
| 125 | use vars qw($ID $DEBUG @ATTRS @REQD_ATTRS %DEFAULTS) ; | ||
| 126 | |||
| 127 | @ATTRS = qw(isActive icResult dateCollected | ||
| 128 | Subject Marker Sample AlleleCalls AssayAttrs) ; | ||
| 129 | |||
| 130 | @REQD_ATTRS = qw(isActive | ||
| 131 | Subject Marker AlleleCalls) ; | ||
| 132 | |||
| 133 | %DEFAULTS = () ; | ||
| 134 | |||
| 135 | |||
| 136 | =head1 Public methods | ||
| 137 | |||
| 138 | =head2 printXML | ||
| 139 | |||
| 140 | Function : Print an XML representation of the object. | ||
| 141 | Argument : An XML::Writer object being used to generate the XML. | ||
| 142 | Returns : String | ||
| 143 | Scope : Public | ||
| 144 | Comments : Calls Genetics::Object->printGeneralXML to generate XML elements | ||
| 145 | common to all Genetics::Object objects. | ||
| 146 | |||
| 147 | =cut | ||
| 148 | |||
| 149 | sub printXML { | ||
| 150 | my($self, $writer) = @_ ; | ||
| 151 | my($class, $value, $hashPtr, $attrListPtr, $hashPtr2, $tag, $typeVal, | ||
| 152 | $type, $val) ; | ||
| 153 | |||
| 154 | $class = ref $self ; | ||
| 155 | $class =~ s/.*::// ; | ||
| 156 | |||
| 157 | ## Common Attributes/Elements | ||
| 158 | $self->printGeneralXML($writer) ; | ||
| 159 | |||
| 160 | ## Genotype Elements | ||
| 161 | # SubjectRef | ||
| 162 | $hashPtr = $self->field('Subject') ; | ||
| 163 | $writer->startTag('SubjectRef') ; | ||
| 164 | $writer->dataElement('Name', $$hashPtr{name}) ; | ||
| 165 | $writer->dataElement('ID', $$hashPtr{id}) ; | ||
| 166 | $writer->endTag('SubjectRef') ; | ||
| 167 | # MarkerRef | ||
| 168 | $hashPtr = $self->field('Marker') ; | ||
| 169 | $writer->startTag('MarkerRef') ; | ||
| 170 | $writer->dataElement('Name', $$hashPtr{name}) ; | ||
| 171 | $writer->dataElement('ID', $$hashPtr{id}) ; | ||
| 172 | $writer->endTag('MarkerRef') ; | ||
| 173 | # IsActive | ||
| 174 | $writer->dataElement('IsActive', $self->field('isActive')) ; | ||
| 175 | # ManualICResult | ||
| 176 | if (defined ($value = $self->field('manualICResult'))) { | ||
| 177 | $writer->dataElement('ManualICResult', $value) ; | ||
| 178 | } | ||
| 179 | # GenotypetAssayMethod | ||
| 180 | |||
| 181 | # AlleleCall | ||
| 182 | if (defined ($value = $self->field('AlleleCall'))) { | ||
| 183 | foreach $hashPtr (@$value) { | ||
| 184 | $writer->startTag('AlleleCall') ; | ||
| 185 | $writer->startTag('Allele') ; | ||
| 186 | $writer->dataElement('Name', $$hashPtr{alleleName}) ; | ||
| 187 | $writer->dataElement('Type', $$hashPtr{alleleType}) ; | ||
| 188 | $writer->endTag('Allele') ; | ||
| 189 | if (defined ($attrListPtr = $$hashPtr{Attr})) { | ||
| 190 | foreach $hashPtr2 (@$attrListPtr) { | ||
| 191 | $writer->startTag('Attribute') ; | ||
| 192 | while (($tag, $typeVal) = each(%$hashPtr2)) { | ||
| 193 | ($type, $val) = split(/\s*=\s*/, $typeVal) ; | ||
| 194 | $writer->dataElement('Name', $tag) ; | ||
| 195 | $writer->dataElement('DataType', $type) ; | ||
| 196 | $writer->dataElement('Value', $val) ; | ||
| 197 | } | ||
| 198 | $writer->endTag('Attribute') ; | ||
| 199 | } | ||
| 200 | } | ||
| 201 | $writer->endTag('AlleleCall') ; | ||
| 202 | } | ||
| 203 | } | ||
| 204 | $writer->endTag($class) ; | ||
| 205 | |||
| 206 | return(1) ; | ||
| 207 | } | ||
| 208 | |||
| 209 | =head2 asHTML | ||
| 210 | |||
| 211 | Function : Generate an HTML representation of the object. | ||
| 212 | Argument : A Genetics::Genotype object and a scalar containing the name | ||
| 213 | of the GenPerl database in which the object is stored. | ||
| 214 | Returns : Scalar containing the HTML text. | ||
| 215 | Scope : Public Instance Method | ||
| 216 | Comments : Calls Genetics::Object->_generalHTMLParam to generate HTML | ||
| 217 | elements common to all Genetics::Object objects. An | ||
| 218 | HTML::Template object is used to actually generate the HTML. | ||
| 219 | |||
| 220 | =cut | ||
| 221 | |||
| 222 | sub asHTML { | ||
| 223 | my($self, $db) = @_ ; | ||
| 224 | my $tmpl = new HTML::Template(filename => "/home/slm/work/GenPerl/templates/genotype.tmpl") ; | ||
| 225 | my(%param, $acListPtr, $acPtr, @alleles) ; | ||
| 226 | |||
| 227 | %param = (DB => $db) ; # DB is the database the object is in. It is used | ||
| 228 | # to conscruct URL links to associated objects | ||
| 229 | |||
| 230 | # Object data | ||
| 231 | $self->_generalHTMLParam(\%param) ; | ||
| 232 | |||
| 233 | # Genotype data | ||
| 234 | $param{ISACTIVE} = $self->isActive() ; | ||
| 235 | $self->icResult() and $param{ICRESULT} = $self->icResult() ; | ||
| 236 | $self->dateCollected() and $param{DATECOLL} = $self->dateCollected() ; | ||
| 237 | $param{SUBJECT} = $self->Subject->{name} ; | ||
| 238 | $param{SUBJECTID} = $self->Subject->{id} ; | ||
| 239 | $param{MARKER} = $self->Marker->{name} ; | ||
| 240 | $param{MARKERID} = $self->Marker->{id} ; | ||
| 241 | $acListPtr = $self->AlleleCalls() ; | ||
| 242 | foreach $acPtr (@$acListPtr) { | ||
| 243 | push @alleles, $$acPtr{alleleName} ; | ||
| 244 | } | ||
| 245 | $param{ALLELES} = join(", ", @alleles) ; | ||
| 246 | |||
| 247 | $tmpl->param( %param ) ; | ||
| 248 | |||
| 249 | return $tmpl->output() ; | ||
| 250 | } | ||
| 251 | |||
| 252 | 1; | ||
| 253 |