Skip to content

Commit

Permalink
Merge pull request #96 from djarecka/enh/bican_biolink_update
Browse files Browse the repository at this point in the history
adding script and GA to edit bican_biolink
  • Loading branch information
djarecka authored Dec 3, 2024
2 parents 5065b1b + af46e1f commit b497979
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 1 deletion.
50 changes: 50 additions & 0 deletions .github/workflows/bican_biolink_edit.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: generating other formats

on:
push:
branches:
- main
paths:
- 'linkml-schema/bican_biolink.yaml'

permissions:
contents: write


jobs:
generate:
runs-on: ubuntu-latest
steps:
- name: Checkout this repository
uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.9

- name: Install the required python packages
run: python -m pip install .[test]

- name: Other installations
run: |
sudo apt-get update
sudo apt-get install -y build-essential git wget curl
- name: Editing the bican biolink yaml file
run: |
cd linkml-schema
python ../utils/bican_biolink_edit.py bican_biolink.yaml
cd ..
- name: Adding edited file to git
run: |
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
if ! git diff linkml-schema/bican_biolink.yaml --quiet; then
git add linkml-schema/bican_biolink.yaml
git commit -m "Updating the bican biolink yaml file for the bican specific case"
git push
else
echo "No changes to commit"
fi
2 changes: 1 addition & 1 deletion .github/workflows/generate_other_formats.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
paths:
- 'linkml-schema/**'
workflow_run:
workflows: [ generating yaml file ]
workflows: [ "generating yaml file", "bican_biolink_edit" ]
types:
- completed

Expand Down
28 changes: 28 additions & 0 deletions utils/bican_biolink_edit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Functions to edit the biolink model after running the general trimmer from bkbit
# Edits are specific to our needs in bican and are not generalizable.
# Earlier the issues were "fixed" by adding "slot_usage", but it might be easier to add it to the bican_biolink directly.
import sys
import yaml
from pathlib import Path

def bican_biolink_edit(schema_yaml: str) -> None:
"""
Edit the biolink model to fit the bican needs
:param schema: SchemaView object
"""
# Change the category slot to have a curie range and a pattern for bican categories
schema_yaml_path = Path(schema_yaml)
with schema_yaml_path.open("r") as f:
schema_dict = yaml.safe_load(f)
schema_dict["slots"]["category"]["range"] = "curie"
schema_dict["slots"]["category"]["pattern"] = r"^bican:[A-Z][A-Za-z]+$"
schema_dict["slots"]["category"]["description"] = schema_dict["slots"]["category"]["description"] + ". NOTE: The category slot was modified to have a curie range and a pattern for bican categories."

with schema_yaml_path.open("w") as f:
f.write(yaml.dump(schema_dict, sort_keys=False))


if __name__ == '__main__':
bican_biolink_yaml_path = sys.argv[1]
bican_biolink_edit(bican_biolink_yaml_path)

0 comments on commit b497979

Please sign in to comment.