Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/celltype_annotation_automl' into…
Browse files Browse the repository at this point in the history
… celltype_annotation_automl
  • Loading branch information
xingzhongyu committed Dec 18, 2024
2 parents d452973 + 67fb57b commit e87e1f6
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 8 deletions.
14 changes: 14 additions & 0 deletions dance/transforms/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,20 @@ def __init__(
@register_preprocessor("filter", "cell")
@add_mod_and_transform
class FilterCellsCommonMod(BaseTransform):
"""Initialize the FilterCellsCommonMod class.
Parameters
----------
mod1 : str
Name of the first modality in the single-cell dataset.
mod2 : str
Name of the second modality in the single-cell dataset.
sol : Optional[str], default=None
Name of the optional solution dataset containing cell labels or annotations.
**kwargs : dict
Additional keyword arguments passed to the base transformation class.
"""

def __init__(self, mod1: str, mod2: str, sol: Optional[str] = None, **kwargs):
super().__init__(**kwargs)
Expand Down
12 changes: 12 additions & 0 deletions dance/utils/wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ def wrapped_func(*args):


def add_mod_and_transform(cls):
"""A decorator that modifies a class to add functionality for working with specific
modalities (`mod`) in a `mudata` object."""
original_init = cls.__init__
original_call = cls.__call__
cls.add_mod_and_transform = "add_mod_and_transform"
Expand All @@ -107,6 +109,16 @@ def new_init(self, *args, **kwargs):

@functools.wraps(original_call)
def new_call(self, data: Data, *args, **kwargs):
"""
Parameters
----------
data : Data
The input data object containing the `mudata` with multiple modalities.
Returns
-------
Any
The result of the original_call method.
"""
if hasattr(self, 'mod') and self.mod is not None:
md_data = data.data
ad_data = Data(data=transform_mod_to_anndata(md_data, self.mod))
Expand Down
17 changes: 9 additions & 8 deletions examples/get_result_web.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,23 @@

def check_identical_strings(string_list):
if not string_list:
raise ValueError("列表为空")
raise ValueError("The list is empty")

arr = np.array(string_list)
if not np.all(arr == arr[0]):
raise ValueError("发现不同的字符串")
raise ValueError("Different strings found")

return string_list[0]


# if not string_list:
# raise ValueError("列表为空")
# raise ValueError("The list is empty")
# first_string = string_list[0]
# for s in string_list[1:]:
# if s != first_string:
# raise ValueError(f"发现不同的字符串: '{first_string}' '{s}'")
# raise ValueError(f"Different strings found: '{first_string}' and '{s}'")
# return first_string


def get_sweep_url(step_csv: pd.DataFrame, single=True):
ids = step_csv["id"]
sweep_urls = []
Expand All @@ -57,7 +58,7 @@ def spilt_web(url: str):
if match:
entity = match.group(1)
project = match.group(2)
pattern = r'/sweeps/([^/?]+)' # 正则表达式模式
pattern = r'/sweeps/([^/?]+)' # Regular expression pattern
match = re.search(pattern, url)
if match:
sweep_id = match.group(1)
Expand Down Expand Up @@ -161,8 +162,8 @@ def write_ans(tissue):
step3_urls = []
for i in range(3):
file_csv = f"{file_path}/results/params/{i}_best_test_acc.csv"
if not os.path.exists(file_csv): #no parameter
print(f"文件 {file_csv} 不存在,跳过。")
if not os.path.exists(file_csv): # no parameter
print(f"File {file_csv} does not exist, skipping.")
continue
step3_urls.append(get_sweep_url(pd.read_csv(file_csv)))
step3_str = ",".join(step3_urls)
Expand Down

0 comments on commit e87e1f6

Please sign in to comment.