|
35 | 35 | from rocrate.rocrate import ROCrate |
36 | 36 |
|
37 | 37 | from .constants import PROFILES_BASE, PROFILES_VERSION, TERMS_NAMESPACE |
38 | | -from .utils import as_list |
| 38 | +from .utils import as_list, parse_img |
39 | 39 |
|
40 | 40 |
|
41 | 41 | WORKFLOW_BASENAME = "packed.cwl" |
|
61 | 61 |
|
62 | 62 | WROC_PROFILE_VERSION = "1.0" |
63 | 63 |
|
| 64 | +DOCKER_IMG_TYPE = "https://w3id.org/ro/terms/workflow-run#DockerImage" |
| 65 | + |
64 | 66 |
|
65 | 67 | def convert_cwl_type(cwl_type): |
66 | 68 | if isinstance(cwl_type, list): |
@@ -503,9 +505,24 @@ def to_wf_p(k): |
503 | 505 | action["endTime"] = activity.end().time.isoformat() |
504 | 506 | action["object"] = self.add_action_params(crate, activity, to_wf_p, "usage") |
505 | 507 | action["result"] = self.add_action_params(crate, activity, to_wf_p, "generation") |
| 508 | + self.add_container_images(crate, action, activity) |
506 | 509 | for job in activity.steps(): |
507 | 510 | self.add_action(crate, job, parent_instrument=instrument) |
508 | 511 |
|
| 512 | + def add_container_images(self, crate, action, activity): |
| 513 | + images = set() |
| 514 | + for assoc in activity.association(): |
| 515 | + for agent in activity.provenance.prov_doc.get_record(assoc.agent_id): |
| 516 | + images |= agent.get_attribute("cwlprov:image") |
| 517 | + for im in images: |
| 518 | + properties = parse_img(im) |
| 519 | + properties.update({ |
| 520 | + "@type": "ContainerImage", |
| 521 | + "additionalType": {"@id": DOCKER_IMG_TYPE} |
| 522 | + }) |
| 523 | + roc_img = crate.add(ContextEntity(crate, properties=properties)) |
| 524 | + action.append_to("containerImage", roc_img, compact=True) |
| 525 | + |
509 | 526 | def add_action_params(self, crate, activity, to_wf_p, ptype="usage"): |
510 | 527 | action_params = [] |
511 | 528 | all_roles = set() |
|
0 commit comments