Genetics/API/DB/Read.pm untested

filter: Statementstmt 0.0% 0 / 989 Branchbran 0.0% 0 / 74 Conditioncond 0.0% 0 / 638 MC/DCmcdc 0.0% 0 / 411 Subroutinesub 0.0% 0 / 32 Podpod 0.0% 0 / 28 totaltotal 0.0% 0 / 2172 CC 38 SCAR 28.5
CC
38
Cov
0%
getStudyVariable
56.0
getSubject
30.0
getMiniStudyVariable
30.0
CRAP 17.3
1 # GenPerl module
2 #
3  
4 # POD documentation - main docs before the code
5  
6 =head1 NAME
7  
8 Genetics::API::DB::Read
9  
10 =head1 SYNOPSIS
11  
12 use Genetics::API ;
13  
14 $api = new Genetics::API(DSN => {driver => "mysql",
15 host => $Host,
16 database => $Database},
17 user => $UserName,
18 password => $Password) ;
19  
20 $id = 123456 ;
21 $subject = $api->getSubject($id) ;
22  
23 =head1 DESCRIPTION
24  
25 The Genetics::API::DB packages provide an interface for the manipulation of
26 Genperl objects in a relationa; database. This package contains the methods
27 for retrieving objects from a database by id. To retrieve objects using more
28 complex criteria, see Genetics::API::DB::Query.
29  
30 Two versions of get methods are provided for most object types. One returns
31 "full" objects containing all the data in the database associated with an
32 object id; the other returns "mini" objects containing only a subset of the
33 data associated with an object. Generally, the getMini methods do not return
34 any of the general object annotation fields (ie. things like Keywords,
35 DBXReferences, etc. are not returned with "mini" objects). In some cases,
36 certain class-specific data is also left out of "mini" objects. See the
37 individual getMini method descriptions for details on this.
38  
39 =head1 LICENSE
40  
41 This program is free software; you can redistribute it and/or modify
42 it under the terms of the GNU General Public License as published by
43 the Free Software Foundation; either version 2 of the License, or
44 (at your option) any later version.
45  
46 This program is distributed in the hope that it will be useful,
47 but WITHOUT ANY WARRANTY; without even the implied warranty of
48 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
49 GNU General Public License for more details.
50  
51 You should have received a copy of the GNU General Public License
52 along with this program; if not, write to the Free Software
53 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
54  
55 =head1 FEEDBACK
56  
57 Currently, all feedback should be sent directly to the author.
58  
59 =head1 AUTHOR - Steve Mathias
60  
61 Email: mathias@genomica.com
62  
63 Phone: (720) 565-4029
64  
65 Address: Genomica Corporation
66 1745 38th Street
67 Boulder, CO 80301
68  
69 =head1 DETAILS
70  
71 The rest of the documentation describes each of the object variables and
72 methods. The names of internal variables and methods are preceded with an
73 underscore (_).
74  
75 =cut
76  
77 ##################
78 # #
79 # Begin the code #
80 # #
81 ##################
82  
83 package Genetics::API::DB::Read ;
84  
85 BEGIN {
86 $ID = "Genetics::API::DB::Read" ;
87 #$DEBUG = $main::DEBUG ;
88 $DEBUG = 0 ;
89 $DEBUG and warn "Debugging in $ID is on" ;
90 }
91  
92 =head1 Imported Packages
93  
94 strict Just to be anal
95 vars Global variables
96 Carp Error reporting
97  
98 =cut
99  
100 use strict ;
101 use vars qw(@ISA @EXPORT @EXPORT_OK $ID $DEBUG) ;
102 use Carp ;
103 use Exporter ;
104  
105 =head1 Inheritance
106  
107 Exporter Make methods available to importing packages
108  
109 =cut
110  
111 @ISA = qw(Exporter) ;
112  
113 @EXPORT = qw(getCluster getSubject getKindred getMarker getSNP getGenotype
114 getStudyVariable getPhenotype getFrequencySource
115 getHtMarkerCollection getHaplotype getDNASample getTissueSample
116 getMap _getObjAssocData
117 getMiniCluster getMiniSubject getMiniKindred getMiniMarker
118 getMiniSNP getMiniGenotype getMiniPhenotype getMiniStudyVariable
119 getMiniMap getMiniMarkerByName getMiniFrequencySource ) ;
120 @EXPORT_OK = qw();
121  
122 =head1 Public Methods
123  
124 =head2 getCluster
125  
126 Function : Get (read) a Genetics::Object::Cluster object from the database.
127 Argument : The Object ID of the Cluster to be returned.
128 Returns : A Genetics::Object::Cluster object.
129 Scope : Public
130  
131 =cut
132  
133 sub getCluster {
134 my($self, $id) = @_ ;
135 my($cluster, %param, $sth, $arrRef, $clusterType, $objName, $contentsListPtr) ;
136 my $dbh = $self->{dbh} ;
137  
138 $DEBUG and carp " ->[getCluster] $id" ;
139  
140 $self->_getObjAssocData($id, \%param) ;
141  
142 ( $clusterType ) = $dbh->selectrow_array("select clusterType
143 from Cluster
144 where clusterID = $id") ;
145 defined $clusterType or return(undef) ;
146 $param{clusterType} = $clusterType ;
147 # Contents
148 $sth = $dbh->prepare("select objID from ClusterContents
149 where clusterID = $id") ;
150 $sth->execute() ;
151 while ($arrRef = $sth->fetchrow_arrayref()) {
152 ( $objName ) = $dbh->selectrow_array("select name from Object
153 where id = $$arrRef[0]") ;
154 push(@$contentsListPtr, {name => $objName, id => $$arrRef[0]}) ;
155 }
156 $param{Contents} = $contentsListPtr ;
157
158 $cluster = new Genetics::Cluster(%param) ;
159
160 $DEBUG and carp " ->[getCluster] $cluster" ;
161  
162 return($cluster) ;
163 }
164  
165 =head2 getMiniCluster
166  
167 Function : Get a "light" version of a Genetics::Object::Cluster object
168 from the database.
169 Argument : The Object ID of the Cluster to be returned.
170 Returns : A Genetics::Object::Cluster object.
171 Scope : Public
172 Comments : "Light" version means that the object has only the name and id
173 fields from Object, and it does not contain any associated NameAlias,
174 Contact, DBXReference or Keyword data.
175  
176 =cut
177  
178 sub getMiniCluster {
179 my($self, $id) = @_ ;
180 my($cluster, $sth, $arrRef, %param, $objName, $contentsListPtr) ;
181 my $dbh = $self->{dbh} ;
182  
183 $DEBUG and carp " ->[getMiniCluster] $id" ;
184  
185 $sth = $dbh->prepare("select name, id, dateCreated, dateModified, comment, clusterType
186 from Object, Cluster
187 where id = $id
188 and id = clusterID") ;
189 $sth->execute() ;
190 $arrRef = $sth->fetchrow_arrayref() ;
191 $sth->finish() ;
192 defined $arrRef or return(undef) ;
193  
194 $param{name} = $$arrRef[0] ;
195 $param{id} = $$arrRef[1] ;
196 $param{dateCreated} = $$arrRef[2] ;
197 $param{dateModified} = $$arrRef[3] ;
198 $param{comment} = $$arrRef[4] ;
199 $param{clusterType} = $$arrRef[5] ;
200 # Contents
201 $sth = $dbh->prepare("select objID from ClusterContents
202 where clusterID = $id") ;
203 $sth->execute() ;
204 while ($arrRef = $sth->fetchrow_arrayref()) {
205 ( $objName ) = $dbh->selectrow_array("select name from Object
206 where id = $$arrRef[0]") ;
207 push(@$contentsListPtr, {name => $objName, id => $$arrRef[0]}) ;
208 }
209 $param{Contents} = $contentsListPtr ;
210
211 $cluster = new Genetics::Cluster(%param) ;
212
213 $DEBUG and carp " ->[getMiniCluster] $cluster" ;
214  
215 return($cluster) ;
216 }
217  
218 =head2 getSubject
219  
220 Function : Get (read) a Genetics::Object::Subject object from the database.
221 Argument : The Object ID of the Subject to be returned.
222 Returns : A Genetics::Object::Subject object.
223 Scope : Public
224  
225 =cut
226  
227 sub getSubject {
228 my($self, $id) = @_ ;
229 my($subject, $sth, $arrRef, %param, $kindredID, $kindredName, $motherID,
230 $motherName, $fatherID, $fatherName, $orgID, %init) ;
231 my $dbh = $self->{dbh} ;
232
233 $DEBUG and carp " ->[getSubject] Start" ;
234  
235 $sth = $dbh->prepare("select organismID, kindredID, motherID, fatherID,
236 gender, dateOfBirth, dateOfDeath, isProband
237 from Subject
238 where subjectID = $id") ;
239 $sth->execute() ;
240 $arrRef = $sth->fetchrow_arrayref() ;
241 defined $arrRef or return(undef) ;
242 $sth->finish() ;
243  
244 $self->_getObjAssocData($id, \%param) ;
245  
246 $param{gender} = $$arrRef[4] ;
247 defined $$arrRef[5] and $param{dateOfBirth} = $$arrRef[5] ;
248 defined $$arrRef[6] and $param{dateOfDeath} = $$arrRef[6] ;
249 $param{isProband} = $$arrRef[7] ;
250 if ( defined ($kindredID = $$arrRef[1]) ) {
251 ( $kindredName) = $dbh->selectrow_array("select name from Object
252 where id = $kindredID") ;
253 $param{Kindred} = { name => $kindredName,
254 id => $kindredID } ;
255 }
256 if ( defined ($motherID = $$arrRef[2]) ) {
257 ( $motherName) = $dbh->selectrow_array("select name from Object
258 where id = $motherID") ;
259 $param{Mother} = { name => $motherName,
260 id => $motherID } ;
261 }
262 if ( defined ($fatherID = $$arrRef[3]) ) {
263 ( $fatherName) = $dbh->selectrow_array("select name from Object
264 where id = $fatherID") ;
265 $param{Father} = { name => $fatherName,
266 id => $fatherID } ;
267 }
268 if ( defined ($orgID = $$arrRef[0]) ) {
269 $sth = $dbh->prepare("select genusSpecies, subspecies, strain
270 from Organism
271 where organismID = $orgID") ;
272 $sth->execute() ;
273 $arrRef = $sth->fetchrow_arrayref() ;
274 $init{genusSpecies} = $$arrRef[0] ;
275 defined $$arrRef[1] and $init{subspecies} = $$arrRef[1] ;
276 defined $$arrRef[2] and $init{strain} = $$arrRef[2] ;
277 $param{Organism} = { %init } ;
278 $sth->finish() ;
279 }
280  
281 $subject = new Genetics::Subject(%param) ;
282
283 $DEBUG and carp " ->[getSubject] $subject" ;
284  
285 return($subject) ;
286 }
287  
288 =head2 getMiniSubject
289  
290 Function : Get a "light" version of a Genetics::Object::Subject object from
291 the database, by id.
292 Argument : The Object ID of the Subject to be returned.
293 Returns : A Genetics::Object::Subject object.
294 Scope : Public
295 Comments : "Light" version means that the object has only the name and id
296 fields from Object, and it does not contain any associated NameAlias,
297 Contact, DBXReference or Keyword data. It also has a sub-set of
298 Subject-specific fields.
299  
300 =cut
301  
302 sub getMiniSubject {
303 my($self, $id) = @_ ;
304 my($subject, $sth, $arrRef, %param, $kindredID, $kindredName, $motherID,
305 $motherName, $fatherID, $fatherName, $orgID, %init) ;
306 my $dbh = $self->{dbh} ;
307
308 $DEBUG and carp " ->[getMiniSubject] $id" ;
309  
310 $sth = $dbh->prepare("select name, id, dateCreated, dateModified, comment,
311 kindredID, motherID, fatherID, gender, isProband
312 from Object, Subject
313 where id = subjectID
314 and subjectID = $id") ;
315 $sth->execute() ;
316 $arrRef = $sth->fetchrow_arrayref() ;
317 $sth->finish() ;
318 defined $arrRef or return(undef) ;
319  
320 $param{name} = $$arrRef[0] ;
321 $param{id} = $$arrRef[1] ;
322 $param{dateCreated} = $$arrRef[2] ;
323 $param{dateModified} = $$arrRef[3] ;
324 $param{comment} = $$arrRef[4] ;
325 $param{gender} = $$arrRef[8] ;
326 $param{isProband} = $$arrRef[9] ;
327 if ( defined ($kindredID = $$arrRef[5]) ) {
328 ( $kindredName) = $dbh->selectrow_array("select name from Object
329 where id = $kindredID") ;
330 $param{Kindred} = { name => $kindredName,
331 id => $kindredID } ;
332 }
333 if ( defined ($motherID = $$arrRef[6]) ) {
334 ( $motherName) = $dbh->selectrow_array("select name from Object
335 where id = $motherID") ;
336 $param{Mother} = { name => $motherName,
337 id => $motherID } ;
338 }
339 if ( defined ($fatherID = $$arrRef[7]) ) {
340 ( $fatherName) = $dbh->selectrow_array("select name from Object
341 where id = $fatherID") ;
342 $param{Father} = { name => $fatherName,
343 id => $fatherID } ;
344 }
345  
346 $subject = new Genetics::Subject(%param) ;
347
348 $DEBUG and carp " ->[getMiniSubject] $subject" ;
349  
350 return($subject) ;
351 }
352  
353 =head2 getKindred
354  
355 Function : Get (read) a Genetics::Object::Kindred object from the database.
356 Argument : The Object ID of the Kindred to be returned.
357 Returns : A Genetics::Object::Kindred object.
358 Scope : Public
359  
360 =cut
361  
362 sub getKindred {
363 my($self, $id) = @_ ;
364 my($kindred, %param, $sth, $arrRef, $parentID, $parentName, $subjName, $subjListPtr) ;
365 my $dbh = $self->{dbh} ;
366
367 $DEBUG and carp " ->[getKindred] $id" ;
368  
369 $sth = $dbh->prepare("select isDerived, parentID
370 from Kindred
371 where kindredID = $id") ;
372 $sth->execute() ;
373 $arrRef = $sth->fetchrow_arrayref() ;
374 $sth->finish() ;
375 defined $arrRef or return(undef) ;
376
377 $self->_getObjAssocData($id, \%param) ;
378  
379 $param{isDerived} = $$arrRef[0] ;
380 if ( defined($parentID = $$arrRef[1]) ) {
381 ( $parentName) = $dbh->selectrow_array("select name from Object
382 where id = $parentID") ;
383 $param{DerivedFrom} = { name => $parentName,
384 id => $parentID } ;
385 }
386  
387 $sth = $dbh->prepare("select subjectID from KindredSubject
388 where kindredID = $id") ;
389 $sth->execute() ;
390 while ($arrRef = $sth->fetchrow_arrayref()) {
391 ( $subjName) = $dbh->selectrow_array("select name from Object
392 where id = $$arrRef[0]") ;
393 push( @$subjListPtr, {name => $subjName, id => $$arrRef[0]} ) ;
394 }
395 defined $subjListPtr and $param{Subjects} = $subjListPtr ;
396  
397 $kindred = new Genetics::Kindred(%param) ;
398
399 $DEBUG and carp " ->[getKindred] $kindred" ;
400  
401 return($kindred) ;
402 }
403  
404 =head2 getMiniKindred
405  
406 Function : Get a "light" version of a Genetics::Object::Kindred object from
407 the database.
408 Argument : The Object ID of the Kindred to be returned.
409 Returns : A Genetics::Object::Kindred object.
410 Scope : Public
411 Comments : "Light" version means that the object has only the name and id
412 fields from Object, and it does not contain any associated NameAlias,
413 Contact, DBXReference or Keyword data.
414  
415 =cut
416  
417 sub getMiniKindred {
418 my($self, $id) = @_ ;
419 my($kindred, %param, $sth, $arrRef, $parentID, $parentName, $subjName, $subjListPtr) ;
420 my $dbh = $self->{dbh} ;
421
422 $DEBUG and carp " ->[getMiniKindred] $id" ;
423  
424 $sth = $dbh->prepare("select name, id, dateCreated, dateModified, comment,
425 isDerived, parentID
426 from Object, Kindred
427 where id = kindredID
428 and kindredID = $id") ;
429 $sth->execute() ;
430 $arrRef = $sth->fetchrow_arrayref() ;
431 $sth->finish() ;
432 defined $arrRef or return(undef) ;
433
434 $param{name} = $$arrRef[0] ;
435 $param{id} = $$arrRef[1] ;
436 $param{dateCreated} = $$arrRef[2] ;
437 $param{dateModified} = $$arrRef[3] ;
438 $param{comment} = $$arrRef[4] ;
439 $param{isDerived} = $$arrRef[5] ;
440 if ( defined($parentID = $$arrRef[6]) ) {
441 ( $parentName) = $dbh->selectrow_array("select name from Object
442 where id = $parentID") ;
443 $param{DerivedFrom} = { name => $parentName,
444 id => $parentID } ;
445 }
446  
447 $sth = $dbh->prepare("select subjectID from KindredSubject
448 where kindredID = $id") ;
449 $sth->execute() ;
450 while ($arrRef = $sth->fetchrow_arrayref()) {
451 ( $subjName) = $dbh->selectrow_array("select name from Object
452 where id = $$arrRef[0]") ;
453 push( @$subjListPtr, {name => $subjName, id => $$arrRef[0]} ) ;
454 }
455 defined $subjListPtr and $param{Subjects} = $subjListPtr ;
456  
457 $kindred = new Genetics::Kindred(%param) ;
458
459 $DEBUG and carp " ->[getMiniKindred] $kindred" ;
460  
461 return($kindred) ;
462 }
463  
464 =head2 getMarker
465  
466 Function : Get (read) a Genetics::Object::Marker object from the database.
467 Argument : The Object ID of the Marker to be returned.
468 Returns : A Genetics::Object::Marker object.
469 Scope : Public
470  
471 =cut
472  
473 sub getMarker {
474 my($self, $id) = @_ ;
475 my($marker, %param, $sth, $sth2, $arrRef, $arrRef1, $arrRef2, %init, $orgID,
476 $alleleListPtr, $iscnListPtr, $seqID, $seq, $len, $units) ;
477 my $dbh = $self->{dbh} ;
478
479 $DEBUG and carp " ->[getMarker] $id" ;
480  
481 $self->_getObjAssocData($id, \%param) ;
482  
483 # SequenceObject and Marker data
484 $sth = $dbh->prepare("select chromosome, organismID, sequenceID, malePloidy,
485 femalePloidy, polymorphismType, polymorphismIndex1,
486 polymorphismIndex2, repeatSequence
487 from SequenceObject, Marker
488 where markerID = $id
489 and markerID = seqObjectID") ;
490 $sth->execute() ;
491 $arrRef = $sth->fetchrow_arrayref() ;
492 defined $$arrRef[0] and $param{chromosome} = $$arrRef[0] ;
493 defined $$arrRef[3] and $param{malePloidy} = $$arrRef[3] ;
494 defined $$arrRef[4] and $param{femalePloidy} = $$arrRef[4] ;
495 defined $$arrRef[5] and $param{polymorphismType} = $$arrRef[5] ;
496 defined $$arrRef[6] and $param{polymorphismIndex1} = $$arrRef[6] ;
497 defined $$arrRef[7] and $param{polymorphismIndex2} = $$arrRef[7] ;
498 defined $$arrRef[8] and $param{repeatSequence} = $$arrRef[8] ;
499 $sth->finish() ;
500 # Organism data
501 if ( defined ($orgID = $$arrRef[1]) ) {
502 $sth = $dbh->prepare("select genusSpecies, subspecies, strain
503 from Organism
504 where organismID = $orgID") ;
505 $sth->execute() ;
506 $arrRef1 = $sth->fetchrow_arrayref() ;
507 $init{genusSpecies} = $$arrRef1[0] ;
508 defined $$arrRef1[1] and $init{subspecies} = $$arrRef1[1] ;
509 defined $$arrRef1[2] and $init{strain} = $$arrRef1[2] ;
510 $param{Organism} = { %init } ;
511 $sth->finish() ;
512 }
513 # Allele data
514 $sth = $dbh->prepare("select name, type
515 from Allele
516 where poID = $id") ;
517 $sth->execute() ;
518 while ($arrRef1 = $sth->fetchrow_arrayref()) {
519 push( @$alleleListPtr, {name => $$arrRef1[0], type => $$arrRef1[1]} ) ;
520 }
521 defined $alleleListPtr and $param{Alleles} = $alleleListPtr ;
522 # ISCNMapLocation data
523 $sth = $dbh->prepare("select iscnMapLocID
524 from SeqObjISCN
525 where seqObjectID = $id") ;
526 $sth->execute() ;
527 while ($arrRef1 = $sth->fetchrow_arrayref()) {
528 $sth2 = $dbh->prepare("select chrNumber, chrArm, band, bandingMethod
529 from ISCNMapLocation
530 where iscnMapLocID = $$arrRef1[0]") ;
531 $sth2->execute() ;
532 while ($arrRef2 = $sth2->fetchrow_arrayref()) {
533 %init = () ;
534 $init{chrNumber} = $$arrRef2[0] ;
535 defined $$arrRef2[1] and $init{chrArm} = $$arrRef2[1] ;
536 defined $$arrRef2[2] and $init{band} = $$arrRef2[2] ;
537 defined $$arrRef2[3] and $init{bandingMethod} = $$arrRef2[3] ;
538 push( @$iscnListPtr, { %init } ) ;
539 }
540 }
541 defined $iscnListPtr and $param{ISCNMapLocations} = $iscnListPtr ;
542 # Sequence data
543 if ( defined($seqID = $$arrRef[2]) ) {
544 ( $seq, $len, $units ) = $dbh->selectrow_array("select sequence, length, lengthUnits
545 from Sequence
546 where sequenceID = $seqID") ;
547 if (defined $seq) {
548 %init = () ;
549 $init{sequence} = $seq ;
550 defined $len and $init{length} = $len ;
551 defined $units and $init{lengthUnits} = $units ;
552 $param{Sequence} = { %init } ;
553 }
554 }
555  
556 $marker = new Genetics::Marker(%param) ;
557
558 $DEBUG and carp " ->[getMarker] $marker" ;
559 return($marker) ;
560 }
561  
562 =head2 getMiniMarker
563  
564 Function : Get a "light" version of a Genetics::Object::Marker object from the
565 database.
566 Argument : The Object ID of the Marker to be returned.
567 Returns : A Genetics::Object::Marker object.
568 Scope : Public
569 Comments : "Light" version means that the object has only the name and id
570 fields from Object, and it does not contain any associated NameAlias,
571 Contact, DBXReference or Keyword data. It also has a sub-set of
572 Marker-specific fields.
573  
574 =cut
575  
576 sub getMiniMarker {
577 my($self, $id) = @_ ;
578 my($marker, %param, $sth, $arrRef, $alleleListPtr) ;
579 my $dbh = $self->{dbh} ;
580
581 $DEBUG and carp " ->[getMiniMarker] $id" ;
582  
583 $sth = $dbh->prepare("select name, id, dateCreated, dateModified, comment,
584 chromosome, malePloidy, femalePloidy,
585 polymorphismType, repeatSequence
586 from Object, SequenceObject, Marker
587 where id = $id
588 and id = markerID
589 and markerID = seqObjectID") ;
590 $sth->execute() ;
591 $arrRef = $sth->fetchrow_arrayref() ;
592 $sth->finish() ;
593 defined $arrRef or return(undef) ;
594  
595 $param{name} = $$arrRef[0] ;
596 $param{id} = $$arrRef[1] ;
597 $param{dateCreated} = $$arrRef[2] ;
598 $param{dateModified} = $$arrRef[3] ;
599 $param{comment} = $$arrRef[4] ;
600 defined $$arrRef[5] and $param{chromosome} = $$arrRef[5] ;
601 defined $$arrRef[6] and $param{malePloidy} = $$arrRef[6] ;
602 defined $$arrRef[7] and $param{femalePloidy} = $$arrRef[7] ;
603 defined $$arrRef[8] and $param{polymorphismType} = $$arrRef[8] ;
604 defined $$arrRef[9] and $param{repeatSequence} = $$arrRef[9] ;
605 # Allele data
606 $sth = $dbh->prepare("select name, type
607 from Allele
608 where poID = $param{id}") ;
609 $sth->execute() ;
610 while ($arrRef = $sth->fetchrow_arrayref()) {
611 push @$alleleListPtr, {name => $$arrRef[0], type => $$arrRef[1]} ;
612 }
613 defined($alleleListPtr) and $param{Alleles} = $alleleListPtr ;
614  
615 $marker = new Genetics::Marker(%param) ;
616
617 $DEBUG and carp " ->[getMiniMarker] $marker" ;
618  
619 return($marker) ;
620 }
621  
622 =head2 getMiniMarkerByName
623  
624 Function : Get a "light" version of a Genetics::Object::Marker object from the
625 database, by name.
626 Argument : The name of the Marker to be returned.
627 Returns : A Genetics::Object::Marker object.
628 Scope : Public
629 Comments : If there is more than one Marker object with the same name, this
630 will only return ONE of them. Which one? Good question. Caveat
631 Programmor!
632 "Light" version means that the object has only the name and id
633 fields from Object, and it does not contain any associated NameAlias,
634 Contact, DBXReference or Keyword data.
635  
636 =cut
637  
638 sub getMiniMarkerByName {
639 my($self, $name) = @_ ;
640 my($marker, %param, $sth, $arrRef, $alleleListPtr) ;
641 my $dbh = $self->{dbh} ;
642
643 $DEBUG and carp " ->[getMiniMarkerByName] $name" ;
644  
645 $sth = $dbh->prepare("select name, id, dateCreated, dateModified, comment,
646 chromosome, malePloidy, femalePloidy,
647 polymorphismType, repeatSequence
648 from Object, SequenceObject, Marker
649 where name = '$name'
650 and id = markerID
651 and markerID = seqObjectID") ;
652 $sth->execute() ;
653 $arrRef = $sth->fetchrow_arrayref() ;
654 $sth->finish() ;
655 defined $arrRef or return(undef) ;
656  
657 $param{name} = $$arrRef[0] ;
658 $param{id} = $$arrRef[1] ;
659 $param{dateCreated} = $$arrRef[2] ;
660 $param{dateModified} = $$arrRef[3] ;
661 $param{comment} = $$arrRef[4] ;
662 defined $$arrRef[5] and $param{chromosome} = $$arrRef[5] ;
663 defined $$arrRef[6] and $param{malePloidy} = $$arrRef[6] ;
664 defined $$arrRef[7] and $param{femalePloidy} = $$arrRef[7] ;
665 defined $$arrRef[8] and $param{polymorphismType} = $$arrRef[8] ;
666 defined $$arrRef[9] and $param{repeatSequence} = $$arrRef[9] ;
667 # Allele data
668 $sth = $dbh->prepare("select name, type
669 from Allele
670 where poID = $param{id}") ;
671 $sth->execute() ;
672 while ($arrRef = $sth->fetchrow_arrayref()) {
673 push @$alleleListPtr, {name => $$arrRef[0], type => $$arrRef[1]} ;
674 }
675 defined($alleleListPtr) and $param{Alleles} = $alleleListPtr ;
676  
677 $marker = new Genetics::Marker(%param) ;
678
679 $DEBUG and carp " ->[getMiniMarkerByName] $marker" ;
680  
681 return($marker) ;
682 }
683  
684 =head2 getSNP
685  
686 Function : Get (read) a Genetics::Object::SNP object from the database.
687 Argument : The Object ID of the SNP to be returned.
688 Returns : A Genetics::Object::SNP object.
689 Scope : Public
690  
691 =cut
692  
693 sub getSNP {
694 my($self, $id) = @_ ;
695 my($snp, %param, $sth, $sth2, $arrRef, $arrRef1, $arrRef2, %init, $orgID,
696 $alleleListPtr, $iscnListPtr, $seqID, $seq, $len, $units) ;
697 my $dbh = $self->{dbh} ;
698
699 $DEBUG and carp " ->[getSNP] $id" ;
700  
701 $self->_getObjAssocData($id, \%param) ;
702  
703 # SequenceObject and SNP data
704 $sth = $dbh->prepare("select chromosome, organismID, sequenceID, malePloidy,
705 femalePloidy, snpType, functionClass,
706 snpIndex, isConfirmed, confirmMethod
707 from SequenceObject, SNP
708 where snpID = $id
709 and snpID = seqObjectID") ;
710 $sth->execute() ;
711 $arrRef = $sth->fetchrow_arrayref() ;
712 defined $$arrRef[0] and $param{chromosome} = $$arrRef[0] ;
713 defined $$arrRef[3] and $param{malePloidy} = $$arrRef[3] ;
714 defined $$arrRef[4] and $param{femalePloidy} = $$arrRef[4] ;
715 defined $$arrRef[5] and $param{snpType} = $$arrRef[5] ;
716 defined $$arrRef[6] and $param{functionClass} = $$arrRef[6] ;
717 defined $$arrRef[7] and $param{snpIndex} = $$arrRef[7] ;
718 defined $$arrRef[8] and $param{isConfirmed} = $$arrRef[8] ;
719 defined $$arrRef[9] and $param{confirmMethod} = $$arrRef[9] ;
720 $sth->finish() ;
721 # Organism data
722 if ( defined ($orgID = $$arrRef[1]) ) {
723 $sth = $dbh->prepare("select genusSpecies, subspecies, strain
724 from Organism
725 where organismID = $orgID") ;
726 $sth->execute() ;
727 $arrRef1 = $sth->fetchrow_arrayref() ;
728 $init{genusSpecies} = $$arrRef1[0] ;
729 defined $$arrRef1[1] and $init{subspecies} = $$arrRef1[1] ;
730 defined $$arrRef1[2] and $init{strain} = $$arrRef1[2] ;
731 $param{Organism} = { %init } ;
732 $sth->finish() ;
733 }
734 # Allele data
735 $sth = $dbh->prepare("select name, type
736 from Allele
737 where poID = $id") ;
738 $sth->execute() ;
739 while ($arrRef1 = $sth->fetchrow_arrayref()) {
740 push( @$alleleListPtr, {name => $$arrRef1[0], type => $$arrRef1[1]} ) ;
741 }
742 defined $alleleListPtr and $param{Alleles} = $alleleListPtr ;
743 # ISCNMapLocation data
744 $sth = $dbh->prepare("select iscnMapLocID
745 from SeqObjISCN
746 where seqObjectID = $id") ;
747 $sth->execute() ;
748 while ($arrRef1 = $sth->fetchrow_arrayref()) {
749 $sth2 = $dbh->prepare("select chrNumber, chrArm, band, bandingMethod
750 from ISCNMapLocation
751 where iscnMapLocID = $$arrRef1[0]") ;
752 $sth2->execute() ;
753 while ($arrRef2 = $sth2->fetchrow_arrayref()) {
754 %init = () ;
755 $init{chrNumber} = $$arrRef2[0] ;
756 defined $$arrRef2[1] and $init{chrArm} = $$arrRef2[1] ;
757 defined $$arrRef2[2] and $init{band} = $$arrRef2[2] ;
758 defined $$arrRef2[3] and $init{bandingMethod} = $$arrRef2[3] ;
759 push( @$iscnListPtr, { %init } ) ;
760 }
761 }
762 defined $iscnListPtr and $param{ISCNMapLocations} = $iscnListPtr ;
763 # Sequence data
764 if ( defined($seqID = $$arrRef[2]) ) {
765 ( $seq, $len, $units ) = $dbh->selectrow_array("select sequence, length, lengthUnits
766 from Sequence
767 where sequenceID = $seqID") ;
768 if (defined $seq) {
769 %init = () ;
770 $init{sequence} = $seq ;
771 defined $len and $init{length} = $len ;
772 defined $units and $init{lengthUnits} = $units ;
773 $param{Sequence} = { %init } ;
774 }
775 }
776  
777 $snp = new Genetics::SNP(%param) ;
778
779 $DEBUG and carp " ->[getSNP] $snp" ;
780 return($snp) ;
781 }
782  
783 =head2 getMiniSNP
784  
785 Function : Get a "light" version of a Genetics::Object::SNP object from the
786 database.
787 Argument : The Object ID of the SNP to be returned.
788 Returns : A Genetics::Object::SNP object.
789 Scope : Public
790 Comments : "Light" version means that the object has only the name and id
791 fields from Object, and it does not contain any associated NameAlias,
792 Contact, DBXReference or Keyword data. It also has a sub-set of
793 SNP-specific fields.
794  
795 =cut
796  
797 sub getMiniSNP {
798 my($self, $id) = @_ ;
799 my($snp, %param, $sth, $arrRef, $alleleListPtr) ;
800 my $dbh = $self->{dbh} ;
801
802 $DEBUG and carp " ->[getMiniSNP] $id" ;
803
804 # SequenceObject and SNP data
805 $sth = $dbh->prepare("select name, id, dateCreated, dateModified, comment,
806 chromosome, malePloidy, femalePloidy, snpType,
807 functionClass, isConfirmed, confirmMethod
808 from Object, SequenceObject, SNP
809 where id = $id
810 and id = snpID
811 and snpID = seqObjectID") ;
812 $sth->execute() ;
813 $arrRef = $sth->fetchrow_arrayref() ;
814 $sth->finish() ;
815 defined $arrRef or return(undef) ;
816  
817 $param{name} = $$arrRef[0] ;
818 $param{id} = $$arrRef[1] ;
819 $param{dateCreated} = $$arrRef[2] ;
820 $param{dateModified} = $$arrRef[3] ;
821 $param{comment} = $$arrRef[4] ;
822 defined $$arrRef[5] and $param{chromosome} = $$arrRef[5] ;
823 defined $$arrRef[6] and $param{malePloidy} = $$arrRef[6] ;
824 defined $$arrRef[7] and $param{femalePloidy} = $$arrRef[7] ;
825 defined $$arrRef[8] and $param{snpType} = $$arrRef[8] ;
826 defined $$arrRef[9] and $param{functionClass} = $$arrRef[9] ;
827 defined $$arrRef[10] and $param{isConfirmed} = $$arrRef[10] ;
828 defined $$arrRef[11] and $param{confirmMethod} = $$arrRef[11] ;
829 # Allele data
830 $sth = $dbh->prepare("select name, type
831 from Allele
832 where poID = $id") ;
833 $sth->execute() ;
834 while ($arrRef = $sth->fetchrow_arrayref()) {
835 push( @$alleleListPtr, {name => $$arrRef[0], type => $$arrRef[1]} ) ;
836 }
837 defined $alleleListPtr and $param{Alleles} = $alleleListPtr ;
838
839 $snp = new Genetics::SNP(%param) ;
840
841 $DEBUG and carp " ->[getMiniSNP] $snp" ;
842  
843 return($snp) ;
844 }
845  
846 =head2 getGenotype
847  
848 Function : Get (read) a Genetics::Object::Genotype object from the database.
849 Argument : The Object ID of the Genotype to be returned.
850 Returns : A Genetics::Object::Genotype object.
851 Scope : Public
852  
853 =cut
854  
855 sub getGenotype {
856 my($self, $id) = @_ ;
857 my($gt, %param, $sth, $arrRef, $sth1, $arrRef1, $subjName, $poName,
858 %acInit, $alleleName, $type, @acList, @aaList, $aaName, $dataType, $value) ;
859 my $dbh = $self->{dbh} ;
860
861 $DEBUG and carp " ->[getGenotype] $id" ;
862  
863 $self->_getObjAssocData($id, \%param) ;
864  
865 # Genotype data
866 $sth = $dbh->prepare("select subjectID, poID, isActive, icResult, dateCollected
867 from Genotype
868 where gtID = $id") ;
869 $sth->execute() ;
870 $arrRef = $sth->fetchrow_arrayref() ;
871 ( $subjName ) = $dbh->selectrow_array("select name from Object
872 where id = $$arrRef[0]") ;
873 $param{Subject} = {name => $subjName, id => $$arrRef[0]} ;
874 ( $poName ) = $dbh->selectrow_array("select name from Object
875 where id = $$arrRef[1]") ;
876 $param{Marker} = {name => $poName, id => $$arrRef[1]} ;
877 $param{isActive} = $$arrRef[2] ;
878 defined $$arrRef[3] and $param{icResult} = $$arrRef[3] ;
879 defined $$arrRef[4] and $param{dateCollected} = $$arrRef[4] ;
880 $sth->finish() ;
881 # Genotype AssayAttrs
882 $sth = $dbh->prepare("select objID, attrID, stringValue, numberValue,
883 dateValue, booleanValue
884 from AttributeValue
885 where objID = $id") ;
886 $sth->execute() ;
887 @aaList = () ;
888 while ($arrRef = $sth->fetchrow_arrayref()) {
889 ($aaName, $dataType) = $dbh->selectrow_array("select name, dataType
890 from AssayAttribute
891 where attrID = $$arrRef[1]") ;
892 $value = $$arrRef[2] || $$arrRef[3] || $$arrRef[4] || $$arrRef[5] ;
893 push(@aaList, {name => $aaName,
894 dataType => $dataType,
895 value => $value }) ;
896 }
897 defined $aaList[0] and $param{AssayAttrs} = [ @aaList ] ;
898
899 # AlleleCall data
900 $sth = $dbh->prepare("select alleleCallID, alleleID, sortOrder, phase
901 from AlleleCall
902 where gtID = $id
903 order by sortOrder") ;
904 $sth->execute() ;
905 while ($arrRef = $sth->fetchrow_arrayref()) {
906 %acInit = () ;
907 ($alleleName, $type) = $dbh->selectrow_array("select name, type
908 from Allele
909 where alleleID = $$arrRef[1]") ;
910 %acInit = (alleleName => $alleleName,
911 alleleType => $type,
912 phase => $$arrRef[3]) ;
913 # AlleleCall AssayAttrs
914 $sth1 = $dbh->prepare("select alleleCallID, attrID, stringValue, numberValue,
915 dateValue, booleanValue
916 from AttributeValue
917 where alleleCallID = $$arrRef[0]") ;
918 $sth1->execute() ;
919 @aaList = () ;
920 while ($arrRef1 = $sth1->fetchrow_arrayref()) {
921 ($aaName, $dataType) = $dbh->selectrow_array("select name, dataType
922 from AssayAttribute
923 where attrID = $$arrRef1[1]") ;
924 $value = $$arrRef1[2] || $$arrRef1[3] || $$arrRef1[4] || $$arrRef1[5] ;
925 push(@aaList, {name => $aaName,
926 dataType => $dataType,
927 value => $value }) ;
928 }
929 defined $aaList[0] and $acInit{AssayAttrs} = [ @aaList ] ;
930 push( @acList, { %acInit } ) ;
931 }
932 $param{AlleleCalls} = \@acList ;
933  
934 $gt = new Genetics::Genotype(%param) ;
935
936 $DEBUG and carp " ->[getGenotype] $gt" ;
937  
938 return($gt) ;
939 }
940  
941 =head2 getMiniGenotype
942  
943 Function : Get a "light" version of a Genetics::Object::Genotype object from
944 the database.
945 Argument : The Object ID of the Genotype to be returned.
946 Returns : A Genetics::Object::Genotype object.
947 Scope : Public
948 Comments : "Light" version means that the object has only the name and id
949 fields from Object, and it does not contain any associated NameAlias,
950 Contact, DBXReference or Keyword data. It also has a sub-set of
951 Genotype-specific fields.
952  
953 =cut
954  
955 sub getMiniGenotype {
956 my($self, $id) = @_ ;
957 my($gt, %param, $sth, $arrRef, $subjName, $poName, $alleleName, $type,
958 %acInit, @acList) ;
959 my $dbh = $self->{dbh} ;
960
961 $DEBUG and carp " ->[getMiniGenotype] $id" ;
962  
963 # Genotype data
964 $sth = $dbh->prepare("select name, id, dateCreated, dateModified, comment,
965 subjectID, poID, isActive, icResult
966 from Object, Genotype
967 where id = $id
968 and id = gtID") ;
969 $sth->execute() ;
970 $arrRef = $sth->fetchrow_arrayref() ;
971 $sth->finish() ;
972 defined $arrRef or return(undef) ;
973  
974 $param{name} = $$arrRef[0] ;
975 $param{id} = $$arrRef[1] ;
976 $param{dateCreated} = $$arrRef[2] ;
977 $param{dateModified} = $$arrRef[3] ;
978 $param{comment} = $$arrRef[4] ;
979 ( $subjName ) = $dbh->selectrow_array("select name from Object
980 where id = $$arrRef[5]") ;
981 $param{Subject} = {name => $subjName, id => $$arrRef[5]} ;
982 ( $poName ) = $dbh->selectrow_array("select name from Object
983 where id = $$arrRef[6]") ;
984 $param{Marker} = {name => $poName, id => $$arrRef[6]} ;
985 $param{isActive} = $$arrRef[7] ;
986 defined $$arrRef[8] and $param{icResult} = $$arrRef[8] ;
987 # AlleleCall data
988 $sth = $dbh->prepare("select alleleCallID, alleleID, sortOrder, phase
989 from AlleleCall
990 where gtID = $id
991 order by sortOrder") ;
992 $sth->execute() ;
993 while ($arrRef = $sth->fetchrow_arrayref()) {
994 %acInit = () ;
995 ($alleleName, $type) = $dbh->selectrow_array("select name, type
996 from Allele
997 where alleleID = $$arrRef[1]") ;
998 %acInit = (alleleName => $alleleName,
999 alleleType => $type,
1000 phase => $$arrRef[3]) ;
1001 push( @acList, { %acInit } ) ;
1002 }
1003 $param{AlleleCalls} = \@acList ;
1004  
1005 $gt = new Genetics::Genotype(%param) ;
1006
1007 $DEBUG and carp " ->[getMiniGenotype] $gt" ;
1008  
1009 return($gt) ;
1010 }
1011  
1012 =head2 getStudyVariable
1013  
1014 Function : Get (read) a Genetics::Object::StudyVariable object from the database.
1015 Argument : The Object ID of the StudyVariable to be returned.
1016 Returns : A Genetics::Object::StudyVariable object.
1017 Scope : Public
1018  
1019 =cut
1020  
1021 sub getStudyVariable {
1022 my($self, $id) = @_ ;
1023 my($sv, %param, $sth, $sth1, $arrRef, $arrRef1, %init, %init1, $category,
1024 $format, @codesList, @aseList, @lcList, $p11, $p12, $p22, $mp1, $mp2) ;
1025 my $dbh = $self->{dbh} ;
1026
1027 $DEBUG and carp " ->[getStudyVariable] $id" ;
1028  
1029 $self->_getObjAssocData($id, \%param) ;
1030  
1031 # StudyVariable data
1032 $sth = $dbh->prepare("select category, format, isXLinked, description,
1033 numberLowerBound, numberUpperBound,
1034 dateLowerBound, dateUpperBound
1035 from StudyVariable
1036 where studyVariableID = $id") ;
1037 $sth->execute() ;
1038 $arrRef = $sth->fetchrow_arrayref() ;
1039 $category = $param{category} = $$arrRef[0] ;
1040 $format = $param{format} = $$arrRef[1] ;
1041 $param{isXLinked} = $$arrRef[2] ;
1042 defined $$arrRef[3] and $param{description} = $$arrRef[3] ;
1043 defined $$arrRef[4] and $param{lowerBound} = $$arrRef[4] ;
1044 defined $$arrRef[5] and $param{upperBound} = $$arrRef[5] ;
1045 defined $$arrRef[6] and $param{lowerBound} = $$arrRef[6] ;
1046 defined $$arrRef[7] and $param{upperBound} = $$arrRef[7] ;
1047 $sth->finish() ;
1048 # CodeDerivation data
1049 if ($format eq "Code") {
1050 if ($category eq "StaticLiabilityClass") {
1051 $sth = $dbh->prepare("select codeDerivationID, code, description, formula
1052 from CodeDerivation
1053 where studyVariableID = $id") ;
1054 $sth->execute() ;
1055 $sth1 = $dbh->prepare("select pen11, pen12, pen22, malePen1, malePen2
1056 from StaticLCPenetrance
1057 where cdID = ?") ;
1058 while ($arrRef = $sth->fetchrow_arrayref()) {
1059 %init = () ;
1060 $sth1->execute($$arrRef[0]) ;
1061 ($p11, $p12, $p22, $mp1, $mp2) = $sth1->fetchrow_array() ;
1062 $init{code} = $$arrRef[1] ;
1063 $init{pen11} = $p11 ;
1064 $init{pen12} = $p12 ;
1065 $init{pen22} = $p22 ;
1066 defined $mp1 and $init{malePen1} = $mp1 ;
1067 defined $mp2 and $init{malePen2} = $mp2 ;
1068 defined $$arrRef[2] and $init{description} = $$arrRef[2] ;
1069 defined $$arrRef[3] and $init{formula} = $$arrRef[3] ;
1070 push(@codesList, { %init }) ;
1071 }
1072 } else {
1073 $sth = $dbh->prepare("select code, description, formula
1074 from CodeDerivation
1075 where studyVariableID = $id") ;
1076 $sth->execute() ;
1077 while ($arrRef = $sth->fetchrow_arrayref()) {
1078 %init = () ;
1079 $init{code} = $$arrRef[0] ;
1080 defined $$arrRef[1] and $init{description} = $$arrRef[1] ;
1081 defined $$arrRef[2] and $init{formula} = $$arrRef[2] ;
1082 push(@codesList, { %init }) ;
1083 }
1084 }
1085 }
1086 defined $codesList[0] and $param{Codes} = \@codesList ;
1087
1088 if ($category =~ /AffectionStatus$/) {
1089 # AffectionStatus data
1090 $sth = $dbh->prepare("select name, diseaseAlleleFreq, pen11, pen12,
1091 pen22, malePen1, malePen2, asDefID
1092 from AffectionStatusDefinition
1093 where studyVariableID = $id") ;
1094 $sth->execute() ;
1095 if ( defined ($arrRef = $sth->fetchrow_arrayref()) ) {
1096 %init = () ;
1097 $init{name} = $$arrRef[0] ;
1098 $init{diseaseAlleleFreq} = $$arrRef[1] ;
1099 $init{pen11} = $$arrRef[2] ;
1100 $init{pen12} = $$arrRef[3] ;
1101 $init{pen22} = $$arrRef[4] ;
1102 defined $$arrRef[5] and $init{malePen1} = $$arrRef[5] ;
1103 defined $$arrRef[6] and $init{malePen2} = $$arrRef[6] ;
1104 # Elements
1105 $sth1 = $dbh->prepare("select code, type, formula
1106 from AffectionStatusElement
1107 where asDefID = $$arrRef[7]") ;
1108 $sth1->execute() ;
1109 while ($arrRef1 = $sth1->fetchrow_arrayref()) {
1110 push(@aseList, {code => $$arrRef1[0],
1111 type => $$arrRef1[1],
1112 formula => $$arrRef1[2]}) ;
1113 }
1114 if (defined($aseList[0])) {
1115 $init{AffStatElements} = \@aseList ;
1116 }
1117 $param{AffStatDef} = { %init } ;
1118 # LiabilityClass data
1119 # This is for dynamic LCs
1120 $sth = $dbh->prepare("select name, lcDefID
1121 from LiabilityClassDefinition
1122 where studyVariableID = $id") ;
1123 $sth->execute() ;
1124 if ( defined($arrRef = $sth->fetchrow_arrayref()) ) {
1125 %init = () ;
1126 $init{name} = $$arrRef[0] ;
1127 # Classes
1128 $sth1 = $dbh->prepare("select code, description, pen11, pen12, pen22,
1129 malePen1, malePen2, formula
1130 from LiabilityClass
1131 where lcDefID = $$arrRef[1]") ;
1132 $sth1->execute() ;
1133 while ($arrRef1 = $sth1->fetchrow_arrayref()) {
1134 %init1 = () ;
1135 $init1{code} = $$arrRef1[0] ;
1136 defined $$arrRef1[1] and $init1{description} = $$arrRef1[1] ;
1137 $init1{pen11} = $$arrRef1[2] ;
1138 $init1{pen12} = $$arrRef1[3] ;
1139 $init1{pen22} = $$arrRef1[4] ;
1140 defined $$arrRef1[5] and $init1{malePen1} = $$arrRef1[5] ;
1141 defined $$arrRef1[6] and $init1{malePen2} = $$arrRef1[6] ;
1142 $init1{formula} = $$arrRef1[7] ;
1143 push(@lcList, { %init1 }) ;
1144 }
1145 $init{LiabilityClasses} = \@lcList ;
1146 $param{LCDef} = { %init } ;
1147 }
1148 }
1149 }
1150  
1151 $sv = new Genetics::StudyVariable(%param) ;
1152
1153 $DEBUG and carp " ->[getStudyVariable] $sv" ;
1154  
1155 return($sv) ;
1156 }
1157  
1158 =head2 getMiniStudyVariable
1159  
1160 Function : Get a "light" version of a Genetics::Object::StudyVariable object
1161 from the database.
1162 Argument : The Object ID of the StudyVariable to be returned.
1163 Returns : A Genetics::Object::StudyVariable object.
1164 Scope : Public
1165 Comments : "Light" version means that the object has only the name and id
1166 fields from Object, and it does not contain any associated NameAlias,
1167 Contact, DBXReference or Keyword data. It also has a sub-set of
1168 StudyVariable-specific fields.
1169 =cut
1170  
1171 sub getMiniStudyVariable {
1172 my($self, $id) = @_ ;
1173 my($sv, %param, $sth, $sth1, $arrRef, $arrRef1, %init, %init1, $category,
1174 $format, @codesList, @aseList, @lcList, $p11, $p12, $p22, $mp1, $mp2) ;
1175 my $dbh = $self->{dbh} ;
1176
1177 $DEBUG and carp " ->[getMiniStudyVariable] $id" ;
1178  
1179 # StudyVariable data
1180 $sth = $dbh->prepare("select name, id, dateCreated, dateModified, comment,
1181 category, format, isXLinked, description
1182 from Object, StudyVariable
1183 where id = $id
1184 and id = studyVariableID") ;
1185 $sth->execute() ;
1186 $arrRef = $sth->fetchrow_arrayref() ;
1187 $sth->finish() ;
1188 defined $arrRef or return(undef) ;
1189  
1190 $param{name} = $$arrRef[0] ;
1191 $param{id} = $$arrRef[1] ;
1192 $param{dateCreated} = $$arrRef[2] ;
1193 $param{dateModified} = $$arrRef[3] ;
1194 $param{comment} = $$arrRef[4] ;
1195 $category = $param{category} = $$arrRef[5] ;
1196 $format = $param{format} = $$arrRef[6] ;
1197 $param{isXLinked} = $$arrRef[7] ;
1198 defined $$arrRef[8] and $param{description} = $$arrRef[8] ;
1199 # CodeDerivation data
1200 if ($format eq "Code") {
1201 if ($category eq "StaticLiabilityClass") {
1202 $sth = $dbh->prepare("select codeDerivationID, code, description, formula
1203 from CodeDerivation
1204 where studyVariableID = $id") ;
1205 $sth->execute() ;
1206 $sth1 = $dbh->prepare("select pen11, pen12, pen22, malePen1, malePen2
1207 from StaticLCPenetrance
1208 where cdID = ?") ;
1209 while ($arrRef = $sth->fetchrow_arrayref()) {
1210 %init = () ;
1211 $sth1->execute($$arrRef[0]) ;
1212 ($p11, $p12, $p22, $mp1, $mp2) = $sth1->fetchrow_array() ;
1213 $init{code} = $$arrRef[1] ;
1214 $init{pen11} = $p11 ;
1215 $init{pen12} = $p12 ;
1216 $init{pen22} = $p22 ;
1217 defined $mp1 and $init{malePen1} = $mp1 ;
1218 defined $mp2 and $init{malePen2} = $mp2 ;
1219 defined $$arrRef[2] and $init{description} = $$arrRef[2] ;
1220 defined $$arrRef[3] and $init{formula} = $$arrRef[3] ;
1221 push(@codesList, { %init }) ;
1222 }
1223 } else {
1224 $sth = $dbh->prepare("select code, description, formula
1225 from CodeDerivation
1226 where studyVariableID = $id") ;
1227 $sth->execute() ;
1228 while ($arrRef = $sth->fetchrow_arrayref()) {
1229 %init = () ;
1230 $init{code} = $$arrRef[0] ;
1231 defined $$arrRef[1] and $init{description} = $$arrRef[1] ;
1232 defined $$arrRef[2] and $init{formula} = $$arrRef[2] ;
1233 push(@codesList, { %init }) ;
1234 }
1235 }
1236 }
1237 defined $codesList[0] and $param{Codes} = \@codesList ;
1238
1239 if ($category =~ /AffectionStatus$/) {
1240 # AffectionStatus data
1241 $sth = $dbh->prepare("select name, diseaseAlleleFreq, pen11, pen12,
1242 pen22, malePen1, malePen2, asDefID
1243 from AffectionStatusDefinition
1244 where studyVariableID = $id") ;
1245 $sth->execute() ;
1246 if ( defined ($arrRef = $sth->fetchrow_arrayref()) ) {
1247 %init = () ;
1248 $init{name} = $$arrRef[0] ;
1249 $init{diseaseAlleleFreq} = $$arrRef[1] ;
1250 $init{pen11} = $$arrRef[2] ;
1251 $init{pen12} = $$arrRef[3] ;
1252 $init{pen22} = $$arrRef[4] ;
1253 defined $$arrRef[5] and $init{malePen1} = $$arrRef[5] ;
1254 defined $$arrRef[6] and $init{malePen2} = $$arrRef[6] ;
1255 # Elements
1256 $sth1 = $dbh->prepare("select code, type, formula
1257 from AffectionStatusElement
1258 where asDefID = $$arrRef[7]") ;
1259 $sth1->execute() ;
1260 while ($arrRef1 = $sth1->fetchrow_arrayref()) {
1261 push(@aseList, {code => $$arrRef1[0],
1262 type => $$arrRef1[1],
1263 formula => $$arrRef1[2]}) ;
1264 }
1265 $init{AffStatElements} = \@aseList ;
1266 $param{AffStatDef} = { %init } ;
1267 }
1268 }
1269  
1270 $sv = new Genetics::StudyVariable(%param) ;
1271
1272 $DEBUG and carp " ->[getMiniStudyVariable] $sv" ;
1273  
1274 return($sv) ;
1275 }
1276  
1277 =head2 getPhenotype
1278  
1279 Function : Get (read) a Genetics::Object::Phenotype object from the database.
1280 Argument : The Object ID of the Phenotype to be returned.
1281 Returns : A Genetics::Object::Phenotype object.
1282 Scope : Public
1283  
1284 =cut
1285  
1286 sub getPhenotype {
1287 my($self, $id) = @_ ;
1288 my($pt, %param, $sth, $arrRef, $sth1, $arrRef1, $subjName, $svName,
1289 @aaList, $aaName, $dataType, $value) ;
1290 my $dbh = $self->{dbh} ;
1291
1292 $DEBUG and carp " ->[getPhenotype] $id" ;
1293  
1294 $self->_getObjAssocData($id, \%param) ;
1295  
1296 # Phenotype data
1297 $sth = $dbh->prepare("select subjectID, svID, numberValue, codeValue,
1298 dateValue, isActive, dateCollected
1299 from Phenotype
1300 where ptID = $id") ;
1301 $sth->execute() ;
1302 $arrRef = $sth->fetchrow_arrayref() ;
1303 ( $subjName ) = $dbh->selectrow_array("select name from Object
1304 where id = $$arrRef[0]") ;
1305 $param{Subject} = {name => $subjName, id => $$arrRef[0]} ;
1306 ( $svName ) = $dbh->selectrow_array("select name from Object
1307 where id = $$arrRef[1]") ;
1308 $param{StudyVariable} = {name => $svName, id => $$arrRef[1]} ;
1309 $value = $$arrRef[2] || $$arrRef[3] || $$arrRef[4] ;
1310 $param{value} = $value || 0 ; # the 'or 0' here is for cases where the number
1311 # or code value is 0, in which case the above
1312 # statement sets value to false. I think this
1313 # is ok, since there has to be a value.
1314 $param{isActive} = $$arrRef[5] ;
1315 defined $$arrRef[6] and $param{dateCollected} = $$arrRef[6] ;
1316 $sth->finish() ;
1317 # Phenotype AssayAttrs
1318 $sth = $dbh->prepare("select objID, attrID, stringValue, numberValue,
1319 dateValue, booleanValue
1320 from AttributeValue
1321 where objID = $id") ;
1322 $sth->execute() ;
1323 while ($arrRef = $sth->fetchrow_arrayref()) {
1324 ($aaName, $dataType) = $dbh->selectrow_array("select name, dataType
1325 from AssayAttribute
1326 where attrID = $$arrRef[1]") ;
1327 $value = $$arrRef[2] || $$arrRef[3] || $$arrRef[4] || $$arrRef[5] ;
1328 push(@aaList, {name => $aaName,
1329 dataType => $dataType,
1330 value => $value }) ;
1331 }
1332 defined $aaList[0] and $param{AssayAttrs} = [ @aaList ] ;
1333
1334 $pt = new Genetics::Phenotype(%param) ;
1335
1336 $DEBUG and carp " ->[getPhenotype] $pt" ;
1337  
1338 return($pt) ;
1339 }
1340  
1341 =head2 getMiniPhenotype
1342  
1343 Function : Get a "light" version of a Genetics::Object::Phenotype object from
1344 the database.
1345 Argument : The Object ID of the Phenotype to be returned.
1346 Returns : A Genetics::Object::Phenotype object.
1347 Scope : Public
1348 Comments : "Light" version means that the object has only the name and id
1349 fields from Object, and it does not contain any associated NameAlias,
1350 Contact, DBXReference or Keyword data. It also has a sub-set of
1351 Phenotype-specific fields.
1352  
1353 =cut
1354  
1355 sub getMiniPhenotype {
1356 my($self, $id) = @_ ;
1357 my($pt, %param, $sth, $arrRef, $subjName, $svName, $value) ;
1358 my $dbh = $self->{dbh} ;
1359
1360 $DEBUG and carp " ->[getMiniPhenotype] $id" ;
1361  
1362 # Phenotype data
1363 $sth = $dbh->prepare("select name, id, dateCreated, dateModified, comment,
1364 subjectID, svID, numberValue, codeValue,
1365 dateValue, isActive
1366 from Object, Phenotype
1367 where id = $id
1368 and id = ptID") ;
1369 $sth->execute() ;
1370 $arrRef = $sth->fetchrow_arrayref() ;
1371 $sth->finish() ;
1372 defined $arrRef or return(undef) ;
1373  
1374 $param{name} = $$arrRef[0] ;
1375 $param{id} = $$arrRef[1] ;
1376 $param{dateCreated} = $$arrRef[2] ;
1377 $param{dateModified} = $$arrRef[3] ;
1378 $param{comment} = $$arrRef[4] ;
1379 ( $subjName ) = $dbh->selectrow_array("select name from Object
1380 where id = $$arrRef[5]") ;
1381 $param{Subject} = {name => $subjName, id => $$arrRef[5]} ;
1382 ( $svName ) = $dbh->selectrow_array("select name from Object
1383 where id = $$arrRef[6]") ;
1384 $param{StudyVariable} = {name => $svName, id => $$arrRef[6]} ;
1385 $value = $$arrRef[7] || $$arrRef[8] || $$arrRef[9] ;
1386 $param{value} = $value || 0 ; # the 'or 0' here is for cases where the number
1387 # or code value is 0, in which case the above
1388 # statement sets value to false. I think this
1389 # is ok, since there has to be a value.
1390 $param{isActive} = $$arrRef[10] ;
1391
1392 $pt = new Genetics::Phenotype(%param) ;
1393
1394 $DEBUG and carp " ->[getMiniPhenotype] $pt" ;
1395  
1396 return($pt) ;
1397 }
1398  
1399 =head2 getFrequencySource
1400  
1401 Function : Get (read) a Genetics::Object::FrequencySource object from the database.
1402 Argument : The Object ID of the FrequencySource to be returned.
1403 Returns : A Genetics::Object::FrequencySource object.
1404 Scope : Public
1405  
1406 =cut
1407  
1408 sub getFrequencySource {
1409 my($self, $id) = @_ ;
1410 my($fs, %param, $sth, $arrRef, $sth1, $arrRef1, $obsFreqID, %init, $alleleName,
1411 $alleleType, $poID, $poName, @oafList, $htName, @ohfList) ;
1412 my $dbh = $self->{dbh} ;
1413
1414 $DEBUG and carp " ->[getFrequencySource] $id" ;
1415  
1416 $self->_getObjAssocData($id, \%param) ;
1417  
1418 # FrequencySource data
1419 $sth = $dbh->prepare("select obsFreqID
1420 from FreqSourceObsFrequency
1421 where freqSourceID = $id") ;
1422 $sth->execute() ;
1423 $sth1 = $dbh->prepare("select type, alleleID, htID, frequency
1424 from ObsFrequency
1425 where obsFreqID = ?") ;
1426 while ($arrRef = $sth->fetchrow_arrayref()) {
1427 $obsFreqID = $$arrRef[0] ;
1428 $sth1->bind_param( 1, $obsFreqID ) ;
1429 $sth1->execute() ;
1430 while ($arrRef1 = $sth1->fetchrow_arrayref()) {
1431 %init = () ;
1432 if ($$arrRef1[0] eq "Allele") {
1433 ( $alleleName, $alleleType, $poID ) =
1434 $dbh->selectrow_array("select name, type, poID
1435 from Allele
1436 where alleleID = $$arrRef1[1]") ;
1437 ( $poName ) = $dbh->selectrow_array("select name from Object
1438 where id = $poID") ;
1439 $init{name} = $alleleName ;
1440 $init{type} = $alleleType ;
1441 $init{Marker} = { name => $poName, id => $poID } ;
1442 push(@oafList, { Allele => { %init },
1443 frequency => $$arrRef1[3] }) ;
1444 } elsif ($$arrRef1[0] eq "Ht") {
1445 ( $htName ) = $dbh->selectrow_array("select name from Object
1446 where id = $$arrRef1[2]") ;
1447 $init{name} = $htName ;
1448 $init{id} = $$arrRef1[2] ;
1449 push(@ohfList, { Haplotype => { %init },
1450 frequency => $$arrRef1[3] }) ;
1451 }
1452 }
1453 }
1454 defined $oafList[0] and $param{ObsAlleleFrequencies} = \@oafList ;
1455 defined $ohfList[0] and $param{ObsHtFrequencies} = \@ohfList ;
1456  
1457 $fs = new Genetics::FrequencySource(%param) ;
1458
1459 $DEBUG and carp " ->[getFrequencySource] $fs" ;
1460  
1461 return($fs) ;
1462 }
1463  
1464 =head2 getMiniFrequencySource
1465  
1466 Function : Get (read) a Genetics::Object::FrequencySource object from the database.
1467 Argument : The Object ID of the FrequencySource to be returned.
1468 Returns : A Genetics::Object::FrequencySource object.
1469 Scope : Public
1470  
1471 =cut
1472  
1473 sub getMiniFrequencySource {
1474 my($self, $id) = @_ ;
1475 my($fs, %param, $sth, $arrRef, $sth1, $arrRef1, $obsFreqID, %init, $alleleName,
1476 $alleleType, $poID, $poName, @oafList, $htName, @ohfList) ;
1477 my $dbh = $self->{dbh} ;
1478
1479 $DEBUG and carp " ->[getMiniFrequencySource] $id" ;
1480  
1481 $sth = $dbh->prepare("select name, id dateCreated, dateModified, comment,
1482 from Object
1483 where id = $id") ;
1484 $sth->execute() ;
1485 $arrRef = $sth->fetchrow_arrayref() ;
1486 $sth->finish() ;
1487 defined $arrRef or return(undef) ;
1488  
1489 $param{name} = $$arrRef[0] ;
1490 $param{id} = $$arrRef[1] ;
1491 $param{dateCreated} = $$arrRef[2] ;
1492 $param{dateModified} = $$arrRef[3] ;
1493 $param{comment} = $$arrRef[4] ;
1494
1495 # FrequencySource data
1496 $sth = $dbh->prepare("select obsFreqID
1497 from FreqSourceObsFrequency
1498 where freqSourceID = $id") ;
1499 $sth->execute() ;
1500 $sth1 = $dbh->prepare("select type, alleleID, htID, frequency
1501 from ObsFrequency
1502 where obsFreqID = ?") ;
1503 while ($arrRef = $sth->fetchrow_arrayref()) {
1504 $obsFreqID = $$arrRef[0] ;
1505 $sth1->bind_param( 1, $obsFreqID ) ;
1506 $sth1->execute() ;
1507 while ($arrRef1 = $sth1->fetchrow_arrayref()) {
1508 %init = () ;
1509 if ($$arrRef1[0] eq "Allele") {
1510 ( $alleleName, $alleleType, $poID ) =
1511 $dbh->selectrow_array("select name, type, poID
1512 from Allele
1513 where alleleID = $$arrRef1[1]") ;
1514 ( $poName ) = $dbh->selectrow_array("select name from Object
1515 where id = $poID") ;
1516 $init{name} = $alleleName ;
1517 $init{type} = $alleleType ;
1518 $init{Marker} = { name => $poName, id => $poID } ;
1519 push(@oafList, { Allele => { %init },
1520 frequency => $$arrRef1[3] }) ;
1521 } elsif ($$arrRef1[0] eq "Ht") {
1522 ( $htName ) = $dbh->selectrow_array("select name from Object
1523 where id = $$arrRef1[2]") ;
1524 $init{name} = $htName ;
1525 $init{id} = $$arrRef1[2] ;
1526 push(@ohfList, { Haplotype => { %init },
1527 frequency => $$arrRef1[3] }) ;
1528 }
1529 }
1530 }
1531 defined $oafList[0] and $param{ObsAlleleFrequencies} = \@oafList ;
1532 defined $ohfList[0] and $param{ObsHtFrequencies} = \@ohfList ;
1533  
1534 $fs = new Genetics::FrequencySource(%param) ;
1535
1536 $DEBUG and carp " ->[getMiniFrequencySource] $fs" ;
1537  
1538 return($fs) ;
1539 }
1540  
1541 =head2 getHtMarkerCollection
1542  
1543 Function : Get (read) a Genetics::Object::HtMarkerCollection object from the database.
1544 Argument : The Object ID of the HtMarkerCollection to be returned.
1545 Returns : A Genetics::Object::HtMarkerCollection object.
1546 Scope : Public
1547  
1548 =cut
1549  
1550 sub getHtMarkerCollection {
1551 my($self, $id) = @_ ;
1552 my($hmc, %param, $sth, $arrRef, %init, $poName, @markersList) ;
1553 my $dbh = $self->{dbh} ;
1554
1555 $DEBUG and carp " ->[getHtMarkerCollection] $id" ;
1556  
1557 $self->_getObjAssocData($id, \%param) ;
1558  
1559 # HtMarkerCollection data
1560 $sth = $dbh->prepare("select distanceUnits
1561 from HtMarkerCollection
1562 where hmcID = $id") ;
1563 $sth->execute() ;
1564 if ( defined ($arrRef = $sth->fetchrow_arrayref()) ) {
1565 $param{distanceUnits} = $$arrRef[0] ;
1566 } else {
1567 return(undef) ;
1568 }
1569 $sth->finish() ;
1570 $sth = $dbh->prepare("select poID, sortOrder, distance
1571 from HMCPolyObj
1572 where hmcID = $id
1573 order by sortOrder") ;
1574 $sth->execute() ;
1575 while ($arrRef = $sth->fetchrow_arrayref()) {
1576 %init = () ;
1577 ( $poName ) = $dbh->selectrow_array("select name from Object
1578 where id = $$arrRef[0]") ;
1579 $init{name} = $poName ;
1580 $init{id} = $$arrRef[0] ;
1581 defined $$arrRef[2] and $init{distance} = $$arrRef[2] ;
1582 push(@markersList, { %init }) ;
1583 }
1584 $param{Markers} = \@markersList ;
1585  
1586 $hmc = new Genetics::HtMarkerCollection(%param) ;
1587
1588 $DEBUG and carp " ->[getHtMarkerCollection] $hmc" ;
1589 return($hmc) ;
1590 }
1591  
1592 =head2 getHaplotype
1593  
1594 Function : Get (read) a Genetics::Object::Haplotype object from the database.
1595 Argument : The Object ID of the Haplotype to be returned.
1596 Returns : A Genetics::Object::Haplotype object.
1597 Scope : Public
1598  
1599 =cut
1600  
1601 sub getHaplotype {
1602 my($self, $id) = @_ ;
1603 my($ht, %param, $sth, $arrRef, $hmcID, $hmcName, %init, $name, $type, @alleleList) ;
1604 my $dbh = $self->{dbh} ;
1605
1606 $DEBUG and carp " ->[getHaplotype] $id" ;
1607  
1608 $self->_getObjAssocData($id, \%param) ;
1609  
1610 # Haplotype data
1611 ( $hmcID ) = $dbh->selectrow_array("select hmcID
1612 from Haplotype
1613 where haplotypeID = $id") ;
1614 ( $hmcName ) = $dbh->selectrow_array("select name
1615 from Object
1616 where id = $hmcID") ;
1617 $param{MarkerCollection} = { name => $hmcName,
1618 id => $hmcID } ;
1619 $sth = $dbh->prepare("select alleleID, sortOrder
1620 from HaplotypeAllele
1621 where haplotypeID = $id
1622 order by sortOrder") ;
1623 $sth->execute() ;
1624 while ($arrRef = $sth->fetchrow_arrayref()) {
1625 %init = () ;
1626 ( $name, $type ) = $dbh->selectrow_array("select name, type
1627 from Allele
1628 where alleleID = $$arrRef[0]") ;
1629 push(@alleleList, { name => $name, type => $type}) ;
1630 }
1631 $param{Alleles} = \@alleleList ;
1632
1633 $ht = new Genetics::Haplotype(%param) ;
1634
1635 $DEBUG and carp " ->[getHaplotype] $ht" ;
1636  
1637 return($ht) ;
1638 }
1639  
1640 =head2 getMiniHaplotype
1641  
1642 Function : Get a "light" version of a Genetics::Object::Haplotype object
1643 from the database.
1644 Argument : The Object ID of the Haplotype to be returned.
1645 Returns : A Genetics::Object::Haplotype object.
1646 Scope : Public
1647 Comments : "Light" version means that the object has only the name and id
1648 fields from Object, and it does not contain any associated NameAlias,
1649 Contact, DBXReference or Keyword data.
1650  
1651 =cut
1652  
1653 sub getMiniHaplotype {
1654 my($self, $id) = @_ ;
1655 my($ht, %param, $htName, $sth, $arrRef, $hmcID, $hmcName, %init, $name, $type,
1656 @alleleList) ;
1657 my $dbh = $self->{dbh} ;
1658
1659 $DEBUG and carp " ->[getMiniHaplotype] $id" ;
1660  
1661 # Haplotype data
1662 $sth = $dbh->prepare("select name, id, dateCreated, dateModified, comment, hmcID
1663 from Object, Haplotype
1664 where id = $id
1665 and id = haplotypeID") ;
1666 $sth->execute() ;
1667 $arrRef = $sth->fetchrow_arrayref() ;
1668 $sth->finish() ;
1669 defined $name or return(undef) ;
1670  
1671 $param{name} = $$arrRef[0] ;
1672 $param{id} = $$arrRef[1] ;
1673 $param{dateCreated} = $$arrRef[2] ;
1674 $param{dateModified} = $$arrRef[3] ;
1675 $param{comment} = $$arrRef[4] ;
1676 $hmcID = $$arrRef[5] ;
1677  
1678 ( $hmcName ) = $dbh->selectrow_array("select name
1679 from Object
1680 where id = $hmcID") ;
1681
1682 $param{MarkerCollection} = { name => $hmcName,
1683 id => $hmcID } ;
1684 $sth = $dbh->prepare("select alleleID, sortOrder
1685 from HaplotypeAllele
1686 where haplotypeID = $id
1687 order by sortOrder") ;
1688 $sth->execute() ;
1689 while ($arrRef = $sth->fetchrow_arrayref()) {
1690 %init = () ;
1691 ( $name, $type ) = $dbh->selectrow_array("select name, type
1692 from Allele
1693 where alleleID = $$arrRef[0]") ;
1694 push(@alleleList, { name => $name, type => $type}) ;
1695 }
1696 $param{Alleles} = \@alleleList ;
1697
1698 $ht = new Genetics::Haplotype(%param) ;
1699
1700 $DEBUG and carp " ->[getMiniHaplotype] $ht" ;
1701  
1702 return($ht) ;
1703 }
1704  
1705 =head2 getDNASample
1706  
1707 Function : Get (read) a Genetics::Object::DNASample object from the database.
1708 Argument : The Object ID of the DNASample to be returned.
1709 Returns : A Genetics::Object::DNASample object.
1710 Scope : Public
1711  
1712 =cut
1713  
1714 sub getDNASample {
1715 my($self, $id) = @_ ;
1716 my($sample, %param, $sth, $arrRef, $subjID, $subjName, $gtName, @gtList) ;
1717 my $dbh = $self->{dbh} ;
1718
1719 $DEBUG and carp " ->[getDNASample] $id" ;
1720  
1721 $self->_getObjAssocData($id, \%param) ;
1722  
1723 # DNASample data
1724 $sth = $dbh->prepare("select dateCollected, amount, amountUnits,
1725 concentration, concUnits
1726 from Sample, DNASample
1727 where sampleID = $id
1728 and sampleID = dnaSampleID") ;
1729 $sth->execute() ;
1730 $arrRef = $sth->fetchrow_arrayref() ;
1731 defined $$arrRef[0] and $param{dateCollected} = $$arrRef[0] ;
1732 defined $$arrRef[1] and $param{amount} = $$arrRef[1] ;
1733 defined $$arrRef[2] and $param{amountUnits} = $$arrRef[2] ;
1734 defined $$arrRef[3] and $param{concentration} = $$arrRef[3] ;
1735 defined $$arrRef[4] and $param{concUnits} = $$arrRef[4] ;
1736 $sth->finish() ;
1737 # Subject
1738 ( $subjID ) = $dbh->selectrow_array( "select subjectID
1739 from SubjectSample
1740 where sampleID = $id" ) ;
1741 if (defined $subjID) {
1742 ( $subjName ) = $dbh->selectrow_array( "select name
1743 from Object
1744 where id = $subjID" ) ;
1745 $param{Subject} = {name => $subjName, id => $subjID} ;
1746 }
1747 # Genotypes
1748 $sth = $dbh->prepare( "select gtID
1749 from SampleGenotype
1750 where sampleID = $id" ) ;
1751 $sth->execute() ;
1752 while ($arrRef = $sth->fetchrow_arrayref()) {
1753 ( $gtName ) = $dbh->selectrow_array( "select name
1754 from Object
1755 where id = $subjID" ) ;
1756 push(@gtList, {name => $gtName, id => $$arrRef[0]}) ;
1757 }
1758 if (defined $gtList[0]) {
1759 $param{Genotypes} = \@gtList ;
1760 }
1761  
1762 $sample = new Genetics::DNASample(%param) ;
1763
1764 $DEBUG and carp " ->[getDNASample] $sample" ;
1765  
1766 return($sample) ;
1767 }
1768  
1769 =head2 getTissueSample
1770  
1771 Function : Get (read) a Genetics::Object::TissueSample object from the database.
1772 Argument : The Object ID of the TissueSample to be returned.
1773 Returns : A Genetics::Object::TissueSample object.
1774 Scope : Public
1775  
1776 =cut
1777  
1778 sub getTissueSample {
1779 my($self, $id) = @_ ;
1780 my($sample, %param, $sth, $arrRef, $subjID, $subjName, $dsName, @dsList) ;
1781 my $dbh = $self->{dbh} ;
1782
1783 $DEBUG and carp " ->[getTissueSample] $id" ;
1784  
1785 $self->_getObjAssocData($id, \%param) ;
1786  
1787 # TissueSample data
1788 $sth = $dbh->prepare("select dateCollected, tissue, amount, amountUnits
1789 from Sample, TissueSample
1790 where sampleID = $id
1791 and sampleID = tissueSampleID") ;
1792 $sth->execute() ;
1793 $arrRef = $sth->fetchrow_arrayref() ;
1794 defined $$arrRef[0] and $param{dateCollected} = $$arrRef[0] ;
1795 defined $$arrRef[1] and $param{tissue} = $$arrRef[1] ;
1796 defined $$arrRef[2] and $param{amount} = $$arrRef[2] ;
1797 defined $$arrRef[3] and $param{amountUnits} = $$arrRef[3] ;
1798 $sth->finish() ;
1799 # Subject
1800 ( $subjID ) = $dbh->selectrow_array( "select subjectID
1801 from SubjectSample
1802 where sampleID = $id" ) ;
1803 if (defined $subjID) {
1804 ( $subjName ) = $dbh->selectrow_array( "select name
1805 from Object
1806 where id = $subjID" ) ;
1807 $param{Subject} = {name => $subjName, id => $subjID} ;
1808 }
1809 # DNASamples
1810 $sth = $dbh->prepare( "select dnaSampleID
1811 from TissueDNASample
1812 where tissueSampleID = $id" ) ;
1813 $sth->execute() ;
1814 while ($arrRef = $sth->fetchrow_arrayref()) {
1815 ( $dsName ) = $dbh->selectrow_array( "select name
1816 from Object
1817 where id = $subjID" ) ;
1818 push(@dsList, {name => $dsName, id => $$arrRef[0]}) ;
1819 }
1820 if (defined $dsList[0]) {
1821 $param{DNASAmples} = \@dsList ;
1822 }
1823  
1824 $sample = new Genetics::TissueSample(%param) ;
1825
1826 $DEBUG and carp " ->[getTissueSample] $sample" ;
1827  
1828 return($sample) ;
1829 }
1830  
1831 =head2 getMap
1832  
1833 Function : Get (read) a Genetics::Object::Map object from the database.
1834 Argument : The Object ID of the Map to be returned.
1835 Returns : A Genetics::Object::Map object.
1836 Scope : Public
1837  
1838 =cut
1839  
1840 sub getMap {
1841 my($self, $id) = @_ ;
1842 my($map, %param, $sth, $arrRef, $orgID, %init, $soName, @omeList) ;
1843 my $dbh = $self->{dbh} ;
1844
1845 $DEBUG and carp " ->[getMap] $id" ;
1846  
1847 $self->_getObjAssocData($id, \%param) ;
1848  
1849 # Map data
1850 $sth = $dbh->prepare("select chromosome, organismID,
1851 orderingMethod, distanceUnits
1852 from Map
1853 where mapiD = $id") ;
1854 $sth->execute() ;
1855 $arrRef = $sth->fetchrow_arrayref() ;
1856 defined $$arrRef[0] and $param{chromosome} = $$arrRef[0] ;
1857 defined $$arrRef[2] and $param{orderingMethod} = $$arrRef[2] ;
1858 defined $$arrRef[3] and $param{distanceUnits} = $$arrRef[3] ;
1859 $sth->finish() ;
1860 # Organism data
1861 if ( defined ($orgID = $$arrRef[1]) ) {
1862 $sth = $dbh->prepare("select genusSpecies, subspecies, strain
1863 from Organism
1864 where organismID = $orgID") ;
1865 $sth->execute() ;
1866 $arrRef = $sth->fetchrow_arrayref() ;
1867 $init{genusSpecies} = $$arrRef[0] ;
1868 defined $$arrRef[1] and $init{subspecies} = $$arrRef[1] ;
1869 defined $$arrRef[2] and $init{strain} = $$arrRef[2] ;
1870 $param{Organism} = { %init } ;
1871 $sth->finish() ;
1872 }
1873 # OrderedMapElement data
1874 $sth = $dbh->prepare("select soID, sortOrder, name, distance, comment
1875 from OrderedMapElement
1876 where mapID = $id
1877 order by sortOrder") ;
1878 $sth->execute() ;
1879 while ($arrRef = $sth->fetchrow_arrayref()) {
1880 %init = () ;
1881 ( $soName ) = $dbh->selectrow_array("select name from Object
1882 where id = $$arrRef[0]") ;
1883 $init{SeqObj} = {name => $soName, id => $$arrRef[0]} ;
1884 $init{name} = $$arrRef[2] ;
1885 defined $$arrRef[3] and $init{distance} = $$arrRef[3] ;
1886 defined $$arrRef[4] and $init{comment} = $$arrRef[4] ;
1887 push(@omeList, { %init }) ;
1888 }
1889 $param{OrderedMapElements} = \@omeList ;
1890  
1891 $map = new Genetics::Map(%param) ;
1892
1893 $DEBUG and carp " ->[getMap] $map" ;
1894  
1895 return($map) ;
1896 }
1897  
1898 =head2 getMiniMap
1899  
1900 Function : Get "light" version of a Genetics::Object::Map object from
1901 the database.
1902 Argument : The Object ID of the Map to be returned.
1903 Returns : A Genetics::Object::Map object.
1904 Scope : Public
1905 Comments : "Light" version means that the object has only the name and id
1906 fields from Object, and it does not contain any associated NameAlias,
1907 Contact, DBXReference or Keyword data. It also has a sub-set of
1908 Map-specific fields.
1909  
1910 =cut
1911  
1912 sub getMiniMap {
1913 my($self, $id) = @_ ;
1914 my($map, %param, $sth, $arrRef, %init, $soName, @omeList) ;
1915 my $dbh = $self->{dbh} ;
1916
1917 $DEBUG and carp " ->[getMiniMap] $id" ;
1918  
1919 $self->_getObjAssocData($id, \%param) ;
1920  
1921 # Map data
1922 $sth = $dbh->prepare("select name, id, dateCreated, dateModified, comment,
1923 chromosome, orderingMethod, distanceUnits
1924 from Object, Map
1925 where id = $id
1926 and id = mapiD") ;
1927 $sth->execute() ;
1928 $arrRef = $sth->fetchrow_arrayref() ;
1929 $sth->finish() ;
1930 defined $arrRef or return(undef) ;
1931  
1932 $param{name} = $$arrRef[0] ;
1933 $param{id} = $$arrRef[1] ;
1934 $param{dateCreated} = $$arrRef[2] ;
1935 $param{dateModified} = $$arrRef[3] ;
1936 $param{comment} = $$arrRef[4] ;
1937 defined $$arrRef[5] and $param{chromosome} = $$arrRef[5] ;
1938 defined $$arrRef[6] and $param{orderingMethod} = $$arrRef[6] ;
1939 defined $$arrRef[7] and $param{distanceUnits} = $$arrRef[7] ;
1940  
1941 # OrderedMapElement data
1942 $sth = $dbh->prepare("select soID, sortOrder, name, distance, comment
1943 from OrderedMapElement
1944 where mapID = $id
1945 order by sortOrder") ;
1946 $sth->execute() ;
1947 while ($arrRef = $sth->fetchrow_arrayref()) {
1948 %init = () ;
1949 ( $soName ) = $dbh->selectrow_array("select name from Object
1950 where id = $$arrRef[0]") ;
1951 $init{SeqObj} = {name => $soName, id => $$arrRef[0]} ;
1952 $init{name} = $$arrRef[2] ;
1953 defined $$arrRef[3] and $init{distance} = $$arrRef[3] ;
1954 defined $$arrRef[4] and $init{comment} = $$arrRef[4] ;
1955 push(@omeList, { %init }) ;
1956 }
1957 $param{OrderedMapElements} = \@omeList ;
1958  
1959 $map = new Genetics::Map(%param) ;
1960
1961 $DEBUG and carp " ->[getMiniMap] $map" ;
1962  
1963 return($map) ;
1964 }
1965  
1966 =head1 Private methods
1967  
1968 =head2 _getObjAssocData
1969  
1970 Function : get (read) data from and associated with the Object table/object.
1971 Arguments : Scalar containing an Object.id and a reference to a hash which
1972 will be populated with the data.
1973 Returns : N/A
1974 Scope : Private
1975 Called by : The various getObjectSubClass methods.
1976 Comments : The format of the data structure created by this method is
1977 identical to that passed to Object::new().
1978  
1979 =cut
1980  
1981 sub _getObjAssocData {
1982 my($self, $id, $paramPtr) = @_ ;
1983 my($sth, $arrRef1, $arrRef2, %init, $contactName, $contactID, $naListPtr, $contactPtr,
1984 $xRefListPtr, $kwListPtr) ;
1985 my $dbh = $self->{dbh} ;
1986  
1987 $sth = $dbh->prepare("select name, id, dateCreated, dateModified, comment,
1988 url, contactID
1989 from Object
1990 where Object.id = $id") ;
1991 $sth->execute() ;
1992 $arrRef1 = $sth->fetchrow_arrayref() ;
1993 defined $arrRef1 or return(undef) ;
1994 $sth->finish() ;
1995  
1996 $$paramPtr{name} = $$arrRef1[0] ;
1997 $$paramPtr{id} = $$arrRef1[1] ;
1998 $$paramPtr{dateCreated} = $$arrRef1[2] ;
1999 defined $$arrRef1[3] and $$paramPtr{dateModified} = $$arrRef1[3] ;
2000 defined $$arrRef1[4] and $$paramPtr{comment} = $$arrRef1[4] ;
2001 defined $$arrRef1[5] and $$paramPtr{url} = $$arrRef1[5] ;
2002  
2003 # NameAliases
2004 $sth = $dbh->prepare("select name, contactID
2005 from NameAlias
2006 where objID = $id") ;
2007 $sth->execute() ;
2008 while ($arrRef2 = $sth->fetchrow_arrayref()) {
2009 %init = () ;
2010 $init{name} = $$arrRef2[0] ;
2011 if ( defined($contactID = $$arrRef2[1]) ) {
2012 ( $contactName ) = $dbh->selectrow_array("select name from Contact
2013 where contactID = $contactID") ;
2014 defined $contactName and $init{contactName} = $contactName ;
2015 }
2016 push(@$naListPtr, { %init }) ;
2017 }
2018 defined $naListPtr and $$paramPtr{NameAliases} = $naListPtr ;
2019 # Contact
2020 if ( defined ($contactID = $$arrRef1[6]) ) {
2021 $sth = $dbh->prepare("select addressID, name, organization, comment
2022 from Contact
2023 where contactID = $contactID") ;
2024 $sth->execute() ;
2025 $arrRef2 = $sth->fetchrow_arrayref() ;
2026 $sth->finish() ;
2027 %init = () ;
2028 $init{name} = $$arrRef2[1] ;
2029 defined $$arrRef2[2] and $init{organization} = $$arrRef2[2] ;
2030 defined $$arrRef2[3] and $init{comment} = $$arrRef2[3] ;
2031 $$paramPtr{Contact} = { %init } ;
2032 }
2033 # DBXReferences
2034 $sth = $dbh->prepare("select accessionNumber, databaseName, schemaName, comment
2035 from DBXReference
2036 where objID = $id") ;
2037 $sth->execute() ;
2038 while ($arrRef2 = $sth->fetchrow_arrayref()) {
2039 %init = (accessionNumber => $$arrRef2[0],
2040 databaseName => $$arrRef2[1]) ;
2041 defined $$arrRef2[2] and $init{schemaName} = $$arrRef2[2] ;
2042 defined $$arrRef2[3] and $init{comment} = $$arrRef2[3] ;
2043 push(@$xRefListPtr, { %init }) ;
2044 }
2045 defined $xRefListPtr and $$paramPtr{DBXReferences} = $xRefListPtr ;
2046 # Keywords
2047 $sth = $dbh->prepare("select name, dataType, description, stringValue,
2048 numberValue, dateValue, booleanValue
2049 from KeywordType, Keyword
2050 where Keyword.objID = $id
2051 and Keyword.keywordTypeID = KeywordType.keywordTypeID") ;
2052 $sth->execute() ;
2053 while ($arrRef2 = $sth->fetchrow_arrayref()) {
2054 %init = () ;
2055 $init{name} = $$arrRef2[0] ;
2056 $init{dataType} = $$arrRef2[1] ;
2057 defined $$arrRef2[2] and $init{description} = $$arrRef2[2] ;
2058 $$arrRef2[1] eq "String" and $init{value} = $$arrRef2[3] ;
2059 $$arrRef2[1] eq "Number" and $init{value} = $$arrRef2[4] ;
2060 $$arrRef2[1] eq "Date" and $init{value} = $$arrRef2[5] ;
2061 $$arrRef2[1] eq "Boolean" and $init{value} = $$arrRef2[6] ;
2062 push(@$kwListPtr, { %init }) ;
2063 }
2064 defined $kwListPtr and $$paramPtr{Keywords} = $kwListPtr ;
2065  
2066 return(1) ;
2067 }
2068  
2069 1;
2070