Source code for denspp.offline.data_call.call_cellbib
import numpy as np
from dataclasses import dataclass
from denspp.offline import check_key_elements, check_elem_unique
[docs]
@dataclass
class SettingsCellSelector:
"""Class for Merging different labels of a dataset to a new dataset
Attributes:
original_id: Dictionary with original label names [key] and given id [value]
original_to_reduced: Dictionary with new label class [key] and corresponding id as list [value]
original_to_group: Dictionary with new label subclass [key] and corresponding id as list [value]
original_to_type: Dictionary with new label subclass [key] and corresponding id as list [value]
"""
original_id: dict
original_to_reduced: dict
original_to_group: dict
original_to_type: dict
[docs]
class CellSelector:
_used_id_libraray: dict
_process_mode: bool
def __init__(self, cell_merge: SettingsCellSelector, mode: int) -> None:
"""Class for separating the classes into new subset
:param cell_merge: Class with handling process
:param mode: 0=original dataset, 1=reduced dataset, 2= original to subgroup dataset, 3= original to subtype dataset
:return: None
"""
# Mode selection
assert mode in [0, 1, 2, 3], "Wrong mode selected - Please check!"
self._data_origin = mode == 0
if mode == 0:
self._used_id_libraray = cell_merge.original_id
elif mode == 1:
self._used_id_libraray = cell_merge.original_to_reduced
elif mode == 2:
self._used_id_libraray = cell_merge.original_to_group
elif mode == 3:
self._used_id_libraray = cell_merge.original_to_type
[docs]
def get_id_from_key(self, name: str) -> int or list:
"""Getting the ID from a cell type / class name / key
:param name: Key name of the label from dataset
:return: Corresponding ID to key label
"""
keylist = [key for key in self._used_id_libraray.keys()]
assert check_key_elements(name, keylist), f"Key not available: {keylist}"
return self._used_id_libraray.get(name)
[docs]
def get_name_from_id(self, cluster_id: int | np.ndarray) -> str:
"""Getting the name of the cell type of a given cluster ID/class
:param cluster_id: Cluster ID
:return: String with label
"""
if self._data_origin:
cell_name = [key for key, values in self._used_id_libraray.items() if cluster_id == values]
else:
cell_name = [key for key, values in self._used_id_libraray.items() if cluster_id in values]
return cell_name[0] if len(cell_name) else ''
[docs]
def get_label_list(self) -> list:
"""Getting the label names of used dataset as list
:return: List of used cell type names as label
"""
keylist = [key for key in self._used_id_libraray.keys()]
assert check_elem_unique(keylist), f"Keys of dataset labels are not unique - Please check!"
return keylist