Skip to content

Instantly share code, notes, and snippets.

@seandavi
Created February 17, 2011 05:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seandavi/831017 to your computer and use it in GitHub Desktop.
Save seandavi/831017 to your computer and use it in GitHub Desktop.
Python wrapper around SymD executable and xml tool description for running behind galaxy
<tool id="symd_tool" name="Perform SymD calculation on a PDB file">
<description>Use this tool to run symd on a PDB file</description>
<command interpreter="python">symd_wrapper.py $input $trfm_file $info_file ${input.name} </command>
<inputs>
<param format="txt" name="input" type="data" label="PDB file"/>
</inputs>
<outputs>
<data format="txt" name="trfm_file" />
<data format="txt" name="info_file" />
</outputs>
<help>
This tool simply runs SymD on the input file.
</help>
</tool>
import os
import subprocess
import sys
import tempfile
import shutil
# This is the name from galaxy for the input .pdb file
# Unfortunately, it has a name that ends in .dat
fname = sys.argv[1]
# These are the names of the datafiles supplied by galaxy
# for storing the output.
outfname1 = sys.argv[2]
outfname2 = sys.argv[3]
# this is the original filename
origfname = sys.argv[4]
# We simply symlink the galaxy system filename to the original
# filename to get SymD the protein name and the .pdb extension
os.symlink(fname,origfname)
# These are the names of the output files as created by
# SymD. We will need to copy these files back to
# outfname1 and outfname2 above.
symdinfofname = os.path.splitext(origfname)[0] + "-info.txt"
symdpdbfname = os.path.splitext(origfname)[0] + "-trfm.pdb"
# Call SymD with the symlinked file ending with .pdb
symdcmd = "SymD %s" % origfname
res = subprocess.call(symdcmd,stderr=subprocess.PIPE,stdout=subprocess.PIPE,shell=True)
if(res<>0):
print(stderr)
else:
# Finally, copy the output files from SymD back to the data files.
shutil.copy(symdinfofname,outfname1)
shutil.copy(symdpdbfname,outfname2)
@seandavi
Copy link
Author

To use these two files:

  1. Make sure that SymD is in the PATH
  2. make a directory in tools called "local_tools"
  3. Place both of these files inside "local_tools"
  4. Edit the tool_data.xml to include a section like:

    <section name="Local Tools" id="local_tools">
      <tool file="local_tools/symd_tool.xml" />
    </section>

@alexbk66
Copy link

Unfortunately ${input.name} is a job name and ONLY in case of file upload happens to be the original file name. If you feed an output from ANOTHER tool as input for this tool - it will be something like "<TOOL-NAME on data XX".

So this script only works on uploaded data.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment