Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added res/datasets/fake/pheno/cad_all.feather
Binary file not shown.
4,099 changes: 4,099 additions & 0 deletions res/datasets/fake/splits.yaml

Large diffs are not rendered by default.

82 changes: 82 additions & 0 deletions test/plugins/tabular/fake_data_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
"""Tests that the fake covariate/pheno/metabolomics feather datasets under
res/datasets/fake/ (used by downstream demos, e.g. the OGM repository's
train_demo.yaml) actually load via TabularPlugin.

These feather files are derived directly from the existing fake h5ad
triplets in the same directories (same eids, same values, just reformatted
for TabularPlugin instead of H5adPlugin), so this mirrors
test/plugins/h5ad/h5ad_plugin_test.py's geno/cov/metabol/pheno fixtures.
"""
import os

import hydra
import pytest
from hydra.core.global_hydra import GlobalHydra

from udm.plugins.tabular.tabular_plugin import TabularPlugin
from test.utils import try_clear_hydra

UDM_HOME = "../../.."
UDM_HOME_ABSPATH = os.path.abspath(os.path.join(os.path.dirname(__file__), UDM_HOME))

FAKE_FEATHER_FILES = {
"covariates_new_base": "covariate/covariates_new_base_all.feather",
"covariates_new_extended": "covariate/covariates_new_extended_all.feather",
"covariates_new_extended_categorical": "covariate/covariates_new_extended_categorical_all.feather",
"covariates_new_extended_continous": "covariate/covariates_new_extended_continous_all.feather",
"cad": "pheno/cad_all.feather",
"additional_pheno": "additional_pheno/additional_pheno_all.feather",
"metabolomics": "metabolomics/metabolomics_all.feather",
}

# First eid of res/datasets/fake/geno/genetic_extended_tr.obs.csv; every fake
# dataset under res/datasets/fake/ shares this eid across geno/covariate/
# pheno/additional_pheno/metabolomics, none of it is real UK Biobank data.
FIRST_EID = 5797


def _config_for(name):
try_clear_hydra()
config_path = os.path.join(UDM_HOME, "config", "plugins", "tabular")
hydra.initialize(version_base=None, config_path=config_path)
data_path = os.path.join(
UDM_HOME_ABSPATH, "res/datasets/fake", FAKE_FEATHER_FILES[name]
)
return hydra.compose("default.yaml", overrides=[f"data_paths={data_path}"])


@pytest.fixture(params=list(FAKE_FEATHER_FILES))
def fake_feather_config(request):
yield _config_for(request.param)


class TestFakeTabularData(object):
def setUp(self) -> None:
if GlobalHydra.instance().is_initialized():
GlobalHydra().instance().clear()

def test__init__(self, fake_feather_config):
TabularPlugin.from_config(fake_feather_config)

def test_prepare_data(self, fake_feather_config):
plugin = TabularPlugin.from_config(fake_feather_config)
plugin.prepare_data()

def test_setup(self, fake_feather_config):
plugin = TabularPlugin.from_config(fake_feather_config)
plugin.prepare_data()
plugin.setup()

def test__len__(self, fake_feather_config):
plugin = TabularPlugin.from_config(fake_feather_config)
plugin.prepare_data()
plugin.setup()
assert len(plugin) == 4096

def test__getitem__(self, fake_feather_config):
plugin = TabularPlugin.from_config(fake_feather_config)
plugin.prepare_data()
plugin.setup()
item = plugin[FIRST_EID]
assert "tabular_data" in item
assert item["tabular_data"].numel() > 0
Loading