diff --git a/ro-crate-metadata/ro-crate-metadata.json b/ro-crate-metadata/ro-crate-metadata.json index a15bb16..828f347 100644 --- a/ro-crate-metadata/ro-crate-metadata.json +++ b/ro-crate-metadata/ro-crate-metadata.json @@ -4,14 +4,16 @@ { "@id": "./", "@type": "Dataset", - "datePublished": "2024-08-08T08:29:52+00:00", - "description": "Test Description", - "hasPart": [ + "conformsTo": [ { - "@id": "merged.ttl" - }, + "@id": "https://w3id.org/ro/crate/1.1/context" + } + ], + "datePublished": "2024-08-14T11:05:10+00:00", + "description": "This RO-Crate contains the merged RDF triples from multiple RO-Crates sourced from WorkflowHub.", + "hasPart": [ { - "@id": "#12c6426a-fe66-48e6-9863-bde836ce0b16" + "@id": "#95e109d1-6250-4d45-8124-fb98a2a7627b" }, { "@id": "Dockerfile" @@ -22,6 +24,9 @@ { "@id": "README.md" }, + { + "@id": "merged.ttl" + }, { "@id": "Snakefile" } @@ -47,29 +52,32 @@ ] }, { - "@id": "merged.ttl", - "@type": "File", - "author": [ - { - "@id": "https://orcid.org/0000-0000-0000-0000" - }, - { - "@id": "https://orcid.org/0000-0000-0000-0001" - } - ], - "description": "This file contains merged RDF triples from multiple RO-Crates sourced from WorkflowHub.", - "encodingFormat": "text/turtle", - "name": "Merged Data File" + "@id": "https://orcid.org/0000-0000-0000-0000", + "@type": "Person", + "affiliation": "University of Flatland", + "name": "Alice Doe" }, { - "@id": "#12c6426a-fe66-48e6-9863-bde836ce0b16", + "@id": "https://orcid.org/0000-0000-0000-0001", + "@type": "Person", + "affiliation": "University of Flatland", + "name": "Bob Doe" + }, + { + "@id": "#95e109d1-6250-4d45-8124-fb98a2a7627b", "@type": "Dataset", "description": "A directory containing modules used by the workflow.", "name": "WorkflowHub Graph" }, { "@id": "Dockerfile", - "@type": "File" + "@type": "File", + "conformsTo": { + "@id": "https://docs.docker.com/reference/dockerfile/" + }, + "description": "The Dockerfile used to build the Docker images for the workflow.", + "encodingFormat": "application/yaml", + "name": "Dockerfile" }, { "@id": "poetry.lock", @@ -79,6 +87,17 @@ "@id": "README.md", "@type": "File" }, + { + "@id": "merged.ttl", + "@type": "File", + "author": [ + "https://orcid.org/0000-0000-0000-0000", + "https://orcid.org/0000-0000-0000-0001" + ], + "description": "This file contains merged RDF triples from multiple RO-Crates sourced from WorkflowHub.", + "encodingFormat": "text/turtle", + "name": "Merged Data File" + }, { "@id": "Snakefile", "@type": [ @@ -87,18 +106,12 @@ "ComputationalWorkflow" ], "author": [ - { - "@id": "https://orcid.org/0000-0000-0000-0000" - }, - { - "@id": "https://orcid.org/0000-0000-0000-0001" - } + "https://orcid.org/0000-0000-0000-0000", + "https://orcid.org/0000-0000-0000-0001" ], "description": "This is the Snakemake workflow used to generate the merged RDF triples.", "name": "Snakemake Workflow", - "output": { - "@id": "merged.ttl" - }, + "output": "merged.ttl", "programmingLanguage": { "@id": "https://w3id.org/workflowhub/workflow-ro-crate#snakemake" } @@ -115,16 +128,17 @@ } }, { - "@id": "https://orcid.org/0000-0000-0000-0000", - "@type": "Person", - "affiliation": "University of Flatland", - "name": "Alice Doe" - }, - { - "@id": "https://orcid.org/0000-0000-0000-0001", - "@type": "Person", - "affiliation": "University of Flatland", - "name": "Bob Doe" + "@id": "#6075be5c-e748-4c95-995c-5095d5fc7c9d", + "@type": "CreateAction", + "agent": [ + "https://orcid.org/0000-0000-0000-0000", + "https://orcid.org/0000-0000-0000-0001" + ], + "description": "Merging RDF triples from sourced crates.", + "endTime": "11:05:10.204371", + "instrument": "Snakefile", + "name": "Merge RDF Triples", + "result": "merged.ttl" } ] } \ No newline at end of file diff --git a/workflowhub_graph/create_ro_crate.py b/workflowhub_graph/create_ro_crate.py index 009e24c..65874c1 100644 --- a/workflowhub_graph/create_ro_crate.py +++ b/workflowhub_graph/create_ro_crate.py @@ -1,6 +1,8 @@ import sys +import uuid +from datetime import datetime -from rocrate.model import Person +from rocrate.model import ContextEntity, Person from rocrate.rocrate import ROCrate @@ -14,15 +16,29 @@ def create_ro_crate(input_file: str, workflow_file: str, output_dir: str) -> Non """ crate = ROCrate() - data_entity = crate.add_file( - input_file, - properties={ - "name": "Merged Data File", - "description": "This file contains merged RDF triples from multiple RO-Crates sourced from WorkflowHub.", - "encodingFormat": "text/turtle", - }, + crate.name = "WorkflowHub Knowledge Graph" + crate.description = ( + "This RO-Crate contains the merged RDF triples from multiple RO-Crates sourced from " + "WorkflowHub." + ) + + # Add authors: + alice = crate.add( + Person( + crate, + "https://orcid.org/0000-0000-0000-0000", + properties={"name": "Alice Doe", "affiliation": "University of Flatland"}, + ) + ) + bob = crate.add( + Person( + crate, + "https://orcid.org/0000-0000-0000-0001", + properties={"name": "Bob Doe", "affiliation": "University of Flatland"}, + ) ) + # Add dataset and files: crate.add_dataset( "./workflowhub_graph/", properties={ @@ -31,44 +47,64 @@ def create_ro_crate(input_file: str, workflow_file: str, output_dir: str) -> Non }, ) - crate.add_file("./Dockerfile") + crate.add_file( + "./Dockerfile", + properties={ + "@type": "File", + "name": "Dockerfile", + "encodingFormat": "application/yaml", + "description": "The Dockerfile used to build the Docker images for the workflow.", + "conformsTo": {"@id": "https://docs.docker.com/reference/dockerfile/"}, + }, + ) + crate.add_file("./poetry.lock") crate.add_file("./README.md") + # Add data and workflow entities: + data_entity = crate.add_file( + input_file, + properties={ + "name": "Merged Data File", + "description": "This file contains merged RDF triples from multiple RO-Crates sourced from WorkflowHub.", + "encodingFormat": "text/turtle", + "author": [alice["@id"], bob["@id"]], + }, + ) + workflow_entity = crate.add_workflow( source=workflow_file, properties={ "name": "Snakemake Workflow", "description": "This is the Snakemake workflow used to generate the merged RDF triples.", + "author": [alice["@id"], bob["@id"]], + "output": data_entity["@id"], }, main=True, lang="snakemake", ) - # Authors: - alice = crate.add( - Person( - crate, - "https://orcid.org/0000-0000-0000-0000", - properties={"name": "Alice Doe", "affiliation": "University of Flatland"}, + if "conformsTo" not in crate.root_dataset: + crate.root_dataset.append_to( + "conformsTo", {"@id": "https://w3id.org/ro/wfrun/workflow/0.5"} ) - ) - bob = crate.add( - Person( + + crate.add( + ContextEntity( crate, - "https://orcid.org/0000-0000-0000-0001", - properties={"name": "Bob Doe", "affiliation": "University of Flatland"}, + identifier=str(uuid.uuid4()), + properties={ + "@type": "CreateAction", + "name": "Merge RDF Triples", + "description": "Merging RDF triples from sourced crates.", + "agent": [alice["@id"], bob["@id"]], + "endTime": datetime.now().time().isoformat(), + "instrument": workflow_entity["@id"], + "result": data_entity["@id"], + }, ) ) - crate.name = "WorkflowHub Knowledge Graph" - crate.description = "Test Description" - - data_entity["author"] = [alice, bob] - - workflow_entity["output"] = data_entity - workflow_entity["author"] = [alice, bob] - # Writing the RO-Crate metadata: crate.write(output_dir)