Skip to content

Commit

Permalink
create_ro_crate.py now builds an RO crate that better fits workflow r…
Browse files Browse the repository at this point in the history
…un profile (#39)

- Addresses #39
- create_ro_crate.py refactored and updated to create crate that includes CreateAction with relevant metadata
- Metadata added to Dockerfile
- Example RO Crate Metadata updated to reflect this
  • Loading branch information
alexhambley committed Aug 14, 2024
1 parent 7acea3a commit f2bab54
Show file tree
Hide file tree
Showing 2 changed files with 118 additions and 68 deletions.
94 changes: 54 additions & 40 deletions ro-crate-metadata/ro-crate-metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -22,6 +24,9 @@
{
"@id": "README.md"
},
{
"@id": "merged.ttl"
},
{
"@id": "Snakefile"
}
Expand All @@ -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",
Expand All @@ -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": [
Expand All @@ -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"
}
Expand All @@ -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"
}
]
}
92 changes: 64 additions & 28 deletions workflowhub_graph/create_ro_crate.py
Original file line number Diff line number Diff line change
@@ -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


Expand All @@ -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={
Expand All @@ -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)

Expand Down

0 comments on commit f2bab54

Please sign in to comment.