Skip to content

Commit

Permalink
change some formatted strings.
Browse files Browse the repository at this point in the history
  • Loading branch information
tanliwei-coder committed Dec 4, 2024
1 parent 9a7806a commit b33a003
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 18 deletions.
29 changes: 16 additions & 13 deletions stereo/core/cell.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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]
Expand Down
8 changes: 4 additions & 4 deletions stereo/core/gene.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
6 changes: 6 additions & 0 deletions stereo/core/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down
35 changes: 34 additions & 1 deletion stereo/core/stereo_exp_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__()
Expand Down

0 comments on commit b33a003

Please sign in to comment.