[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.36, Wed Sep 14 13:52:34 2005 UTC revision 1.42, Tue Oct 18 06:58:09 2005 UTC
# Line 610  Line 610 
610          if ($prevContig eq $contigID && $dir eq $prevDir) {          if ($prevContig eq $contigID && $dir eq $prevDir) {
611              # Here the new segment is in the same direction on the same contig. Insure the              # Here the new segment is in the same direction on the same contig. Insure the
612              # new segment's beginning is next to the old segment's end.              # new segment's beginning is next to the old segment's end.
613              if (($dir eq "-" && $beg == $prevBeg - $prevLen) ||              if ($dir eq "-" && $beg + $len == $prevBeg) {
614                  ($dir eq "+" && $beg == $prevBeg + $prevLen)) {                  # Here we're merging two backward blocks, so we keep the new begin point
615                  # Here we need to merge two segments. Adjust the beginning and length values                  # and adjust the length.
616                  # to include both segments.                  $len += $prevLen;
617                    # Pop the old segment off. The new one will replace it later.
618                    pop @retVal;
619                } elsif ($dir eq "+" && $beg == $prevBeg + $prevLen) {
620                    # Here we need to merge two forward blocks. Adjust the beginning and
621                    # length values to include both segments.
622                  $beg = $prevBeg;                  $beg = $prevBeg;
623                  $len += $prevLen;                  $len += $prevLen;
624                  # Pop the old segment off. The new one will replace it later.                  # Pop the old segment off. The new one will replace it later.
# Line 659  Line 664 
664      shift if UNIVERSAL::isa($_[0],__PACKAGE__);      shift if UNIVERSAL::isa($_[0],__PACKAGE__);
665      my ($location) = @_;      my ($location) = @_;
666      # Parse it into segments.      # Parse it into segments.
667      $location =~ /^(.*)_(\d*)([+-_])(\d*)$/;      $location =~ /^(.+)_(\d+)([+\-_])(\d+)$/;
668      my ($contigID, $start, $dir, $len) = ($1, $2, $3, $4);      my ($contigID, $start, $dir, $len) = ($1, $2, $3, $4);
669      # If the direction is an underscore, convert it to a + or -.      # If the direction is an underscore, convert it to a + or -.
670      if ($dir eq "_") {      if ($dir eq "_") {
# Line 770  Line 775 
775          Trace("Parse of \"$location\" is $beg$dir$len.") if T(SDNA => 4);          Trace("Parse of \"$location\" is $beg$dir$len.") if T(SDNA => 4);
776          if ($dir eq "+") {          if ($dir eq "+") {
777              $start = $beg;              $start = $beg;
778              $stop = $beg + $len;              $stop = $beg + $len - 1;
779          } else {          } else {
780              $start = $beg - $len;              $start = $beg - $len + 1;
781              $stop = $beg + 1;              $stop = $beg;
782          }          }
783          Trace("Looking for sequences containing $start to $stop.") if T(SDNA => 4);          Trace("Looking for sequences containing $start through $stop.") if T(SDNA => 4);
784          my $query = $self->Get(['IsMadeUpOf','Sequence'],          my $query = $self->Get(['IsMadeUpOf','Sequence'],
785              "IsMadeUpOf(from-link) = ? AND IsMadeUpOf(start-position) + IsMadeUpOf(len) > ? AND " .              "IsMadeUpOf(from-link) = ? AND IsMadeUpOf(start-position) + IsMadeUpOf(len) > ? AND " .
786              " IsMadeUpOf(start-position) < ? ORDER BY IsMadeUpOf(start-position)",              " IsMadeUpOf(start-position) <= ? ORDER BY IsMadeUpOf(start-position)",
787              [$contigID, $start, $stop]);              [$contigID, $start, $stop]);
788          # Loop through the sequences.          # Loop through the sequences.
789          while (my $sequence = $query->Fetch()) {          while (my $sequence = $query->Fetch()) {
# Line 790  Line 795 
795              Trace("Sequence is from $startPosition to $stopPosition.") if T(SDNA => 4);              Trace("Sequence is from $startPosition to $stopPosition.") if T(SDNA => 4);
796              # Figure out the start point and length of the relevant section.              # Figure out the start point and length of the relevant section.
797              my $pos1 = ($start < $startPosition ? 0 : $start - $startPosition);              my $pos1 = ($start < $startPosition ? 0 : $start - $startPosition);
798              my $len1 = ($stopPosition <= $stop ? $stopPosition : $stop) - $startPosition - $pos1;              my $len1 = ($stopPosition < $stop ? $stopPosition : $stop) + 1 - $startPosition - $pos1;
799              Trace("Position is $pos1 for length $len1.") if T(SDNA => 4);              Trace("Position is $pos1 for length $len1.") if T(SDNA => 4);
800              # Add the relevant data to the location data.              # Add the relevant data to the location data.
801              $locationDNA .= substr($sequenceData, $pos1, $len1);              $locationDNA .= substr($sequenceData, $pos1, $len1);
# Line 869  Line 874 
874      # Set it from the sequence data, if any.      # Set it from the sequence data, if any.
875      if ($sequence) {      if ($sequence) {
876          my ($start, $len) = $sequence->Values(['IsMadeUpOf(start-position)', 'IsMadeUpOf(len)']);          my ($start, $len) = $sequence->Values(['IsMadeUpOf(start-position)', 'IsMadeUpOf(len)']);
877          $retVal = $start + $len;          $retVal = $start + $len - 1;
878        }
879        # Return the result.
880        return $retVal;
881    }
882    
883    =head3 ClusterPEGs
884    
885    C<< my $clusteredList = $sprout->ClusterPEGs($sub, \@pegs); >>
886    
887    Cluster the PEGs in a list according to the cluster coding scheme of the specified
888    subsystem. In order for this to work properly, the subsystem object must have
889    been used recently to retrieve the PEGs using the B<get_pegs_from_cell> method.
890    This causes the cluster numbers to be pulled into the subsystem's color hash.
891    If a PEG is not found in the color hash, it will not appear in the output
892    sequence.
893    
894    =over 4
895    
896    =item sub
897    
898    Sprout subsystem object for the relevant subsystem, from the L</get_subsystem>
899    method.
900    
901    =item pegs
902    
903    Reference to the list of PEGs to be clustered.
904    
905    =item RETURN
906    
907    Returns a list of the PEGs, grouped into smaller lists by cluster number.
908    
909    =back
910    
911    =cut
912    #: Return Type $@@;
913    sub ClusterPEGs {
914        # Get the parameters.
915        my ($self, $sub, $pegs) = @_;
916        # Declare the return variable.
917        my $retVal = [];
918        # Loop through the PEGs, creating arrays for each cluster.
919        for my $pegID (@{$pegs}) {
920            my $clusterNumber = $sub->get_cluster_number($pegID);
921            # Only proceed if the PEG is in a cluster.
922            if ($clusterNumber >= 0) {
923                # Push this PEG onto the sub-list for the specified cluster number.
924                push @{$retVal->[$clusterNumber]}, $pegID;
925            }
926      }      }
927      # Return the result.      # Return the result.
928      return $retVal;      return $retVal;
# Line 1019  Line 1072 
1072    
1073  =head3 FeatureAnnotations  =head3 FeatureAnnotations
1074    
1075  C<< my @descriptors = $sprout->FeatureAnnotations($featureID); >>  C<< my @descriptors = $sprout->FeatureAnnotations($featureID, $rawFlag); >>
1076    
1077  Return the annotations of a feature.  Return the annotations of a feature.
1078    
# Line 1029  Line 1082 
1082    
1083  ID of the feature whose annotations are desired.  ID of the feature whose annotations are desired.
1084    
1085    =item rawFlag
1086    
1087    If TRUE, the annotation timestamps will be returned in raw form; otherwise, they
1088    will be returned in human-readable form.
1089    
1090  =item RETURN  =item RETURN
1091    
1092  Returns a list of annotation descriptors. Each descriptor is a hash with the following fields.  Returns a list of annotation descriptors. Each descriptor is a hash with the following fields.
1093    
1094  * B<featureID> ID of the relevant feature.  * B<featureID> ID of the relevant feature.
1095    
1096  * B<timeStamp> time the annotation was made, in user-friendly format.  * B<timeStamp> time the annotation was made.
1097    
1098  * B<user> ID of the user who made the annotation  * B<user> ID of the user who made the annotation
1099    
# Line 1047  Line 1105 
1105  #: Return Type @%;  #: Return Type @%;
1106  sub FeatureAnnotations {  sub FeatureAnnotations {
1107      # Get the parameters.      # Get the parameters.
1108      my ($self, $featureID) = @_;      my ($self, $featureID, $rawFlag) = @_;
1109      # Create a query to get the feature's annotations and the associated users.      # Create a query to get the feature's annotations and the associated users.
1110      my $query = $self->Get(['IsTargetOfAnnotation', 'Annotation', 'MadeAnnotation'],      my $query = $self->Get(['IsTargetOfAnnotation', 'Annotation', 'MadeAnnotation'],
1111                             "IsTargetOfAnnotation(from-link) = ?", [$featureID]);                             "IsTargetOfAnnotation(from-link) = ?", [$featureID]);
# Line 1060  Line 1118 
1118              $annotation->Values(['IsTargetOfAnnotation(from-link)',              $annotation->Values(['IsTargetOfAnnotation(from-link)',
1119                                   'Annotation(time)', 'MadeAnnotation(from-link)',                                   'Annotation(time)', 'MadeAnnotation(from-link)',
1120                                   'Annotation(annotation)']);                                   'Annotation(annotation)']);
1121            # Convert the time, if necessary.
1122            if (! $rawFlag) {
1123                $timeStamp = FriendlyTimestamp($timeStamp);
1124            }
1125          # Assemble them into a hash.          # Assemble them into a hash.
1126          my $annotationHash = { featureID => $featureID,          my $annotationHash = { featureID => $featureID,
1127                                 timeStamp => FriendlyTimestamp($timeStamp),                                 timeStamp => $timeStamp,
1128                                 user => $user, text => $text };                                 user => $user, text => $text };
1129          # Add it to the return list.          # Add it to the return list.
1130          push @retVal, $annotationHash;          push @retVal, $annotationHash;
# Line 1266  Line 1328 
1328          my $query = $self->Get(['IsBidirectionalBestHitOf'],          my $query = $self->Get(['IsBidirectionalBestHitOf'],
1329                                 "IsBidirectionalBestHitOf(from-link) = ? AND IsBidirectionalBestHitOf(genome) = ?",                                 "IsBidirectionalBestHitOf(from-link) = ? AND IsBidirectionalBestHitOf(genome) = ?",
1330                                 [$featureID, $genomeID]);                                 [$featureID, $genomeID]);
1331          # Look for the best hit.          # Peel off the BBHs found.
1332          my $bbh = $query->Fetch;          my @found = ();
1333          if ($bbh) {          while (my $bbh = $query->Fetch) {
1334              my ($targetFeature) = $bbh->Value('IsBidirectionalBestHitOf(to-link)');              push @found, $bbh->Value('IsBidirectionalBestHitOf(to-link)');
             $retVal{$featureID} = $targetFeature;  
1335          }          }
1336            $retVal{$featureID} = \@found;
1337      }      }
1338      # Return the mapping.      # Return the mapping.
1339      return \%retVal;      return \%retVal;
# Line 2547  Line 2609 
2609                                      ['HasSSCell(from-link)', 'IsRoleOf(from-link)']);                                      ['HasSSCell(from-link)', 'IsRoleOf(from-link)']);
2610      # Create the return value.      # Create the return value.
2611      my %retVal = ();      my %retVal = ();
2612        # Build a hash to weed out duplicates. Sometimes the same PEG and role appears
2613        # in two spreadsheet cells.
2614        my %dupHash = ();
2615      # Loop through the results, adding them to the hash.      # Loop through the results, adding them to the hash.
2616      for my $record (@subsystems) {      for my $record (@subsystems) {
2617            # Get this subsystem and role.
2618          my ($subsys, $role) = @{$record};          my ($subsys, $role) = @{$record};
2619          if (exists $retVal{$subsys}) {          # Insure it's the first time for both.
2620            my $dupKey = "$subsys\n$role";
2621            if (! exists $dupHash{"$subsys\n$role"}) {
2622                $dupHash{$dupKey} = 1;
2623              push @{$retVal{$subsys}}, $role;              push @{$retVal{$subsys}}, $role;
         } else {  
             $retVal{$subsys} = [$role];  
2624          }          }
2625      }      }
2626      # Return the hash.      # Return the hash.
# Line 3154  Line 3221 
3221    
3222  sub FriendlyTimestamp {  sub FriendlyTimestamp {
3223      my ($timeValue) = @_;      my ($timeValue) = @_;
3224      my $retVal = strftime("%a %b %e %H:%M:%S %Y", localtime($timeValue));      my $retVal = localtime($timeValue);
3225      return $retVal;      return $retVal;
3226  }  }
3227    

Legend:
Removed from v.1.36  
changed lines
  Added in v.1.42

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3