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

Diff of /Sprout/SproutLoad.pm

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

revision 1.74, Sat Oct 21 06:44:17 2006 UTC revision 1.80, Wed Dec 20 20:04:58 2006 UTC
# Line 80  Line 80 
80  Either the name of the file containing the list of trusted subsystems or a reference  Either the name of the file containing the list of trusted subsystems or a reference
81  to a list of subsystem names. If nothing is specified, all NMPDR subsystems will be  to a list of subsystem names. If nothing is specified, all NMPDR subsystems will be
82  considered trusted. (A subsystem is considered NMPDR if it has a file named C<NMPDR>  considered trusted. (A subsystem is considered NMPDR if it has a file named C<NMPDR>
83  in its data directory.) Only subsystem data related to the trusted subsystems is loaded.  in its data directory.) Only subsystem data related to the NMPDR subsystems is loaded.
84    
85  =item options  =item options
86    
# Line 138  Line 138 
138          if (! defined $subsysFile || $subsysFile eq '') {          if (! defined $subsysFile || $subsysFile eq '') {
139              # Here we want all the usable subsystems. First we get the whole list.              # Here we want all the usable subsystems. First we get the whole list.
140              my @subs = $fig->all_subsystems();              my @subs = $fig->all_subsystems();
141              # Loop through, checking for usability.              # Loop through, checking for the NMPDR file.
142              for my $sub (@subs) {              for my $sub (@subs) {
143                  if ($fig->usable_subsystem($sub)) {                  if ($fig->nmpdr_subsystem($sub)) {
144                      $subsystems{$sub} = 1;                      $subsystems{$sub} = 1;
145                  }                  }
146              }              }
# Line 168  Line 168 
168              my $name = $subsystem;              my $name = $subsystem;
169              $name =~ s/_/ /g;              $name =~ s/_/ /g;
170              my $classes = $fig->subsystem_classification($subsystem);              my $classes = $fig->subsystem_classification($subsystem);
171              my @classList = map { " $_" } @{$classes};              $name .= " " . join(" ", @{$classes});
             $name .= join("", @classList);  
172              $subsystems{$subsystem} = $name;              $subsystems{$subsystem} = $name;
173          }          }
174      }      }
# Line 470  Line 469 
469      IsLocatedIn      IsLocatedIn
470      HasFeature      HasFeature
471      HasRoleInSubsystem      HasRoleInSubsystem
472        FeatureEssential
473        FeatureVirulent
474        FeatureIEDB
475    
476  =over 4  =over 4
477    
# Line 498  Line 500 
500      my $loadFeatureUpstream = $self->_TableLoader('FeatureUpstream');      my $loadFeatureUpstream = $self->_TableLoader('FeatureUpstream');
501      my $loadHasFeature = $self->_TableLoader('HasFeature', $self->PrimaryOnly);      my $loadHasFeature = $self->_TableLoader('HasFeature', $self->PrimaryOnly);
502      my $loadHasRoleInSubsystem = $self->_TableLoader('HasRoleInSubsystem', $self->PrimaryOnly);      my $loadHasRoleInSubsystem = $self->_TableLoader('HasRoleInSubsystem', $self->PrimaryOnly);
503        my $loadFeatureEssential = $self->_TableLoader('FeatureEssential');
504        my $loadFeatureVirulent = $self->_TableLoader('FeatureVirulent');
505        my $loadFeatureIEDB = $self->_TableLoader('FeatureIEDB');
506      # Get the subsystem hash.      # Get the subsystem hash.
507      my $subHash = $self->{subsystems};      my $subHash = $self->{subsystems};
508      # Get the maximum sequence size. We need this later for splitting up the      # Get the maximum sequence size. We need this later for splitting up the
# Line 516  Line 521 
521              # Sort and count the list.              # Sort and count the list.
522              my @featureTuples = sort { $a->[0] cmp $b->[0] } @{$features};              my @featureTuples = sort { $a->[0] cmp $b->[0] } @{$features};
523              my $count = scalar @featureTuples;              my $count = scalar @featureTuples;
524                my @fids = map { $_->[0] } @featureTuples;
525              Trace("$count features found for genome $genomeID.") if T(3);              Trace("$count features found for genome $genomeID.") if T(3);
526                # Get the attributes for this genome and put them in a hash by feature ID.
527                my $attributes = GetGenomeAttributes($fig, $genomeID, \@fids);
528              # Set up for our duplicate-feature check.              # Set up for our duplicate-feature check.
529              my $oldFeatureID = "";              my $oldFeatureID = "";
530              # Loop through the features.              # Loop through the features.
# Line 530  Line 538 
538                      $oldFeatureID = $featureID;                      $oldFeatureID = $featureID;
539                      # Count this feature.                      # Count this feature.
540                      $loadFeature->Add("featureIn");                      $loadFeature->Add("featureIn");
541                      # Get the functional assignment.                      # Begin building the keywords. We start with the genome ID, the
542                      my $assignment = $fig->function_of($featureID);                      # feature ID, the taxonomy, and the organism name.
543                      # Begin building the keywords.                      my @keywords = ($genomeID, $featureID, $fig->genus_species($genomeID),
544                      my $keywords = "$assignment $genomeID";                                      $fig->taxonomy_of($genomeID));
545                      # Link this feature to the parent genome.                      # Get the functional assignment and aliases. This
546                      $loadHasFeature->Put($genomeID, $featureID, $type);                      # depends on the feature type.
547                        my $assignment;
548                        if ($type eq "peg") {
549                            $assignment = $fig->function_of($featureID);
550                      # Create the aliases.                      # Create the aliases.
551                      for my $alias ($fig->feature_aliases($featureID)) {                      for my $alias ($fig->feature_aliases($featureID)) {
552                          $loadFeatureAlias->Put($featureID, $alias);                          $loadFeatureAlias->Put($featureID, $alias);
553                          $keywords .= " $alias";                              push @keywords, $alias;
554                            }
555                        } else {
556                            # For other types, the assignment is the first (and ONLY) alias.
557                            ($assignment) = $fig->feature_aliases($featureID);
558                      }                      }
559                        Trace("Assignment for $featureID is: $assignment") if T(4);
560                        # Break the assignment into words and shove it onto the
561                        # keyword list.
562                        push @keywords, split(/\s+/, $assignment);
563                        # Link this feature to the parent genome.
564                        $loadHasFeature->Put($genomeID, $featureID, $type);
565                      # Get the links.                      # Get the links.
566                      my @links = $fig->fid_links($featureID);                      my @links = $fig->fid_links($featureID);
567                      for my $link (@links) {                      for my $link (@links) {
# Line 570  Line 591 
591                              $loadHasRoleInSubsystem->Put($featureID, $subsystem, $genomeID, $type);                              $loadHasRoleInSubsystem->Put($featureID, $subsystem, $genomeID, $type);
592                              # Save the subsystem's keyword data.                              # Save the subsystem's keyword data.
593                              my $subKeywords = $subHash->{$subsystem};                              my $subKeywords = $subHash->{$subsystem};
594                              $keywords .= " $subKeywords";                              push @keywords, split /\s+/, $subKeywords;
595                                # Now we need to get this feature's role in the subsystem.
596                                my $subObject = $fig->get_subsystem($subsystem);
597                                my @roleColumns = $subObject->get_peg_roles($featureID);
598                                my @allRoles = $subObject->get_roles();
599                                for my $col (@roleColumns) {
600                                    my $role = $allRoles[$col];
601                                    push @keywords, split /\s+/, $role;
602                                    push @keywords, $subObject->get_role_abbr($col);
603                                }
604                            }
605                          }                          }
606                        # There are three special attributes computed from property
607                        # data that we build next. If the special attribute is non-empty,
608                        # its name will be added to the keyword list. First, we get all
609                        # the attributes for this feature. They will come back as
610                        # 4-tuples: [peg, name, value, URL]. We use a 3-tuple instead:
611                        # [name, value, value with URL]. (We don't need the PEG, since
612                        # we already know it.)
613                        my @attributes = map { [$_->[1], $_->[2], Tracer::CombineURL($_->[2], $_->[3])] }
614                                             @{$attributes->{$featureID}};
615                        # Now we process each of the special attributes.
616                        if (SpecialAttribute($featureID, \@attributes,
617                                             1, [0,2], '^(essential|potential_essential)$',
618                                             $loadFeatureEssential)) {
619                            push @keywords, 'essential';
620                            $loadFeature->Add('essential');
621                        }
622                        if (SpecialAttribute($featureID, \@attributes,
623                                             0, [2], '^virulen',
624                                             $loadFeatureVirulent)) {
625                            push @keywords, 'virulent';
626                            $loadFeature->Add('virulent');
627                        }
628                        if (SpecialAttribute($featureID, \@attributes,
629                                             0, [0,2], '^iedb_',
630                                             $loadFeatureIEDB)) {
631                            push @keywords, 'iedb';
632                            $loadFeature->Add('iedb');
633                        }
634                        # Now we need to bust up hyphenated words in the keyword
635                        # list. We keep them separate and put them at the end so
636                        # the original word order is available.
637                        my $keywordString = "";
638                        my $bustedString = "";
639                        for my $keyword (@keywords) {
640                            if (length $keyword >= 3) {
641                                $keywordString .= " $keyword";
642                                if ($keyword =~ /-/) {
643                                    my @words = split /-/, $keyword;
644                                    $bustedString .= join(" ", "", @words);
645                      }                      }
                     # The final task is to add virulence and essentiality attributes.  
                     if ($fig->virulent($featureID)) {  
                         $keywords .= " virulent";  
646                      }                      }
                     if ($fig->essential($featureID)) {  
                         $keywords .= " essential";  
647                      }                      }
648                        $keywordString .= $bustedString;
649                        # Get rid of annoying punctuation.
650                        $keywordString =~ s/[();]//g;
651                      # Clean the keyword list.                      # Clean the keyword list.
652                      my $cleanWords = $sprout->CleanKeywords($keywords);                      my $cleanWords = $sprout->CleanKeywords($keywordString);
653                        Trace("Keyword string for $featureID: $cleanWords") if T(4);
654                      # Create the feature record.                      # Create the feature record.
655                      $loadFeature->Put($featureID, 1, $type, $assignment, $cleanWords);                      $loadFeature->Put($featureID, 1, $type, $assignment, $cleanWords);
656                      # This part is the roughest. We need to relate the features to contig                      # This part is the roughest. We need to relate the features to contig
# Line 726  Line 795 
795                  # Now for the classification string. This comes back as a list                  # Now for the classification string. This comes back as a list
796                  # reference and we convert it to a space-delimited string.                  # reference and we convert it to a space-delimited string.
797                  my $classList = $fig->subsystem_classification($subsysID);                  my $classList = $fig->subsystem_classification($subsysID);
798                  my $classString = join(" : ", grep { $_ } @$classList);                  my $classString = join($FIG_Config::splitter, grep { $_ } @$classList);
799                  $loadSubsystemClass->Put($subsysID, $classString);                  $loadSubsystemClass->Put($subsysID, $classString);
800                  # Connect it to its roles. Each role is a column in the subsystem spreadsheet.                  # Connect it to its roles. Each role is a column in the subsystem spreadsheet.
801                  for (my $col = 0; defined($roleID = $sub->get_role($col)); $col++) {                  for (my $col = 0; defined($roleID = $sub->get_role($col)); $col++) {
# Line 939  Line 1008 
1008              my @features = map { $_->[0] } @{$fig->all_features_detailed($genomeID)};              my @features = map { $_->[0] } @{$fig->all_features_detailed($genomeID)};
1009              my $featureCount = 0;              my $featureCount = 0;
1010              my $propertyCount = 0;              my $propertyCount = 0;
1011                # Get the properties for this genome's features.
1012                my $attributes = GetGenomeAttributes($fig, $genomeID, \@features);
1013                Trace("Property hash built for $genomeID.") if T(3);
1014              # Loop through the features, creating HasProperty records.              # Loop through the features, creating HasProperty records.
1015              for my $fid (@features) {              for my $fid (@features) {
1016                  # Get all attributes for this feature. We do this one feature at a time                  # Get all attributes for this feature. We do this one feature at a time
1017                  # to insure we do not get any genome attributes.                  # to insure we do not get any genome attributes.
1018                  my @attributeList = $fig->get_attributes($fid, '', '', '');                  my @attributeList = @{$attributes->{$fid}};
                 # Add essentiality and virulence attributes.  
                 if ($fig->essential($fid)) {  
                     push @attributeList, [$fid, 'essential', 1, ''];  
                 }  
                 if ($fig->virulent($fid)) {  
                     push @attributeList, [$fid, 'virulent', 1, ''];  
                 }  
1019                  if (scalar @attributeList) {                  if (scalar @attributeList) {
1020                      $featureCount++;                      $featureCount++;
1021                  }                  }
# Line 1545  Line 1610 
1610      return $retVal;      return $retVal;
1611  }  }
1612    
1613    =head3 LoadDrugData
1614    
1615    C<< my $stats = $spl->LoadDrugData(); >>
1616    
1617    Load the drug target data into Sprout.
1618    
1619    The following relations are loaded by this method.
1620    
1621        DrugProject
1622        ContainsTopic
1623        DrugTopic
1624        ContainsAnalysisOf
1625        PDB
1626        IncludesBound
1627        IsBoundIn
1628        BindsWith
1629        Ligand
1630        DescribesProteinForFeature
1631        FeatureConservation
1632    
1633    The source information for these relations is taken from flat files in the
1634    C<$FIG_Config::drug_directory>. The file C<master_tables.list> contains
1635    a list of drug project names paired with file names. The named file (in the
1636    same directory) contains all the data for the project.
1637    
1638    =over 4
1639    
1640    =item RETURNS
1641    
1642    Returns a statistics object for the loads.
1643    
1644    =back
1645    
1646    =cut
1647    #: Return Type $%;
1648    sub LoadDrugData {
1649        # Get this object instance.
1650        my ($self) = @_;
1651        # Get the FIG object.
1652        my $fig = $self->{fig};
1653        # Get the genome hash.
1654        my $genomeHash = $self->{genomes};
1655        # Create load objects for the tables we're loading.
1656        my $loadDrugProject = $self->_TableLoader('DrugProject');
1657        my $loadContainsTopic = $self->_TableLoader('ContainsTopic');
1658        my $loadDrugTopic = $self->_TableLoader('DrugTopic');
1659        my $loadContainsAnalysisOf = $self->_TableLoader('ContainsAnalysisOf');
1660        my $loadPDB = $self->_TableLoader('PDB');
1661        my $loadIncludesBound = $self->_TableLoader('IncludesBound');
1662        my $loadIsBoundIn = $self->_TableLoader('IsBoundIn');
1663        my $loadBindsWith = $self->_TableLoader('BindsWith');
1664        my $loadLigand = $self->_TableLoader('Ligand');
1665        my $loadDescribesProteinForFeature = $self->_TableLoader('DescribesProteinForFeature');
1666        my $loadFeatureConservation = $self->_TableLoader('FeatureConservation');
1667        if ($self->{options}->{loadOnly}) {
1668            Trace("Loading from existing files.") if T(2);
1669        } else {
1670            Trace("Generating drug target data.") if T(2);
1671            # Load the project list. The file comes in as a list of chomped lines,
1672            # and we split them on the TAB character to make the project name the
1673            # key and the file name the value of the resulting hash.
1674            my %projects = map { split /\t/, $_ } Tracer::GetFile("$FIG_Config::drug_directory/master_tables.list");
1675            # Create hashes for the derived objects: PDBs, Features, and Ligands. These objects
1676            # may occur multiple times in a single project file or even in multiple project
1677            # files.
1678            my %ligands = ();
1679            my %pdbs = ();
1680            my %features = ();
1681            my %bindings = ();
1682            # Set up a counter for drug topics. This will be used as the key.
1683            my $topicCounter = 0;
1684            # Loop through the projects. We sort the keys not because we need them sorted, but
1685            # because it makes it easier to infer our progress from trace messages.
1686            for my $project (sort keys %projects) {
1687                Trace("Processing project $project.") if T(3);
1688                # Only proceed if the download file exists.
1689                my $projectFile = "$FIG_Config::drug_directory/$projects{$project}";
1690                if (! -f $projectFile) {
1691                    Trace("Project file $projectFile not found.") if T(0);
1692                } else {
1693                    # Create the project record.
1694                    $loadDrugProject->Put($project);
1695                    # Create a hash for the topics. Each project has one or more topics. The
1696                    # topic is identified by a URL, a category, and an identifier.
1697                    my %topics = ();
1698                    # Now we can open the project file.
1699                    Trace("Reading project file $projectFile.") if T(3);
1700                    Open(\*PROJECT, "<$projectFile");
1701                    # Get the first record, which is a list of column headers. We don't use this
1702                    # for anything, but it may be useful for debugging.
1703                    my $headerLine = <PROJECT>;
1704                    # Loop through the rest of the records.
1705                    while (! eof PROJECT) {
1706                        # Get the current line of data. Note that not all lines will have all
1707                        # the fields. In particular, the CLIBE data is fairly rare.
1708                        my ($authorOrganism, $category, $tag, $refURL, $peg, $conservation,
1709                            $pdbBound, $pdbBoundEval, $pdbFree, $pdbFreeEval, $pdbFreeTitle,
1710                            $protDistInfo, $passAspInfo, $passAspFile, $passWeightInfo,
1711                            $passWeightFile, $clibeInfo, $clibeURL, $clibeTotalEnergy,
1712                            $clibeVanderwaals, $clibeHBonds, $clibeEI, $clibeSolvationE)
1713                           = Tracer::GetLine(\*PROJECT);
1714                        # The tag contains an identifier for the current line of data followed
1715                        # by a text statement that generally matches a property name in the
1716                        # main database. We split it up, since the identifier goes with
1717                        # the PDB data and the text statement is part of the topic.
1718                        my ($lineID, $topicTag) = split /\s*,\s*/, $tag;
1719                        $loadDrugProject->Add("data line");
1720                        # Check for a new topic.
1721                        my $topicData = "$category\t$topicTag\t$refURL";
1722                        if (! exists $topics{$topicData}) {
1723                            # Here we have a new topic. Compute its ID.
1724                            $topicCounter++;
1725                            $topics{$topicData} = $topicCounter;
1726                            # Create its database record.
1727                            $loadDrugTopic->Put($topicCounter, $refURL, $category, $authorOrganism,
1728                                                $topicTag);
1729                            # Connect it to the project.
1730                            $loadContainsTopic->Put($project, $topicCounter);
1731                            $loadDrugTopic->Add("topic");
1732                        }
1733                        # Now we know the topic ID exists in the hash and the topic will
1734                        # appear in the database, so we get this topic's ID.
1735                        my $topicID = $topics{$topicData};
1736                        # If the feature in this line is new, we need to save its conservation
1737                        # number.
1738                        if (! exists $features{$peg}) {
1739                            $loadFeatureConservation->Put($peg, $conservation);
1740                            $features{$peg} = 1;
1741                        }
1742                        # Now we have two PDBs to deal with-- a bound PDB and a free PDB.
1743                        # The free PDB will have data about docking points; the bound PDB
1744                        # will have data about docking. We store both types as PDBs, and
1745                        # the special data comes from relationships. First we process the
1746                        # bound PDB.
1747                        if ($pdbBound) {
1748                            $loadPDB->Add("bound line");
1749                            # Insure this PDB is in the database.
1750                            $self->CreatePDB($pdbBound, lc "$pdbFreeTitle (bound)", "bound", \%pdbs, $loadPDB);
1751                            # Connect it to this topic.
1752                            $loadIncludesBound->Put($topicID, $pdbBound);
1753                            # Check for CLIBE data.
1754                            if ($clibeInfo) {
1755                                $loadLigand->Add("clibes");
1756                                # We have CLIBE data, so we create a ligand and relate it to the PDB.
1757                                if (! exists $ligands{$clibeInfo}) {
1758                                    # This is a new ligand, so create its record.
1759                                    $loadLigand->Put($clibeInfo);
1760                                    $loadLigand->Add("ligand");
1761                                    # Make sure we know this ligand already exists.
1762                                    $ligands{$clibeInfo} = 1;
1763                                }
1764                                # Now connect the PDB to the ligand using the CLIBE data.
1765                                $loadBindsWith->Put($pdbBound, $clibeInfo, $clibeURL, $clibeHBonds, $clibeEI,
1766                                                    $clibeSolvationE, $clibeVanderwaals);
1767                            }
1768                            # Connect this PDB to the feature.
1769                            $loadDescribesProteinForFeature->Put($pdbBound, $peg, $protDistInfo, $pdbBoundEval);
1770                        }
1771                        # Next is the free PDB.
1772                        if ($pdbFree) {
1773                            $loadPDB->Add("free line");
1774                            # Insure this PDB is in the database.
1775                            $self->CreatePDB($pdbFree, lc $pdbFreeTitle, "free", \%pdbs, $loadPDB);
1776                            # Connect it to this topic.
1777                            $loadContainsAnalysisOf->Put($topicID, $pdbFree, $passAspInfo,
1778                                                         $passWeightFile, $passWeightInfo, $passAspFile);
1779                            # Connect this PDB to the feature.
1780                            $loadDescribesProteinForFeature->Put($pdbFree, $peg, $protDistInfo, $pdbFreeEval);
1781                        }
1782                        # If we have both PDBs, we may need to link them.
1783                        if ($pdbFree && $pdbBound) {
1784                            $loadIsBoundIn->Add("connection");
1785                            # Insure we only link them once.
1786                            my $bindingKey =  "$pdbFree\t$pdbBound";
1787                            if (! exists $bindings{$bindingKey}) {
1788                                $loadIsBoundIn->Add("newConnection");
1789                                $loadIsBoundIn->Put($pdbFree, $pdbBound);
1790                                $bindings{$bindingKey} = 1;
1791                            }
1792                        }
1793                    }
1794                    # Close off this project.
1795                    close PROJECT;
1796                }
1797            }
1798        }
1799        # Finish the load.
1800        my $retVal = $self->_FinishAll();
1801        return $retVal;
1802    }
1803    
1804    
1805  =head2 Internal Utility Methods  =head2 Internal Utility Methods
1806    
1807    =head3 SpecialAttribute
1808    
1809    C<< my $count = SproutLoad::SpecialAttribute($id, \@attributes, $idxMatch, \@idxValues, $pattern, $loader); >>
1810    
1811    Look for special attributes of a given type. A special attribute is found by comparing one of
1812    the columns of the incoming attribute list to a search pattern. If a match is found, then
1813    a set of columns is put into an output table connected to the specified ID.
1814    
1815    For example, when processing features, the attribute list we look at has three columns: attribute
1816    name, attribute value, and attribute value HTML. The IEDB attribute exists if the attribute name
1817    begins with C<iedb_>. The call signature is therefore
1818    
1819        my $found = SpecialAttribute($fid, \@attributeList, 0, [0,2], '^iedb_', $loadFeatureIEDB);
1820    
1821    The pattern is matched against column 0, and if we have a match, then column 2's value is put
1822    to the output along with the specified feature ID.
1823    
1824    =over 4
1825    
1826    =item id
1827    
1828    ID of the object whose special attributes are being loaded. This forms the first column of the
1829    output.
1830    
1831    =item attributes
1832    
1833    Reference to a list of tuples.
1834    
1835    =item idxMatch
1836    
1837    Index in each tuple of the column to be matched against the pattern. If the match is
1838    successful, an output record will be generated.
1839    
1840    =item idxValues
1841    
1842    Reference to a list containing the indexes in each tuple of the columns to be put as
1843    the second column of the output.
1844    
1845    =item pattern
1846    
1847    Pattern to be matched against the specified column. The match will be case-insensitive.
1848    
1849    =item loader
1850    
1851    An object to which each output record will be put. Usually this is an B<ERDBLoad> object,
1852    but technically it could be anything with a C<Put> method.
1853    
1854    =item RETURN
1855    
1856    Returns a count of the matches found.
1857    
1858    =item
1859    
1860    =back
1861    
1862    =cut
1863    
1864    sub SpecialAttribute {
1865        # Get the parameters.
1866        my ($id, $attributes, $idxMatch, $idxValues, $pattern, $loader) = @_;
1867        # Declare the return variable.
1868        my $retVal = 0;
1869        # Loop through the attribute rows.
1870        for my $row (@{$attributes}) {
1871            # Check for a match.
1872            if ($row->[$idxMatch] =~ m/$pattern/i) {
1873                # We have a match, so output a row. This is a bit tricky, since we may
1874                # be putting out multiple columns of data from the input.
1875                my $value = join(" ", map { $row->[$_] } @{$idxValues});
1876                $loader->Put($id, $value);
1877                $retVal++;
1878            }
1879        }
1880        Trace("$retVal special attributes found for $id and loader " . $loader->RelName() . ".") if T(4) && $retVal;
1881        # Return the number of matches.
1882        return $retVal;
1883    }
1884    
1885    =head3 CreatePDB
1886    
1887    C<< $loader->CreatePDB($pdbID, $title, $type, \%pdbHash); >>
1888    
1889    Insure that a PDB record exists for the identified PDB. If one does not exist, it will be
1890    created.
1891    
1892    =over 4
1893    
1894    =item pdbID
1895    
1896    ID string (usually an unqualified file name) for the desired PDB.
1897    
1898    =item title
1899    
1900    Title to use if the PDB must be created.
1901    
1902    =item type
1903    
1904    Type of PDB: C<free> or C<bound>
1905    
1906    =item pdbHash
1907    
1908    Hash containing the IDs of PDBs that have already been created.
1909    
1910    =item pdbLoader
1911    
1912    Load object for the PDB table.
1913    
1914    =back
1915    
1916    =cut
1917    
1918    sub CreatePDB {
1919        # Get the parameters.
1920        my ($self, $pdbID, $title, $type, $pdbHash, $pdbLoader) = @_;
1921        $pdbLoader->Add("PDB check");
1922        # Check to see if this is a new PDB.
1923        if (! exists $pdbHash->{$pdbID}) {
1924            # It is, so we create it.
1925            $pdbLoader->Put($pdbID, $title, $type);
1926            $pdbHash->{$pdbID} = 1;
1927            # Count it.
1928            $pdbLoader->Add("PDB-$type");
1929        }
1930    }
1931    
1932  =head3 TableLoader  =head3 TableLoader
1933    
1934  Create an ERDBLoad object for the specified table. The object is also added to  Create an ERDBLoad object for the specified table. The object is also added to
# Line 1651  Line 2031 
2031      # Return the load statistics.      # Return the load statistics.
2032      return $retVal;      return $retVal;
2033  }  }
2034    =head3 GetGenomeAttributes
2035    
2036    C<< my $aHashRef = GetGenomeAttributes($fig, $genomeID, \@fids); >>
2037    
2038    Return a hash of attributes keyed on feature ID. This method gets all the attributes
2039    for all the features of a genome in a single call, then organizes them into a hash.
2040    
2041    =over 4
2042    
2043    =item fig
2044    
2045    FIG-like object for accessing attributes.
2046    
2047    =item genomeID
2048    
2049    ID of the genome who's attributes are desired.
2050    
2051    =item fids
2052    
2053    Reference to a list of the feature IDs whose attributes are to be kept.
2054    
2055    =item RETURN
2056    
2057    Returns a reference to a hash. The key of the hash is the feature ID. The value is the
2058    reference to a list of the feature's attribute tuples. Each tuple contains the feature ID,
2059    the attribute key, and one or more attribute values.
2060    
2061    =back
2062    
2063    =cut
2064    
2065    sub GetGenomeAttributes {
2066        # Get the parameters.
2067        my ($fig, $genomeID, $fids) = @_;
2068        # Declare the return variable.
2069        my $retVal = {};
2070        # Get the attributes.
2071        my @aList = $fig->get_attributes("fig|$genomeID%");
2072        # Initialize the hash. This not only enables us to easily determine which FIDs to
2073        # keep, it insures that the caller sees a list reference for every known fid,
2074        # simplifying the logic.
2075        for my $fid (@{$fids}) {
2076            $retVal->{$fid} = [];
2077        }
2078        # Populate the hash.
2079        for my $aListEntry (@aList) {
2080            my $fid = $aListEntry->[0];
2081            if (exists $retVal->{$fid}) {
2082                push @{$retVal->{$fid}}, $aListEntry;
2083            }
2084        }
2085        # Return the result.
2086        return $retVal;
2087    }
2088    
2089  1;  1;

Legend:
Removed from v.1.74  
changed lines
  Added in v.1.80

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3