[Bio] / Sprout / Sprout.pm Repository:
ViewVC logotype

Diff of /Sprout/Sprout.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.125, Mon Mar 16 00:24:23 2009 UTC revision 1.128, Tue Jun 30 19:53:01 2009 UTC
# Line 45  Line 45 
45    
46  =head3 new  =head3 new
47    
48      my $sprout = Sprout->new($dbName, \%options);      my $sprout = Sprout->new(%parms)
49    
50  This is the constructor for a sprout object. It connects to the database and loads the  This is the constructor for a sprout object. It connects to the database and loads the
51  database definition into memory. The positional first parameter specifies the name of the  database definition into memory. The incoming parameter hash has the following permissible
52  database.  members (others will be ignored without error.
53    
54  =over 4  =over 4
55    
56    =item DBD
57    
58    Name of the XML file containing the database definition (default C<SproutDBD.xml> in
59    the DBD directory).
60    
61  =item dbName  =item dbName
62    
63  Name of the database. If omitted, the default Sprout database name is used.  Name of the database. If omitted, the default Sprout database name is used.
64    
65  =item options  =item options
66    
67  Table of options.  Sub-hash of special options.
68    
69  * B<dbType> type of database (currently C<mysql> for MySQL and C<pg> for PostgreSQL) (default C<mysql>)  * B<dbType> type of database (currently C<mysql> for MySQL and C<pg> for PostgreSQL) (default C<mysql>)
70    
71  * B<dataDir> directory containing the database definition file and the flat files used to load the data (default C<Data>)  * B<dataDir> directory containing the database definition file and the flat files used to load the data (default C<Data>)
72    
 * B<xmlFileName> name of the XML file containing the database definition (default C<SproutDBD.xml>)  
   
73  * B<userData> user name and password, delimited by a slash (default same as SEED)  * B<userData> user name and password, delimited by a slash (default same as SEED)
74    
75  * B<port> connection port (default C<0>)  * B<port> connection port (default C<0>)
# Line 87  Line 90 
90  I<fig> with a password of I<admin>. The database load files are in the directory  I<fig> with a password of I<admin>. The database load files are in the directory
91  F</usr/fig/SproutData>.  F</usr/fig/SproutData>.
92    
93      my $sprout = Sprout->new('Sprout', { userData => 'fig/admin', dataDir => '/usr/fig/SproutData' });      my $sprout = Sprout->new(dbName => 'Sprout', options => { userData => 'fig/admin', dataDir => '/usr/fig/SproutData' });
   
 In order to work properly with [[ERDBGeneratorPl]], the constructor has an alternate  
 form.  
94    
95      my $sprout = Sprout->new(dbd => $filename);  The odd constructor signature is a result of Sprout's status as the first ERDB database,
96    and the need to make it compatible with the needs of its younger siblings.
 Where I<$fileName> is the name of the DBD file. This enables us to specify an alternate  
 DBD for the loader, which is important when the database format changes.  
97    
98  =cut  =cut
99    
100  sub new {  sub new {
101      # Get the parameters.      # Get the parameters.
102      my ($class, $dbName, $options) = @_;      my ($class, %parms) = @_;
103      # Check for the alternate signature, and default the database name if it is missing.      # Look for an options hash.
104      if ($dbName eq 'dbd') {      my $options = $parms{options} || {};
105          $dbName = $FIG_Config::sproutDB;      # Plug in the DBD and name parameters.
106          $options = { xmlFileName => $options };      if ($parms{DBD}) {
107      } elsif (! defined $dbName) {          $options->{xmlFileName} = $parms{DBD};
         $dbName = $FIG_Config::sproutDB;  
     } elsif (ref $dbName eq 'HASH') {  
         $options = $dbName;  
         $dbName = $FIG_Config::sproutDB;  
108      }      }
109        my $dbName = $parms{dbName} || $FIG_Config::sproutDB;
110      # Compute the DBD directory.      # Compute the DBD directory.
111      my $dbd_dir = (defined($FIG_Config::dbd_dir) ? $FIG_Config::dbd_dir :      my $dbd_dir = (defined($FIG_Config::dbd_dir) ? $FIG_Config::dbd_dir :
112                                                    $FIG_Config::fig );                                                    $FIG_Config::fig );
# Line 746  Line 741 
741      return $retVal;      return $retVal;
742  }  }
743    
744    =head3 Cleanup
745    
746        $sprout->Cleanup();
747    
748    Release the internal cache structures to free up memory.
749    
750    =cut
751    
752    sub Cleanup {
753        # Get the parameters.
754        my ($self) = @_;
755        # Delete the stemmer.
756        delete $self->{stemmer};
757        # Delete the attribute database.
758        delete $self->{_ca};
759        # Delete the group hash.
760        delete $self->{groupHash};
761        # Is there a FIG object?
762        if (defined $self->{fig}) {
763            # Yes, clear its subsystem cache.
764            $self->{fig}->clear_subsystem_cache();
765        }
766    }
767    
768    
769  =head3 Stem  =head3 Stem
770    
# Line 1000  Line 1019 
1019  }  }
1020    
1021    
   
