Genetics/FrequencySource.pm untested

filter: Statementstmt 0.0% 0 / 65 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 89 CC 4 SCAR 17.6
CC
4
Cov
0%
printXML
12.0
getAlleleFreqsByMarkerName
6.0
BEGIN
2.0
CRAP 5.8
1 # GenPerl module
2 #
3  
4 # POD documentation - main docs before the code
5  
6 =head1 NAME
7  
8 Genetics::FrequencySource
9  
10 =head1 SYNOPSIS
11  
12 $fs = new Genetics::FrequencySource(name => 'WICGR SNP Freqs',
13 importID => 270,
14 dateCreated => $today,
15 Keywords => [ {name => "Test Data",
16 dataType => "Boolean",
17 value => 1},
18 ],
19 ObsAlleleFrequencies => [ {Allele => {Marker => {name => "EAEx1.1",
20 importID => 265},
21 name => "T",
22 type => "nucleotide"},
23 frequency => "0.64",
24 },
25 {Allele => {Marker => {name => "EAEx1.1",
26 importID => 265},
27 name => "C",
28 type => "nucleotide"},
29 frequency => "0.36",
30 }
31 ],
32 ObsHtFrequencies => [ {Haplotype => {name => '12pEA1.2',
33 importID => 269,},
34 frequency => 1.00,
35 }
36 ]
37 ) ;
38
39 See the GenPerl Tutorial for more information.
40  
41 =head1 DESCRIPTION
42  
43 FrequencySource objects represent the allele and/or haplotype frequencies
44 in a particular group of Subjects not represented in the database.
45  
46 =head1 LICENSE
47  
48 This program is free software; you can redistribute it and/or modify
49 it under the terms of the GNU General Public License as published by
50 the Free Software Foundation; either version 2 of the License, or
51 (at your option) any later version.
52  
53 This program is distributed in the hope that it will be useful,
54 but WITHOUT ANY WARRANTY; without even the implied warranty of
55 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
56 GNU General Public License for more details.
57  
58 You should have received a copy of the GNU General Public License
59 along with this program; if not, write to the Free Software
60 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
61  
62 =head1 FEEDBACK
63  
64 Currently, all feedback should be sent directly to the author.
65  
66 =head1 AUTHOR - Steve Mathias
67  
68 Email: mathias@genomica.com
69  
70 Phone: (720) 565-4029
71  
72 Address: Genomica Corporation
73 1745 38th Street
74 Boulder, CO 80301
75  
76 =head1 DETAILS
77  
78 The rest of the documentation describes each of the object variables and
79 methods. The names of internal variables and methods are preceded with an
80 underscore (_).
81  
82 =cut
83  
84 ##################
85 # #
86 # Begin the code #
87 # #
88 ##################
89  
90 package Genetics::FrequencySource ;
91  
92 BEGIN {
93 $ID = "Genetics::FrequencySource" ;
94 #$DEBUG = $main::DEBUG ;
95 $DEBUG = 0 ;
96 $DEBUG and warn "Debugging in $ID is on" ;
97 }
98  
99 =head1 Imported Packages
100  
101 Genetics::Object Superclass
102 strict Just to be anal
103 vars Global variables
104  
105 =cut
106  
107 use Genetics::Object ;
108 use strict ;
109 use vars qw(@ISA $ID $DEBUG @ATTRS @REQD_ATTRS %DEFAULTS) ;
110  
111 require 5.004 ;
112  
113 @ISA = qw(Genetics::Object) ;
114  
115 @ATTRS = qw(ObsAlleleFrequencies ObsHtFrequencies) ;
116  
117 @REQD_ATTRS = qw() ;
118  
119 %DEFAULTS = () ;
120  
121  
122 =head1 Public methods
123  
124 =head2 getAlleleFreqsByMarkerName
125  
126 Function : Return allele frequencies for an individual marker.
127 Argument : A Marker object and a string containing an allele type.
128 Returns : Hash reference to a hash with the following structure:
129 $freqs{AlleleName} = $number
130 Scope : Public
131 Comments : This method requires that Markers are uniquely named within the
132 FrequencySource.
133  
134 =cut
135  
136 sub getAlleleFreqsByMarkerName {
137 my($self, $markerName, $alleleType) = @_ ;
138 my($oafListPtr, $oafPtr, $allelePtr, %freqs) ;
139  
140 $oafListPtr = $self->field("ObsAlleleFrequencies") ;
141  
142 foreach $oafPtr (@$oafListPtr) {
143 $allelePtr = $$oafPtr{Allele} ;
144 if ($$allelePtr{Marker}{name} eq $markerName and
145 $$allelePtr{type} eq $alleleType) {
146 $freqs{$$allelePtr{name}} = $$oafPtr{frequency} ;
147 }
148 }
149  
150 return(\%freqs) ;
151 }
152  
153 =head2 printXML
154  
155 Function : Print an XML representation of the object.
156 Argument : An XML::Writer object being used to generate the XML.
157 Returns : String
158 Scope : Public Instance Method
159 Comments : Calls Genetics::Object->printGeneralXML to generate XML elements
160 common to all Genetics::Object objects.
161  
162 =cut
163  
164 sub printXML {
165 my($self, $writer) = @_ ;
166 my($class, $listPtr, $hashPtr, $hashPtr2, $listPtr2) ;
167  
168 $class = ref $self ;
169 $class =~ s/.*::// ;
170
171 ## Common Attributes/Elements
172 $self->printGeneralXML($writer) ;
173  
174 ## FrequencySource Elements
175 # ObsAlleleFrequency
176 if (defined ($listPtr = $self->field('ObsAlleleFrequency'))) {
177 foreach $hashPtr (@$listPtr) {
178 $writer->startTag('ObsAlleleFrequency') ;
179 $hashPtr2 = $$hashPtr{Marker} ;
180 $writer->startTag('MarkerRef') ;
181 $writer->dataElement('Name', $$hashPtr2{name}) ;
182 $writer->dataElement('ID', $$hashPtr2{id}) ;
183 $writer->endTag('MarkerRef') ;
184 $hashPtr2 = $$hashPtr{Allele} ;
185 $writer->startTag('Allele') ;
186 $writer->dataElement('Name', $$hashPtr2{name}) ;
187 $writer->dataElement('Type', $$hashPtr2{type}) ;
188 $writer->endTag('Allele') ;
189 $writer->dataElement('Frequency', $$hashPtr{frequency}) ;
190 $writer->endTag('ObsAlleleFrequency') ;
191 }
192 }
193 # ObsGtFrequency
194 if (defined ($listPtr = $self->field('ObsGtFrequency'))) {
195 foreach $hashPtr (@$listPtr) {
196 $writer->startTag('ObsGtFrequency') ;
197 $hashPtr2 = $$hashPtr{Marker} ;
198 $writer->startTag('MarkerRef') ;
199 $writer->dataElement('Name', $$hashPtr2{name}) ;
200 $writer->dataElement('ID', $$hashPtr2{id}) ;
201 $writer->endTag('MarkerRef') ;
202 $listPtr2 = $$hashPtr{Allele} ;
203 foreach $hashPtr2 (@$listPtr2) {
204 $writer->startTag('Allele') ;
205 $writer->dataElement('Name', $$hashPtr2{name}) ;
206 $writer->dataElement('Type', $$hashPtr2{type}) ;
207 $writer->endTag('Allele') ;
208 }
209 $writer->dataElement('Frequency', $$hashPtr{frequency}) ;
210 $writer->endTag('ObsGtFrequency') ;
211 }
212 }
213  
214 $writer->endTag($class) ;
215  
216 return(1) ;
217 }
218  
219  
220 1;
221