Skip to content

Commit 3da7052

Browse files
authored
CC Integration Update (#259)
1 parent dfaee41 commit 3da7052

3 files changed

Lines changed: 216 additions & 107 deletions

File tree

main/como/combine_distributions.py

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def _combine_z_distribution_for_batch(
2828
matrix: pd.DataFrame,
2929
source: SourceTypes,
3030
output_combined_matrix_filepath: Path,
31-
output_figure_dirpath: Path,
31+
output_figure_dirpath: Path | None,
3232
) -> pd.DataFrame:
3333
"""Combine z-score distributions across samples for a single batch.
3434
@@ -42,7 +42,9 @@ def _combine_z_distribution_for_batch(
4242
:returns: A pandas dataframe of the weighted z-distributions
4343
"""
4444
output_combined_matrix_filepath.parent.mkdir(parents=True, exist_ok=True)
45-
output_figure_dirpath.mkdir(parents=True, exist_ok=True)
45+
46+
if output_figure_dirpath is not None:
47+
output_figure_dirpath.mkdir(parents=True, exist_ok=True)
4648

4749
logger.trace(
4850
f"Combining z-score distributions: batch #{batch.batch_num}, "
@@ -107,7 +109,7 @@ def _combine_z_distribution_for_source(
107109
context_name: str,
108110
replicates_per_batch: Sequence[int],
109111
output_combined_matrix_filepath: Path,
110-
output_figure_filepath: Path,
112+
output_figure_filepath: Path | None,
111113
weighted_z_floor: int = -6,
112114
weighted_z_ceiling: int = 6,
113115
) -> pd.DataFrame:
@@ -135,7 +137,9 @@ def _combine_z_distribution_for_source(
135137
return out_df
136138

137139
output_combined_matrix_filepath.parent.mkdir(parents=True, exist_ok=True)
138-
output_figure_filepath.parent.mkdir(parents=True, exist_ok=True)
140+
141+
if output_figure_filepath is not None:
142+
output_figure_filepath.parent.mkdir(parents=True, exist_ok=True)
139143

140144
# alidate alignment between columns and replicate vector
141145
batch_column_names: list[str] = list(merged_source_data.columns)
@@ -190,7 +194,7 @@ def _combine_z_distribution_for_source(
190194
def _combine_z_distribution_for_context(
191195
context: str,
192196
zscore_results: list[_CombineOmicsInput],
193-
output_graph_filepath: Path,
197+
output_graph_filepath: Path | None,
194198
) -> pd.DataFrame:
195199
if not zscore_results:
196200
logger.warning("No zscore results exist, returning empty dataframe")
@@ -275,14 +279,12 @@ def _begin_combining_distributions(
275279
batch_names: _BatchNames,
276280
source_weights: _SourceWeights,
277281
output_filepaths: _OutputCombinedSourceFilepath,
278-
output_figure_dirpath: Path,
282+
output_figure_dirpath: Path | None,
279283
output_final_model_scores: Path,
280284
weighted_z_floor: int = -6,
281285
weighted_z_ceiling: int = 6,
282286
):
283287
logger.info(f"Starting to combine z-scores for context '{context_name}'")
284-
output_figure_dirpath.mkdir(parents=True, exist_ok=True)
285-
286288
z_score_results: list[_CombineOmicsInput] = []
287289

288290
matrix: pd.DataFrame | None
@@ -372,7 +374,9 @@ def _begin_combining_distributions(
372374
/ f"{context_name}_{source.value}_combined_zscore_distribution.csv"
373375
),
374376
output_figure_filepath=(
375-
output_figure_dirpath / f"{context_name}_{source.value}_combined_zscore_distribution.pdf"
377+
(output_figure_dirpath / f"{context_name}_{source.value}_combined_zscore_distribution.pdf")
378+
if output_figure_dirpath is not None
379+
else None
376380
),
377381
weighted_z_floor=weighted_z_floor,
378382
weighted_z_ceiling=weighted_z_ceiling,
@@ -394,7 +398,11 @@ def _begin_combining_distributions(
394398
merged_context_results = _combine_z_distribution_for_context(
395399
context=context_name,
396400
zscore_results=z_score_results,
397-
output_graph_filepath=output_figure_dirpath / f"{context_name}_combined_omics_distribution.pdf",
401+
output_graph_filepath=(
402+
(output_figure_dirpath / f"{context_name}_combined_omics_distribution.pdf")
403+
if output_figure_dirpath is not None
404+
else None
405+
),
398406
)
399407
merged_context_results.to_csv(output_final_model_scores, index=len(merged_context_results.columns) <= 1)
400408
logger.success(f"Wrote combined z-scores for context '{context_name}' to {output_final_model_scores}")

0 commit comments

Comments
 (0)