diff --git a/stereo/core/cell.py b/stereo/core/cell.py index e5f28e4e..06f51cd9 100644 --- a/stereo/core/cell.py +++ b/stereo/core/cell.py @@ -43,6 +43,9 @@ def __init__( self.batch = self._set_batch(batch) self.cell_border = cell_border self.cell_point = None + + def __getattr__(self, key): + return getattr(self._obs, key) def __contains__(self, item): return item in self._obs.columns @@ -91,17 +94,17 @@ def size(self): def shape(self): return self._obs.shape - @property - def loc(self): - return self._obs.loc + # @property + # def loc(self): + # return self._obs.loc - @property - def iloc(self): - return self._obs.iloc + # @property + # def iloc(self): + # return self._obs.iloc - @property - def to_csv(self): - return self._obs.to_csv + # @property + # def to_csv(self): + # return self._obs.to_csv @property def obs(self): @@ -314,11 +317,11 @@ def __init__( # else: # object.__setattr__(self, key, value) - def __str__(self): - return str(self.__based_ann_data.obs) + # def __str__(self): + # return str(self.__based_ann_data.obs) - def __repr__(self): - return self.__str__() + # def __repr__(self): + # return self.__str__() def __getitem__(self, item): return self.__based_ann_data.obs[item] diff --git a/stereo/core/gene.py b/stereo/core/gene.py index 2ea9c807..f4045ecc 100644 --- a/stereo/core/gene.py +++ b/stereo/core/gene.py @@ -256,11 +256,11 @@ def __init__(self, based_ann_data: AnnData, gene_name: Optional[np.ndarray] = No # return # object.__setattr__(self, key, value) - def __str__(self): - return str(self.__based_ann_data.var) + # def __str__(self): + # return str(self.__based_ann_data.var) - def __repr__(self): - return self.__str__() + # def __repr__(self): + # return self.__str__() def __getitem__(self, item): return self.__based_ann_data.var[item] diff --git a/stereo/core/result.py b/stereo/core/result.py index 55454e04..4e378a0f 100644 --- a/stereo/core/result.py +++ b/stereo/core/result.py @@ -387,6 +387,7 @@ def __init__(self, data: AnnBasedStereoExpData): super().__init__() # self.__stereo_exp_data = data self.__based_ann_data = data.adata + self.__result_keys = [] # @property # def adata(self): @@ -557,6 +558,8 @@ def _real_set_item(self, type, key, value): def __setitem__(self, key, value): super().__setitem__(key, value) + self.__result_keys.append(key) + for name_type, name_dict in AnnBasedResult.TYPE_NAMES_DICT.items(): if key in name_dict and self._real_set_item(name_type, key, value): return @@ -757,6 +760,9 @@ def set_value(self, key, value): self.__based_ann_data.uns[key] = value else: self.__based_ann_data.uns[key] = value + + def keys(self): + return self.__result_keys class MSDataPipeLineResult(dict): diff --git a/stereo/core/stereo_exp_data.py b/stereo/core/stereo_exp_data.py index c017f36b..27d5a4bd 100644 --- a/stereo/core/stereo_exp_data.py +++ b/stereo/core/stereo_exp_data.py @@ -856,7 +856,40 @@ def __init__( self.file_format = 'h5ad' def __str__(self): - return str(self._ann_data) + # return str(self._ann_data) + format_str = f"AnnBasedStereoExpData object with n_cells X n_genes = {self.shape[0]} X {self.shape[1]}" + format_str += f"\nadata: {id(self._ann_data)}" + format_str += f"\nbin_type: {self.bin_type}" + if self.bin_type == 'bins': + format_str += f"\n{'bin_size: %d' % self.bin_size}" + format_str += f"\noffset_x = {self.offset_x}" + format_str += f"\noffset_y = {self.offset_y}" + format_str += str(self.cells) + format_str += str(self.genes) + if self.cells_matrix: + format_str += f"\ncells_matrix = {list(self.cells_matrix.keys())}" + if self.genes_matrix: + format_str += f"\ngenes_matrix = {list(self.genes_matrix.keys())}" + if self.cells_pairwise: + format_str += f"\ncells_pairwise = {list(self.cells_pairwise.keys())}" + if self.genes_pairwise: + format_str += f"\ngenes_pairwise = {list(self.genes_pairwise.keys())}" + format_str += f"\n{str(self.layers)}" + format_key_record = { + key: value + for key, value in self.tl.key_record.items() if value + } + if format_key_record: + format_str += f"\nkey_record: {format_key_record}" + result_key = [] + for rks in self.tl.key_record.values(): + if rks is not None and len(rks) > 0: + result_key += rks + for rk in self.tl.result.keys(): + if rk not in result_key: + result_key.append(rk) + format_str += f"\nresult: {result_key}" + return format_str def __repr__(self): return self.__str__()