Created
November 3, 2021 20:08
-
-
Save cthoyt/e172d01bb9f4468da17ca31fe36361f3 to your computer and use it in GitHub Desktop.
Download and parse all of Reactome with PyBioPAX
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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