GenUtil.pm Show Source

The GenUtil package provides a variety of miscellaneous utility functions that are needed by packages and applications.

$fullpath = findExecutable(name)
attempts to locate the full path of a executable with the given name
 
$dir = findDataDir(name)
attempts to locate the MMTSB data directory
 
setLogFile(name)
sets a log file for debug messages
 
log(tag,text[,stderr])
writes a debug message to a log file if one has been set previously with setLogFile The message consists of a tag and the actual text.
 
makeDir(directory)
creates a directory unless it exists already
 
$handle = getInputFile(file)
returns an input file handle for a given file in a rather flexible manner. If a file name is given as argument, the file is opened. Without any argument or if "-" is given, the handle for standard input is returned. If the file is compressed, gunzip is called automatically through a pipe to provide the uncompressed data.
A previously opened file handle can also be given as argument which will then be simply returned without further action.
 
$handle = getOutputFile(file)
returns an output file handle for a given file handle in a similar manner as getInputFile for file input.
If a file name is given a file handle is opened for reading. No argument or "-" returns standard output and if a file handle is given as argument it is passed along.
 
$handle = getAppendFile(file)
returns an output file handle to append to a given file handle in a similar manner as getOutputFile.
 
$list = fragListFromOption(string)
converts a fragment list command line argument into a list data structure
 
$string = fragOptionFromList(list[,force])
generates a command line option string from a fragment list data structure. A force constant may be given separately to be included in the output if the force field is not defined in the input list.
 
$list = gradForceList($list,$force) 
generates a list with gradually increasing force constants away from the list boundaries
 
$list = fragListFromArray(arr[,chain])
generates a fragment list data structure from an array of residues
 
$list = readFormat(handle,reclen,numrec)
reads a formatted line with fields of a specific record length
 
$buffer = readData(handle,pattern)
reads data from the given handle into a buffer until a pattern is found.
 
$status = validGzip(filename)
checks whether a file is a valid compressed gzip file.
 
$status = checkFile(filename)
checks whether a file is available and readable
 
remove(filename)
removes a file if it exists
 
compress(filename)
compresses a file with gzip if it exists
 
$value = dihedral(coor1,coor2,coor3,coor4)
calculates the dihedral value for four points given by the coor* arguments.
 
$dir = dataDir(index)
returns the ensemble data directory for a given index
 
($avg,stddev,$n) = average(list)
calculates average and standard deviation of values given in the list argument
 
$list = limRange(list,min,max)
generates a sublist from the list given as argument with values that lie within the range given by min and max.
 
($list,$lastlimit,$average,$stddev,$n) = 
 limCore(list[,parameters])
generates a sublist by excluding data points that are further away from the mean than a multiple of the standard deviation. Parameters in hash-style key=>value pair form can be given to select whether all values below (lower) and above (upper) are cropped, to change the multiple mult (default: 3) and to change a tolerance limit tol for terminating the iterative solution.
Return values are the reduced list, the last limit value used, and the average, standard deviation and number of points for the reduced list.
 
$corr = spRank($xlist,$ylist)
calculates a Spearman rank coefficient for x and y values given as list arguments.
 
($m,$n,$corr) = linearFit($xlist,$ylist)
calculates a linear fit for x and y values given as list arguments. The slope, intercept and correlation coefficient are returned.
 
$status = dataAvailable(handle,timeout)
checks whether input data is available at the given handle.
 
ret = safeToSend(filename)
determines whether a file is safe to be sent to a client from a replica exchange or ensemble server.
 
str = HTMLFont
 
$port = getServerPort(base)
finds an available TCP/IP port starting from base
 
$socket = getServerSocket(port)
obtains a server socket handle for incoming connections at the given port address
 
$num = getServerID()
generates a random server ID
 
$status = alive(host,port)
checks whether a server is alive at the given host and port.
 
$socket = connectToServer(host,port)
obtains a client socket to connect to the given host and port address.
 
waitForData(socket)
blocks until data is available on socket
 
readyToWrite(socket)
blocks until socket is ready for writing
 
$data = readFromSocket(socket,nbytes)
reads data from a socket
 
$data = recvFixedData(socket)
reads next data item from socket
 
$ret = writeToSocket(socket,data)
writes data to socket
 
$ret = sendFixedData(socket,data)
writes data item to socket
 
$ret = sendCommand(socket,command[,keepOpen])
sends a command to a server through the previously opened socket handle. It returns the answer from the server. The socket connection is closed unless the keepOpen flag is set.
 
$list = readHostFile(file)
reads a remote host file and returns the data as a list.
 
$maxavail = remoteCPUs(hostrec)
returns the maximum number of CPUs available on a remote machine
 
($pid,$cpusleft) = 
  submitRemote(hostrec,serverhost,serverport,serverid,
               cpus,directory,command,options)
submits a remote client job on the host given by hostrec. On the remote machine the given command is executed in the given directory with the given options. Additional options are set to connect to the job server using the serverhost, serverport, and serverid variables and request up to the given number of CPUs.
Return values are the process ID of the subprocess running rsh and the number of CPUs left.
 
readCustomFile(custom, file)
reads custom commands from a custom file
 
writeCustomFile(custom,file)
writes custom commands to a custom file
 
writeArchiveFile(file,data,inx)
writes data set to archive file
 
archiveFile(arfile,file,inx)
copies a given file into an archive file at the given index
 
$data=readArchiveFile(file,inx)
reads data set from archive file
 
($length,$count,$filetype,$aux)=readArchiveHeader(file)
reads header from archive file
 
parsePar(hash,string) 
parses the given parameter string and stores the values in the hash data structure
 
zPad(num,len) 
pads the input number with leading zeros to return a string of the desired length
 
readFortran(handle)
 
acos(value) 
Michael Feig, Brooks group, TSRI