Skip to content

Commit

Permalink
[GEN-996] convert the clinical template columns from a set to a list (#…
Browse files Browse the repository at this point in the history
…554)

* convert the clinical template columns from a set to a list

* add test function for Clinical.preprocess
  • Loading branch information
danlu1 authored Apr 17, 2024
1 parent e306ea9 commit eb18202
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
2 changes: 1 addition & 1 deletion genie_registry/clinical.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ def preprocess(self, newpath):
"sample is True and inClinicalDb is True"
)
sample_cols = sample_cols_table.asDataFrame()["fieldName"].tolist()
clinicalTemplate = pd.DataFrame(columns=set(patient_cols + sample_cols))
clinicalTemplate = pd.DataFrame(columns=list(set(patient_cols + sample_cols)))
sample = True
patient = True

Expand Down
45 changes: 45 additions & 0 deletions tests/test_clinical.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,33 @@ def table_query_results(*args):
)
)

patientdf = pd.DataFrame(
dict(
fieldName=["PATIENT_ID", "SEX", "PRIMARY_RACE"],
patient=[True, True, True],
sample=[True, False, False],
)
)
sampledf = pd.DataFrame(
dict(
fieldName=["PATIENT_ID", "SAMPLE_ID"],
patient=[True, False],
sample=[True, True],
)
)


table_query_results_map = {
("select * from syn7434222",): createMockTable(sexdf),
("select * from syn7434236",): createMockTable(no_nan),
("select * from syn7434242",): createMockTable(no_nan),
("select * from syn7434273",): createMockTable(no_nan),
(
"select fieldName from syn8545211 where patient is True and inClinicalDb is True",
): createMockTable(patientdf),
(
"select fieldName from syn8545211 where sample is True and inClinicalDb is True",
): createMockTable(sampledf),
}

json_oncotreeurl = (
Expand Down Expand Up @@ -1382,3 +1404,26 @@ def test_that__cross_validate_assay_info_has_seq_returns_expected_msg_if_valid(
)
assert warnings == expected_warning
assert errors == expected_error


def test_preprocess(clin_class, newpath=None):
"""Test preprocess function"""
expected = {
"clinicalTemplate": pd.DataFrame(
columns=["PATIENT_ID", "SEX", "PRIMARY_RACE", "SAMPLE_ID"]
),
"sample": True,
"patient": True,
"patientCols": ["PATIENT_ID", "SEX", "PRIMARY_RACE"],
"sampleCols": ["PATIENT_ID", "SAMPLE_ID"],
}
results = clin_class.preprocess(newpath)
assert (
results["clinicalTemplate"]
.sort_index(axis=1)
.equals(expected["clinicalTemplate"].sort_index(axis=1))
)
assert results["sample"] == expected["sample"]
assert results["patient"] == expected["patient"]
assert results["patientCols"] == expected["patientCols"]
assert results["sampleCols"] == expected["sampleCols"]

0 comments on commit eb18202

Please sign in to comment.