[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.8, Thu Jan 27 00:30:20 2005 UTC revision 1.9, Mon Feb 7 00:32:07 2005 UTC
# Line 852  Line 852 
852  Returns a three-element list. The first element is a list of feature IDs for the features that  Returns a three-element list. The first element is a list of feature IDs for the features that
853  overlap the region of interest. The second and third elements are the minimum and maximum  overlap the region of interest. The second and third elements are the minimum and maximum
854  locations of the features provided on the specified contig. These may extend outside  locations of the features provided on the specified contig. These may extend outside
855  the start and stop values.  the start and stop values. The first element (that is, the list of features) is sorted
856    roughly by location.
857    
858  =back  =back
859    
860  =cut  =cut
861  #: Return Type @;  #: Return Type @@;
862  sub GenesInRegion {  sub GenesInRegion {
863          # Get the parameters.          # Get the parameters.
864          my $self = shift @_;          my $self = shift @_;
# Line 865  Line 866 
866          # Get the maximum segment length.          # Get the maximum segment length.
867          my $maximumSegmentLength = $self->MaxSegment;          my $maximumSegmentLength = $self->MaxSegment;
868          # Create a hash to receive the feature list. We use a hash so that we can eliminate          # Create a hash to receive the feature list. We use a hash so that we can eliminate
869          # duplicates easily.          # duplicates easily. The hash key will be the feature ID. The value will be a two-element
870            # containing the minimum and maximum offsets. We will use the offsets to sort the results
871            # when we're building the result set.
872          my %featuresFound = ();          my %featuresFound = ();
873          # Prime the values we'll use for the returned beginning and end.          # Prime the values we'll use for the returned beginning and end.
874          my ($min, $max) = ($self->ContigLength($contigID), 0);          my @initialMinMax = ($self->ContigLength($contigID), 0);
875            my ($min, $max) = @initialMinMax;
876          # Create a table of parameters for each query. Each query looks for features travelling in          # Create a table of parameters for each query. Each query looks for features travelling in
877          # a particular direction. The query parameters include the contig ID, the feature direction,          # a particular direction. The query parameters include the contig ID, the feature direction,
878          # the lowest possible start position, and the highest possible start position. This works          # the lowest possible start position, and the highest possible start position. This works
# Line 898  Line 902 
902                                          $found = 1;                                          $found = 1;
903                                  }                                  }
904                          } elsif ($dir eq '-') {                          } elsif ($dir eq '-') {
905                                  $end = $beg - $len;                                  # Note we switch things around so that the beginning is to the left of the
906                                  if ($end <= $stop) {                                  # ending.
907                                    ($beg, $end) = ($beg - $len, $beg);
908                                    if ($beg <= $stop) {
909                                          # Denote we found a useful feature.                                          # Denote we found a useful feature.
910                                          $found = 1;                                          $found = 1;
911                                  }                                  }
912                          }                          }
913                          if ($found) {                          if ($found) {
914                                  # Here we need to record the feature and update the minimum and maximum.                                  # Here we need to record the feature and update the minima and maxima. First,
915                                  $featuresFound{$featureID} = 1;                                  # get the current entry for the specified feature.
916                                  if ($beg < $min) { $min = $beg; }                                  my ($loc1, $loc2) = (exists $featuresFound{$featureID} ? @{$featuresFound{$featureID}} :
917                                  if ($end < $min) { $min = $end; }                                                                           @initialMinMax);
918                                  if ($beg > $max) { $max = $beg; }                                  # Merge the current segment's begin and end into the feature begin and end and the
919                                  if ($end > $max) { $max = $end; }                                  # global min and max.
920                                    if ($beg < $loc1) {
921                                            $loc1 = $beg;
922                                            $min = $beg if $beg < $min;
923                                    }
924                                    if ($end > $loc2) {
925                                            $loc2 = $end;
926                                            $max = $end if $end > $max;
927                                    }
928                                    # Store the entry back into the hash table.
929                                    $featuresFound{$featureID} = [$loc1, $loc2];
930                          }                          }
931                  }                  }
932          }          }
933          # Compute a list of the IDs for the features found.          # Now we must compute the list of the IDs for the features found. We start with a list
934          my @list = (sort (keys %featuresFound));          # of midpoints / feature ID pairs. (It's not really a midpoint, it's twice the midpoint,
935            # but the result of the sort will be the same.)
936            my @list = map { [$featuresFound{$_}->[0] + $featuresFound{$_}->[1], $_] } keys %featuresFound;
937            # Now we sort by midpoint and yank out the feature IDs.
938            my @retVal = map { $_->[1] } sort { $a->[0] <=> $b->[0] } @list;
939          # Return it along with the min and max.          # Return it along with the min and max.
940          return (\@list, $min, $max);          return (\@retVal, $min, $max);
941  }  }
942    
943  =head3 FType  =head3 FType

Legend:
Removed from v.1.8  
changed lines
  Added in v.1.9

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3