[Bio] / FigKernelPackages / ServerThing.pm Repository:
ViewVC logotype

Diff of /FigKernelPackages/ServerThing.pm

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

revision 1.50, Wed Apr 28 15:31:12 2010 UTC revision 1.56, Thu Oct 14 17:28:49 2010 UTC
# Line 98  Line 98 
98    
99  =head3 AddSubsystemFilter  =head3 AddSubsystemFilter
100    
101      ServerThing::AddSubsystemFilter(\$filter, $args);      ServerThing::AddSubsystemFilter(\$filter, $args, $roles);
102    
103  Add subsystem filtering information to the specified query filter clause  Add subsystem filtering information to the specified query filter clause
104  based on data in the argument hash. The argument hash will be checked for  based on data in the argument hash. The argument hash will be checked for
105  the C<-usable> parameter, which includes or excludes unusuable subsystems, and  the C<-usable> parameter, which includes or excludes unusuable subsystems,
106  the C<-exclude> parameter, which lists types of subsystems that should be  the C<-exclude> parameter, which lists types of subsystems that should be
107  excluded.  excluded, and the C<-aux> parameter, which filters on auxiliary roles.
108    
109  =over 4  =over 4
110    
# Line 118  Line 118 
118  Reference to the parameter hash for the current server call. This hash will  Reference to the parameter hash for the current server call. This hash will
119  be examined for the C<-usable> and C<-exclude> parameters.  be examined for the C<-usable> and C<-exclude> parameters.
120    
121    =item roles
122    
123    If TRUE, role filtering will be applied. In this case, the default action
124    is to exclude auxiliary roles unless C<-aux> is TRUE.
125    
126  =back  =back
127    
128  =cut  =cut
# Line 128  Line 133 
133    
134  sub AddSubsystemFilter {  sub AddSubsystemFilter {
135      # Get the parameters.      # Get the parameters.
136      my ($filter, $args) = @_;      my ($filter, $args, $roles) = @_;
137      # We'll put the new filter stuff in here.      # We'll put the new filter stuff in here.
138      my @newFilters;      my @newFilters;
139      # Unless unusable subsystems are desired, we must add a clause to the filter.      # Unless unusable subsystems are desired, we must add a clause to the filter.
# Line 152  Line 157 
157              push @newFilters, "Subsystem($exclusion) = 0";              push @newFilters, "Subsystem($exclusion) = 0";
158          }          }
159      }      }
160        # Check for role filtering.
161        if ($roles) {
162            # Here, we filter out auxiliary roles unless the user requests
163            # them.
164            if (! $args->{-aux}) {
165                push @newFilters, "Includes(auxiliary) = 0"
166            }
167        }
168      # Do we need to update the incoming filter?      # Do we need to update the incoming filter?
169      if (@newFilters) {      if (@newFilters) {
170          # Yes. If the incoming filter is nonempty, push it onto the list          # Yes. If the incoming filter is nonempty, push it onto the list
# Line 292  Line 305 
305      }      }
306  }  }
307    
308    =head3 ReadCountVector
309    
310        my $vector = ServerThing::ReadCountVector($qh, $field, $rawFlag);
311    
312    Extract a count vector from a query. The query can contain zero or more results,
313    and the vectors in the specified result field of the query must be concatenated
314    together in order. This method is optimized for the case (expected to be most
315    common) where there is only one result.
316    
317    =over 4
318    
319    =item qh
320    
321    Handle for the query from which results are to be extracted.
322    
323    =item field
324    
325    Name of the field containing the count vectors.
326    
327    =item rawFlag
328    
329    TRUE if the vector is to be returned as a raw string, FALSE if it is to be returned
330    as reference to a list of numbers.
331    
332    =item RETURN
333    
334    Returns the desired vector, either encoded as a string or as a reference to a list
335    of numbers.
336    
337    =back
338    
339    =cut
340    
341    sub ReadCountVector {
342        # Get the parameters.
343        my ($qh, $field, $rawFlag) = @_;
344        # Declare the return variable.
345        my $retVal;
346        # Loop through the query results.
347        while (my $resultRow = $qh->Fetch()) {
348            # Get this vector.
349            my ($levelVector) = $resultRow->Value($field, $rawFlag);
350            # Is this the first result?
351            if (! defined $retVal) {
352                # Yes. Assign the result directly.
353                $retVal = $levelVector;
354            } elsif ($rawFlag) {
355                # This is a second result and the vectors are coded as strings.
356                $retVal .= $levelVector;
357            } else {
358                # This is a second result and the vectors are coded as array references.
359                push @$retVal, @$levelVector;
360            }
361        }
362        # Return the result.
363        return $retVal;
364    }
365    
366    
367  =head2 Gene Correspondence File Methods  =head2 Gene Correspondence File Methods
368    
# Line 666  Line 737 
737  Returns TRUE if the first genome would be stored on the server as a target, FALSE if  Returns TRUE if the first genome would be stored on the server as a target, FALSE if
738  it would be stored as a source.  it would be stored as a source.
739    
740    =back
741    
742  =cut  =cut
743    
744  sub MustFlipGenomeIDs {  sub MustFlipGenomeIDs {
# Line 853  Line 926 
926      return $retVal;      return $retVal;
927  }  }
928    
929    =head3 GetCorrespondenceData
930    
931        my $corrList = ServerThing::GetCorrespondenceData($genome1, $genome2, $passive, $full);
932    
933    Return the L</Gene Correspondence List> for the specified source and target genomes. If the
934    list is in a file, it will be read. If the file does not exist, it may be created.
935    
936    =over 4
937    
938    =item genome1
939    
940    ID of the source genome.
941    
942    =item genome2
943    
944    ID of the target genome.
945    
946    =item passive
947    
948    If TRUE, then the correspondence file will not be created if it does not exist.
949    
950    =item full
951    
952    If TRUE, then both directions of the correspondence will be represented; otherwise, only
953    correspondences from the source to the target (including bidirectional corresopndences)
954    will be included.
955    
956    =item RETURN
957    
958    Returns a L</Gene Correspondence List> in the form of a reference to a list of lists, or an
959    undefined value if an error occurs or no file exists and passive mode was specified.
960    
961    =back
962    
963    =cut
964    
965    sub GetCorrespondenceData {
966        # Get the parameters.
967        my ($genome1, $genome2, $passive, $full) = @_;
968        # Declare the return variable.
969        my $retVal;
970        # Check for a gene correspondence file.
971        my ($fileName, $converse) = ServerThing::CheckForGeneCorrespondenceFile($genome1, $genome2);
972        if ($fileName) {
973            # Here we found one, so read it in.
974            $retVal = ServerThing::ReadGeneCorrespondenceFile($fileName, $converse, $full);
975        }
976        # Were we successful?
977        if (! defined $retVal) {
978            # Here we either don't have a correspondence file, or the one that's there is
979            # invalid. If we are NOT in passive mode, then this means we need to create
980            # the file.
981            if (! $passive) {
982                ($fileName, $converse) = ServerThing::CreateGeneCorrespondenceFile($genome1, $genome2);
983                # Now try reading the new file.
984                if (defined $fileName) {
985                    $retVal = ServerThing::ReadGeneCorrespondenceFile($fileName, $converse);
986                }
987            }
988        }
989        # Return the result.
990        return $retVal;
991    
992    }
993    
994    
995  =head2 Internal Utility Methods  =head2 Internal Utility Methods
996    
# Line 920  Line 1058 
1058      # Get the parameters.      # Get the parameters.
1059      my ($cgi, $serverThing, $docURL) = @_;      my ($cgi, $serverThing, $docURL) = @_;
1060      # Determine the request type.      # Determine the request type.
1061      if ($cgi->param('pod')) {      my $module = $cgi->param('pod');
1062          # Here we have a documentation request. In this case, we produce POD HTML.      if ($module) {
1063            # Here we have a documentation request.
1064            if ($module eq 'ServerScripts') {
1065                # Here we list the server scripts.
1066                require ListServerScripts;
1067                ListServerScripts::main();
1068            } else {
1069                # In this case, we produce POD HTML.
1070          ProducePod($cgi->param('pod'));          ProducePod($cgi->param('pod'));
1071            }
1072      } elsif ($cgi->param('code')) {      } elsif ($cgi->param('code')) {
1073          # Here the user wants to see the code for one of our scripts.          # Here the user wants to see the code for one of our scripts.
1074          LineNumberize($cgi->param('code'));          LineNumberize($cgi->param('code'));
# Line 947  Line 1093 
1093          # Insure the function name is valid.          # Insure the function name is valid.
1094          Die("Invalid function name.")          Die("Invalid function name.")
1095              if $function =~ /\W/;              if $function =~ /\W/;
1096            # Determing the encoding scheme. The default is YAML.
1097            my $encoding = $cgi->param('encoding') || 'yaml';
1098          # The parameter structure will go in here.          # The parameter structure will go in here.
1099          my $args;          my $args = {};
1100          # Start the timer.          # Start the timer.
1101          my $start = time();          my $start = time();
1102          # The output document goes in here.          # The output document goes in here.
# Line 958  Line 1106 
1106          # Protect from errors.          # Protect from errors.
1107          eval {          eval {
1108              # Here we parse the arguments. This is affected by the encoding parameter.              # Here we parse the arguments. This is affected by the encoding parameter.
             # The default is YAML.  
             my $encoding = $cgi->param('encoding') || 'yaml';  
1109              # Get the argument string.              # Get the argument string.
1110              my $argString = $cgi->param('args');              my $argString = $cgi->param('args');
1111                # Only proceed if we found one.
1112                if ($argString) {
1113              if ($encoding eq 'yaml') {              if ($encoding eq 'yaml') {
1114                  # Parse the arguments using YAML.                  # Parse the arguments using YAML.
1115                  $args = YAML::Load($argString);                  $args = YAML::Load($argString);
# Line 972  Line 1120 
1120              } else {              } else {
1121                  Die("Invalid encoding type $encoding.");                  Die("Invalid encoding type $encoding.");
1122              }              }
1123                }
1124          };          };
1125          # Check to make sure we got everything.          # Check to make sure we got everything.
1126          if ($@) {          if ($@) {
# Line 985  Line 1134 
1134                  SendError($@, "Error detected by service.");                  SendError($@, "Error detected by service.");
1135                  Trace("Error encountered by service: $@") if T(0);                  Trace("Error encountered by service: $@") if T(0);
1136              } else {              } else {
1137                  # No error, so we output the result.                  # No error, so we output the result. Start with an HTML header.
1138                  print $cgi->header(-type => 'text/plain');                  print $cgi->header(-type => 'text/plain');
1139                  my $string = YAML::Dump($document);                  # The nature of the output depends on the encoding type.
1140                    my $string;
1141                    if ($encoding eq 'yaml') {
1142                        $string = YAML::Dump($document);
1143                    } else {
1144                        $string = JSON::Any->objToJson($document);
1145                    }
1146                  print $string;                  print $string;
1147                  MemTrace(length($string) . " bytes returned from $function by task $$.") if T(Memory => 3);                  MemTrace(length($string) . " bytes returned from $function by task $$.") if T(Memory => 3);
1148              }              }

Legend:
Removed from v.1.50  
changed lines
  Added in v.1.56

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3