|
| 1 | +# Basics: Downloading Ontologies |
| 2 | + |
| 3 | +This minimal tutorial shows how to download ontologies using either Pooch or Download Manager, and how to load from the catalog or a URL. |
| 4 | + |
| 5 | +--- |
| 6 | + |
| 7 | +## 1. Choose a Global Default Downloader |
| 8 | + |
| 9 | +Set the default once in `ontograph/config/settings.py`: |
| 10 | + |
| 11 | +```python |
| 12 | +DEFAULT_DOWNLOADER = "pooch" |
| 13 | +# or |
| 14 | +DEFAULT_DOWNLOADER = "download_manager" |
| 15 | +``` |
| 16 | + |
| 17 | +Now any client will use the configured backend unless you pass a downloader explicitly. |
| 18 | + |
| 19 | +--- |
| 20 | + |
| 21 | +## 2. Use Pooch Explicitly |
| 22 | + |
| 23 | +```python |
| 24 | +from ontograph.client import ClientCatalog, ClientOntology |
| 25 | +from ontograph.downloader import PoochDownloaderAdapter |
| 26 | +from ontograph.config.settings import DEFAULT_CACHE_DIR |
| 27 | + |
| 28 | +downloader = PoochDownloaderAdapter(cache_dir=DEFAULT_CACHE_DIR) |
| 29 | + |
| 30 | +catalog = ClientCatalog(cache_dir="./data/out", downloader=downloader) |
| 31 | +catalog.load_catalog() |
| 32 | + |
| 33 | +client = ClientOntology(cache_dir="./data/out", downloader=downloader) |
| 34 | +client.load(source="go") # catalog download |
| 35 | +``` |
| 36 | + |
| 37 | +--- |
| 38 | + |
| 39 | +## 3. Use Download Manager Explicitly |
| 40 | + |
| 41 | +```python |
| 42 | +from ontograph.client import ClientCatalog, ClientOntology |
| 43 | +from ontograph.downloader import DownloadManagerAdapter |
| 44 | +from ontograph.config.settings import DEFAULT_CACHE_DIR |
| 45 | + |
| 46 | +downloader = DownloadManagerAdapter( |
| 47 | + cache_dir=DEFAULT_CACHE_DIR, |
| 48 | + backend="requests", |
| 49 | +) |
| 50 | + |
| 51 | +catalog = ClientCatalog(cache_dir="./data/out", downloader=downloader) |
| 52 | +catalog.load_catalog() |
| 53 | + |
| 54 | +client = ClientOntology(cache_dir="./data/out", downloader=downloader) |
| 55 | +client.load(source="go") # catalog download |
| 56 | +``` |
| 57 | + |
| 58 | +--- |
| 59 | + |
| 60 | +## 4. Download From a URL |
| 61 | + |
| 62 | +```python |
| 63 | +from ontograph.client import ClientOntology |
| 64 | +from ontograph.downloader import PoochDownloaderAdapter |
| 65 | +from ontograph.config.settings import DEFAULT_CACHE_DIR |
| 66 | + |
| 67 | +downloader = PoochDownloaderAdapter(cache_dir=DEFAULT_CACHE_DIR) |
| 68 | + |
| 69 | +# URL to GO ontology |
| 70 | +source_go = "https://purl.obolibrary.org/obo/go.obo" |
| 71 | + |
| 72 | +client = ClientOntology(cache_dir=DEFAULT_CACHE_DIR, downloader=downloader) |
| 73 | +client.load(source=source_go) |
| 74 | +``` |
0 commit comments