Skip to content

Instantly share code, notes, and snippets.

@cthoyt
Created November 3, 2021 20:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cthoyt/e172d01bb9f4468da17ca31fe36361f3 to your computer and use it in GitHub Desktop.
Save cthoyt/e172d01bb9f4468da17ca31fe36361f3 to your computer and use it in GitHub Desktop.
Download and parse all of Reactome with PyBioPAX
from pathlib import Path
import pandas as pd
import pybiopax
ALL_PATHWAYS = "https://reactome.org/download/current/ReactomePathways.txt"
def download_reactome(directory):
directory = Path(directory).resolve()
directory.mkdir(exist_ok=True)
reactome_ids = pd.read_csv(ALL_PATHWAYS, sep="\t", usecols=[0], squeeze=True)
for reactome_id in reactome_ids:
if not reactome_id.startswith("R-HSA"):
continue
# Downloads from API and parses into object model
model = pybiopax.model_from_reactome(reactome_id)
# Save from object model. Yes, this is a little roundabout
# from just saving from the API, but it demonstrates parsing
path = directory.joinpath(reactome_id).with_suffix(".xml")
pybiopax.model_to_owl_file(model, path)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment