[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.89, Wed Sep 27 16:55:38 2006 UTC revision 1.99, Fri Apr 27 22:21:46 2007 UTC
# Line 5  Line 5 
5      @ISA = qw(Exporter ERDB);      @ISA = qw(Exporter ERDB);
6      use Data::Dumper;      use Data::Dumper;
7      use strict;      use strict;
     use Carp;  
8      use DBKernel;      use DBKernel;
9      use XML::Simple;      use XML::Simple;
10      use DBQuery;      use DBQuery;
11      use DBObject;      use ERDBObject;
12      use Tracer;      use Tracer;
13      use FIGRules;      use FIGRules;
14      use FidCheck;      use FidCheck;
15      use Stats;      use Stats;
16      use POSIX qw(strftime);      use POSIX qw(strftime);
17      use BasicLocation;      use BasicLocation;
18        use CustomAttributes;
19        use RemoteCustomAttributes;
20    
21  =head1 Sprout Database Manipulation Object  =head1 Sprout Database Manipulation Object
22    
# Line 133  Line 134 
134      $retVal->{_xmlName} = $xmlFileName;      $retVal->{_xmlName} = $xmlFileName;
135      # Set up space for the group file data.      # Set up space for the group file data.
136      $retVal->{groupHash} = undef;      $retVal->{groupHash} = undef;
137        # Connect to the attributes.
138        if ($FIG_Config::attrURL) {
139            Trace("Remote attribute server $FIG_Config::attrURL chosen.") if T(3);
140            $retVal->{_ca} = RemoteCustomAttributes->new($FIG_Config::attrURL);
141        } elsif ($FIG_Config::attrDbName) {
142            Trace("Local attribute database $FIG_Config::attrDbName chosen.") if T(3);
143            my $user = ($FIG_Config::arch eq 'win' ? 'self' : scalar(getpwent()));
144            $retVal->{_ca} = CustomAttributes->new(user => $user);
145        }
146      # Return it.      # Return it.
147      return $retVal;      return $retVal;
148  }  }
# Line 921  Line 931 
931      my ($self, $genomeID) = @_;      my ($self, $genomeID) = @_;
932      # Declare the return variable.      # Declare the return variable.
933      my $retVal = {};      my $retVal = {};
934      # Query the genome's features and annotations. We'll put the oldest annotations      # Query the genome's features.
935      # first so that the last assignment to go into the hash will be the correct one.      my $query = $self->Get(['HasFeature', 'Feature'], "HasFeature(from-link) = ?",
     my $query = $self->Get(['HasFeature', 'IsTargetOfAnnotation', 'Annotation'],  
                            "HasFeature(from-link) = ? ORDER BY Annotation(time)",  
936                             [$genomeID]);                             [$genomeID]);
937      # Loop through the annotations.      # Loop through the features.
938      while (my $data = $query->Fetch) {      while (my $data = $query->Fetch) {
939          # Get the feature ID and annotation text.          # Get the feature ID and assignment.
940          my ($fid, $annotation) = $data->Values(['HasFeature(to-link)',          my ($fid, $assignment) = $data->Values(['Feature(id)', 'Feature(assignment)']);
941                                                  'Annotation(annotation)']);          if ($assignment) {
         # Check to see if this is an assignment. Note that the user really  
         # doesn't matter to us, other than we use it to determine whether or  
         # not this is an assignment.  
         my ($user, $assignment) = _ParseAssignment('fig', $annotation);  
         if ($user) {  
             # Here it's an assignment. We put it in the return hash, overwriting  
             # any older assignment that might be present.  
942              $retVal->{$fid} = $assignment;              $retVal->{$fid} = $assignment;
943          }          }
944      }      }
# Line 1299  Line 1300 
1300  Return the most recently-determined functional assignment of a particular feature.  Return the most recently-determined functional assignment of a particular feature.
1301    
1302  The functional assignment is handled differently depending on the type of feature. If  The functional assignment is handled differently depending on the type of feature. If
1303  the feature is identified by a FIG ID (begins with the string C<fig|>), then a functional  the feature is identified by a FIG ID (begins with the string C<fig|>), then the functional
1304  assignment is a type of annotation. The format of an assignment is described in  assignment is taken from the B<Feature> or C<Annotation> table, depending.
 L</ParseAssignment>. Its worth noting that we cannot filter on the content of the  
 annotation itself because it's a text field; however, this is not a big problem because  
 most features only have a small number of annotations.  
1305    
1306  Each user has an associated list of trusted users. The assignment returned will be the most  Each user has an associated list of trusted users. The assignment returned will be the most
1307  recent one by at least one of the trusted users. If no trusted user list is available, then  recent one by at least one of the trusted users. If no trusted user list is available, then
# Line 1322  Line 1320 
1320    
1321  =item userID (optional)  =item userID (optional)
1322    
1323  ID of the user whose function determination is desired. If omitted, only the latest  ID of the user whose function determination is desired. If omitted, the primary
1324  C<FIG> assignment will be returned.  functional assignment in the B<Feature> table will be returned.
1325    
1326  =item RETURN  =item RETURN
1327    
# Line 1340  Line 1338 
1338      my $retVal;      my $retVal;
1339      # Determine the ID type.      # Determine the ID type.
1340      if ($featureID =~ m/^fig\|/) {      if ($featureID =~ m/^fig\|/) {
1341          # Here we have a FIG feature ID. We must build the list of trusted          # Here we have a FIG feature ID.
1342          # users.          if (!$userID) {
1343                # Use the primary assignment.
1344                ($retVal) = $self->GetEntityValues('Feature', $featureID, ['Feature(assignment)']);
1345            } else {
1346                # We must build the list of trusted users.
1347          my %trusteeTable = ();          my %trusteeTable = ();
1348          # Check the user ID.          # Check the user ID.
1349          if (!$userID) {          if (!$userID) {
# Line 1384  Line 1386 
1386                  }                  }
1387              }              }
1388          }          }
1389            }
1390      } else {      } else {
1391          # Here we have a non-FIG feature ID. In this case the user ID does not          # Here we have a non-FIG feature ID. In this case the user ID does not
1392          # matter. We simply get the information from the External Alias Function          # matter. We simply get the information from the External Alias Function
# Line 1504  Line 1507 
1507          # Peel off the BBHs found.          # Peel off the BBHs found.
1508          my @found = ();          my @found = ();
1509          for my $bbh (@bbhData) {          for my $bbh (@bbhData) {
1510              push @found, $bbh->[0];              my $fid = $bbh->[0];
1511                my $bbGenome = $self->GenomeOf($fid);
1512                if ($bbGenome eq $genomeID) {
1513                    push @found, $fid;
1514                }
1515          }          }
1516          $retVal{$featureID} = \@found;          $retVal{$featureID} = \@found;
1517      }      }
# Line 2536  Line 2543 
2543    
2544  Return a list of the properties with the specified characteristics.  Return a list of the properties with the specified characteristics.
2545    
2546  Properties are arbitrary key-value pairs associated with a feature. (At some point they  Properties are the Sprout analog of the FIG attributes. The call is
2547  will also be associated with genomes.) A property value is represented by a 4-tuple of  passed directly to the CustomAttributes or RemoteCustomAttributes object
2548  the form B<($fid, $key, $value, $url)>. These exactly correspond to the parameter  contained in this object.
2549    
2550  =over 4  This method returns a series of tuples that match the specified criteria. Each tuple
2551    will contain an object ID, a key, and one or more values. The parameters to this
2552    method therefore correspond structurally to the values expected in each tuple. In
2553    addition, you can ask for a generic search by suffixing a percent sign (C<%>) to any
2554    of the parameters. So, for example,
2555    
2556  =item fid      my @attributeList = $sprout->GetProperties('fig|100226.1.peg.1004', 'structure%', 1, 2);
2557    
2558  ID of the feature possessing the property.  would return something like
2559    
2560  =item key      ['fig}100226.1.peg.1004', 'structure', 1, 2]
2561        ['fig}100226.1.peg.1004', 'structure1', 1, 2]
2562        ['fig}100226.1.peg.1004', 'structure2', 1, 2]
2563        ['fig}100226.1.peg.1004', 'structureA', 1, 2]
2564    
2565  Name or key of the property.  Use of C<undef> in any position acts as a wild card (all values). You can also specify
2566    a list reference in the ID column. Thus,
2567    
2568  =item value      my @attributeList = $sprout->GetProperties(['100226.1', 'fig|100226.1.%'], 'PUBMED');
2569    
2570  Value of the property.  would get the PUBMED attribute data for Streptomyces coelicolor A3(2) and all its
2571    features.
2572    
2573  =item url  In addition to values in multiple sections, a single attribute key can have multiple
2574    values, so even
2575    
2576  URL of the document that indicated the property should have this particular value, or an      my @attributeList = $sprout->GetProperties($peg, 'virulent');
 empty string if no such document exists.  
2577    
2578  =back  which has no wildcard in the key or the object ID, may return multiple tuples.
2579    
2580  The parameters act as a filter for the desired data. Any non-null parameter will  =over 4
2581  automatically match all the tuples returned. So, specifying just the I<$fid> will  
2582  return all the properties of the specified feature; similarly, specifying the I<$key>  =item objectID
2583  and I<$value> parameters will return all the features having the specified property  
2584  value.  ID of object whose attributes are desired. If the attributes are desired for multiple
2585    objects, this parameter can be specified as a list reference. If the attributes are
2586    desired for all objects, specify C<undef> or an empty string. Finally, you can specify
2587    attributes for a range of object IDs by putting a percent sign (C<%>) at the end.
2588    
2589  A single property key can have many values, representing different ideas about the  =item key
 feature in question. For example, one paper may declare that a feature C<fig|83333.1.peg.10> is  
 virulent, and another may declare that it is not virulent. A query about the virulence of  
 C<fig|83333.1.peg.10> would be coded as  
2590    
2591      my @list = $sprout->GetProperties('fig|83333.1.peg.10', 'virulence', '', '');  Attribute key name. A value of C<undef> or an empty string will match all
2592    attribute keys. If the values are desired for multiple keys, this parameter can be
2593    specified as a list reference. Finally, you can specify attributes for a range of
2594    keys by putting a percent sign (C<%>) at the end.
2595    
2596    =item values
2597    
2598    List of the desired attribute values, section by section. If C<undef>
2599    or an empty string is specified, all values in that section will match. A
2600    generic match can be requested by placing a percent sign (C<%>) at the end.
2601    In that case, all values that match up to and not including the percent sign
2602    will match. You may also specify a regular expression enclosed
2603    in slashes. All values that match the regular expression will be returned. For
2604    performance reasons, only values have this extra capability.
2605    
2606  Here the I<$value> and I<$url> fields are left blank, indicating that those fields are  =item RETURN
 not to be filtered. The tuples returned would be  
2607    
2608      ('fig|83333.1.peg.10', 'virulence', 'yes', 'http://www.somewhere.edu/first.paper.pdf')  Returns a list of tuples. The first element in the tuple is an object ID, the
2609      ('fig|83333.1.peg.10', 'virulence', 'no', 'http://www.somewhere.edu/second.paper.pdf')  second is an attribute key, and the remaining elements are the sections of
2610    the attribute value. All of the tuples will match the criteria set forth in
2611    the parameter list.
2612    
2613    =back
2614    
2615  =cut  =cut
2616  #: Return Type @@;  
2617  sub GetProperties {  sub GetProperties {
2618      # Get the parameters.      # Get the parameters.
2619      my ($self, @parms) = @_;      my ($self, @parms) = @_;
2620      # Declare the return variable.      # Declare the return variable.
2621      my @retVal = ();      my @retVal = $self->{_ca}->GetAttributes(@parms);
     # Now we need to create a WHERE clause that will get us the data we want. First,  
     # we create a list of the columns containing the data for each parameter.  
     my @colNames = ('HasProperty(from-link)', 'Property(property-name)',  
                     'Property(property-value)', 'HasProperty(evidence)');  
     # Now we build the WHERE clause and the list of parameter values.  
     my @where = ();  
     my @values = ();  
     for (my $i = 0; $i <= $#colNames; $i++) {  
         my $parm = $parms[$i];  
         if (defined $parm && ($parm ne '')) {  
             push @where, "$colNames[$i] = ?";  
             push @values, $parm;  
         }  
     }  
     # Format the WHERE clause.  
     my $filter = (@values > 0 ? (join " AND ", @where) : undef);  
     # Ask for all the propertie values with the desired characteristics.  
     my $query = $self->Get(['HasProperty', 'Property'], $filter, \@values);  
     while (my $valueObject = $query->Fetch()) {  
         my @tuple = $valueObject->Values(\@colNames);  
         push @retVal, \@tuple;  
     }  
2622      # Return the result.      # Return the result.
2623      return @retVal;      return @retVal;
2624  }  }
# Line 2621  Line 2631 
2631  that specify special characteristics of the feature. For example, a property could indicate  that specify special characteristics of the feature. For example, a property could indicate
2632  that a feature is essential to the survival of the organism or that it has benign influence  that a feature is essential to the survival of the organism or that it has benign influence
2633  on the activities of a pathogen. Each property is returned as a triple of the form  on the activities of a pathogen. Each property is returned as a triple of the form
2634  C<($key,$value,$url)>, where C<$key> is the property name, C<$value> is its value (commonly  C<($key,@values)>, where C<$key> is the property name and  C<@values> are its values.
 a 1 or a 0, but possibly a string or a floating-point value), and C<$url> is a string describing  
 the web address or citation in which the property's value for the feature was identified.  
