annotate ngsap-vc/gatk/tool-data/destinations.py @ 3:0d10255b5434 draft default tip

Uploaded
author scisjnu123
date Thu, 03 Oct 2019 10:42:15 -0400
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3
0d10255b5434 Uploaded
scisjnu123
parents:
diff changeset
1 from galaxy.jobs import JobDestination
0d10255b5434 Uploaded
scisjnu123
parents:
diff changeset
2 import os
0d10255b5434 Uploaded
scisjnu123
parents:
diff changeset
3 import sys
0d10255b5434 Uploaded
scisjnu123
parents:
diff changeset
4 import json
0d10255b5434 Uploaded
scisjnu123
parents:
diff changeset
5 import cStringIO
0d10255b5434 Uploaded
scisjnu123
parents:
diff changeset
6 import logging
0d10255b5434 Uploaded
scisjnu123
parents:
diff changeset
7
0d10255b5434 Uploaded
scisjnu123
parents:
diff changeset
8 log = logging.getLogger( __name__ )
0d10255b5434 Uploaded
scisjnu123
parents:
diff changeset
9
0d10255b5434 Uploaded
scisjnu123
parents:
diff changeset
10
0d10255b5434 Uploaded
scisjnu123
parents:
diff changeset
11 def dump(obj, nested_level=0, output=sys.stdout):
0d10255b5434 Uploaded
scisjnu123
parents:
diff changeset
12 spacing = ' '
0d10255b5434 Uploaded
scisjnu123
parents:
diff changeset
13 if type(obj) == dict:
0d10255b5434 Uploaded
scisjnu123
parents:
diff changeset
14 print >> output, '%s{' % ((nested_level) * spacing)
0d10255b5434 Uploaded
scisjnu123
parents:
diff changeset
15 for k, v in obj.items():
0d10255b5434 Uploaded
scisjnu123
parents:
diff changeset
16 if hasattr(v, '__iter__'):
0d10255b5434 Uploaded
scisjnu123
parents:
diff changeset
17 print >> output, '%s%s:' % ((nested_level + 1) * spacing, k)
0d10255b5434 Uploaded
scisjnu123
parents:
diff changeset
18 dump(v, nested_level + 1, output)
0d10255b5434 Uploaded
scisjnu123
parents:
diff changeset
19 else:
0d10255b5434 Uploaded
scisjnu123
parents:
diff changeset
20 print >> output, '%s%s: %s' % ((nested_level + 1) * spacing, k, v)
0d10255b5434 Uploaded
scisjnu123
parents:
diff changeset
21 print >> output, '%s}' % (nested_level * spacing)
0d10255b5434 Uploaded
scisjnu123
parents:
diff changeset
22 elif type(obj) == list:
0d10255b5434 Uploaded
scisjnu123
parents:
diff changeset
23 print >> output, '%s[' % ((nested_level) * spacing)
0d10255b5434 Uploaded
scisjnu123
parents:
diff changeset
24 for v in obj:
0d10255b5434 Uploaded
scisjnu123
parents:
diff changeset
25 if hasattr(v, '__iter__'):
0d10255b5434 Uploaded
scisjnu123
parents:
diff changeset
26 dump(v, nested_level + 1, output)
0d10255b5434 Uploaded
scisjnu123
parents:
diff changeset
27 else:
0d10255b5434 Uploaded
scisjnu123
parents:
diff changeset
28 print >> output, '%s%s' % ((nested_level + 1) * spacing, v)
0d10255b5434 Uploaded
scisjnu123
parents:
diff changeset
29 print >> output, '%s]' % ((nested_level) * spacing)
0d10255b5434 Uploaded
scisjnu123
parents:
diff changeset
30 else:
0d10255b5434 Uploaded
scisjnu123
parents:
diff changeset
31 print >> output, '%s%s' % (nested_level * spacing, obj)
0d10255b5434 Uploaded
scisjnu123
parents:
diff changeset
32
0d10255b5434 Uploaded
scisjnu123
parents:
diff changeset
33
0d10255b5434 Uploaded
scisjnu123
parents:
diff changeset
34 def dynamic_slurm_cluster_gatk(job, tool_id):
0d10255b5434 Uploaded
scisjnu123
parents:
diff changeset
35 # Allocate extra time
0d10255b5434 Uploaded
scisjnu123
parents:
diff changeset
36 inp_data = dict( [ ( da.name, da.dataset ) for da in job.input_datasets ] )
0d10255b5434 Uploaded
scisjnu123
parents:
diff changeset
37 inp_data.update( [ ( da.name, da.dataset ) for da in job.input_library_datasets ] )
0d10255b5434 Uploaded
scisjnu123
parents:
diff changeset
38 inp_data.update( [ ( da.name, json.loads(da.value) ) for da in job.parameters ] )
0d10255b5434 Uploaded
scisjnu123
parents:
diff changeset
39 out = cStringIO.StringIO()
0d10255b5434 Uploaded
scisjnu123
parents:
diff changeset
40 dump(inp_data, 1, out)
0d10255b5434 Uploaded
scisjnu123
parents:
diff changeset
41 log.debug(out.getvalue())
0d10255b5434 Uploaded
scisjnu123
parents:
diff changeset
42
0d10255b5434 Uploaded
scisjnu123
parents:
diff changeset
43 nativeSpecs = '--nodes=1 --ntasks=1'
0d10255b5434 Uploaded
scisjnu123
parents:
diff changeset
44
0d10255b5434 Uploaded
scisjnu123
parents:
diff changeset
45 # runner doesn't allow to specify --cpus-per-task
0d10255b5434 Uploaded
scisjnu123
parents:
diff changeset
46 # thus the mem calculation gets messy with more than 1 node
0d10255b5434 Uploaded
scisjnu123
parents:
diff changeset
47 # --> translate nt ==> nodes, nct ==> ntasks
0d10255b5434 Uploaded
scisjnu123
parents:
diff changeset
48
0d10255b5434 Uploaded
scisjnu123
parents:
diff changeset
49 if 'cond_threads' not in inp_data:
0d10255b5434 Uploaded
scisjnu123
parents:
diff changeset
50 return JobDestination(runner="slurm")
0d10255b5434 Uploaded
scisjnu123
parents:
diff changeset
51
0d10255b5434 Uploaded
scisjnu123
parents:
diff changeset
52 if inp_data['cond_threads']['cond_threads_enabled'] == "True":
0d10255b5434 Uploaded
scisjnu123
parents:
diff changeset
53 nNodes = int(inp_data['cond_threads']['nt'])
0d10255b5434 Uploaded
scisjnu123
parents:
diff changeset
54 nCPU = int(inp_data['cond_threads']['nct'])
0d10255b5434 Uploaded
scisjnu123
parents:
diff changeset
55 nMEM = int(inp_data['cond_threads']['mem'])
0d10255b5434 Uploaded
scisjnu123
parents:
diff changeset
56 if nMEM > 0:
0d10255b5434 Uploaded
scisjnu123
parents:
diff changeset
57 nativeSpecs = '--nodes=%d --ntasks=%d --mem=%d' % (nNodes, nCPU*nNodes, nMEM)
0d10255b5434 Uploaded
scisjnu123
parents:
diff changeset
58 else:
0d10255b5434 Uploaded
scisjnu123
parents:
diff changeset
59 nativeSpecs = '--nodes=%d --ntasks=%d' % (nNodes, nCPU*nNodes)
0d10255b5434 Uploaded
scisjnu123
parents:
diff changeset
60
0d10255b5434 Uploaded
scisjnu123
parents:
diff changeset
61 return JobDestination(runner="slurm", params={"nativeSpecification": nativeSpecs})
0d10255b5434 Uploaded
scisjnu123
parents:
diff changeset
62