Skip to content

Commit 439514d

Browse files
Fix imat build (#233)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
1 parent ae0c52b commit 439514d

41 files changed

Lines changed: 183834 additions & 1270 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/continuous_integration.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
runs-on: ubuntu-latest
1212
strategy:
1313
matrix:
14-
python-version: [ "3.10", "3.11", "3.12", "3.13" ]
14+
python-version: [ "3.11", "3.12", "3.13" ]
1515
steps:
1616
- name: Checkout
1717
uses: actions/checkout@v4
@@ -27,7 +27,7 @@ jobs:
2727
run: uv sync --python "${{ matrix.python-version }}" --all-extras --dev
2828

2929
- name: Run tests
30-
run: uv run --python "${{ matrix.python-version }}" pytest --cov --junitxml=junit.xml -o junit_family=legacy
30+
run: uv run --python "${{ matrix.python-version }}" pytest
3131

3232
- name: Cache Clear
3333
run: uv cache prune --ci

main/COMO.ipynb

Lines changed: 83 additions & 146 deletions
Large diffs are not rendered by default.

main/como/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from como import plot
12
from como.data_types import AdjustmentMethod, Algorithm, CobraCompartments, FilteringTechnique, LogLevel, Solver
23
from como.utils import stringlist_to_list
34

main/como/combine_distributions.py

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
)
2424

2525

26-
async def _combine_z_distribution_for_batch(
26+
def _combine_z_distribution_for_batch(
2727
context_name: str,
2828
batch: _BatchEntry,
2929
matrix: pd.DataFrame,
@@ -33,6 +33,21 @@ async def _combine_z_distribution_for_batch(
3333
weighted_z_floor: int,
3434
weighted_z_ceiling: int,
3535
) -> pd.DataFrame:
36+
"""Combine z-score distributions across samples for a single batch.
37+
38+
Args:
39+
context_name: Name of the context (e.g., tissue or condition).
40+
batch: Batch entry containing batch number and sample names.
41+
matrix: DataFrame with 'ensembl_gene_id' and sample columns.
42+
source: Source type (e.g., trna, mrna, scrna, proteomics).
43+
output_combined_matrix_filepath: Path to save the combined z-score matrix.
44+
output_figure_dirpath: Path to save the z-score distribution figure.
45+
weighted_z_floor: Minimum z-score value after combining.
46+
weighted_z_ceiling: Maximum z-score value after combining.
47+
48+
Returns:
49+
A pandas dataframe of the weighted z-distributions
50+
"""
3651
output_combined_matrix_filepath.parent.mkdir(parents=True, exist_ok=True)
3752
output_figure_dirpath.mkdir(parents=True, exist_ok=True)
3853

@@ -80,15 +95,29 @@ async def _combine_z_distribution_for_batch(
8095
return weighted_matrix
8196

8297

83-
async def _combine_z_distribution_for_source(
98+
def _combine_z_distribution_for_source(
8499
merged_source_data: pd.DataFrame,
85100
context_name: str,
86101
num_replicates: int,
87102
output_combined_matrix_filepath: Path,
88103
output_figure_filepath: Path,
89104
weighted_z_floor: int = -6,
90105
weighted_z_ceiling: int = 6,
91-
):
106+
) -> pd.DataFrame:
107+
"""Combine z-score distributions across batches for a single source.
108+
109+
Args:
110+
merged_source_data: DataFrame with 'ensembl_gene_id' and batch columns.
111+
context_name: Name of the context (e.g., tissue or condition).
112+
num_replicates: Number of replicates (samples) for weighting.
113+
output_combined_matrix_filepath: Path to save the combined z-score matrix.
114+
output_figure_filepath: Path to save the z-score distribution figure.
115+
weighted_z_floor: Minimum z-score value after combining.
116+
weighted_z_ceiling: Maximum z-score value after combining.
117+
118+
Returns:
119+
A pandas dataframe of the weighted z-distributions
120+
"""
92121
if _num_columns(merged_source_data) <= 2:
93122
logger.warning("A single source exists, returning matrix as-is because no additional combining can be done")
94123
merged_source_data.columns = ["ensembl_gene_id", "combine_z"]
@@ -144,14 +173,10 @@ def _combine_z_distribution_for_context(
144173
return pd.DataFrame({"ensembl_gene_id": [], "combine_z": []})
145174

146175
z_matrices = [
147-
result.z_score_matrix.set_index("ensembl_gene_id").rename(columns=dict.fromkeys(result.z_score_matrix.columns[1:], result.type.value))
148-
for result in zscore_results
176+
res.z_score_matrix.set_index("ensembl_gene_id").rename(columns=dict.fromkeys(res.z_score_matrix.columns[1:], res.type.value))
177+
for res in zscore_results
149178
]
150-
z_matrix = pd.DataFrame()
151-
for matrix in z_matrices:
152-
z_matrix = z_matrix.merge(right=matrix, left_index=True, right_index=True, how="outer") if not z_matrix.empty else matrix
153-
z_matrix = z_matrix.reset_index(drop=False)
154-
# z_matrix = pd.concat(z_matrices, axis=1, join="outer").reset_index()
179+
z_matrix = pd.concat(z_matrices, axis=1, join="outer").reset_index()
155180
if _num_columns(z_matrix) <= 1:
156181
logger.trace(f"Only 1 source exists for '{context}', returning dataframe as-is becuase no data exists to combine")
157182
z_matrix.columns = ["ensembl_gene_id", "combine_z"]
@@ -229,7 +254,7 @@ async def _begin_combining_distributions(
229254
matrix=matrix[[GeneIdentifier.ENSEMBL_GENE_ID.value, *batch.sample_names]],
230255
source=source,
231256
output_combined_matrix_filepath=(
232-
output_filepaths[source.value].parent / f"{context_name}_{source.value}_batch{batch.batch_num}_combined_z_distribution_.csv"
257+
output_filepaths[source.value].parent / f"{context_name}_{source.value}_batch{batch.batch_num}_combined_z_distribution.csv"
233258
),
234259
output_figure_dirpath=output_figure_dirpath,
235260
weighted_z_floor=weighted_z_floor,
@@ -243,7 +268,7 @@ async def _begin_combining_distributions(
243268
for df in batch_results:
244269
merged_batch_results = df if merged_batch_results.empty else merged_batch_results.merge(df, on="ensembl_gene_id", how="outer")
245270

246-
merged_source_results: pd.DataFrame = await _combine_z_distribution_for_source(
271+
merged_source_results: pd.DataFrame = _combine_z_distribution_for_source(
247272
merged_source_data=merged_batch_results,
248273
context_name=context_name,
249274
num_replicates=sum(batch.num_samples for batch in batch_names[source.value]),

0 commit comments

Comments
 (0)