Repository: DataBiosphere/toil

Issue:
CWL: --workdir should default to --tmpdir-prefix, if present
Hi, 
I am trying to run this [workflow](https://github.com/DataBiosphere/topmed-workflows/blob/develop/aligner/sbg-alignment-cwl/topmed-alignment.cwl) using cwltoil on a cloud instance as following: 
```
cwltoil --no-match-user --tmp-outdir-prefix=/CWLProv_workflow_testing/intermediate_temp/temp --tmpdir-prefix=/CWLProv_workflow_testing/intermediate_temp/temp topmed-workflows/aligner/sbg-alignment-cwl/topmed-alignment.cwl topmed-workflows/aligner/sbg-alignment-cwl/topmed-alignment.sample.json.new
```
Here is the error that I get: 

```
Traceback (most recent call last):
  File "/CWLProv_workflow_testing/toiltesting/bin/cwltoil", line 11, in <module>
    sys.exit(main())
  File "/CWLProv_workflow_testing/toiltesting/local/lib/python2.7/site-packages/toil/cwl/cwltoil.py", line 1204, in main
    outobj = toil.start(wf1)
  File "/CWLProv_workflow_testing/toiltesting/local/lib/python2.7/site-packages/toil/common.py", line 784, in start
    return self._runMainLoop(rootJobGraph)
  File "/CWLProv_workflow_testing/toiltesting/local/lib/python2.7/site-packages/toil/common.py", line 1059, in _runMainLoop
    jobCache=self._jobCache).run()
  File "/CWLProv_workflow_testing/toiltesting/local/lib/python2.7/site-packages/toil/leader.py", line 208, in run
    self.innerLoop()
  File "/CWLProv_workflow_testing/toiltesting/local/lib/python2.7/site-packages/toil/leader.py", line 539, in innerLoop
    self._gatherUpdatedJobs(updatedJobTuple)
  File "/CWLProv_workflow_testing/toiltesting/local/lib/python2.7/site-packages/toil/leader.py", line 496, in _gatherUpdatedJobs
    self.processFinishedJob(jobID, result, wallTime=wallTime)
  File "/CWLProv_workflow_testing/toiltesting/local/lib/python2.7/site-packages/toil/leader.py", line 807, in processFinishedJob
    self.jobStore.update(jobGraph)
  File "/CWLProv_workflow_testing/toiltesting/local/lib/python2.7/site-packages/toil/jobStores/fileJobStore.py", line 214, in update
    pickle.dump(job, f)
IOError: [Errno 28] No space left on device
```
I have an attached volume with ample disk space and have an XXlarge instance which has enough cores and memory. The issue is, despite using tmpdir prefixes cwltoil is not using these resources but is limited to the default 10G. 
I have read the documentations and could not find any way to redirect this computation to use these resources. 
cwltool on itself works fine when tmpdirs are assigned a location. 

I am not sure what's the solution of this issue. 
Any help will be much appreciated.

┆Issue is synchronized with this [Jira Story](https://ucsc-cgl.atlassian.net/browse/TOIL-336)
┆Issue Number: TOIL-336



Discussion:
@mr-c Yes setting --workDir worked fine and I was able to run this workflow. 
Thanks a lot. 
@mr-c Are there any problems left to address?  I'm inclined to close this.
For a better user experience  --workdir should default to --tmpdir-prefix, if present. 
I'll send a PR tomorrow

Resolving patch:
diff --git a/src/toil/cwl/cwltoil.py b/src/toil/cwl/cwltoil.py
--- a/src/toil/cwl/cwltoil.py
+++ b/src/toil/cwl/cwltoil.py
@@ -1073,6 +1073,10 @@ def main(args=None, stdout=sys.stdout):
     # we use workdir as jobStore:
     options = parser.parse_args([workdir] + args)
 
+    # if tmpdir_prefix is not the default value, set workDir too
+    if options.tmpdir_prefix != 'tmp':
+        options.workDir = options.tmpdir_prefix
+
     if options.provisioner and not options.jobStore:
         raise NoSuchJobStoreException(
             'Please specify a jobstore with the --jobStore option when specifying a provisioner.')


Test patch:
diff --git a/src/toil/test/cwl/cwlTest.py b/src/toil/test/cwl/cwlTest.py
--- a/src/toil/test/cwl/cwlTest.py
+++ b/src/toil/test/cwl/cwlTest.py
@@ -15,24 +15,25 @@
 from __future__ import print_function
 import json
 import os
-from toil import subprocess
+import sys
 import unittest
 import re
 import shutil
+import zipfile
 import pytest
 from future.moves.urllib.request import urlretrieve
-import zipfile
-
-# Python 3 compatibility imports
 from six.moves import StringIO
 from six import u as str
 
+pkg_root = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))  # noqa
+sys.path.insert(0, pkg_root)  # noqa
+
+from toil import subprocess
 from toil.test import (ToilTest, needs_cwl, slow, needs_docker, needs_lsf,
                        needs_mesos, needs_parasol, needs_gridengine, needs_slurm,
                        needs_torque)
 
 
-
 @needs_cwl
 class CWLTest(ToilTest):