Creating an EPP Wrapper Script With Python

by Mark Luszniak on May 17, 2013 in Technology
Technology Image

Background

Most facilities have the need for the LIMS to initiate an external application or algorithm as a consequence of a user completing an operation within the desktop client. This functionality requires the use of the GenoLogics External Program Plugin (EPP), which associates a Process with the command line syntax required to drive the external application. Occasionally there is a need for a single Process to initiate two (or more!) external applications. Such an example might be that when a user runs a transfer or re-array process, two external applications are initiated by the LIMS: the first produces a file to be consumed by the Liquid Handling Robot to effect the transfer, and the second produces bar-coded labels to attach to the new daughter plates. The EPP plugin does not inherently support interactions with multiple applications, but this functionality can be enabled by using a ‘wrapper’ script that intercepts the multiple commands, and marshals them appropriately. The following code is an example of such a ‘wrapper’ script.

Script

Since Python is ubiquitous on Unix/Linux systems – and easily installed on other platforms – I opted to create my wrapper script in Python. For reference, this script was named epp_wrapper.py

import os
import sys

def main():
   args = ""
   for arg in sys.argv[1:]:
       args = args + arg + " "

   arglist = args.split( "script:" )

   for arg in arglist:
       arg = arg.strip()
       arg = arg.replace("'", '"')
       if len( arg ) > 0:
           ## print( "\n\n" + arg )
           os.system( arg )

if __name__ == "__main__":
   main()

About the Script

It took several iterations for me to come up with a robust script that worked with complex command lines, and handled quotes appropriately. Specifically, early versions failed to perform as expected if the command line to initiate the external application contained redirection operators, since these were being interpreted by the call to the epp_wrapper.py script, when they should have been treated as part of the parameter list passed to the script. This was solved by wrapping the entire parameter list in double quotes. However, this meant that if the parameter list also contained double quotes this caused further confusion within the script. Several iterations later, we present what we believe to be a robust solution to this problem.

Use

When configuring a Process to utilize this wrapper script, the command line syntax defined in the Process configuration dialog box should be in the following format:

python epp_wrapper.py "script: 1st command line script: 2nd command line script: Nth command line"

Such a command line would lead to the following commands being executed on the external system:

1st command line
2nd command line
Nth command line

If your individual command lines need to contain embedded double quotes, use single quotes instead. For example:

python epp_wrapper.py "script: 1st command line which produces a file
'/home/gls/example file 1' script: 2nd command line which produces
a file '/home/gls/example file 2' script: Nth command line which produces a file
'/home/gls/example file N'"

Such a command line would lead to the following commands being executed on the external system:

1st command line which produces a file "/home/gls/example file 1"
2nd command line which produces a file "/home/gls/example file 2"
Nth command line which produces a file "/home/gls/example file N"

Notes

  1. This code was written and tested using Python version 3.2, but it should have reasonable backward compatibility
  2. This code was tested against GenoLogics LIMS versions 7.3 and 7.4
  3. This solution makes the assumption that both external applications are running on the same external system

 

 

Share