[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.35, Fri Jan 29 16:08:29 2010 UTC revision 1.36, Thu Feb 25 20:30:10 2010 UTC
# Line 291  Line 291 
291      }      }
292  }  }
293    
294    =head3 FindGeneCorrespondenceFile
295    
296        my $ih = ServerThing::FindGeneCorrespondenceFile($genome1, $genome2);
297    
298    Return an open input handle for a file that maps the genes in the first genome
299    to corresponding genes in the second genome. These files can be found for some
300    genomes in the organism directories. Additional files are available in the
301    organism cache directory (I<$FIG_Config::orgCache>). If the desired file does
302    not exist, one will be created in the organism cache directory, presumably to be
303    moved to a permanent location at a later time.
304    
305    =over 4
306    
307    =item genome1
308    
309    ID of the source genome.
310    
311    =item genome2
312    
313    ID of the target genome.
314    
315    =item RETURN
316    
317    Returns the name of a tab-delimited file. The first column in the file contains IDs
318    of genes in the source genome; the second column contains IDs of genes in the
319    target genone. The remaining columns contain additional data about the correspondence.
320    
321    =back
322    
323    =cut
324    
325    sub FindGeneCorrespondenceFile {
326        # Get the parameters.
327        my ($genome1, $genome2) = @_;
328        # Declare the return variable.
329        my $retVal;
330        # Look for a pre-computed file in the organism directories.
331        my $fileName = "$FIG_Config::organisms/$genome1/CorrToReferenceGenomes/$genome2";
332        if (-f $fileName) {
333            # Use the pre-computed file.
334            Trace("Using pre-computed file $fileName for genome correspondence.") if T(3);
335            $retVal = Open(undef, "<$fileName");
336        } else {
337            # Check for an organism cache.
338            if (! $FIG_Config::orgCache) {
339                # No cache, so simply open a pipe.
340                Trace("No organism cache found: using pipe to compute $genome1 vs. $genome2.") if T(3);
341                $retVal = Open(undef, "$FIG_Config::bin/svr_corresponding_genes $genome1 $genome2 |");
342            } else {
343                # Insure the source organism has a subdirectory in the cache.
344                my $orgDir = "$FIG_Config::orgCache/$genome1";
345                Tracer::Insure($orgDir, 0777);
346                # Check for a correspondence file that matches the target genome.
347                $fileName = "$orgDir/$genome2";
348                if (-f $fileName) {
349                    # We found one, so try to open it.
350                    my $ok = open $retVal, "<$fileName";
351                    # If the open failed, then the file is being built by another process, so
352                    # use a pipe.
353                    if (! $ok) {
354                        Trace("Failed to open $fileName. Using pipe to compute correspondence.") if T(3);
355                        $retVal = Open(undef, "$FIG_Config::bin/svr_corresponding_genes $genome1 $genome2 |");
356                    } else {
357                        Trace("Using cached file $fileName for genome correspondence.") if T(3);
358                    }
359                } else {
360                    # Here we need to create the file.
361                    Trace("Creating genome correspondence file $fileName.") if T(3);
362                    system "svr_corresponding_genes $genome1 $genome2 >$fileName";
363                    Trace("Using created file for genome correspondence.") if T(3);
364                    $retVal = Open(undef, "<$fileName");
365                }
366            }
367        }
368        # Return the desired file handle.
369        return $retVal;
370    }
371    
372    
373  =head2 Internal Utility Methods  =head2 Internal Utility Methods
374    

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

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3