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

Diff of /FigKernelPackages/FIG.pm

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

revision 1.291, Fri Jun 10 16:08:52 2005 UTC revision 1.292, Mon Jun 13 09:32:09 2005 UTC
# Line 151  Line 151 
151          my $figrpc = new FIGrpc($ENV{FIG_URL});          my $figrpc = new FIGrpc($ENV{FIG_URL});
152          return $figrpc;          return $figrpc;
153      }      }
154      # Here we have the normal case. Check for default tracing.      # Here we have the normal case. Check for default tracing. We only do this if
155      if (defined $FIG_Config::trace_levels) {      # the proper parameters are present and nobody else has set up tracing yet.
156        if (defined($FIG_Config::trace_levels) && Tracer::Setups() == 0) {
157          # It's on, so we set it up. If the type is omitted, we default to WARN, which          # It's on, so we set it up. If the type is omitted, we default to WARN, which
158          # is the standard error output.          # is the standard error output.
159          my $trace_type = (defined $FIG_Config::trace_type ? $FIG_Config::trace_type : "WARN");          my $trace_type = (defined $FIG_Config::trace_type ? $FIG_Config::trace_type : "WARN");
# Line 179  Line 180 
180      return $self->{_dbf};      return $self->{_dbf};
181  }  }
182    
183    
184    =head3 Open
185    
186    C<< my $ok = FIG::Open($handle, $fileSpec, $message); >>
187    
188    Open a file, translating invalid characters in the file name.
189    
190    This is a general-purpose file open method that provides an easy way to deal with
191    invalid file name characters. It functions identically to C<Tracer::Open> with the
192    exception that the characters in the C<$FIG_Config::bad_chars> string will be
193    translated into underscores before the open takes place.
194    
195    To find the file name, the method looks for a filemode character sequence and takes
196    everything after it, trimming spaces off either end. So, for example, in the
197    following strings the file name is C</usr/fig/myfile.txt>.
198    
199        >>/usr/fig/myfile.txt
200        </usr/fig/myfile.txt
201        | sort -u > /usr/fig/myfile.txt
202    
203    Note that the file handle parameter has to be specified using glob syntax. To open
204    a file with the handle C<TMP>, you use
205    
206        Open(\*TMP, "| sort -u > /usr/fig/myfile.txt");
207    
208    =over 4
209    
210    =item handle
211    
212    File handle. If this parameter is C<undef>, a file handle will be generated
213    and returned as the value of this method.
214    
215    =item fileSpec
216    
217    File name and mode, as per the PERL C<open> function.
218    
219    =item message (optional)
220    
221    Error message to use if the open fails. If omitted, a standard error message
222    will be generated. In either case, the error information from the file system
223    is appended to the message. To specify a conditional open that does not throw
224    an error if it fails, use C<0>.
225    
226    =item RETURN
227    
228    Returns the file handle assigned to the file, or C<undef> if the open failed.
229    
230    =back
231    
232    =cut
233    #: Return Type $;
234    sub Open {
235        # Get the parameters.
236        my ($handle, $fileSpec, $message) = @_;
237        # Check to see if we need to clean.
238        if ($FIG_Config::bad_chars) {
239            my ($fileName, $pos, $len) = Tracer::FindNamePart($fileSpec);
240            substr $fileSpec, $pos, $len, NameClean($fileName);
241        }
242        # Open the file.
243        my $retVal = Tracer::Open($handle, $fileSpec, $message);
244        # Return the result.
245        return $retVal;
246    }
247    
248    =head3 OpenDir
249    
250    C<< my @files = FIG::OpenDir($dirName, $filtered); >>
251    
252    Open a directory and return all the file names. This function essentially performs
253    the functions of an C<opendir> and C<readdir>. If the I<$filtered> parameter is
254    set to TRUE, all filenames beginning with a period (C<.>) will be filtered out of
255    the return list. If the directory does not open, an exception is thrown. So,
256    for example,
257    
258            my @files = FIG::OpenDir("/Volumes/fig/contigs", 1);
259    
260    is effectively the same as
261    
262            opendir(TMP, "/Volumes/fig/contigs") || Confess("Could not open /Volumes/fig/contigs.");
263            my @files = grep { $_ !~ /^\./ } readdir(TMP);
264    
265    Similarly, the following code
266    
267            my @files = grep { $_ =~ /^\d/ } FIG::OpenDir("/Volumes/fig/orgs");
268    
269    Returns the names of all files in C</Volumes/fig/orgs> that begin with digits and
270    automatically throws an error if the directory fails to open.
271    
272    Unlike C<Tracer::OpenDir>, this version cleans bad characters out of the directory
273    name. See L</Open> for details about file name cleaning. Unlike L</Open>, however,
274    this method cleans the whole directory name. There is no need to scan for mode characters
275    or pipes.
276    
277    =over 4
278    
279    =item dirName
280    
281    Name of the directory to open.
282    
283    =item filtered
284    
285    TRUE if files whose names begin with a period (C<.>) should be automatically removed
286    from the list, else FALSE.
287    
288    =back
289    
290    =cut
291    #: Return Type @;
292    sub OpenDir {
293        # Get the parameters.
294        my ($dirName, $filtered) = @_;
295        # Clean the directory name, if necessary.
296        if ($FIG_Config::bad_chars) {
297            $dirName = NameClean($dirName);
298        }
299        # Open and read the directory.
300        my @retVal = Tracer::OpenDir($dirName, $filtered);
301        return @retVal;
302    }
303    
304    =head3 NameClean
305    
306    C<< my $cleanName = FIG::NameClean($fileName); >>
307    
308    Clean invalid characters from a file name. The characters cleaned are those found int
309    the C<$FIG_Config::bad_chars> configuration variable, and they will all be replaced by
310    underscores.
311    
312    =over 4
313    
314    =item fileName
315    
316    File name to be cleaned.
317    
318    =item RETURN
319    
320    Returns the incoming file name with all of the designated characters converted to
321    underscores.
322    
323    =back
324    
325    =cut
326    #: Return Type $;
327    sub NameClean {
328        # Get the parameters.
329        my ($fileName) = @_;
330        # Clean the file name.
331        my $retVal = $fileName;
332        my $badChars = "[$FIG_Config::bad_chars]";
333        $retVal =~ s/$badChars/_/g;
334        # Return the result.
335        return $retVal;
336    }
337    
338  =head3 cached  =head3 cached
339    
340  C<< my $x = $fig->cached($name); >>  C<< my $x = $fig->cached($name); >>
# Line 2797  Line 2953 
2953  Returns the name of the genome's domain (archaea, bacteria, etc.), or C<undef> if  Returns the name of the genome's domain (archaea, bacteria, etc.), or C<undef> if
2954  the genome is not in the database.  the genome is not in the database.
2955    
2956    =back
2957    
2958  =cut  =cut
2959    
2960  sub genome_domain {  sub genome_domain {

Legend:
Removed from v.1.291  
changed lines
  Added in v.1.292

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3