Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add author and tools details in RO-Crate #18820

Open
wants to merge 17 commits into
base: dev
Choose a base branch
from
Open
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 71 additions & 1 deletion lib/galaxy/model/store/ro_crate_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,77 @@ def _add_workflows(self, crate: ROCrate):

crate.license = self.workflow.license or ""
crate.mainEntity["name"] = self.workflow.name
crate.mainEntity["subjectOf"] = cwl_wf

# Adding the creator information
if hasattr(self.workflow, 'creator_metadata') and self.workflow.creator_metadata:
Marie59 marked this conversation as resolved.
Show resolved Hide resolved
creators = self.workflow.creator_metadata
if creators and isinstance(creators, list) and len(creators) > 0:
Marie59 marked this conversation as resolved.
Show resolved Hide resolved
first_creator = creators[0]
Marie59 marked this conversation as resolved.
Show resolved Hide resolved
creator_entity = crate.add(
ContextEntity(
crate,
first_creator.get('identifier', ''), # Default to empty string if identifier is missing
properties={
"@type": "Person",
"name": first_creator.get('name', ''), # Default to empty string if name is missing
Marie59 marked this conversation as resolved.
Show resolved Hide resolved
"orcid": first_creator.get('identifier', ''), # Assuming identifier as orcid, or adjust accordingly
},
)
)
crate.mainEntity.append_to("creator", creator_entity)

# Add CWL workflow entity if exists
crate.mainEntity["subjectOf"] = cwl_wf if cwl_wf else ""
Marie59 marked this conversation as resolved.
Show resolved Hide resolved

# Add tools used in the workflow
self._add_tools(crate)

def _add_tools(self, crate: ROCrate):
tool_entities = []

# Iterate over each step in the workflow
for step in self.workflow.steps:
# Check if the step corresponds to a tool
if step.type == "tool":
Marie59 marked this conversation as resolved.
Show resolved Hide resolved
tool_id = step.tool_id
Marie59 marked this conversation as resolved.
Show resolved Hide resolved
tool_version = step.tool_version
tool_name = step.label or tool_id # use label if available, fallback to tool_id
Marie59 marked this conversation as resolved.
Show resolved Hide resolved

# Initialize tool description for each tool
tool_description = ""
Marie59 marked this conversation as resolved.
Show resolved Hide resolved

# Check if the tool step has annotations
if hasattr(step, 'annotations') and step.annotations:
Marie59 marked this conversation as resolved.
Show resolved Hide resolved
# Assuming each annotation object has an 'annotation' attribute
annotations_list = []
for annotation_obj in step.annotations:
annotation_text = getattr(annotation_obj, 'annotation', None)
if annotation_text: # Check if annotation_text is not None
annotations_list.append(annotation_text)
Marie59 marked this conversation as resolved.
Show resolved Hide resolved

# Join annotations into a single string or handle them individually, depending on your requirement
tool_description = " ".join(annotations_list) if annotations_list else ""
Marie59 marked this conversation as resolved.
Show resolved Hide resolved

# Add tool entity to the RO-Crate
tool_entity = crate.add(
ContextEntity(
crate,
tool_id,
properties={
"@type": "SoftwareApplication",
"name": tool_name,
"version": tool_version,
"description": tool_description,
"url": "https://toolshed.g2.bx.psu.edu", # URL if relevant
},
)
)
tool_entities.append(tool_entity)

# Link tool entity with the workflow
crate.mainEntity.append_to("instrument", tool_entity)

return tool_entities

def _add_create_action(self, crate: ROCrate):
self.create_action = crate.add(
Expand Down