Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
lhjohn committed Dec 18, 2024
0 parents commit 856e977
Show file tree
Hide file tree
Showing 11 changed files with 251 additions and 0 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: CI

on:
push:
branches:
- '**'
pull_request:
branches:
- '**'

env:
UV_SYSTEM_PYTHON: 1

jobs:
uv-example:
name: python
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Install uv
uses: astral-sh/setup-uv@v4

- name: Set up Python
run: uv python install

- name: Install the project
run: uv sync --all-extras --dev

- name: Run tests
run: uv run pytest tests
13 changes: 13 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Python-generated files
__pycache__/
*.py[oc]
build/
dist/
wheels/
*.egg-info

# Virtual environments
.venv

# Project files
.idea/
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.13
Empty file added README.md
Empty file.
30 changes: 30 additions & 0 deletions context/graph.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import networkx as nx
import time


class Graph:
def __init__(self, concept_ids, hierarchy):
"""
:param concept_ids: list of concept ids to create a hierarchy from
:param hierarchy: full hierarchy edge list (e.g. SNOMED's
CONCEPT_ANCESTOR.csv)
"""
self.graph = nx.DiGraph()
start = time.time()



delta = time.time() - start
print(f"Processed data in {delta:.2f} seconds")

def add_edge(self, u, v):
self.graph.add_edge(u, v)

def remove_edge(self, u, v):
self.graph.remove_edge(u, v)

def has_edge(self, u, v):
return self.graph.has_edge(u, v)

def get_neighbors(self, u):
return list(self.graph.successors(u))
9 changes: 9 additions & 0 deletions examples/example_usage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from context.graph import Graph
import networkx as nx
import polars as pl

concept_ids = [1, 2, 3, 4]
hierarchy = pl.read_csv("~/Desktop/snomed_vocabulary/CONCEPT_ANCESTOR.csv")

g = Graph(concept_ids, hierarchy)

6 changes: 6 additions & 0 deletions hello.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
def main():
print("Hello from context!")


if __name__ == "__main__":
main()
16 changes: 16 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[project]
name = "context"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.13"
dependencies = [
"networkx>=3.4.2",
"numpy>=2.2.0",
"polars>=1.17.1",
]

[dependency-groups]
dev = [
"pytest>=8.3.4",
]
3 changes: 3 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"""Requests test package initialisation."""

import warnings
13 changes: 13 additions & 0 deletions tests/test_edge-list.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from context.graph import Graph
import networkx as nx


def test_addition():
assert (1 + 1) == 2


def test_directed_graph():
concept_ids = [1, 2, 3, 4]
hierarchy = [(1, 2), (2, 3), (3, 4)]
g = Graph(concept_ids, hierarchy)
assert isinstance(g.graph, nx.DiGraph), "Graph is not a directed graph"
128 changes: 128 additions & 0 deletions uv.lock

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

0 comments on commit 856e977

Please sign in to comment.