Update.pm

- NAME
- SYNOPSIS
- DESCRIPTION
- LICENSE
- FEEDBACK
- AUTHOR - Steve Mathias
- DETAILS
- Imported Packages
- Inheritance
- Public Methods

- updateCluster
- updateSubject
- updateKindred
- updateMarker
- updateSNP
- updateGenotype
- updateStudyVariable
- updatePhenotype
- updateFrequencySource
- updateHtMarkerCollection
- updateHaplotype
- updateDNASample
- updateTissueSample
- updateMap

- Private methods

- _updateObjAssocData
- _updateSubjectKindredRefs
- _updateKindredSubjectRefs
- _updateAssayAttrs

# NAME

Genetics::API::DB::Update

# SYNOPSIS

      use Genetics::API ;

      $api = new Genetics::API(DSN => {driver => "mysql",
                                       host => $Host,
                                       database => $Database},
                               user => $UserName,
                               password => $Password) ;

      $subject = $api->getSubject(3) ;
      $subject->name("Elvis") ;
      $api->updateSubject($subject) ;

# DESCRIPTION

The Genetics::API::DB packages provide an interface for the manipulation of Genperl objects in a relational database. This package contains the methods for updating objects that have previously been saved to the database. To save new objects, see Genetics::API::DB::Create.

The following describes the update behavior implemented by the methods in this package: - The data in each object field will completely replace the data in the database for that field. - Data for fields not present in an object will not be affected. - In order to delete data for a particular field, the value of that field should be set to ``DELETE''. - In order to add to existing data for a particular field, use an appropriate method in Genetics::API or handle it manually.

Examples:

      To completely replace a SNPs set of Alleles:
         @alleles = ( {name => "A", type => "Nucleotide"},
                       name => "C", type => "Nucleotide"} ) ;
         $snp = $api->getSNP(11) ;
         $snp->Alleles(\@alleles) ;
         $api->updateSNP($snp) ;

      To add an Allele to a SNP:
         $snp = $api->getSNP(11) ;
         $alleleListptr = $snp->Alleles ;
         push( @$alleleListptr, {name => "A", type => "Nucleotide"} ) ;
         $snp->Alleles($alleleListptr) ;
         $api->updateSNP($snp) ;

# LICENSE

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

# FEEDBACK

Currently, all feedback should be sent directly to the author.

# AUTHOR - Steve Mathias

Email: mathias@genomica.com

Phone: (720) 565-4029

Address: Genomica Corporation 1745 38th Street Boulder, CO 80301

# DETAILS

The rest of the documentation describes each of the object variables and methods. The names of internal variables and methods are preceded with an underscore (_).

# Imported Packages

     strict             Just to be anal
     vars               Global variables
     Carp               Error reporting

# Inheritance

     Exporter           Make methods available to importing packages

# Public Methods

## updateCluster

      Function  : Update a Genetics::Object::Cluster object in the database.
      Argument  : The Genetics::Object::Cluster object to be updated.
      Returns   : 1 on success, undef otherwise.
      Scope     : Public
      Comments  : Cluster.clusterType cannot be modified, so this method does
                  not touch the Cluster table.

## updateSubject

      Function  : Update a Genetics::Object::Subject object in the database.
      Argument  : The Genetics::Object::Subject object to be updated.
      Returns   : 1 on success, undef otherwise.
      Scope     : Public
      Comments  : If Subject.kindredID is modified, the approprate updates are also
                  made to KindredSubject.  In other words, the reciprocal
                  relationships Kindred->Subjects and Subject->Kindred are kept in
                  synch.

## updateKindred

      Function  : Update a Genetics::Object::Kindred object in the database.
      Argument  : The Genetics::Object::Kindred object to be updated.
      Returns   : 1 on success, undef otherwise.
      Scope     : Public
      Comments  : If the set of Subjects contained in a Kindred is modified,
                  the approprate updates are also made to the Subject.kindredID
                  field of each of the Subjects.  In other words, the reciprocal
                  relationships Kindred->Subjects and Subject->Kindred are kept
                  in synch.  This only applies to primary Kindreds, of course.

## updateMarker

      Function  : Update a Genetics::Object::Marker object in the database.
      Argument  : The Genetics::Object::Marker object to be updated.
      Returns   : 1 on success, undef otherwise.
      Scope     : Public

## updateSNP

      Function  : Update a Genetics::Object::SNP object in the database.
      Argument  : The Genetics::Object::SNP object to be updated.
      Returns   : 1 on success, undef otherwise.
      Scope     : Public

## updateGenotype

      Function  : Update a Genetics::Object::Genotype object in the database.
      Argument  : The Genetics::Object::Genotype object to be updated.
      Returns   : 1 on success, undef otherwise.
      Scope     : Public

## updateStudyVariable

      Function  : Update a Genetics::Object::StudyVariable object in the database.
      Argument  : The Genetics::Object::StudyVariable object to be updated.
      Returns   : 1 on success, undef otherwise.
      Scope     : Public
      Comments  : StudyVariable.format cannot be modified.

## updatePhenotype

      Function  : Update a Genetics::Object::Phenotype object in the database.
      Argument  : The Genetics::Object::Phenotype object to be updated.
      Returns   : 1 on success, undef otherwise.
      Scope     : Public
      Comments  :

    =cut

