.\" Automatically generated by Pod::Man 2.25 (Pod::Simple 3.16) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is turned on, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .ie \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . nr % 0 . rr F .\} .el \{\ . de IX .. .\} .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "Bio::Root::IO 3pm" .TH Bio::Root::IO 3pm "2012-03-02" "perl v5.14.2" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Bio::Root::IO \- module providing several methods often needed when dealing with file IO .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 6 \& # utilize stream I/O in your module \& $self\->{\*(Aqio\*(Aq} = Bio::Root::IO\->new(\-file => "myfile"); \& $self\->{\*(Aqio\*(Aq}\->_print("some stuff"); \& $line = $self\->{\*(Aqio\*(Aq}\->_readline(); \& $self\->{\*(Aqio\*(Aq}\->_pushback($line); \& $self\->{\*(Aqio\*(Aq}\->close(); \& \& # obtain platform\-compatible filenames \& $path = Bio::Root::IO\->catfile($dir, $subdir, $filename); \& # obtain a temporary file (created in $TEMPDIR) \& ($handle) = $io\->tempfile(); .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" This module provides methods that will usually be needed for any sort of file\- or stream-related input/output, e.g., keeping track of a file handle, transient printing and reading from the file handle, a close method, automatically closing the handle on garbage collection, etc. .PP To use this for your own code you will either want to inherit from this module, or instantiate an object for every file or stream you are dealing with. In the first case this module will most likely not be the first class off which your class inherits; therefore you need to call \fI_initialize_io()\fR with the named parameters in order to set file handle, open file, etc automatically. .PP Most methods start with an underscore, indicating they are private. In \&\s-1OO\s0 speak, they are not private but protected, that is, use them in your module code, but a client code of your module will usually not want to call them (except those not starting with an underscore). .PP In addition this module contains a couple of convenience methods for cross-platform safe tempfile creation and similar tasks. There are some \s-1CPAN\s0 modules related that may not be available on all platforms. At present, File::Spec and File::Temp are attempted. This module defines \f(CW$PATHSEP\fR, \f(CW$TEMPDIR\fR, and \f(CW$ROOTDIR\fR, which will always be set, and \f(CW$OPENFLAGS\fR, which will be set if either of File::Spec or File::Temp fails. .PP The \-noclose boolean (accessed via the noclose method) prevents a filehandle from being closed when the \s-1IO\s0 object is cleaned up. This is special behavior when a object like a parser might share a filehandle with an object like an indexer where it is not proper to close the filehandle as it will continue to be reused until the end of the stream is reached. In general you won't want to play with this flag. .SH "FEEDBACK" .IX Header "FEEDBACK" .SS "Mailing Lists" .IX Subsection "Mailing Lists" User feedback is an integral part of the evolution of this and other Bioperl modules. Send your comments and suggestions preferably to one of the Bioperl mailing lists. Your participation is much appreciated. .PP .Vb 2 \& bioperl\-l@bioperl.org \- General discussion \& http://bioperl.org/wiki/Mailing_lists \- About the mailing lists .Ve .SS "Support" .IX Subsection "Support" Please direct usage questions or support issues to the mailing list: .PP \&\fIbioperl\-l@bioperl.org\fR .PP rather than to the module maintainer directly. Many experienced and reponsive experts will be able look at the problem and quickly address it. Please include a thorough description of the problem with code and data examples if at all possible. .SS "Reporting Bugs" .IX Subsection "Reporting Bugs" Report bugs to the Bioperl bug tracking system to help us keep track the bugs and their resolution. Bug reports can be submitted via the web: .PP .Vb 1 \& https://redmine.open\-bio.org/projects/bioperl/ .Ve .SH "AUTHOR \- Hilmar Lapp" .IX Header "AUTHOR - Hilmar Lapp" Email hlapp@gmx.net .SH "CONTRIBUTORS" .IX Header "CONTRIBUTORS" Mark A. Jensen ( maj \-at\- fortinbras \-dot\- us ) .SH "APPENDIX" .IX Header "APPENDIX" The rest of the documentation details each of the object methods. Internal methods are usually preceded with a _ .SS "new" .IX Subsection "new" .Vb 6 \& Title : new \& Usage : \& Function: Overridden here to automatically call _initialize_io(). \& Example : \& Returns : new instance of this class \& Args : named parameters .Ve .SS "_initialize_io" .IX Subsection "_initialize_io" .Vb 3 \& Title : initialize_io \& Usage : $self\->_initialize_io(@params); \& Function: Initializes filehandle and other properties from the parameters. \& \& Currently recognizes the following named parameters: \& \-file name of file to open \& \-string a string that is to be converted to a filehandle \& \-url name of URL to open \& \-input name of file, or GLOB, or IO::Handle object \& \-fh file handle (mutually exclusive with \-file) \& \-flush boolean flag to autoflush after each write \& \-noclose boolean flag, when set to true will not close a \& filehandle (must explicitly call close($io\->_fh) \& \-retries number of times to try a web fetch before failure \& \& \-ua_parms hashref of key => value parameters to pass \& to LWP::UserAgent\->new() \& (only meaningful with \-url is set) \& A useful value might be, for example, \& { timeout => 60 } (ua default is 180 sec) \& Returns : TRUE \& Args : named parameters .Ve .SS "_fh" .IX Subsection "_fh" .Vb 6 \& Title : _fh \& Usage : $obj\->_fh($newval) \& Function: Get/set the file handle for the stream encapsulated. \& Example : \& Returns : value of _filehandle \& Args : newvalue (optional) .Ve .SS "mode" .IX Subsection "mode" .Vb 10 \& Title : mode \& Usage : $obj\->mode() \& Function: \& Example : \& Returns : mode of filehandle: \& \*(Aqr\*(Aq for readable \& \*(Aqw\*(Aq for writable \& \*(Aq?\*(Aq if mode could not be determined \& Args : \-force (optional), see notes. \& Notes : once mode() has been called, the filehandle\*(Aqs mode is cached \& for further calls to mode(). to override this behavior so \& that mode() re\-checks the filehandle\*(Aqs mode, call with arg \& \-force .Ve .SS "file" .IX Subsection "file" .Vb 6 \& Title : file \& Usage : $obj\->file($newval) \& Function: Get/set the filename, if one has been designated. \& Example : \& Returns : value of file \& Args : newvalue (optional) .Ve .SS "_print" .IX Subsection "_print" .Vb 5 \& Title : _print \& Usage : $obj\->_print(@lines) \& Function: \& Example : \& Returns : 1 on success, undef on failure .Ve .SS "_insert" .IX Subsection "_insert" .Vb 6 \& Title : _insert \& Usage : $obj\->_insert($string,1) \& Function: Insert some text in a file at the given line number (1\-based). \& Returns : 1 on success \& Args : string to write in file \& line number to insert the string at .Ve .SS "_readline" .IX Subsection "_readline" .Vb 3 \& Title : _readline \& Usage : $obj\->_readline(%args) \& Function: Reads a line of input. \& \& Note that this method implicitely uses the value of $/ that is \& in effect when called. \& \& Note also that the current implementation does not handle pushed \& back input correctly unless the pushed back input ends with the \& value of $/. \& \& Example : \& Args : Accepts a hash of arguments, currently only \-raw is recognized \& passing (\-raw => 1) prevents \er\en sequences from being changed \& to \en. The default value of \-raw is undef, allowing \er\en to be \& converted to \en. \& Returns : .Ve .SS "_pushback" .IX Subsection "_pushback" .Vb 10 \& Title : _pushback \& Usage : $obj\->_pushback($newvalue) \& Function: puts a line previously read with _readline back into a buffer. \& buffer can hold as many lines as system memory permits. \& Example : $obj\->_pushback($newvalue) \& Returns : none \& Args : newvalue \& Note : This is only supported for pushing back data ending with the \& current, localized value of $/. Using this method to push modified \& data back onto the buffer stack is not supported; see bug 843. .Ve .SS "close" .IX Subsection "close" .Vb 6 \& Title : close \& Usage : $io\->close() \& Function: Closes the file handle associated with this IO instance. \& Will not close the FH if \-noclose is specified \& Returns : none \& Args : none .Ve .SS "flush" .IX Subsection "flush" .Vb 5 \& Title : flush \& Usage : $io\->flush() \& Function: Flushes the filehandle \& Returns : none \& Args : none .Ve .SS "noclose" .IX Subsection "noclose" .Vb 8 \& Title : noclose \& Usage : $obj\->noclose($newval) \& Function: Get/Set the NOCLOSE flag \- setting this to true will \& prevent a filehandle from being closed \& when an object is cleaned up or explicitly closed \& This is a bit of hack \& Returns : value of noclose (a scalar) \& Args : on set, new value (a scalar or undef, optional) .Ve .SS "exists_exe" .IX Subsection "exists_exe" .Vb 12 \& Title : exists_exe \& Usage : $exists = $obj\->exists_exe(\*(Aqclustalw\*(Aq); \& $exists = Bio::Root::IO\->exists_exe(\*(Aqclustalw\*(Aq) \& $exists = Bio::Root::IO::exists_exe(\*(Aqclustalw\*(Aq) \& Function: Determines whether the given executable exists either as file \& or within the path environment. The latter requires File::Spec \& to be installed. \& On Win32\-based system, .exe is automatically appended to the program \& name unless the program name already ends in .exe. \& Example : \& Returns : 1 if the given program is callable as an executable, and 0 otherwise \& Args : the name of the executable .Ve .SS "tempfile" .IX Subsection "tempfile" .Vb 4 \& Title : tempfile \& Usage : my ($handle,$tempfile) = $io\->tempfile(); \& Function: Returns a temporary filename and a handle opened for writing and \& and reading. \& \& Caveats : If you do not have File::Temp on your system you should avoid \& specifying TEMPLATE and SUFFIX. (We don\*(Aqt want to recode \& everything, okay?) \& Returns : a 2\-element array, consisting of temporary handle and temporary \& file name \& Args : named parameters compatible with File::Temp: DIR (defaults to \& $Bio::Root::IO::TEMPDIR), TEMPLATE, SUFFIX. .Ve .SS "tempdir" .IX Subsection "tempdir" .Vb 3 \& Title : tempdir \& Usage : my ($tempdir) = $io\->tempdir(CLEANUP=>1); \& Function: Creates and returns the name of a new temporary directory. \& \& Note that you should not use this function for obtaining "the" \& temp directory. Use $Bio::Root::IO::TEMPDIR for that. Calling this \& method will in fact create a new directory. \& \& Returns : The name of a new temporary directory. \& Args : args \- ( key CLEANUP ) indicates whether or not to cleanup \& dir on object destruction, other keys as specified by File::Temp .Ve .SS "catfile" .IX Subsection "catfile" .Vb 3 \& Title : catfile \& Usage : $path = Bio::Root::IO\->catfile(@dirs,$filename); \& Function: Constructs a full pathname in a cross\-platform safe way. \& \& If File::Spec exists on your system, this routine will merely \& delegate to it. Otherwise it tries to make a good guess. \& \& You should use this method whenever you construct a path name \& from directory and filename. Otherwise you risk cross\-platform \& compatibility of your code. \& \& You can call this method both as a class and an instance method. \& \& Returns : a string \& Args : components of the pathname (directories and filename, NOT an \& extension) .Ve .SS "rmtree" .IX Subsection "rmtree" .Vb 3 \& Title : rmtree \& Usage : Bio::Root::IO\->rmtree($dirname ); \& Function: Remove a full directory tree \& \& If File::Path exists on your system, this routine will merely \& delegate to it. Otherwise it runs a local version of that code. \& \& You should use this method to remove directories which contain \& files. \& \& You can call this method both as a class and an instance method. \& \& Returns : number of files successfully deleted \& Args : roots \- rootdir to delete or reference to list of dirs \& \& verbose \- a boolean value, which if TRUE will cause \& C to print a message each time it \& examines a file, giving the name of the file, and \& indicating whether it\*(Aqs using C or \& C to remove it, or that it\*(Aqs skipping it. \& (defaults to FALSE) \& \& safe \- a boolean value, which if TRUE will cause C \& to skip any files to which you do not have delete \& access (if running under VMS) or write access (if \& running under another OS). This will change in the \& future when a criterion for \*(Aqdelete permission\*(Aq \& under OSs other than VMS is settled. (defaults to \& FALSE) .Ve .SS "_flush_on_write" .IX Subsection "_flush_on_write" .Vb 7 \& Title : _flush_on_write \& Usage : $obj\->_flush_on_write($newval) \& Function: Boolean flag to indicate whether to flush \& the filehandle on writing when the end of \& a component is finished (Sequences,Alignments,etc) \& Returns : value of _flush_on_write \& Args : newvalue (optional) .Ve .SS "save_tempfiles" .IX Subsection "save_tempfiles" .Vb 5 \& Title : save_tempfiles \& Usage : $obj\->save_tempfiles(1) \& Function: Boolean flag to indicate whether to retain tempfiles/tempdir \& Returns : Boolean value : 1 = save tempfiles/tempdirs, 0 = remove (default) \& Args : Value evaluating to TRUE or FALSE .Ve