Beispiel #1
0
def test_save_and_get_regressions(output_dir):
    db = DbManager(os.path.join(output_dir, "temp_testing.db"))
    assert db is not None
    db.build()

    r = {}
    r["regression_id"] = "test_regression"
    r["instrument_name"] = "test_instrument"
    r["measure_name"] = "test_measure"
    r["display_name"] = "a test regression with a display name"
    db.save_regression(r)

    r["regression_id"] = "test_regression2"
    r["instrument_name"] = "test_instrument"
    r["measure_name"] = "test_measure2"
    del r["display_name"]
    db.save_regression(r)

    reg = db.get_regression("test_regression")
    assert reg is not None
    assert reg["regression_id"] == "test_regression"
    assert reg["instrument_name"] == "test_instrument"
    assert reg["measure_name"] == "test_measure"
    assert reg["display_name"] == "a test regression with a display name"

    reg = db.get_regression("test_regression2")
    assert reg is not None
    assert reg["regression_id"] == "test_regression2"
    assert reg["instrument_name"] == "test_instrument"
    assert reg["measure_name"] == "test_measure2"
    assert reg["display_name"] is None
Beispiel #2
0
def test_search_measures_by_keyword_in_description(
    fake_phenotype_data_browser_dir, ):
    db = DbManager(fake_phenotype_data_browser_dir)
    assert db is not None
    db.build()
    measure_df = db.search_measures_df(None, "number")
    assert len(measure_df) == 3
    for _, row in measure_df.iterrows():
        assert "number" in row["description"]
Beispiel #3
0
def test_search_measures_by_keyword_in_measure_id(
    fake_phenotype_data_browser_dir, ):
    db = DbManager(fake_phenotype_data_browser_dir)
    assert db is not None
    db.build()
    measure_df = db.search_measures_df(None, "i1.m2")
    assert len(measure_df) == 1
    assert measure_df.iloc[0]["measure_name"] == "m2"
    assert measure_df.iloc[0]["instrument_name"] == "i1"
Beispiel #4
0
 def get_measures_info(self, study_wrapper):
     dbfile = self.get_pheno_dbfile(study_wrapper)
     images_url = self.get_pheno_images_url(study_wrapper)
     db = DbManager(dbfile=dbfile)
     db.build()
     return {
         "base_image_url": images_url,
         "has_descriptions": db.has_descriptions,
         "regression_names": db.regression_display_names,
     }
Beispiel #5
0
def test_db_update(output_dir):
    db = DbManager(os.path.join(output_dir, "temp_testing.db"))
    assert db is not None
    db.build()

    v = {
        "measure_id": "test.measure",
        "instrument_name": "test",
        "measure_name": "measure",
        "measure_type": "other",
        "description": "desc",
    }
    print(v)
    db.save(v)
    print(v)
    v["measure_id"] = "test.measure"
    v["figure_distribution"] = "test_figure.png"
    db.save(v)

    r = db.get("test.measure")
    assert r is not None
    assert r.measure_id == "test.measure"
    assert r.instrument_name == "test"
    assert r.measure_name == "measure"
    assert r.figure_distribution == "test_figure.png"
Beispiel #6
0
def test_has_descriptions(output_dir):
    db = DbManager(os.path.join(output_dir, "test_fake.db"))
    assert db is not None
    db.build()

    for i in range(0, 3):
        v = {
            "measure_id": "test.measure{}".format(i),
            "instrument_name": "test",
            "measure_name": "measure{}".format(i),
            "measure_type": "other",
            "description": None,
        }
        db.save(v)
    assert not db.has_descriptions

    v = {
        "measure_id": "test.measure4",
        "instrument_name": "test",
        "measure_name": "measure4",
        "measure_type": "other",
        "description": "a description",
    }
    db.save(v)
    assert db.has_descriptions
Beispiel #7
0
    def get_regressions(self, study_wrapper):
        dataset_config = self.get_genotype_data_config(
            study_wrapper.study_id)

        pheno_config = self.get_phenotype_db_config()
        browser_dbfile = \
            pheno_config[dataset_config.phenotype_data].browser_dbfile

        db = DbManager(
            browser_dbfile)
        db.build()

        if db is None:
            return None

        return db.regression_display_names_with_ids
Beispiel #8
0
def test_update_regression_values(output_dir):
    db = DbManager(os.path.join(output_dir, "temp_testing.db"))
    assert db is not None
    db.build()

    regression_template = {
        "measure_id": "test.measure",
        "figure_regression": "regfigpath",
        "figure_regression_small": "regfigsmallpath",
    }
    r = regression_template

    r["regression_id"] = "test_regression_1"
    r["pvalue_regression_male"] = "0.1"
    r["pvalue_regression_female"] = "0.2"
    db.save_regression_values(r)

    reg = db.get_regression_values("test.measure")
    assert reg == [(
        "test_regression_1",
        "test.measure",
        "regfigpath",
        "regfigsmallpath",
        0.1,
        0.2,
    )]

    r["pvalue_regression_male"] = "0.3"
    r["pvalue_regression_female"] = "0.4"
    db.save_regression_values(r)

    reg = db.get_regression_values("test.measure")
    assert reg == [(
        "test_regression_1",
        "test.measure",
        "regfigpath",
        "regfigsmallpath",
        0.3,
        0.4,
    )]
