generated from biobricks-ai/brick-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
81 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import os | ||
import shutil | ||
import subprocess | ||
|
||
# Clean up and initialize biobricks | ||
shutil.rmtree('.bb', ignore_errors=True) | ||
subprocess.run('biobricks init && biobricks add pubchem-annotations', shell=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import rdflib | ||
import pathlib | ||
|
||
outdir = pathlib.Path('cache/test') | ||
outdir.mkdir(parents=True, exist_ok=True) | ||
|
||
# Read the turtle file into a graph | ||
graph = rdflib.Graph() | ||
turtle_file = outdir / 'annotations.ttl' | ||
|
||
try: | ||
# Parse the Turtle file into the RDF graph | ||
graph.parse(source=turtle_file.as_posix(), format="turtle") | ||
|
||
# Generate metadata | ||
metadata = { | ||
"triple_count": len(graph), | ||
"namespaces": list(graph.namespaces()), | ||
"sample_triples": list(graph)[:5] # Limit to first 5 triples | ||
} | ||
|
||
# Write metadata to a file | ||
metadata_file = outdir / "test.txt" | ||
with open(metadata_file, "w") as f: | ||
f.write(f"Triple Count: {metadata['triple_count']}\n") | ||
f.write("Namespaces:\n") | ||
for prefix, uri in metadata['namespaces']: | ||
f.write(f" {prefix}: {uri}\n") | ||
f.write("Sample Triples:\n") | ||
for s, p, o in metadata['sample_triples']: | ||
f.write(f" {s} {p} {o}\n") | ||
|
||
print(f"Metadata written to {metadata_file}") | ||
|
||
except Exception as e: | ||
# Explicitly fail if the graph fails to load | ||
print(f"Failed to parse the graph: {e}") | ||
raise |