Skip to content
Merged
6 changes: 6 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ dcicutils
Change Log
----------

8.18.3
======
* dmichaels / 2025-03-05 / branch: dmichaels-20250305-add-portal-get-schema-super-types / PR-328
- Added method portal_utils.get_schema_super_type_names (for use by smaht-submitr).


8.18.1
======
* dmichaels / 2025-02-28 / branch: dmichaels-20250228-correct-submitr-config-path / PR-327
Expand Down
13 changes: 13 additions & 0 deletions dcicutils/portal_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,19 @@ def list_breadth_first(super_type_map: dict, super_type_name: str) -> dict:
super_type_map_flattened[super_type_name] = list_breadth_first(super_type_map, super_type_name)
return super_type_map_flattened

@lru_cache(maxsize=100)
def get_schema_super_type_names(self, schema_name: str, include_schema_name: bool = False) -> List[str]:
super_types = set()
if isinstance(schema_name, str) and (schema_name := self.schema_name(schema_name)):
if isinstance(super_type_map := self.get_schemas_super_type_map(), dict):
for super_type_name in super_type_map:
if schema_name in super_type_map[super_type_name]:
super_types.add(super_type_name)
super_types = list(super_types)
if (include_schema_name is True) and self.get_schema(schema_name):
super_types.insert(0, schema_name)
return super_types

@lru_cache(maxsize=100)
def get_schema_subtype_names(self, type_name: str) -> List[str]:
if not (schemas_super_type_map := self.get_schemas_super_type_map()):
Expand Down
15 changes: 13 additions & 2 deletions dcicutils/submitr/custom_excel.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ def sheet_reader(self, sheet_name: str) -> ExcelSheetReader:
return CustomExcelSheetReader(self, sheet_name=sheet_name, workbook=self._workbook,
custom_column_mappings=self._custom_column_mappings)

def effective_sheet_name(self, sheet_name: str) -> str:
@staticmethod
def effective_sheet_name(sheet_name: str) -> str:
if (underscore := sheet_name.find("_")) > 1:
return sheet_name[underscore + 1:]
return sheet_name
Expand Down Expand Up @@ -151,11 +152,21 @@ def __init__(self, *args, **kwargs) -> None:
ARGUMENT_NAME_CUSTOM_COLUMN_MAPPINGS = "custom_column_mappings"
self._custom_column_mappings = None
if ARGUMENT_NAME_CUSTOM_COLUMN_MAPPINGS in kwargs:
def lookup_custom_column_mappings(custom_column_mappings: dict, sheet_name: str) -> Optional[dict]:
if isinstance(custom_column_mappings, dict) and isinstance(sheet_name, str):
if isinstance(found_custom_column_mappings := custom_column_mappings.get(sheet_name), dict):
return found_custom_column_mappings
if (effective_sheet_name := CustomExcel.effective_sheet_name(sheet_name)) != sheet_name:
if isinstance(found_custom_column_mappings :=
custom_column_mappings.get(effective_sheet_name), dict):
return found_custom_column_mappings
return None
custom_column_mappings = kwargs[ARGUMENT_NAME_CUSTOM_COLUMN_MAPPINGS]
del kwargs[ARGUMENT_NAME_CUSTOM_COLUMN_MAPPINGS]
if not (isinstance(custom_column_mappings, dict) and
isinstance(sheet_name := kwargs.get(ARGUMENT_NAME_SHEET_NAME, None), str) and
isinstance(custom_column_mappings := custom_column_mappings.get(sheet_name), dict)):
isinstance(custom_column_mappings :=
lookup_custom_column_mappings(custom_column_mappings, sheet_name), dict)):
custom_column_mappings = None
self._custom_column_mappings = custom_column_mappings
super().__init__(*args, **kwargs)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "dcicutils"
version = "8.18.1"
version = "8.18.3"
description = "Utility package for interacting with the 4DN Data Portal and other 4DN resources"
authors = ["4DN-DCIC Team <support@4dnucleome.org>"]
license = "MIT"
Expand Down