Skip to content

Commit

Permalink
Create script to generate ncbitaxon obo graph and add it to mira dock…
Browse files Browse the repository at this point in the history
…er image
  • Loading branch information
nanglo123 committed Sep 18, 2024
1 parent a3cd2a9 commit 3cc1ded
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
15 changes: 15 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
# Create an initial docker image to generate the graph and transfer it to the
# second docker image
# We do this to avoid involving additional imports in the second docker image
FROM python:3.10-slim AS graph-builder

WORKDIR /graphs
RUN apt-get update && apt-get install -y git
RUN pip install pyobo networkx obonet

# Copy and run the script to generate the pickled graph
COPY generate_graph.py /graphs/generate_graph.py
RUN python generate_graph.py

FROM ubuntu:focal

WORKDIR /sw
Expand Down Expand Up @@ -42,5 +55,7 @@ RUN python -m pip install --upgrade pip && \
# Copy the example json for reconstructing the ode semantics
RUN wget -O /sw/sir_flux_span.json https://raw.githubusercontent.com/gyorilab/mira/main/tests/sir_flux_span.json

RUN mkdir -p /graphs
COPY --from=graph-builder /graphs/relabeled_obo_graph.pkl /graphs/relabeled_obo_graph.pkl
COPY startup.sh startup.sh
ENTRYPOINT ["/bin/bash", "/sw/startup.sh"]
26 changes: 26 additions & 0 deletions docker/generate_graph.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from pyobo import get_version
from pyobo.getters import _ensure_ontology_path
from pathlib import Path
from obonet import read_obo
import networkx
import pickle

def download_convert_ncbitaxon_obo_to_graph():
resource_prefix = "ncbitaxon"
version = get_version(resource_prefix)

# Checks to see if the pickled ncbitaxon obo graph exists in the container
cached_relabeled_obo_graph_path = Path("/graphs/relabeled_obo_graph.pkl")
if not cached_relabeled_obo_graph_path.exists():
_, obo_path = _ensure_ontology_path(resource_prefix, force=False,
version=version)
obo_graph = read_obo(obo_path)
relabeled_graph = networkx.relabel_nodes(obo_graph,
lambda node_index:
node_index.lower())
with open(cached_relabeled_obo_graph_path,
'wb') as relabeled_graph_file:
pickle.dump(relabeled_graph, relabeled_graph_file)

if __name__ == "__main__":
download_convert_ncbitaxon_obo_to_graph()

0 comments on commit 3cc1ded

Please sign in to comment.