Other utilities

BMERC : needle tools : Programs : Other utilities


These are useful utility programs that are not directly related to molecular biology.

Table of contents

  1. Other utilities
    1. Table of contents
    2. diff-fields.pl
    3. install.pl
    4. init-needle-tools


diff-fields.pl

diff-fields.pl compares selected fields out of two files, one of which may be the standard input, in either cmp or diff style. It has proved useful for debugging, but serves no other purpose in the needle tools suite.

Usage:


    diff-fields.pl [-cmp] [-bitwcefnhls] -fields1 file1 [ -fields2 ] file2
The argument list consists of zero or more -cmp or comparator options (the -bitwcefnhls thing) in any order, followed by the other three or four options in the specified order.

Arguments:

-cmp
specifies that the cmp program be used as the comparator function. By default, diff is used.
-bitwcefnhls
options to the comparator function; see the appropriate man page for details. Zero or more groups of comparator options are permitted before the first fields specification. -l and -s are supported by cmp; all the rest are diff options. diff-fields.pl does not allow digits for the diff -c option, lest it get confused with a character fields specification.
-fields1
fields to select from the first file, a -f or -c specification to the cut command.
file1
first file name, or "-" for the standard input.
-fields2
fields to select from the second file, another -f or -c specification. Default is the same as the -fields1 value.
file2
second file name, or "-" for the standard input (but you will lose if you specify a dash for both file1 and file2).
Each fields specification must start with "-f" or "-c" and include a nonempty comma-separated list of one-based field indices (as digit strings) or ranges of field indices (e.g. "2-5").

diff-fields.pl first cuts the indicated fields out of each file (opening temporary files in /tmp to hold the results), then passes the resulting fields to the comparator program. If the comparator is cmp, then any output is filtered in order to rename the temp files back to their original names. If the comparator is diff (the default), no attempt is made to reinsert eliminated fields in the resulting output. In either case, diff-fields.pl uses the return code from the comparator as its return value. This makes it possible to use "diff-fields.pl -cmp -s" as a silent test for whether certain fields are identical.

Known bugs:

  1. *** diff-fields.pl really should replace chopped fields back into the diff output (by saving and re-substituting the original inputs). But this is a pretty big job . . . -- rgr, 4-Nov-98.
  2. *** On many systems, cut cannot handle lines longer than some fixed maximum length. For most file formats, this is not a problem, but cut has been seen to fail for .tbl format sequence files.


install.pl

install.pl is similar to the Berkeley UNIX install utility that copies software into an executable directory; it has a few enhancements, but is not fully compatible. The enhancements make it easier to maintain
perl scripts in a site-independent manner.

Usage:

    install.pl [file-or-option . . .] directory
where file-or-option is one of
    -m mode | -verbose | -show | -quiet | -inc | file
Except for directory, options are processed from left to right; an option will be respecified if it appears more than once. When installing a given file, the options then in effect are used.

Arguments:

-m mode
specify the "mode" (file permission bits) for the installed file. The mode argument must be an octal string with the usual UNIX interpretation; the default is 555, allowing world read and execute permission, but no write permission to anyone. (install.pl sets the mode directly, rather than calling chmod, so alphanumeric permissions do not work.)
-show
print an "Installing name in directory" message for each file that is actually installed, and "Installing perl script name in directory" for each perl script that is processed as described below.
-verbose
print -show messages for all files, even those that are up to date. If you specify this twice, you also get to see the (raw) modification times of each file.
-quiet
suppress -show and -verbose messages; this is the default.
-inc
for perl scripts, add the destination directory to the @INC list, for loading libraries.
file
the names of one or more files to be installed. Options may be intermixed with file names; each option affects only the files that appear after it, until countermanded.
directory
the last argument on the line must be the destination directory, by analogy with cp. The directory name need not end with a slash ("/"). Since it is easy to forget to include a directory name, install.pl dies with an error message if the last argument is not a directory.
Before copying the indicated files to the destination directory and setting permission bits, install.pl compares the dates on the local and installed versions of the file, and (unlike install) only installs those files that have changed. This makes the dates on the installed versions more closely track when they were last changed.

install.pl also does the following additional things for perl scripts, which are recognized by the ".pl" or ".prl" suffix:

  1. The first line(s) of the script (the "perl invocation header") are replaced with the first line(s) of the install.pl script (which, since it is executing at the time, is safely assumed to be correct).
  2. If the -inc option is specified, the line:
           push(@INC, 'directory');
    
    is inserted at the end of the perl invocation header, where directory is the destination directory into which the script is being installed. This makes installed perl scripts get their libraries from the same place they were invoked (and saves a lot of site customization headaches).
  3. Sets of lines bounded by and including the comment lines "#ifdef DEBUG" and "#endif" are not copied to the installed version. This is used to remove scaffolding inserted for testing, especially alternative @INC directories that should not appear in installed versions.
In order to find the right perl invocation header, install.pl attempts to find itself by using which; if it fails, an error is printed and the program is installed normally. The perl invocation header is considered to start at the beginning of the file and runs through the first blank line or empty comment line; it is expected to be used to invoke the script. This is done at BMERC by:
    #!/usr/local/bin/perl
but different systems may require different pathnames, or different invocation schemes entirely. In particular, many systems still use perl version 4 by default, but needle tools requires perl 5, so simply using "/usr/local/bin/perl" may invoke the wrong version. In that case, one must change the first line to something like the following:
    #!/usr/local/bin/perl5
Thus the needle tools installation procedure involves "bootstrapping" by hand-editing the distributed version of install.pl to meet the local requirements for the perl invocation header, and then using that to install the rest of the software. It is similar to using a retrovirus for gene therapy.

Known bugs:

  1. If the system does not have an install program (or it is not on the search path), install.pl will fail. -- rgr, 10-Sep-97. [Fixed in Release 1.3. -- rgr, 4-Nov-98.]
  2. *** Relative directory pathnames don't work with the -inc option. -- rgr, 12-Nov-99.
  3. *** Should support renaming when installing a single file, e.g.
           install.pl foo.pl /usr/local/bin/bar.pl
           
    This is supported by many versions of install, especially in BSD-derived systems. -- rgr, 19-Jan-00.


init-needle-tools

init-needle-tools establishes the PATH environment variable for running this software. "Sourcing" this file (it's not really a script) in one's .login file allows different system types (e.g. Alpha vs. Sparc, Solaris vs. SunOS 4.1.x) to be accomodated gracefully.

Usage:

    source init-needle-tools
Because it is "sourced" and not invoked as an ordinary script, there are no arguments, and it is also necessary to know the full pathname of the file. At BMERC, this is ~thread/bin/scripts/init-needle-tools.


Bob Rogers <rogers@darwin.bu.edu>
Last modified: Wed Jan 19 15:56:42 EST 2000