You need to agree to share your contact information to access this dataset

This repository is publicly accessible, but you have to accept the conditions to access its files and content.

Log in or Sign Up to review the conditions and access this dataset content.

Step 3 — Install Dependencies

pip install huggingface-hub pandas

Step 4 — Login

from huggingface_hub import login

login(token="YOUR_HF_TOKEN")


Download Script

from huggingface_hub import snapshot_download
import pandas as pd
import os


def download_pathomics(
    ids=None,
    pathomics_dir="pathomics_data",
    hest_dir="pathomics_data",
):

    # -----------------------------
    # load metadata index
    # -----------------------------
    meta = None
    
    csv_files = [f for f in os.listdir(pathomics_dir)
                 if f.startswith("PATHOMICS_v")]

    # print(csv_files)

    if len(csv_files) > 0:
        csv_path = os.path.join(pathomics_dir, sorted(csv_files)[-1])
        meta = pd.read_csv(csv_path)

    if ids is None:
        snapshot_download(
            repo_id="Boyoungc/pathomics",
            allow_patterns="*",
            repo_type="dataset",
            local_dir=pathomics_dir,
        )
        return

    # -----------------------------
    # split ids
    # -----------------------------
    hest_ids = []
    local_ids = []

    if meta is not None and "source" in meta.columns:
        sub = meta[meta["id"].isin(ids)]
        hest_ids = sub[sub["source"] == "hest"]["id"].tolist()
        local_ids = sub[sub["source"] != "hest"]["id"].tolist()
    else:
        local_ids = ids

    # =========================================================
    # 1. HEST DOWNLOAD (STRICT MODALITY FILTER)
    # =========================================================
    if len(hest_ids) > 0:

        hest_patterns = []
    
        for hid in hest_ids:
            hest_patterns.extend([
                f"metadata/{hid}.json",
                f"st/{hid}.h5ad",
                f"wsis/{hid}.tif",
                f"thumbnails/{hid}_*",
                f"spatial_plots/{hid}_*",
            ])
    
        snapshot_download(
            repo_id="MahmoodLab/hest",
            allow_patterns=hest_patterns,
            repo_type="dataset",
            local_dir=hest_dir,
        )
    
        print(f"[HEST] downloaded {len(hest_ids)} samples")

    # =========================================================
    # 2. PATHOMICS SEG ONLY for HEST
    # =========================================================
    if len(hest_ids) > 0:

        seg_patterns = [
            f"cellvit_seg_for_superfocus/{hid}/**"
            for hid in hest_ids
        ]

        snapshot_download(
            repo_id="Boyoungc/pathomics",
            allow_patterns=seg_patterns,
            repo_type="dataset",
            local_dir=pathomics_dir,
        )

        print(f"[SEG] downloaded HEST segmentations")

    # =========================================================
    # 3. PATHOMICS FULL for literature
    # =========================================================
    if len(local_ids) > 0:

        patterns = []

        for sid in local_ids:
            patterns.extend([
                f"metadata/{sid}.json",
                f"st/{sid}.h5ad",
                f"wsis/{sid}.tif",
                f"thumbnails/{sid}_*",
                f"spatial_plots/{sid}_*",
                f"cellvit_seg_for_superfocus/{sid}/**",
            ])

        snapshot_download(
            repo_id="Boyoungc/pathomics",
            allow_patterns=patterns,
            repo_type="dataset",
            local_dir=pathomics_dir,
        )

        print(f"[PATHOMICS] downloaded literature samples")

Usage Examples

Download One Sample

download_pathomics(
    ids=["NCBI689"]
)

Download Multiple Samples

download_pathomics(
    ids=["NCBI689", "MEND62"]
)

Download Entire Dataset

download_pathomics()

Download Only ST Data

download_pathomics(
    ids=["NCBI689"],
    modalities=["st"]
)


Downloads last month
55