1022  =head3 PointLocation  =head3 PointLocation
1023    
1024      my $found = Sprout::PointLocation($location, $point);      my $found = Sprout::PointLocation($location, $point);
# Line 4066  Line 4084 
4084  sub GetSourceObject {  sub GetSourceObject {
4085      # Get the parameters.      # Get the parameters.
4086      my ($self) = @_;      my ($self) = @_;
4087      # Check to see if we already have a source object.      # Do we already have one?
4088      my $retVal = $self->{_fig};      my $retVal = $self->{fig};
4089      if (! defined $retVal) {      if (! defined $retVal) {
4090          # No, so create one.          # Create the object.
4091          require FIG;          require FIG;
4092          $retVal = FIG->new();          $retVal = FIG->new();
4093            Trace("FIG source object created for process $$.") if T(ERDBLoadGroup => 3);
4094            # Set up retries to prevent the lost-connection error when harvesting
4095            # the feature data.
4096            my $dbh = $retVal->db_handle();
4097            $dbh->set_retries(5);
4098            # Save it for other times.
4099            $self->{fig} = $retVal;
4100      }      }
4101      # Return the object.      # Return the object.
4102      return $retVal;      return $retVal;
# Line 4079  Line 4104 
4104    
4105  =head3 SectionList  =head3 SectionList
4106    
4107      my @sections = $erdb->SectionList();      my @sections = $erdb->SectionList($fig);
4108    
4109  Return a list of the names for the different data sections used when loading this database.  Return a list of the names for the different data sections used when loading this database.
4110  The default is a single string, in which case there is only one section representing the  The default is a single string, in which case there is only one section representing the
# Line 4092  Line 4117 
4117      my ($self, $source) = @_;      my ($self, $source) = @_;
4118      # Ask the BaseSproutLoader for a section list.      # Ask the BaseSproutLoader for a section list.
4119      require BaseSproutLoader;      require BaseSproutLoader;
4120      my @retVal = BaseSproutLoader::GetSectionList($self);      my @retVal = BaseSproutLoader::GetSectionList($self, $source);
4121      # Return the list.      # Return the list.
4122      return @retVal;      return @retVal;
4123  }  }
# Line 4102  Line 4127 
4127      my $groupLoader = $erdb->Loader($groupName, $options);      my $groupLoader = $erdb->Loader($groupName, $options);
4128    
4129  Return an [[ERDBLoadGroupPm]] object for the specified load group. This method is used  Return an [[ERDBLoadGroupPm]] object for the specified load group. This method is used
4130  by [[ERDBGeneratorPl]] to create the load group objects. If you are not using  by L<ERDBGenerator.pl> to create the load group objects. If you are not using
4131  [[ERDBGeneratorPl]], you don't need to override this method.  L<ERDBGenerator.pl>, you don't need to override this method.
4132    
4133  =over 4  =over 4
4134    
# Line 4146  Line 4171 
4171      my @groups = $erdb->LoadGroupList();      my @groups = $erdb->LoadGroupList();
4172    
4173  Returns a list of the names for this database's load groups. This method is used  Returns a list of the names for this database's load groups. This method is used
4174  by [[ERDBGeneratorPl]] when the user wishes to load all table groups. The default  by L<ERDBGenerator.pl> when the user wishes to load all table groups. The default
4175  is a single group called 'All' that loads everything.  is a single group called 'All' that loads everything.
4176    
4177  =cut  =cut
4178    
4179  sub LoadGroupList {  sub LoadGroupList {
4180      # Return the list.      # Return the list.
4181      return qw(Genome Subsystem Annotation Property Source Reaction Synonym Feature Drug);      return qw(Feature Subsystem Genome Annotation Property Source Reaction Synonym Drug);
4182  }  }
4183    
4184  =head3 LoadDirectory  =head3 LoadDirectory

Legend:
Removed from v.1.125  
changed lines
  Added in v.1.128

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3