Skip to content

Commit

Permalink
fix harmonizer
Browse files Browse the repository at this point in the history
  • Loading branch information
mschwoer committed Oct 28, 2024
1 parent e9ff5d8 commit 7c79dea
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
11 changes: 4 additions & 7 deletions alphastats/dataset_harmonizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,19 @@ class DataHarmonizer:

def __init__(self, loader: BaseLoader, sample_column: Optional[str] = None):
# map column names to a tuple (new_name, is_mandatory)
rawinput_rename_dict = {
self._rawinput_rename_dict = {
loader.index_column: (Cols.INDEX, True),
loader.gene_names_column: (Cols.GENE_NAMES, False),
}

shared_rename_dict = (
self._metadata_rename_dict = (
{
sample_column: (Cols.SAMPLE, True),
}
if sample_column is not None
else {}
)

self._rawinput_rename_dict = {**rawinput_rename_dict, **shared_rename_dict}
self._metadata_rename_dict = shared_rename_dict

def get_harmonized_rawinput(self, rawinput: pd.DataFrame) -> pd.DataFrame:
"""Harmonize the rawinput data to a common format."""
return self._get_harmonized_data(
Expand All @@ -51,10 +48,10 @@ def _get_harmonized_data(
for source_name, (target_name, is_mandatory) in rename_dict.items():
if target_name in input_df.columns:
raise ValueError(
f"Column name {target_name} already exists. Please rename the column in your input data."
f"Column name '{target_name}' already exists. Please rename the column in your input data."
)
if is_mandatory and source_name not in input_df.columns:
raise ValueError(f"Column name {source_name} not found!")
raise ValueError(f"Column name '{source_name}' not found!")

return input_df.rename(
columns=rename_dict,
Expand Down
1 change: 0 additions & 1 deletion alphastats/statistics/MultiCovaAnalysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ def calculate(self):
quant_data=self.transposed,
annotation=self.metadata,
covariates=self.covariates,
sample_column=self.dataset.sample,
n_permutations=self.n_permutations,
fdr=self.fdr,
s0=self.s0,
Expand Down

0 comments on commit 7c79dea

Please sign in to comment.