Skip to content

Commit

Permalink
【Fix】 format code
Browse files Browse the repository at this point in the history
Zhenbin24 committed Nov 28, 2023
1 parent 818a328 commit 99b35e6
Showing 5 changed files with 26 additions and 23 deletions.
3 changes: 2 additions & 1 deletion stereo/algorithm/community_detection.py
Original file line number Diff line number Diff line change
@@ -235,7 +235,8 @@ def _main(self, slices, annotation="annotation", **kwargs):
f'tissue_{algo.method_key}']
if np.nan in self.slices[slice_id]._ann_data.obs['cell_communities'].values:
if 'unknown' not in self.slices[slice_id]._ann_data.obs['cell_communities'].cat.categories:
self.slices[slice_id]._ann_data.obs['cell_communities'] = self.slices[slice_id]._ann_data.obs['cell_communities'].cat.add_categories('unknown')
self.slices[slice_id]._ann_data.obs['cell_communities'] = self.slices[slice_id]._ann_data.obs[
'cell_communities'].cat.add_categories('unknown')
self.slices[slice_id]._ann_data.obs['cell_communities'].fillna('unknown', inplace=True)
# self.slices[slice_id]._ann_data.obs['cell_communities'].fillna('unknown', inplace=True)

14 changes: 7 additions & 7 deletions stereo/algorithm/regulatory_network_inference/main.py
Original file line number Diff line number Diff line change
@@ -92,7 +92,7 @@ def main(self,
self.use_raw = use_raw
if use_raw and self.stereo_exp_data.raw is None:
raise Exception("The raw data is not found, you need to run 'raw_checkpoint()' first.")

if use_raw:
logger.info('the raw expression matrix will be used.')
matrix = self.stereo_exp_data.raw.to_df()
@@ -523,12 +523,12 @@ def regulons_to_csv(self, regulon_list: list, fn: str = 'regulon_list.csv', fn_p
w.writerows(regulon_dict.items())

def to_loom(
self,
matrix: pd.DataFrame,
auc_matrix: pd.DataFrame,
regulons: list,
loom_fn: str = 'grn_output.loom',
fn_prefix: str = None
self,
matrix: pd.DataFrame,
auc_matrix: pd.DataFrame,
regulons: list,
loom_fn: str = 'grn_output.loom',
fn_prefix: str = None
):
"""
Save GRN results in one loom file
12 changes: 6 additions & 6 deletions stereo/core/ms_pipeline.py
Original file line number Diff line number Diff line change
@@ -34,15 +34,15 @@ def result(self):
@result.setter
def result(self, new_result):
self._result = new_result

@property
def key_record(self):
return self._key_record

@key_record.setter
def key_record(self, key_record):
self._key_record = key_record

# @property
# def scope_data(self):
# return self._scope_data
@@ -65,7 +65,7 @@ def _use_integrate_method(self, item, *args, **kwargs):
ms_data_view = self.ms_data[scope]
if not ms_data_view.merged_data:
ms_data_view.integrate(result=self.ms_data.tl.result)

# key_name = "scope_[" + ",".join(
# [str(self.ms_data._names.index(name)) for name in ms_data_view._names]) + "]"
# self._scope_data[key_name] = self.ms_data._merged_data
@@ -105,10 +105,10 @@ def contain_method(item):
def reset_key_record(key, res_key):
key_name = "scope_[" + ",".join(
[str(self.ms_data._names.index(name)) for name in ms_data_view._names]) + "]"

ms_data_view._merged_data.tl._reset_key_record(key, res_key)
self._key_record[key_name] = ms_data_view._merged_data.tl.key_record

ms_data_view._merged_data.tl.reset_key_record = reset_key_record

new_attr = self.__class__.BASE_CLASS.__dict__.get(item, None)
12 changes: 7 additions & 5 deletions stereo/core/st_pipeline.py
Original file line number Diff line number Diff line change
@@ -1322,10 +1322,12 @@ def annotation(

cluster_res: pd.DataFrame = self.result[cluster_res_key]

if isinstance(annotation_information, (list, np.ndarray)) and len(annotation_information) != cluster_res['group'].cat.categories.size:
if isinstance(annotation_information, (list, np.ndarray)) and \
len(annotation_information) != cluster_res['group'].cat.categories.size:
raise Exception(f"The length of annotation information is {len(annotation_information)}, \
not equal to the categories of cluster result whoes lenght is {cluster_res['group'].cat.categories.size}.")

not equal to the categories of cluster result whoes"
f" lenght is {cluster_res['group'].cat.categories.size}.")

if isinstance(annotation_information, (list, np.ndarray)):
new_categories = np.array(annotation_information, dtype='U')
elif isinstance(annotation_information, dict):
@@ -1334,8 +1336,8 @@ def annotation(
new_categories_list.append(annotation_information[i])
new_categories = np.array(new_categories_list, dtype='U')
else:
raise TypeError(f"The type of 'annotation_information' only supports list, ndarray or dict.")
raise TypeError("The type of 'annotation_information' only supports list, ndarray or dict.")

new_categories_values = new_categories[cluster_res['group'].cat.codes]

self.result[res_key] = pd.DataFrame(data={
8 changes: 4 additions & 4 deletions stereo/core/stereo_exp_data.py
Original file line number Diff line number Diff line change
@@ -601,7 +601,7 @@ def reset_position(self):
self.position[idx] += self.position_min[bno]
self.position_offset = None
self.position_min = None

def __add__(self, other):
from stereo.core.ms_data import MSData
if isinstance(other, StereoExpData):
@@ -767,7 +767,7 @@ def position_z(self, position_z: np.ndarray):
@property
def bin_type(self):
return self._ann_data.uns.get('bin_type', 'bins')

@bin_type.setter
def bin_type(self, bin_type):
self.bin_type_check(bin_type)
@@ -776,7 +776,7 @@ def bin_type(self, bin_type):
@property
def bin_size(self):
return self._ann_data.uns.get('bin_size', 1)

@bin_size.setter
def bin_size(self, bin_size):
self._ann_data.uns['bin_size'] = bin_size
@@ -793,7 +793,7 @@ def sn(self):
for _, row in sn_data.iterrows():
sn[row['batch']] = row['sn']
return sn

@sn.setter
def sn(self, sn):
if isinstance(sn, str):

0 comments on commit 99b35e6

Please sign in to comment.