2635    
2636  =over 4  =over 4
2637    
# Line 2633  Line 2641 
2641    
2642  =item RETURN  =item RETURN
2643    
2644  Returns a list of triples, each triple containing the property name, its value, and a URL or  Returns a list of tuples, each tuple containing the property name and its values.
 citation.  
2645    
2646  =back  =back
2647    
# Line 2644  Line 2651 
2651      # Get the parameters.      # Get the parameters.
2652      my ($self, $featureID) = @_;      my ($self, $featureID) = @_;
2653      # Get the properties.      # Get the properties.
2654      my @retVal = $self->GetAll(['HasProperty', 'Property'], "HasProperty(from-link) = ?", [$featureID],      my @attributes = $self->{_ca}->GetAttributes($featureID);
2655                              ['Property(property-name)', 'Property(property-value)',      # Strip the feature ID off each tuple.
2656                               'HasProperty(evidence)']);      my @retVal = ();
2657        for my $attributeRow (@attributes) {
2658            shift @{$attributeRow};
2659            push @retVal, $attributeRow;
2660        }
2661      # Return the resulting list.      # Return the resulting list.
2662      return @retVal;      return @retVal;
2663  }  }
# Line 2684  Line 2695 
2695  C<< my $id = $sprout->PropertyID($propName, $propValue); >>  C<< my $id = $sprout->PropertyID($propName, $propValue); >>
2696    
2697  Return the ID of the specified property name and value pair, if the  Return the ID of the specified property name and value pair, if the
2698  pair exists.  pair exists. Only a small subset of the FIG attributes are stored as
2699    Sprout properties, mostly for use in search optimization.
2700    
2701  =over 4  =over 4
2702    
# Line 3149  Line 3161 
3161      # Loop through the input triples.      # Loop through the input triples.
3162      my $n = length $sequence;      my $n = length $sequence;
3163      for (my $i = 0; $i < $n; $i += 3) {      for (my $i = 0; $i < $n; $i += 3) {
3164          # Get the current triple from the sequence.          # Get the current triple from the sequence. Note we convert to
3165          my $triple = substr($sequence, $i, 3);          # upper case to insure a match.
3166            my $triple = uc substr($sequence, $i, 3);
3167          # Translate it using the table.          # Translate it using the table.
3168          my $protein = "X";          my $protein = "X";
3169          if (exists $table->{$triple}) { $protein = $table->{$triple}; }          if (exists $table->{$triple}) { $protein = $table->{$triple}; }
# Line 3183  Line 3196 
3196      return @retVal;      return @retVal;
3197  }  }
3198    
3199    =head3 BBHMatrix
3200    
3201    C<< my %bbhMap = $sprout->BBHMatrix($genomeID, $cutoff, @targets); >>
3202    
3203    Find all the bidirectional best hits for the features of a genome in a
3204    specified list of target genomes. The return value will be a hash mapping
3205    features in the original genome to their bidirectional best hits in the
3206    target genomes.
3207    
3208    =over 4
3209    
3210    =item genomeID
3211    
3212    ID of the genome whose features are to be examined for bidirectional best hits.
3213    
3214    =item cutoff
3215    
3216    A cutoff value. Only hits with a score lower than the cutoff will be returned.
3217    
3218    =item targets
3219    
3220    List of target genomes. Only pairs originating in the original
3221    genome and landing in one of the target genomes will be returned.
3222    
3223    =item RETURN
3224    
3225    Returns a hash mapping each feature in the original genome to a hash mapping its
3226    BBH pegs in the target genomes to their scores.
3227    
3228    =back
3229    
3230    =cut
3231    
3232    sub BBHMatrix {
3233        # Get the parameters.
3234        my ($self, $genomeID, $cutoff, @targets) = @_;
3235        # Declare the return variable.
3236        my %retVal = ();
3237        # Ask for the BBHs.
3238        my @bbhList = FIGRules::BatchBBHs("fig|$genomeID.%", $cutoff, @targets);
3239        # We now have a set of 4-tuples that we need to convert into a hash of hashes.
3240        for my $bbhData (@bbhList) {
3241            my ($peg1, $peg2, $score) = @{$bbhData};
3242            if (! exists $retVal{$peg1}) {
3243                $retVal{$peg1} = { $peg2 => $score };
3244            } else {
3245                $retVal{$peg1}->{$peg2} = $score;
3246            }
3247        }
3248        # Return the result.
3249        return %retVal;
3250    }
3251    
3252    
3253    =head3 SimMatrix
3254    
3255    C<< my %simMap = $sprout->SimMatrix($genomeID, $cutoff, @targets); >>
3256    
3257    Find all the similarities for the features of a genome in a
3258    specified list of target genomes. The return value will be a hash mapping
3259    features in the original genome to their similarites in the
3260    target genomes.
3261    
3262    =over 4
3263    
3264    =item genomeID
3265    
3266    ID of the genome whose features are to be examined for similarities.
3267    
3268    =item cutoff
3269    
3270    A cutoff value. Only hits with a score lower than the cutoff will be returned.
3271    
3272    =item targets
3273    
3274    List of target genomes. Only pairs originating in the original
3275    genome and landing in one of the target genomes will be returned.
3276    
3277    =item RETURN
3278    
3279    Returns a hash mapping each feature in the original genome to a hash mapping its
3280    similar pegs in the target genomes to their scores.
3281    
3282    =back
3283    
3284    =cut
3285    
3286    sub SimMatrix {
3287        # Get the parameters.
3288        my ($self, $genomeID, $cutoff, @targets) = @_;
3289        # Declare the return variable.
3290        my %retVal = ();
3291        # Get the list of features in the source organism.
3292        my @fids = $self->FeaturesOf($genomeID);
3293        # Ask for the sims. We only want similarities to fig features.
3294        my $simList = FIGRules::GetNetworkSims($self, \@fids, {}, 1000, $cutoff, "fig");
3295        if (! defined $simList) {
3296            Confess("Unable to retrieve similarities from server.");
3297        } else {
3298            Trace("Processing sims.") if T(3);
3299            # We now have a set of sims that we need to convert into a hash of hashes. First, we
3300            # Create a hash for the target genomes.
3301            my %targetHash = map { $_ => 1 } @targets;
3302            for my $simData (@{$simList}) {
3303                # Get the PEGs and the score.
3304                my ($peg1, $peg2, $score) = ($simData->id1, $simData->id2, $simData->psc);
3305                # Insure the second ID is in the target list.
3306                my ($genome2) = FIGRules::ParseFeatureID($peg2);
3307                if (exists $targetHash{$genome2}) {
3308                    # Here it is. Now we need to add it to the return hash. How we do that depends
3309                    # on whether or not $peg1 is new to us.
3310                    if (! exists $retVal{$peg1}) {
3311                        $retVal{$peg1} = { $peg2 => $score };
3312                    } else {
3313                        $retVal{$peg1}->{$peg2} = $score;
3314                    }
3315                }
3316            }
3317        }
3318        # Return the result.
3319        return %retVal;
3320    }
3321    
3322    
3323  =head3 LowBBHs  =head3 LowBBHs
3324    
3325  C<< my %bbhMap = $sprout->LowBBHs($featureID, $cutoff); >>  C<< my %bbhMap = $sprout->LowBBHs($featureID, $cutoff); >>
# Line 3218  Line 3355 
3355      my @bbhList = FIGRules::BBHData($featureID, $cutoff);      my @bbhList = FIGRules::BBHData($featureID, $cutoff);
3356      # Form the results into the return hash.      # Form the results into the return hash.
3357      for my $pair (@bbhList) {      for my $pair (@bbhList) {
3358          $retVal{$pair->[0]} = $pair->[1];          my $fid = $pair->[0];
3359            if ($self->Exists('Feature', $fid)) {
3360                $retVal{$fid} = $pair->[1];
3361            }
3362      }      }
3363      # Return the result.      # Return the result.
3364      return %retVal;      return %retVal;
# Line 3236  Line 3376 
3376  Similarities can be either raw or expanded. The raw similarities are basic  Similarities can be either raw or expanded. The raw similarities are basic
3377  hits between features with similar DNA. Expanding a raw similarity drags in any  hits between features with similar DNA. Expanding a raw similarity drags in any
3378  features considered substantially identical. So, for example, if features B<A1>,  features considered substantially identical. So, for example, if features B<A1>,
3379  B<A2>, and B<A3> are all substatially identical to B<A>, then a raw similarity  B<A2>, and B<A3> are all substantially identical to B<A>, then a raw similarity
3380  B<[C,A]> would be expanded to B<[C,A] [C,A1] [C,A2] [C,A3]>.  B<[C,A]> would be expanded to B<[C,A] [C,A1] [C,A2] [C,A3]>.
3381    
3382  =over 4  =over 4
# Line 3289  Line 3429 
3429      return $retVal;      return $retVal;
3430  }  }
3431    
3432    =head3 IsAllGenomes
3433    
3434    C<< my $flag = $sprout->IsAllGenomes(\@list, \@checkList); >>
3435    
3436    Return TRUE if all genomes in the second list are represented in the first list at
3437    least one. Otherwise, return FALSE. If the second list is omitted, the first list is
3438    compared to a list of all the genomes.
3439    
3440    =over 4
3441    
3442    =item list
3443    
3444    Reference to the list to be compared to the second list.
3445    
3446    =item checkList (optional)
3447    
3448    Reference to the comparison target list. Every genome ID in this list must occur at
3449    least once in the first list. If this parameter is omitted, a list of all the genomes
3450    is used.
3451    
3452    =item RETURN
3453    
3454    Returns TRUE if every item in the second list appears at least once in the
3455    first list, else FALSE.
3456    
3457    =back
3458    
3459    =cut
3460    
3461    sub IsAllGenomes {
3462        # Get the parameters.
3463        my ($self, $list, $checkList) = @_;
3464        # Supply the checklist if it was omitted.
3465        $checkList = [$self->Genomes()] if ! defined($checkList);
3466        # Create a hash of the original list.
3467        my %testList = map { $_ => 1 } @{$list};
3468        # Declare the return variable. We assume that the representation
3469        # is complete and stop at the first failure.
3470        my $retVal = 1;
3471        my $n = scalar @{$checkList};
3472        for (my $i = 0; $retVal && $i < $n; $i++) {
3473            if (! $testList{$checkList->[$i]}) {
3474                $retVal = 0;
3475            }
3476        }
3477        # Return the result.
3478        return $retVal;
3479    }
3480    
3481  =head3 GetGroups  =head3 GetGroups
3482    
3483  C<< my %groups = $sprout->GetGroups(\@groupList); >>  C<< my %groups = $sprout->GetGroups(\@groupList); >>
# Line 3438  Line 3627 
3627      # Get the parameters.      # Get the parameters.
3628      my ($self, $genomeID, $testFlag) = @_;      my ($self, $genomeID, $testFlag) = @_;
3629      # Perform the delete for the genome's features.      # Perform the delete for the genome's features.
3630      my $retVal = $self->Delete('Feature', "fig|$genomeID.%", $testFlag);      my $retVal = $self->Delete('Feature', "fig|$genomeID.%", testMode => $testFlag);
3631      # Perform the delete for the primary genome data.      # Perform the delete for the primary genome data.
3632      my $stats = $self->Delete('Genome', $genomeID, $testFlag);      my $stats = $self->Delete('Genome', $genomeID, testMode => $testFlag);
3633      $retVal->Accumulate($stats);      $retVal->Accumulate($stats);
3634      # Return the result.      # Return the result.
3635      return $retVal;      return $retVal;
# Line 3593  Line 3782 
3782      return %retVal;      return %retVal;
3783  }  }
3784    
3785    =head3 AddProperty
3786    
3787    C<< my  = $sprout->AddProperty($featureID, $key, @values); >>
3788    
3789    Add a new attribute value (Property) to a feature.
3790    
3791    =over 4
3792    
3793    =item peg
3794    
3795    ID of the feature to which the attribute is to be added.
3796    
3797    =item key
3798    
3799    Name of the attribute (key).
3800    
3801    =item values
3802    
3803    Values of the attribute.
3804    
3805    =back
3806    
3807    =cut
3808    #: Return Type ;
3809    sub AddProperty {
3810        # Get the parameters.
3811        my ($self, $featureID, $key, @values) = @_;
3812        # Add the property using the attached attributes object.
3813        $self->{_ca}->AddAttribute($featureID, $key, @values);
3814    }
3815    
3816    =head2 Virtual Methods
3817    
3818    =head3 CleanKeywords
3819    
3820    C<< my $cleanedString = $sprout->CleanKeywords($searchExpression); >>
3821    
3822    Clean up a search expression or keyword list. This involves converting the periods
3823    in EC numbers to underscores, converting non-leading minus signs to underscores,
3824    a vertical bar or colon to an apostrophe, and forcing lower case for all alphabetic
3825    characters. In addition, any extra spaces are removed.
3826    
3827    =over 4
3828    
3829    =item searchExpression
3830    
3831    Search expression or keyword list to clean. Note that a search expression may
3832    contain boolean operators which need to be preserved. This includes leading
3833    minus signs.
3834    
3835    =item RETURN
3836    
3837    Cleaned expression or keyword list.
3838    
3839    =back
3840    
3841    =cut
3842    
3843    sub CleanKeywords {
3844        # Get the parameters.
3845        my ($self, $searchExpression) = @_;
3846        # Perform the standard cleanup.
3847        my $retVal = $self->ERDB::CleanKeywords($searchExpression);
3848        # Fix the periods in EC and TC numbers.
3849        $retVal =~ s/(\d+|\-)\.(\d+|-)\.(\d+|-)\.(\d+|-)/$1_$2_$3_$4/g;
3850        # Fix non-trailing periods.
3851        $retVal =~ s/\.(\w)/_$1/g;
3852        # Fix non-leading minus signs.
3853        $retVal =~ s/(\w)[\-]/$1_/g;
3854        # Fix the vertical bars and colons
3855        $retVal =~ s/(\w)[|:](\w)/$1'$2/g;
3856        # Return the result.
3857        return $retVal;
3858    }
3859    
3860  =head2 Internal Utility Methods  =head2 Internal Utility Methods
3861    
3862  =head3 ParseAssignment  =head3 ParseAssignment
# Line 3682  Line 3946 
3946      return $retVal;      return $retVal;
3947  }  }
3948    
 =head3 AddProperty  
   
 C<< my  = $sprout->AddProperty($featureID, $key, $value, $url); >>  
   
 Add a new attribute value (Property) to a feature. In the SEED system, attributes can  
 be added to almost any object. In Sprout, they can only be added to features. In  
 Sprout, attributes are implemented using I<properties>. A property represents a key/value  
 pair. If the particular key/value pair coming in is not already in the database, a new  
 B<Property> record is created to hold it.  
   
 =over 4  
   
 =item peg  
   
 ID of the feature to which the attribute is to be replied.  
   
 =item key  
   
 Name of the attribute (key).  
   
 =item value  
   
 Value of the attribute.  
   
 =item url  
   
 URL or text citation from which the property was obtained.  
   
 =back  
   
 =cut  
 #: Return Type ;  
 sub AddProperty {  
     # Get the parameters.  
     my ($self, $featureID, $key, $value, $url) = @_;  
     # Declare the variable to hold the desired property ID.  
     my $propID;  
     # Attempt to find a property record for this key/value pair.  
     my @properties = $self->GetFlat(['Property'],  
                                    "Property(property-name) = ? AND Property(property-value) = ?",  
                                    [$key, $value], 'Property(id)');  
     if (@properties) {  
         # Here the property is already in the database. We save its ID.  
         $propID = $properties[0];  
         # Here the property value does not exist. We need to generate an ID. It will be set  
         # to a number one greater than the maximum value in the database. This call to  
         # GetAll will stop after one record.  
         my @maxProperty = $self->GetAll(['Property'], "ORDER BY Property(id) DESC", [], ['Property(id)'],  
                                         1);  
         $propID = $maxProperty[0]->[0] + 1;  
         # Insert the new property value.  
         $self->Insert('Property', { 'property-name' => $key, 'property-value' => $value, id => $propID });  
     }  
     # Now we connect the incoming feature to the property.  
     $self->Insert('HasProperty', { 'from-link' => $featureID, 'to-link' => $propID, evidence => $url });  
 }  
   
3949    
3950  1;  1;

Legend:
Removed from v.1.89  
changed lines
  Added in v.1.99

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3