Skip to content

Commit 1e0e74c

Browse files
committed
add basis ROHub test cases, just for information exchange
1 parent 5398cee commit 1e0e74c

File tree

6 files changed

+175
-0
lines changed

6 files changed

+175
-0
lines changed

src/ROhub/.env

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[API_SECTION]
2+
API_URL = https://rohub2020-rohub.apps.paas-dev.psnc.pl/api/
3+
4+
[KEYCLOAK_SECTION]
5+
KEYCLOAK_CLIENT_ID = rohub2020-cli
6+
KEYCLOAK_CLIENT_SECRET = 714617a7-87bc-4a88-8682-5f9c2f60337d
7+
KEYCLOAK_URL = https://keycloak-dev.apps.paas-dev.psnc.pl/auth/realms/rohub/protocol/openid-connect/token

src/ROhub/ROhub_env.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name: rohub
2+
channels:
3+
- conda-forge
4+
dependencies:
5+
- python=3.12
6+
- sparqlwrapper
7+
- pip
8+
- pip:
9+
- "--editable=git+https://gitlab.pcss.pl/daisd-public/rohub/rohub-api.git#egg=rohub"

src/ROhub/Readme.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Installation for using the package ROhub with the development server
2+
Install the package via pip (in conda) using the options
3+
4+
`--editable=git+https://gitlab.pcss.pl/daisd-public/rohub/rohub-api.git#egg=rohub`
5+
6+
Find the location of the local installation (`pip show rohub`) and copy the file `.env` into this directory using a single command:
7+
8+
```bash
9+
cp -v .env "$(pip show rohub | awk -F': ' '/Editable project location/ {print $2}')/.env"
10+
```
11+

src/ROhub/test_import.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import rohub
2+
import pandas as pd
3+
4+
print("ROHub API URL:", rohub.settings.API_URL)
5+
# loading credentials from external file
6+
user_name = "[email protected]"
7+
user_pwd = open("passwordROHub.txt").read()
8+
rohub.login(
9+
username=user_name, password=user_pwd
10+
) # Ensure you are logged in to access ROHub features
11+
12+
13+
# zip_path = "./metadata4ing_provenance.zip"
14+
zip_path = "./nextflow_results_linear-elastic-plate-with-hole.zip"
15+
resources_from_zip = rohub.ros_upload(path_to_zip=zip_path)
16+
17+
my_ros = rohub.list_my_ros()
18+
if len(my_ros) == 0:
19+
print("Error fetching RO with id:", id, "creating a new one", e)
20+
ro_title = "The influence of eating habits on sleep"
21+
ro_research_areas = ["Medical science"]
22+
ro = rohub.ros_create(title=ro_title, research_areas=ro_research_areas)
23+
my_ros = rohub.list_my_ros()
24+
25+
26+
# Assuming df is your pandas DataFrame with an "identifier" column
27+
for index, row in my_ros.iterrows():
28+
id = row["identifier"]
29+
ro = rohub.ros_load(id)
30+
print("RO type:", ro.ros_type)
31+
if hasattr(ro, "title") and ro.title:
32+
print("RO title:", ro.title)
33+
if hasattr(ro, "authors") and ro.authors:
34+
print("RO authors:", ro.authors)
35+
if hasattr(ro, "description") and ro.description:
36+
print("RO description:", ro.description)
37+
if hasattr(ro, "research_areas") and ro.research_areas:
38+
print("RO research areas:", ro.research_areas)
39+
if hasattr(ro, "creation_date") and ro.creation_date:
40+
print("RO creation date:", ro.creation_date)
41+
if hasattr(ro, "last_modified_date") and ro.last_modified_date:
42+
print("RO last modified date:", ro.last_modified_date)
43+
if hasattr(ro, "doi") and ro.doi:
44+
print("RO DOI:", ro.doi)
45+
if hasattr(ro, "url") and ro.url:
46+
print("RO URL:", ro.url)
47+
if hasattr(ro, "metadata") and ro.metadata:
48+
print("RO metadata:", ro.metadata)
49+
print("RO metadata:", ro.show_metadata())
50+
print("---------------------------------")

