Skip to content

Commit

Permalink
modified: metax/taxafunc_analyzer/analyzer_utils/basic_stats.py
Browse files Browse the repository at this point in the history
  • Loading branch information
byemaxx committed Nov 8, 2024
1 parent faf2cfa commit 9ac1cea
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions metax/taxafunc_analyzer/analyzer_utils/basic_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class BasicStats:
def __init__(self, tfa):
self.tfa = tfa

def get_mean_by_zero_dominant(self, df: pd.DataFrame) -> pd.Series:
def _get_mean_by_zero_dominant(self, df: pd.DataFrame) -> pd.Series:
"""
Optimized function to calculate the mean of non-zero values in each row if the number of zero values
is less than half of the total values; otherwise, return 0.
Expand Down Expand Up @@ -45,7 +45,7 @@ def get_stats_mean_df_by_group(self, df: pd.DataFrame, condition: list|None = No
zero_dominant = self.tfa.stat_mean_by_zero_dominant
print(f"Caculating mean by zero_dominant: [{zero_dominant}]")

mean_method = self.get_mean_by_zero_dominant if zero_dominant else lambda x: x.mean(axis=1)
mean_method = self._get_mean_by_zero_dominant if zero_dominant else lambda x: x.mean(axis=1)


data = df.copy()
Expand Down Expand Up @@ -214,7 +214,7 @@ def get_combined_sub_meta_df(
print(f"Caculating mean by zero_dominant: [{zero_dominant}]")

if zero_dominant:
grouped_data = df.T.groupby([sample_groups, sub_groups]).apply(lambda x: self.get_mean_by_zero_dominant(x.T)).T
grouped_data = df.T.groupby([sample_groups, sub_groups]).apply(lambda x: self._get_mean_by_zero_dominant(x.T)).T
else:
grouped_data = df.T.groupby([sample_groups, sub_groups]).mean().T

Expand Down

0 comments on commit 9ac1cea

Please sign in to comment.