Beispiel #9
0
    def search_measures(self, study_wrapper, instrument, search_term):
        dbfile = self.get_pheno_dbfile(study_wrapper)
        db = DbManager(dbfile=dbfile)
        db.build()

        measures = db.search_measures(instrument, search_term)

        for m in measures:
            if m["values_domain"] is None:
                m["values_domain"] = ""
            m["measure_type"] = m["measure_type"].name

            m["regressions"] = []
            regressions = db.get_regression_values(m["measure_id"]) or []

            for reg in regressions:
                reg = dict(reg)
                if isnan(reg["pvalue_regression_male"]):
                    reg["pvalue_regression_male"] = "NaN"
                if isnan(reg["pvalue_regression_female"]):
                    reg["pvalue_regression_female"] = "NaN"
                m["regressions"].append(reg)

            yield {
                "measure": m,
            }
Beispiel #10
0
    def run(self):
        db = DbManager(dbfile=self.browser_db)
        db.build()

        if self.pheno_regressions:
            for reg_id, reg_data in self.pheno_regressions.regression.items():
                db.save_regression({
                    "regression_id": reg_id,
                    "instrument_name": reg_data.instrument_name,
                    "measure_name": reg_data.measure_name,
                    "display_name": reg_data.display_name,
                })

        for instrument in list(self.phenotype_data.instruments.values()):
            progress_nl()
            for measure in list(instrument.measures.values()):
                progress(text=str(measure) + "\n")
                var = self.handle_measure(measure)
                db.save(var)
                if self.pheno_regressions:
                    for regression in self.handle_regressions(measure):
                        db.save_regression_values(regression)
Beispiel #11
0
def test_db_search_character_escaping(output_dir):
    db = DbManager(os.path.join(output_dir, "temp_testing.db"))
    assert db is not None
    db.build()

    v = {
        "measure_id": "test_one.measure1",
        "instrument_name": "test_one",
        "measure_name": "measure1",
        "measure_type": "other",
        "description": "desc",
    }

    v2 = {
        "measure_id": "test%two.measure2",
        "instrument_name": "test%two",
        "measure_name": "measure2",
        "measure_type": "other",
        "description": "desc",
    }

    db.save(v)
    db.save(v2)

    r = db.search_measures_df(keyword="test_one")
    assert r is not None
    assert len(r) == 1
    assert r["measure_id"][0] == "test_one.measure1"
    assert r["instrument_name"][0] == "test_one"
    assert r["measure_name"][0] == "measure1"

    r = db.search_measures_df(keyword="test%two")
    assert r is not None
    assert len(r) == 1
    assert r["measure_id"][0] == "test%two.measure2"
    assert r["instrument_name"][0] == "test%two"
    assert r["measure_name"][0] == "measure2"
Beispiel #12
0
def test_regression_ids(output_dir):
    db = DbManager(os.path.join(output_dir, "temp_testing.db"))
    assert db is not None
    db.build()

    r = {}

    r["regression_id"] = "test_regression_1"
    r["instrument_name"] = "test"
    r["measure_name"] = "regressor1"
    db.save_regression(r)

    r["regression_id"] = "test_regression_2"
    r["instrument_name"] = "test"
    r["measure_name"] = "regressor2"
    db.save_regression(r)

    reg_ids = db.regression_ids
    assert reg_ids == ["test_regression_1", "test_regression_2"]
Beispiel #13
0
def test_search_measures_by_keyword_in_instrument_name(
    fake_phenotype_data_browser_dir, ):
    db = DbManager(fake_phenotype_data_browser_dir)
    assert db is not None
    db.build()

    measure_df = db.search_measures_df(None, "i")
    assert len(measure_df) == 15

    measure_df = db.search_measures_df(None, "i1")
    assert len(measure_df) == 12
    for _, row in measure_df.iterrows():
        assert row["instrument_name"] == "i1"
Beispiel #14
0
def test_search_measures_get_by_instrument(fake_phenotype_data_browser_dir):
    db = DbManager(fake_phenotype_data_browser_dir)
    assert db is not None
    db.build()
    measure_df = db.search_measures_df("i1", None)
    assert len(measure_df) == 12
    for _, row in measure_df.iterrows():
        assert row["instrument_name"] == "i1"

    measure_df = db.search_measures_df("i2", None)
    assert len(measure_df) == 3
    print(measure_df)
    for _, row in measure_df.iterrows():
        assert row["instrument_name"] == "i2"
Beispiel #15
0
def test_get_regression_names(output_dir):
    db = DbManager(os.path.join(output_dir, "temp_testing.db"))
    assert db is not None
    db.build()

    r = {}
    r["regression_id"] = "test_regression"
    r["instrument_name"] = "test_instrument"
    r["measure_name"] = "test_measure"
    r["display_name"] = "a test regression with a display name"
    db.save_regression(r)

    r["regression_id"] = "test_regression2"
    r["instrument_name"] = "test_instrument"
    r["measure_name"] = "test_measure2"
    r["display_name"] = "a second test regression with a display name"
    db.save_regression(r)

    reg_names = db.regression_display_names
    assert reg_names == {
        "test_regression": "a test regression with a display name",
        "test_regression2": "a second test regression with a display name",
    }
Beispiel #16
0
def test_db_save(output_dir):
    db = DbManager(os.path.join(output_dir, "temp_testing.db"))
    assert db is not None

    print(db.dbfile)
    db.build()

    v = {
        "measure_id": "test.measure",
        "instrument_name": "test",
        "measure_name": "measure",
        "measure_type": "other",
        "description": "desc",
    }

    db.save(v)

    r = db.get("test.measure")
    assert r is not None
    assert r.measure_id == "test.measure"
    assert r.instrument_name == "test"
    assert r.measure_name == "measure"
    assert r.figure_distribution is None
Beispiel #17
0
def test_search_measures_get_all(fake_phenotype_data_browser_dir):
    db = DbManager(fake_phenotype_data_browser_dir)
    assert db is not None
    db.build()
    assert len(list(db.search_measures())) == 15