Skip to content

Commit

Permalink
ENH: add helper function to load clinical tables (#134)
Browse files Browse the repository at this point in the history
  • Loading branch information
fedorov authored Oct 10, 2024
1 parent afe8975 commit b0c3e28
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
23 changes: 23 additions & 0 deletions idc_index/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,29 @@ def fetch_index(self, index_name) -> None:
self.clinical_data_dir,
)

def get_clinical_table(self, table_name):
"""
Returns the requested clinical table as a pandas DataFrame.
Args:
table_name (str): Name of the clinical table to be loaded.
Returns:
pandas.DataFrame: The requested clinical table.
"""
if self.clinical_data_dir is None:
logger.error(
"Clinical data directory is not available. Please fetch clinical_index first."
)
return None

table_path = os.path.join(self.clinical_data_dir, table_name)
if not os.path.exists(table_path):
logger.error(f"Table {table_name} is not found in {table_path}.")
return None

return pd.read_parquet(table_path)

def get_collections(self):
"""
Returns the collections present in IDC
Expand Down
3 changes: 3 additions & 0 deletions tests/idcindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,9 @@ def test_clinical_index_install(self):
assert i.indices_overview["clinical_index"]["installed"] is True
assert len(os.listdir(i.clinical_data_dir)) > 0

nlst_clinical = i.get_clinical_table("nlst_clinical")
assert nlst_clinical is not None


if __name__ == "__main__":
unittest.main()

0 comments on commit b0c3e28

Please sign in to comment.