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

Diff of /Sprout/SearchHelper.pm

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

revision 1.32, Thu May 17 23:43:30 2007 UTC revision 1.33, Tue Jun 19 21:28:21 2007 UTC
# Line 19  Line 19 
19      use FeatureQuery;      use FeatureQuery;
20      use URI::Escape;      use URI::Escape;
21      use PageBuilder;      use PageBuilder;
22        use POSIX;
23    
24  =head1 Search Helper Base Class  =head1 Search Helper Base Class
25    
# Line 875  Line 876 
876    
877  =head3 OrganismData  =head3 OrganismData
878    
879  C<< my ($orgName, $group) = $shelp->Organism($genomeID); >>  C<< my ($orgName, $group, $domain) = $shelp->Organism($genomeID); >>
880    
881  Return the name and status of the organism corresponding to the specified genome ID.  Return the name and status of the organism corresponding to the specified genome ID.
882  For performance reasons, this information is cached in a special hash table, so we  For performance reasons, this information is cached in a special hash table, so we
# Line 1097  Line 1098 
1098                  $fastaLabel = $fid;                  $fastaLabel = $fid;
1099              }              }
1100              # Now proceed according to the sequence type.              # Now proceed according to the sequence type.
1101              if ($desiredType eq 'prot') {              if ($desiredType =~ /prot/) {
1102                  # We want protein, so get the translation.                  # We want protein, so get the translation.
1103                  $fastaData = $sprout->FeatureTranslation($figID);                  $fastaData = $sprout->FeatureTranslation($figID);
1104                  Trace(length $fastaData . " characters returned for translation of $fastaLabel.") if T(3);                  Trace(length $fastaData . " characters returned for translation of $fastaLabel.") if T(3);
# Line 1166  Line 1167 
1167      Trace("FASTA data sequence: $fastaData") if T(4);      Trace("FASTA data sequence: $fastaData") if T(4);
1168      # Only proceed if no error was detected.      # Only proceed if no error was detected.
1169      if ($okFlag) {      if ($okFlag) {
1170            if ($desiredType =~ /pattern/i) {
1171                # We're doing a scan, so only the data is passed in.
1172                $retVal = $fastaData;
1173            } else {
1174          # We need to format the sequence into 60-byte chunks. We use the infamous          # We need to format the sequence into 60-byte chunks. We use the infamous
1175          # grep-split trick. The split, because of the presence of the parentheses,          # grep-split trick. The split, because of the presence of the parentheses,
1176          # includes the matched delimiters in the output list. The grep strips out          # includes the matched delimiters in the output list. The grep strips out
# Line 1174  Line 1179 
1179          my @chunks = grep { $_ } split /(.{1,60})/, $fastaData;          my @chunks = grep { $_ } split /(.{1,60})/, $fastaData;
1180          $retVal = join("\n", ">$fastaLabel", @chunks, "");          $retVal = join("\n", ">$fastaLabel", @chunks, "");
1181      }      }
1182        }
1183      # Return the result.      # Return the result.
1184      return $retVal;      return $retVal;
1185  }  }
# Line 2774  Line 2780 
2780                                         $dockString);                                         $dockString);
2781              }              }
2782          }          }
2783        } elsif ($type eq 'role') {
2784            # Here the caller wants a functional role assignment. The key is the feature ID.
2785            $retVal = $sprout->FunctionOf($text);
2786        } elsif ($type eq 'loc') {
2787            # This is a tough one. We need to find the nearest feature in the appropriate direction
2788            # on the contig, and then output its id, functional role, and link button.
2789            if ($text =~ /^(.)\/(.+)/) {
2790                my ($direction, $locString) = ($1, $2);
2791                Trace("Location request of type $direction for $locString.") if T(3);
2792                # Convert the location string into a location object.
2793                my $loc = BasicLocation->new($locString);
2794                # Get the contig ID.
2795                my $contigID = $loc->Contig;
2796                # Compute the contig length.
2797                my $contigLen = $sprout->ContigLength($contigID);
2798                # Widen by the area to search in both directions.
2799                $loc->Widen(5000);
2800                # Now, if we're doing a before (-) search, we set the end point to the area's mid point.
2801                # If we're doing an after (+) search, we set the begin point to the area's mid point.
2802                my $mid = ($loc->Left + $loc->Right) / 2;
2803                # Compute the search direction.
2804                my $searchDir = ($direction eq $loc->Dir ? 1 : -1);
2805                # Adjust the midpoint so that it is different in the before direction from what it would
2806                # be in the after direction.
2807                if ($mid != int($mid)) {
2808                    # Here we need to round. The thing here is we want to round in a way that separates
2809                    # the after-search choice from the before-search choice.
2810                    if ($direction eq $loc->Dir) {
2811                        $mid = ceil($mid);
2812                    } else {
2813                        $mid = floor($mid);
2814                    }
2815                } elsif ($direction eq '+') {
2816                    # Here the midpoint is on a nucleotide and we are doing the after search. We bump the
2817                    # midpoint toward the end point.
2818                    $mid += $loc->NumDirection;
2819                }
2820                # Now put the midpoint on the proper end of the region.
2821                if ($direction eq '+') {
2822                    $loc->SetBegin($mid);
2823                } else {
2824                    $loc->SetEnd($mid);
2825                }
2826                Trace("Search region is " . $loc->String . ".") if T(3);
2827                # Find all the genes in the region.
2828                my ($fidList, $beg, $end) = $sprout->GenesInRegion($loc->Contig, $loc->Left, $loc->Right);
2829                Trace(scalar(@{$fidList}) . " features found.") if T(3);
2830                # Look for the best match.
2831                my $distance = 5000;
2832                my $chosenFid = undef;
2833                for my $fid (@{$fidList}) {
2834                    # Get the feature's location.
2835                    my ($locString) = $sprout->FeatureLocation($fid);
2836                    my $locObject = BasicLocation->new($locString);
2837                    # Check its begin point to see if we should keep it.
2838                    my $newDistance = ($mid - $locObject->Begin) * $searchDir;
2839                    Trace("Distance from $mid to $locString is $newDistance.") if T(4);
2840                    if ($newDistance > 0 && $newDistance < $distance) {
2841                        $distance = $newDistance;
2842                        $chosenFid = $fid;
2843                    }
2844                }
2845                # Only proceed if we found something.
2846                if (defined $chosenFid) {
2847                    my $role = $sprout->FunctionOf($chosenFid);
2848                    my $linkButton = SearchHelper::FakeButton('NMPDR', "protein.cgi", undef,
2849                                                               prot => $chosenFid, SPROUT => 1,
2850                                                               new_framework => 0, user => '');
2851                    $retVal = "$chosenFid&nbsp;$linkButton&nbsp;$role";
2852                }
2853            } else {
2854                Confess("Invalid location request %%loc=$text.");
2855            }
2856      }      }
2857      # Return the result.      # Return the result.
2858      return $retVal;      return $retVal;
# Line 2947  Line 3026 
3026      # Compute the target-frame HTML.      # Compute the target-frame HTML.
3027      my $targetHtml = ($target ? " target=\"$target\"" : "");      my $targetHtml = ($target ? " target=\"$target\"" : "");
3028      # Assemble the result.      # Assemble the result.
3029      return "<a href=\"$targetUrl\" $targetHtml><div class=\"button2 button\">$caption</div></a>";      return "<a href=\"$targetUrl\" $targetHtml><span class=\"button2 button\">$caption</span></a>";
3030  }  }
3031    
3032  =head3 Formlet  =head3 Formlet

Legend:
Removed from v.1.32  
changed lines
  Added in v.1.33

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3