sub updatePhenotype { my($self, $pt) = @_ ; my($id, $actualType, $sth, $active, $date, $svFormat, $valueFieldName, $aaListPtr) ; my $dbh = $self->{dbh} ;

      $DEBUG and carp " ->[updatePhenotype] $pt" ;

      $id = $pt->field("id") ;
      ( $actualType ) = $dbh->selectrow_array("select objType from Object
                                               where id = $id") ;
      if ( $actualType ne "Phenotype") {
        carp " ->[updatePhenotype] Object with ID = $id is not a Phenotype!" ;
        return(undef) ;
      }
      # Object
      $self->_updateObjAssocData($pt) ;
      # Phenotype
      if ( defined($active = $pt->field("isActive")) ) {
        $sth = $dbh->prepare( "update Phenotype
                               set isActive = ?
                               where ptID = ?" ) ;
        $sth->execute($active, $id) ;
        $sth->finish() ;
      }
      if ( defined($date = $pt->field("dateCollected")) ) {
        $sth = $dbh->prepare( "update Phenotype
                               set dateCollected = ?
                               where ptID = ?" ) ;
        if ($date eq "DELETE") {
          $sth->execute(undef, $id) ;
        } else {
          $sth->execute($date, $id) ;
        }
        $sth->finish() ;
      }
      ( $svFormat ) = $dbh->selectrow_array( "select format from StudyVariable, Phenotype
                                              where ptID = $id
                                              and Phenotype.svID = StudyVariable.studyVariableID" ) ;
      $valueFieldName = lc($svFormat) . "Value" ;
      $sth = $dbh->prepare( "update Phenotype
                             set $valueFieldName = ?
                             where ptID = ?" ) ;
      $sth->execute($pt->field("value"), $id) ;
      $sth->finish() ;
      # Phenotype AssayAttributes
      if ( defined ($aaListPtr = $pt->field("AssayAttrs")) ) {
        $self->_updateAssayAttrs($aaListPtr, "Phenotype", $id) ;
      }

      $DEBUG and carp " ->[updatePhenotype] End." ;

      return(1) ;
    }

## updateFrequencySource

      Function  : Update a Genetics::Object::FrequencySource object in the database.
      Argument  : The Genetics::Object::FrequencySource object to be updated.
      Returns   : 1 on success, undef otherwise.
      Scope     : Public

## updateHtMarkerCollection

      Function  : Update a Genetics::Object::HtMarkerCollection object in the database.
      Argument  : The Genetics::Object::HtMarkerCollection object to be updated.
      Returns   : 1 on success, undef otherwise.
      Scope     : Public

## updateHaplotype

      Function  : Update a Genetics::Object::Haplotype object in the database.
      Argument  : The Genetics::Object::Haplotype object to be updated.
      Returns   : 1 on success, undef otherwise.
      Scope     : Public

## updateDNASample

      Function  : Update a Genetics::Object::DNASample object in the database.
      Argument  : The Genetics::Object::DNASample object to be updated.
      Returns   : 1 on success, undef otherwise.
      Scope     : Public

## updateTissueSample

      Function  : Update a Genetics::Object::TissueSample object in the database.
      Argument  : The Genetics::Object::TissueSample object to be updated.
      Returns   : 1 on success, undef otherwise.
      Scope     : Public

## updateMap

      Function  : Update a Genetics::Object::Map object in the database.
      Argument  : The Genetics::Object::Map object to be updated.
      Returns   : 1 on success, undef otherwise.
      Scope     : Public

# Private methods

## _updateObjAssocData

      Function  : Update data in, and associated with, the Object table/object.
      Argument  : The Genetics::Object object to be updated.
      Returns   : 1 on success, undef otherwise.
      Scope     : Private
      Called by : The various updateObjectSubClass methods.
      Comments  : The following Object fields cannot be modified: id, objType,
                  dateModified.

## _updateSubjectKindredRefs

      Function  : Updates references between Subjects and Kindreds.
      Argument  : A Subject ID and a Kindred ID (can be undef).
      Returns   : N/A
      Scope     : Private
      Called By : updateSubject() when Subject.kindredID is modified.
      Comments  : This method updates the KindredSubject table based on
                  a change to a Subject.kindredID field.

## _updateKindredSubjectRefs

      Function  : Updates references between Kindreds and Subjects.
      Argument  : A Kindred ID and an array reference to a list of Subject IDs.
      Returns   : N/A
      Scope     : Private
      Called By : updateSubject() and updateKindred().
      Comments  : This method updates the KindredSubject table based on a changes
                  made to a Kindred->Subjects field.
                  This method also updates the Subject.kindredID field of each of
                  the relevant Subjects.

## _updateAssayAttrs

      Function  : Update AssayAttributes associated with a Genotype, AlleleCall
                  or Phenotype.
      Arguments : Array reference to the list of AssayAttributes, scalar
                  containing the type of object with which the AssayAttributes
                  are associated, and another scalar containing the id of that
                  object.
      Returns   : N/A
      Scope     : Private
      Called by : updateGenotype(), updatePhenotype().
      Comments  :