| 1 |
""" |
| 2 |
Models carried over from pbsmrtpipe, still required for SMRT Link interface. |
| 3 |
""" |
| 4 |
|
| 5 |
from collections import namedtuple |
| 6 |
import json |
| 7 |
|
| 8 |
|
| 9 |
class Pipeline: |
| 10 |
|
| 11 |
def __init__(self, idx, display_name, version, description, bindings, |
| 12 |
entry_points, parent_pipeline_ids=None, tags=(), |
| 13 |
task_options=None): |
| 14 |
|
| 15 |
self.idx = idx |
| 16 |
self.version = version |
| 17 |
self.display_name = display_name |
| 18 |
self.description = description.strip() |
| 19 |
|
| 20 |
self.bindings = {x for x in bindings} |
| 21 |
|
| 22 |
self.entry_points = entry_points |
| 23 |
|
| 24 |
self.tags = tags |
| 25 |
if parent_pipeline_ids is None: |
| 26 |
self.parent_pipeline_ids = [] |
| 27 |
else: |
| 28 |
self.parent_pipeline_ids = parent_pipeline_ids |
| 29 |
|
| 30 |
self.task_options = {} if task_options is None else task_options |
| 31 |
|
| 32 |
@property |
| 33 |
def pipeline_id(self): |
| 34 |
return self.idx |
| 35 |
|
| 36 |
@property |
| 37 |
def required_inputs(self): |
| 38 |
return [o for o in self.entry_points if not o.optional] |
| 39 |
|
| 40 |
@property |
| 41 |
def optional_inputs(self): |
| 42 |
return [o for o in self.entry_points if o.optional] |
| 43 |
|
| 44 |
def to_d(self): |
| 45 |
return { |
| 46 |
"id": self.idx, |
| 47 |
"name": self.display_name, |
| 48 |
"description": self.description, |
| 49 |
"entryPoints": self.entry_points, |
| 50 |
"options": [], |
| 51 |
"taskOptions": self.task_options, |
| 52 |
"tags": self.tags, |
| 53 |
"schemaVersion": "2.0.0", |
| 54 |
"_comment": "Automatically generated by pbcommand", |
| 55 |
"version": self.version |
| 56 |
} |
| 57 |
|
| 58 |
def to_json(self): |
| 59 |
return json.dumps(self.to_d(), indent=2) |
| 60 |
|
| 61 |
def write_json(self, file_name): |
| 62 |
with open(file_name, "wt") as json_out: |
| 63 |
json_out.write(self.to_json()) |
| 64 |
|
| 65 |
def __repr__(self): |
| 66 |
|
| 67 |
ek = [e["entryId"] for e in self.entry_points] |
| 68 |
e = " ".join(ek) |
| 69 |
_d = dict(k=self.__class__.__name__, i=self.idx, |
| 70 |
d=self.display_name, b=len(self.bindings), e=e) |
| 71 |
return "<{k} id={i} nbindings={b} entry bindings={e} >".format(**_d) |
| 72 |
|
| 73 |
def summary(self, verbose=True): |
| 74 |
outs = [] |
| 75 |
f = outs.append |
| 76 |
|
| 77 |
def _format_inputs(inputs): |
| 78 |
return ", ".join([ep.short_name for ep in inputs]) |
| 79 |
|
| 80 |
f("Workflow Summary") |
| 81 |
f("Workflow Id : {}".format(self.pipeline_id)) |
| 82 |
f("Name : {}".format(self.display_name)) |
| 83 |
f("Description : {}".format(self.description)) |
| 84 |
f("Required Inputs: {}".format(_format_inputs(self.required_inputs))) |
| 85 |
if len(self.optional_inputs) > 0: |
| 86 |
f("Optional Inputs: {}".format(_format_inputs(self.optional_inputs))) |
| 87 |
if self.tags: |
| 88 |
f("Tags : {} ".format(", ".join(list(set(self.tags))))) |
| 89 |
if len(self.task_options) > 0: |
| 90 |
f("Task Options:") |
| 91 |
for opt in self.task_options: |
| 92 |
f(" {o} = {v}".format(o=opt.option_id, v=opt.default)) |
| 93 |
if verbose: |
| 94 |
f(" {n} ({t})".format(n=opt.name, t=opt.OPTION_TYPE_ID)) |
| 95 |
return "\n".join(outs) |