Script Utilities Package
This is a simple package containing utility methods of use to the server scripts.
Public Methods
GetBatch
my @lines = ScriptThing::GetBatch($ih, $size);
Get a batch of work to do. The specified input stream will be read, and a list of IDs pulled out, along with the contents of the input lines on which the IDs were found. The input stream can be an open file handle or a list of singleton values to return.
- ih
-
Open input file handle, or alternatively a reference to a list of values to return. If a list is specified, the items will be removed from the list as they are returned.
- size (optional)
-
Maximum permissible batch size. If omitted, the default is
10
. - column (optional)
-
Index (1-based) of the column containing the IDs. The default is the last column.
- RETURN
-
Returns a list of 2-tuples; each 2-tuple consists of an ID followed by the text of the input line containing the ID (with the trailing new-line removed).
GetList
my @list = ScriptThing::GetList($ih, $column);
Extract a list of data items from a tab-delimited file. Unlike "GetBatch", this method reads the entire file, and it only returns the column of interest instead of tuples containing the original data lines.
- ih
-
Open file handle for the input.
- column (optional)
-
Index (1-based) of the column containing the IDs. The default is the last column.
- RETURN
-
Returns a list containing the contents of the desired column for every record in the input stream.
GetColumn
my $id = ScriptThing::GetColumn($line, $column);
Get the specified column from a tab-delimited input line.
- line
-
A tab-delimited line of text.
- column
-
The index (1-based) of the column whose value is desired. If undefined or 0, then the last column will be extracted.
- RETURN
-
Returns the value of the desired column. Note that if it is the last column, no trimming of new-line characters will take place.
CommentHash
my %hash = ScriptThing::CommentHash(\@tuples, $column);
Convert the 2-tuples returned by "GetBatch" to a comment hash for FASTA-based methods. The return hash will map each incoming ID to a string containing the fields from the corresponding line.
- tuples
-
Reference to a list of 2-tuples. Each 2-tuple contains an ID followed by a tab-delimited input line (without the new-line character).
- column
-
Index (1-based) of the column containing the ID value. The default is the last column.
- RETURN
-
Returns a hash mapping each incoming ID to the text from its input line.
AdjustStdin
AdjustStdin();
Check the environment for a STDIN variable, and if present, open the named file as STDIN. This is a debugging hack that allows the scripts to be run easily inside a symbolic debugger.