Skip to content

Commit

Permalink
Merge pull request #18 from geneontology/issue-13-cx2-context-attribute
Browse files Browse the repository at this point in the history
Add `@context` network attribute to CX2 output
  • Loading branch information
pkalita-lbl authored Oct 7, 2024
2 parents c981f05 + 167380d commit 709b9ad
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 12 deletions.
10 changes: 9 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ endif


# basename of a YAML file in model/
.PHONY: all clean setup gen-project gen-examples gendoc git-init-add git-init git-add git-commit git-status
.PHONY: all clean setup gen-project gen-examples gendoc git-init-add git-init git-add git-commit git-status lint lint-python lint-fix-python

# note: "help" MUST be the first target in the file,
# when the user types "make" they should get help info
Expand Down Expand Up @@ -148,6 +148,14 @@ test-python:
lint:
$(RUN) linkml-lint $(SOURCE_SCHEMA_PATH)

lint-python:
$(RUN) ruff format --check
$(RUN) ruff check

lint-fix-python:
$(RUN) ruff check --fix
$(RUN) ruff format

check-config:
ifndef LINKML_SCHEMA_NAME
$(error **Project not configured**:\n\n - See '.env.public'\n\n)
Expand Down
37 changes: 32 additions & 5 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ python = "^3.9"
click = "^8"
linkml-runtime = "^1.1.24"
ndex2 = "^3.9.0"
prefixmaps = "^0.2.5"
pydantic = "^2"
pyyaml = "^6"
requests = "^2"
Expand All @@ -20,6 +21,7 @@ requests = "^2"
linkml = "^1.3.5"
mkdocs-material = "^8.2.8"
mkdocs-mermaid2-plugin = ">=1.1.1"
ruff = "^0.6.9"
schemasheets = "^0.1.14"

[tool.poetry.group.test.dependencies]
Expand All @@ -42,3 +44,12 @@ gocam = "gocam.cli:cli"
markers = [
"integration"
]

[tool.ruff]
exclude = [
"project",
"src/gocam/datamodel"
]

[tool.ruff.lint]
select = ["E4", "E7", "E9", "F", "I"]
2 changes: 1 addition & 1 deletion src/gocam/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from gocam._version import __version__
from gocam._version import __version__ as __version__
2 changes: 1 addition & 1 deletion src/gocam/_version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from importlib.metadata import version, PackageNotFoundError
from importlib.metadata import PackageNotFoundError, version

try:
__version__ = version(__package__)
Expand Down
4 changes: 3 additions & 1 deletion src/gocam/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,9 @@ def convert(model, input_format, output_format, output, ndex_upload):
# Make the network searchable
client.set_network_system_properties(network_id, {"index_level": "META"})

click.echo(f"View network at: 'https://www.ndexbio.org/viewer/networks/{network_id}")
click.echo(
f"View network at: 'https://www.ndexbio.org/viewer/networks/{network_id}"
)
else:
click.echo(json.dumps(cx2), file=output)

Expand Down
2 changes: 1 addition & 1 deletion src/gocam/translation/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from gocam.translation.minerva_wrapper import MinervaWrapper
from gocam.translation.minerva_wrapper import MinervaWrapper as MinervaWrapper
2 changes: 1 addition & 1 deletion src/gocam/translation/cx2/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from gocam.translation.cx2.main import model_to_cx2
from gocam.translation.cx2.main import model_to_cx2 as model_to_cx2
10 changes: 9 additions & 1 deletion src/gocam/translation/cx2/main.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import json
import logging
import re
from functools import cache
from typing import Dict, List, Optional, Union

import prefixmaps
from ndex2.cx2 import CX2Network

from gocam.datamodel import (
Expand Down Expand Up @@ -50,13 +53,17 @@ def _remove_species_code_suffix(label: str) -> str:
return label


@cache
def _get_context():
return prefixmaps.load_context("go").as_dict()


# Regex from
# https://github.com/ndexbio/ndex-enrichment-rest/wiki/Enrichment-network-structure#via-node-attributes-preferred-method
IQUERY_GENE_SYMBOL_PATTERN = re.compile("(^[A-Z][A-Z0-9-]*$)|(^C[0-9]+orf[0-9]+$)")


def model_to_cx2(gocam: Model) -> list:

# Internal state
input_output_nodes: Dict[str, int] = {}
activity_nodes: Dict[str, int] = {}
Expand Down Expand Up @@ -101,6 +108,7 @@ def _add_input_output_nodes(
cx2_network = CX2Network()
cx2_network.set_network_attributes(
{
"@context": json.dumps(_get_context()),
"name": gocam.title if gocam.title is not None else gocam.id,
"represents": gocam.id,
}
Expand Down

0 comments on commit 709b9ad

Please sign in to comment.