| 1 | # GenPerl module | ||
| 2 | # | ||
| 3 | |||
| 4 | # POD documentation - main docs before the code | ||
| 5 | |||
| 6 | =head1 NAME | ||
| 7 | |||
| 8 | Genetics::SNP | ||
| 9 | |||
| 10 | =head1 SYNOPSIS | ||
| 11 | |||
| 12 | $snp = new Genetics::SNP(name => 'EAEx1.1', | ||
| 13 | importID => 265, | ||
| 14 | dateCreated => $today, | ||
| 15 | Keywords => [ {name => "Test Data", | ||
| 16 | dataType => "Boolean", | ||
| 17 | value => 1}, | ||
| 18 | ], | ||
| 19 | chromosome => "12", | ||
| 20 | malePloidy => 2, | ||
| 21 | femalePloidy => 2, | ||
| 22 | snpType => "Substitution", | ||
| 23 | functionClass => "Synonymous", | ||
| 24 | snpIndex => 2, | ||
| 25 | isConfirmed => 1, | ||
| 26 | confirmMethod => "Resequencing", | ||
| 27 | comment => "Highly expressed in muscle", | ||
| 28 | Organism => {genusSpecies => "Homo sapiens"}, | ||
| 29 | Alleles => [ {name => "C", type => "Nucleotide"}, | ||
| 30 | {name => "T", type => "Nucleotide"} ], | ||
| 31 | Sequence => {lengthUnits => "bp", | ||
| 32 | length => 17, | ||
| 33 | sequence => "ACGTUMRWSYKVHDBXN"}, | ||
| 34 | ISCNMapLocations => [ {chrNumber => "12", | ||
| 35 | chrArm => "p", | ||
| 36 | band => "12.2", | ||
| 37 | bandingMethod => "Geimsa"}, | ||
| 38 | ], | ||
| 39 | ) ; | ||
| 40 | |||
| 41 | See the GenPerl Tutorial for more information. | ||
| 42 | |||
| 43 | =head1 DESCRIPTION | ||
| 44 | |||
| 45 | SNP objects represent single nucleotide polymorphisms. | ||
| 46 | |||
| 47 | =head1 LICENSE | ||
| 48 | |||
| 49 | This program is free software; you can redistribute it and/or modify | ||
| 50 | it under the terms of the GNU General Public License as published by | ||
| 51 | the Free Software Foundation; either version 2 of the License, or | ||
| 52 | (at your option) any later version. | ||
| 53 | |||
| 54 | This program is distributed in the hope that it will be useful, | ||
| 55 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 56 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 57 | GNU General Public License for more details. | ||
| 58 | |||
| 59 | You should have received a copy of the GNU General Public License | ||
| 60 | along with this program; if not, write to the Free Software | ||
| 61 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
| 62 | |||
| 63 | =head1 FEEDBACK | ||
| 64 | |||
| 65 | Currently, all feedback should be sent directly to the author. | ||
| 66 | |||
| 67 | =head1 AUTHOR - Steve Mathias | ||
| 68 | |||
| 69 | Email: mathias@genomica.com | ||
| 70 | |||
| 71 | Phone: (720) 565-4029 | ||
| 72 | |||
| 73 | Address: Genomica Corporation | ||
| 74 | 1745 38th Street | ||
| 75 | Boulder, CO 80301 | ||
| 76 | |||
| 77 | =head1 DETAILS | ||
| 78 | |||
| 79 | The rest of the documentation describes each of the object variables and | ||
| 80 | methods. The names of internal variables and methods are preceded with an | ||
| 81 | underscore (_). | ||
| 82 | |||
| 83 | =cut | ||
| 84 | |||
| 85 | ################## | ||
| 86 | # # | ||
| 87 | # Begin the code # | ||
| 88 | # # | ||
| 89 | ################## | ||
| 90 | |||
| 91 | package Genetics::SNP ; | ||
| 92 | |||
| 93 | BEGIN { | ||
| 94 | $ID = "Genetics::SNP" ; | ||
| 95 | #$DEBUG = $main::DEBUG ; | ||
| 96 | $DEBUG = 0 ; | ||
| 97 | $DEBUG and warn "Debugging in $ID is on" ; | ||
| 98 | } | ||
| 99 | |||
| 100 | =head1 Imported Packages | ||
| 101 | |||
| 102 | Genetics::Object Superclass | ||
| 103 | strict Just to be anal | ||
| 104 | vars Global variables | ||
| 105 | |||
| 106 | =cut | ||
| 107 | |||
| 108 | use Genetics::Object ; | ||
| 109 | use strict ; | ||
| 110 | use vars qw(@ISA $ID $DEBUG @ATTRS @REQD_ATTRS %DEFAULTS) ; | ||
| 111 | |||
| 112 | require 5.004 ; | ||
| 113 | |||
| 114 | @ISA = qw(Genetics::Object) ; | ||
| 115 | |||
| 116 | @ATTRS = qw(chromosome malePloidy femalePloidy | ||
| 117 | snpType functionClass snpIndex isConfirmed confirmMethod | ||
| 118 | Alleles Sequence ISCNMapLocations Organism | ||
| 119 | ) ; | ||
| 120 | |||
| 121 | @REQD_ATTRS = qw(malePloidy femalePloidy snpType functionClass isConfirmed) ; | ||
| 122 | |||
| 123 | %DEFAULTS = (malePloidy => 2, femalePloidy => 2, isConfirmed => 1) ; | ||
| 124 | |||
| 125 | |||
| 126 | =head1 Public methods | ||
| 127 | |||
| 128 | =head2 getSequence | ||
| 129 | |||
| 130 | Function : Return the nucleotide sequence of a SNP object | ||
| 131 | Arguments : N/A | ||
| 132 | Returns : A scalar text string | ||
| 133 | Example : getSequence() | ||
| 134 | Scope : Public Instance Method | ||
| 135 | Comments : | ||
| 136 | |||
| 137 | =cut | ||
| 138 | |||
| 139 | sub getSequence { | ||
| 140 | my($self) = shift ; | ||
| 141 | |||
| 142 | return(${$self->Sequence()}{sequence}) ; | ||
| 143 | } | ||
| 144 | |||
| 145 | =head2 printXML | ||
| 146 | |||
| 147 | Function : Print an XML representation of the object. | ||
| 148 | Argument : A Genetics::Subject object and the XML::Writer object being used | ||
| 149 | to generate the XML. | ||
| 150 | Returns : N/A | ||
| 151 | Scope : Public Instance Method | ||
| 152 | Comments : Calls Genetics::Object->printGeneralXML to generate XML elements | ||
| 153 | common to all Genetics::Object objects. | ||
| 154 | |||
| 155 | =cut | ||
| 156 | |||
| 157 | sub printXML { | ||
| 158 | my($self, $writer) = @_ ; | ||
| 159 | my($class, $value, $hashPtr, $hashPtr2) ; | ||
| 160 | |||
| 161 | $class = ref $self ; | ||
| 162 | $class =~ s/.*::// ; | ||
| 163 | |||
| 164 | ## Common Attributes/Elements | ||
| 165 | $self->printGeneralXML($writer) ; | ||
| 166 | |||
| 167 | ## SNP Elements | ||
| 168 | # SeqAttributes | ||
| 169 | $hashPtr = $self->field('SeqAttributes') ; | ||
| 170 | $writer->startTag('SeqAttributes') ; | ||
| 171 | if (defined ($hashPtr2 = $$hashPtr{Organism})) { | ||
| 172 | $writer->startTag('Organism') ; | ||
| 173 | $writer->dataElement('Genus', $$hashPtr2{genus}) ; | ||
| 174 | $writer->dataElement('Species', $$hashPtr2{species}) ; | ||
| 175 | $writer->endTag('Organism') ; | ||
| 176 | } | ||
| 177 | if (defined ($hashPtr2 = $$hashPtr{Chromosome})) { | ||
| 178 | $writer->startTag('Chromosome') ; | ||
| 179 | $writer->dataElement('Name', $$hashPtr2{name}) ; | ||
| 180 | $writer->endTag('Chromosome') ; | ||
| 181 | } | ||
| 182 | if (defined ($hashPtr2 = $$hashPtr{NtSequence})) { | ||
| 183 | $writer->startTag('NucleotideSeq') ; | ||
| 184 | $writer->dataElement('LengthUnits', $$hashPtr2{lengthUnits}) ; | ||
| 185 | $writer->dataElement('Length', $$hashPtr2{length}) ; | ||
| 186 | $writer->dataElement('NtSequence', $$hashPtr2{ntSequence}) ; | ||
| 187 | $writer->endTag('NucleotideSeq') ; | ||
| 188 | } | ||
| 189 | if (defined ($hashPtr2 = $$hashPtr{Source})) { | ||
| 190 | $writer->startTag('ContactSource') ; | ||
| 191 | $writer->dataElement('Name', $$hashPtr2{name}) ; | ||
| 192 | $writer->dataElement('Comment', $$hashPtr2{comment}) ; | ||
| 193 | $writer->endTag('ContactSource') ; | ||
| 194 | } | ||
| 195 | $writer->endTag('SeqAttributes') ; | ||
| 196 | # ISCNMapLocation | ||
| 197 | if (defined ($hashPtr = $self->field('ISCNMapLocation'))) { | ||
| 198 | $writer->startTag('ISCNMapLocation') ; | ||
| 199 | $writer->dataElement('ChrNumber', $$hashPtr{chrNumber}) ; | ||
| 200 | $writer->dataElement('ChrArm', $$hashPtr{chrArm}) ; | ||
| 201 | $writer->dataElement('Band', $$hashPtr{band}) ; | ||
| 202 | $writer->dataElement('BandingMethod', $$hashPtr{bandingMethod}) ; | ||
| 203 | $writer->endTag('ISCNMapLocation') ; | ||
| 204 | } | ||
| 205 | # ProbeChar | ||
| 206 | if (defined ($hashPtr = $self->field('ProbeChar'))) { | ||
| 207 | $writer->startTag('ProbeChar') ; | ||
| 208 | $writer->dataElement('ProbeCharType', $$hashPtr{characteristic}) ; | ||
| 209 | $writer->dataElement('Comment', $$hashPtr{comment}) ; | ||
| 210 | $writer->endTag('ProbeChar') ; | ||
| 211 | } | ||
| 212 | # MalePloidy | ||
| 213 | $writer->dataElement('MalePloidy', $self->field('malePloidy')) ; | ||
| 214 | # FemalePloidy | ||
| 215 | $writer->dataElement('FemalePloidy', $self->field('femalePloidy')) ; | ||
| 216 | # Allele | ||
| 217 | if (defined ($value = $self->field('Allele'))) { | ||
| 218 | foreach $hashPtr (@$value) { | ||
| 219 | $writer->startTag('Allele') ; | ||
| 220 | $writer->dataElement('Name', $$hashPtr{name}) ; | ||
| 221 | $writer->dataElement('Type', $$hashPtr{type}) ; | ||
| 222 | $writer->endTag('Allele') ; | ||
| 223 | } | ||
| 224 | } | ||
| 225 | # SNPType | ||
| 226 | $writer->dataElement('SNPType', $self->field('snpType')) ; | ||
| 227 | # Coding | ||
| 228 | if (defined ($value = $self->field('coding'))) { | ||
| 229 | $writer->dataElement('Coding', $value) ; | ||
| 230 | } | ||
| 231 | # SNPIndex | ||
| 232 | if (defined ($value = $self->field('snpIndex'))) { | ||
| 233 | $writer->dataElement('SNPIndex', $value) ; | ||
| 234 | } | ||
| 235 | # GtAssayMethodTemplate | ||
| 236 | |||
| 237 | $writer->endTag($class) ; | ||
| 238 | |||
| 239 | return(1) ; | ||
| 240 | } | ||
| 241 | |||
| 242 | =head2 asHTML | ||
| 243 | |||
| 244 | Function : Generate an HTML representation of the object. | ||
| 245 | Argument : A Genetics::SNP object and a scalar containing the name of the | ||
| 246 | GenPerl database in which the object is stored. | ||
| 247 | Returns : Scalar containing the HTML text. | ||
| 248 | Scope : Public Instance Method | ||
| 249 | Comments : Calls Genetics::Object->_generalHTMLParam to generate HTML | ||
| 250 | elements common to all Genetics::Object objects. An | ||
| 251 | HTML::Template object is used to actually generate the HTML. | ||
| 252 | |||
| 253 | =cut | ||
| 254 | |||
| 255 | sub asHTML { | ||
| 256 | my($self, $db) = @_ ; | ||
| 257 | my $tmpl = new HTML::Template(filename => "/home/slm/work/GenPerl/templates/snp.tmpl") ; | ||
| 258 | my(%param, $alleleListPtr, $allelePtr, @alleles, $orgPtr, $seqPtr, | ||
| 259 | $iscnListPtr, $iscnPtr, @iscnLoc) ; | ||
| 260 | |||
| 261 | %param = (DB => $db) ; # DB is the database the object is in. It is used | ||
| 262 | # to conscruct URL links to associated objects | ||
| 263 | |||
| 264 | # Object data | ||
| 265 | $self->_generalHTMLParam(\%param) ; | ||
| 266 | |||
| 267 | # SNP data | ||
| 268 | $alleleListPtr = $self->Alleles() ; | ||
| 269 | foreach $allelePtr (@$alleleListPtr) { | ||
| 270 | push @alleles, "$$allelePtr{name}($$allelePtr{type})" ; | ||
| 271 | } | ||
| 272 | $param{ALLELES} = join(", ", @alleles) ; | ||
| 273 | if ($orgPtr = $self->Organism()) { | ||
| 274 | $param{ORG} = $$orgPtr{genusSpecies} ; | ||
| 275 | } | ||
| 276 | $self->chromosome() and $param{CHR} = $self->chromosome() ; | ||
| 277 | $self->malePloidy() and $param{MPLOIDY} = $self->malePloidy() ; | ||
| 278 | $self->femalePloidy() and $param{FPLOIDY} = $self->femalePloidy() ; | ||
| 279 | $param{SNPTYPE} = $self->snpType() ; | ||
| 280 | $param{CLASS} = $self->functionClass() ; | ||
| 281 | $self->isConfirmed() and $param{ISCONFIRMED} = $self->isConfirmed() ; | ||
| 282 | $self->confirmMethod() and $param{CONFMETHOD} = $self->confirmMethod() ; | ||
| 283 | $self->snpIndex() and $param{SNPIDX} = $self->snpIndex() ; | ||
| 284 | if ($seqPtr = $self->Sequence()) { | ||
| 285 | $param{SEQUENCE} = $$seqPtr{sequence} ; | ||
| 286 | } | ||
| 287 | if ($iscnListPtr = $self->ISCNMapLocations()) { | ||
| 288 | foreach $iscnPtr (@$iscnListPtr) { | ||
| 289 | push @iscnLoc, "$$iscnPtr{chrNumber }$$iscnPtr{hrArm}$$iscnPtr{band}" ; | ||
| 290 | } | ||
| 291 | $param{ISCNLOC} = join(", ", @iscnLoc) ; | ||
| 292 | } | ||
| 293 | $tmpl->param( %param ) ; | ||
| 294 | |||
| 295 | return $tmpl->output() ; | ||
| 296 | } | ||
| 297 | |||
| 298 | 1; | ||
| 299 |