src/ROhub/test_queryROhub.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
from SPARQLWrapper import SPARQLWrapper, JSON
2+
3+
# SPARQL endpoint
4+
sparql = SPARQLWrapper(
5+
"https://rohub2020-api-virtuoso-route-rohub.apps.paas-dev.psnc.pl/sparql/"
6+
)
7+
8+
# Find datasets that conform to Workflow RO-Crate 1.0
9+
query = """
10+
PREFIX schema: <http://schema.org/>
11+
PREFIX dct: <http://purl.org/dc/terms/>
12+
SELECT ?dataset ?datePublished ?author ?part WHERE {
13+
?dataset a schema:Dataset .
14+
?dataset dct:conformsTo <https://w3id.org/workflowhub/workflow-ro-crate/1.0> .
15+
?dataset schema:author ?author .
16+
FILTER (?author = <https://orcid.org/0000-0000-0000-0000>)
17+
OPTIONAL { ?dataset schema:datePublished ?datePublished }
18+
OPTIONAL { ?dataset schema:hasPart ?part }
19+
}
20+
"""
21+
22+
sparql.setQuery(query)
23+
sparql.setReturnFormat(JSON)
24+
25+
try:
26+
resp = sparql.query().convert()
27+
bindings = resp.get("results", {}).get("bindings", [])
28+
29+
print("Dataset Query Results:")
30+
print("========================================")
31+
# Print directly per row instead of aggregating into a structure
32+
for row in bindings:
33+
print(f"Dataset: {row.get('dataset', {}).get('value', 'None')}")
34+
print(f"Date Published: {row.get('datePublished', {}).get('value', 'None')}")
35+
print(f"Author: {row.get('author', {}).get('value', 'None')}")
36+
print(f"Part: {row.get('part', {}).get('value', 'None')}")
37+
print("-" * 40)
38+
39+
except Exception as e:
40+
print(f"Error executing SPARQL query: {e}")

src/ROhub/test_query_local.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
from rdflib import Graph, URIRef, Namespace
2+
3+
# Load RO-Crate metadata
4+
graph = Graph()
5+
graph.parse("ro-crate-metadata.json", format="json-ld")
6+
7+
# Define namespaces
8+
SCHEMA = Namespace("http://schema.org/")
9+
10+
try:
11+
# Show datasets and their dct:conformsTo values
12+
debug_query = """
13+
PREFIX schema: <http://schema.org/>
14+
PREFIX dct: <http://purl.org/dc/terms/>
15+
SELECT ?dataset ?ct WHERE {
16+
?dataset a schema:Dataset .
17+
OPTIONAL { ?dataset dct:conformsTo ?ct }
18+
}
19+
"""
20+
print("DEBUG: All datasets and their dct:conformsTo objects")
21+
print("=" * 60)
22+
for row in graph.query(debug_query):
23+
print(f"Dataset: {row.dataset}")
24+
print(f"ConformsTo: {row.ct if row.ct else 'None'}")
25+
print("-" * 40)
26+
27+
# Find datasets that conform to Workflow RO-Crate 1.0
28+
query = """
29+
PREFIX schema: <http://schema.org/>
30+
PREFIX dct: <http://purl.org/dc/terms/>
31+
SELECT ?dataset ?datePublished ?author ?part WHERE {
32+
?dataset a schema:Dataset .
33+
?dataset dct:conformsTo <https://w3id.org/workflowhub/workflow-ro-crate/1.0> .
34+
?dataset schema:author ?author .
35+
FILTER (?author = <https://orcid.org/0000-0000-0000-0000>)
36+
OPTIONAL { ?dataset schema:datePublished ?datePublished }
37+
OPTIONAL { ?dataset schema:hasPart ?part }
38+
}
39+
"""
40+
results = graph.query(query)
41+
42+
print("\nWorkflowHub Dataset Query Results:")
43+
print("========================================")
44+
# Print directly per row instead of aggregating into a structure
45+
found_any = False
46+
for row in results:
47+
found_any = True
48+
print(f"Dataset: {row.dataset}")
49+
print(f"Date Published: {row.datePublished if row.datePublished else 'None'}")
50+
print(f"Author: {row.author if row.author else 'None'}")
51+
print(f"Part: {row.part if row.part else 'None'}")
52+
print("-" * 40)
53+
54+
if not found_any:
55+
print("No datasets found that conform to Workflow RO-Crate 1.0")
56+
57+
except Exception as e:
58+
print(f"Error: {e}")

0 commit comments

Comments
 (0)