importosfrompathlibimportPathimportscanpyasscimportwarningsimportsubprocessMODULE_PATH=Path(__file__).parentwarnings.filterwarnings("ignore")zenodo_accession='12741480'################# Human #################
[docs]defhuman_gex_reference_v2():""" Load the human gex reference v2. If the dataset is not found, it will be downloaded from Zenodo. """default_path=os.path.join(MODULE_PATH,'../data/datasets/human_gex_reference_v2.h5ad')ifos.path.exists(default_path):returnsc.read_h5ad(default_path)else:importsubprocessresult=subprocess.run(["curl","-L","-o",default_path,f"https://zenodo.org/records/{zenodo_accession}/files/human_gex_reference_v2.h5ad?download=1"],check=True)ifresult.returncode==0:returnsc.read_h5ad(default_path)else:raiseRuntimeError("Failed to download the dataset.")
[docs]defhuman_tcr_reference_v2():""" Load the human tcr reference v2. Can be generated from the human gex reference v2 via `tdi.pp.unique_tcr_by_individual`. If the dataset is not found, it will be downloaded from Zenodo. """default_path=os.path.join(MODULE_PATH,'../data/datasets/human_tcr_reference_v2.h5ad')ifos.path.exists(default_path):returnsc.read_h5ad(default_path)else:result=subprocess.run(["curl","-L","-o",default_path,f"https://zenodo.org/records/{zenodo_accession}/files/human_tcr_reference_v2.h5ad?download=1"],check=True)ifresult.returncode==0:returnsc.read_h5ad(default_path)else:raiseRuntimeError("Failed to download the dataset.")
################# Mouse #################
[docs]defmouse_gex_reference_v1():""" Load the mouse gex reference v1. """default_path=os.path.join(MODULE_PATH,'../data/datasets/mouse_gex_reference_v1.h5ad')ifos.path.exists(default_path):returnsc.read_h5ad(default_path)else:raiseFileNotFoundError("Dataset has not been published online. Please contact the author for more information.")
[docs]defmouse_tcr_reference_v1():""" Load the mouse tcr reference v1. Can be generated from the mouse gex reference v1 via `tdi.pp.unique_tcr_by_individual` """default_path=os.path.join(MODULE_PATH,'../data/datasets/mouse_tcr_reference_v1.h5ad')ifos.path.exists(default_path):returnsc.read_h5ad(default_path)else:raiseFileNotFoundError("Dataset has not been published online. Please contact the author for more information.")
################# Model #################defdownload_model_weights():""" Download the pretrained weights for the TCR-DeepInsight model. """urls=[f"https://zenodo.org/records/{zenodo_accession}/files/human_gex_reference_v2.scatlasvae.ckpt?download=1",f"https://zenodo.org/records/{zenodo_accession}/files/human_bert_pseudosequence.tcr_v2.ckpt?download=1",f"https://zenodo.org/records/{zenodo_accession}/files/human_bert_pseudosequence_pca.tcr_v2.pkl?download=1"]paths=["../data/pretrained_weights/human_gex_reference_v2.scatlasvae.ckpt","../data/pretrained_weights/human_bert_pseudosequence.tcr_v2.ckpt","../data/pretrained_weights/human_bert_pseudosequence_pca.tcr_v2.pkl"]forurl,pathinzip(urls,paths):result=subprocess.run(["curl","-L","-o",path,url],check=True)ifresult.returncode!=0:raiseRuntimeError(f"Failed to download {url}")