Skip to content

Commit f868dd1

Browse files
authored
Revert mistaken merge (#209)
* feat: include optional dependencies Signed-off-by: Josh Loecker <joshloecker@icloud.com> * fix: include taxon id and input format Signed-off-by: Josh Loecker <joshloecker@icloud.com> * fix: update requirements based on CC Signed-off-by: Josh Loecker <joshloecker@icloud.com> --------- Signed-off-by: Josh Loecker <joshloecker@icloud.com>
1 parent 7e018a5 commit f868dd1

7 files changed

Lines changed: 1551 additions & 152 deletions

File tree

main/COMO.ipynb

Lines changed: 203 additions & 110 deletions
Large diffs are not rendered by default.

main/como/create_context_specific_model.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -340,11 +340,11 @@ def _build_with_imat(
340340
def _build_with_tinit(cobra_model: cobra.Model, s_matrix, lb, ub, expr_vector, solver, idx_force) -> Model:
341341
properties = tINITProperties(
342342
reactions_scores=expr_vector,
343-
solver=solver,
344343
essential_reactions=idx_force,
345344
production_weight=0.0,
346345
allow_excretion=False,
347346
no_reverse_loops=True,
347+
solver=solver,
348348
)
349349
algorithm = tINIT(s_matrix, lb, ub, properties)
350350
algorithm.preprocessing()
@@ -565,7 +565,6 @@ def _collect_boundary_reactions(path: Path) -> _BoundaryReactions:
565565
for column in df.columns:
566566
if column not in [
567567
"boundary",
568-
"reaction",
569568
"abbreviation",
570569
"compartment",
571570
"minimum reaction rate",
@@ -577,7 +576,7 @@ def _collect_boundary_reactions(path: Path) -> _BoundaryReactions:
577576
)
578577

579578
reactions: list[str] = [""] * len(df)
580-
boundary_type: list[str] = df["reaction"].tolist()
579+
boundary_type: list[str] = df["boundary"].tolist()
581580
reaction_abbreviation: list[str] = df["abbreviation"].tolist()
582581
reaction_compartment: list[str] = df["compartment"].tolist()
583582
lower_bound = df["minimum reaction rate"].tolist()

main/como/rnaseq.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -297,8 +297,8 @@ def calculate_tpm(metrics: NamedMetrics) -> NamedMetrics:
297297

298298
def calculate_fpkm(metrics: NamedMetrics) -> NamedMetrics:
299299
"""Calculate the Fragments Per Kilobase of transcript per Million mapped reads (FPKM) for each sample in the metrics dictionary.""" # noqa: E501
300-
matrix_values = []
301300
for study in metrics:
301+
matrix_values = []
302302
for sample in range(metrics[study].num_samples):
303303
layout = metrics[study].layout[sample]
304304
count_matrix: npt.NDArray = metrics[study].count_matrix.iloc[:, sample].values
@@ -311,7 +311,7 @@ def calculate_fpkm(metrics: NamedMetrics) -> NamedMetrics:
311311
case LayoutMethod.paired_end: # FPKM
312312
mean_fragment_lengths = metrics[study].fragment_lengths[sample]
313313
# Ensure non-negative value
314-
effective_length = [max(0, size - (mean_fragment_lengths + 1)) for size in gene_size]
314+
effective_length = [max(1e-9, size - (mean_fragment_lengths + 1)) for size in gene_size]
315315
n = count_matrix.sum()
316316
fpkm = ((count_matrix + 1) * 1e9) / (np.array(effective_length) * n)
317317
matrix_values.append(fpkm)
@@ -326,7 +326,6 @@ def calculate_fpkm(metrics: NamedMetrics) -> NamedMetrics:
326326
fpkm_matrix = pd.DataFrame(matrix_values).T # Transpose is needed because values were appended as rows
327327
fpkm_matrix = fpkm_matrix[~pd.isna(fpkm_matrix)]
328328
metrics[study].normalization_matrix = fpkm_matrix
329-
330329
metrics[study].normalization_matrix.columns = metrics[study].count_matrix.columns
331330

332331
return metrics

main/como/rnaseq_gen.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@ async def _handle_context_batch(
9999
)
100100
rnaseq_output_filepath.parent.mkdir(parents=True, exist_ok=True)
101101

102+
write_zfpkm_png_filepath = write_zfpkm_png_filepath or Path(
103+
f"data/results/{context_name}/zfpkm_{prep.value}_{context_name}.png"
104+
)
105+
102106
await save_rnaseq_tests(
103107
context_name=context_name,
104108
counts_matrix_filepath=rnaseq_input_filepath,

main/como/rnaseq_preprocess.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ async def _create_config_df(context_name: str) -> pd.DataFrame: # noqa: C901
351351
f"this should be defined by user if using zFPKM or rnaseq_gen.py will not run"
352352
)
353353
elif len(layout_files) == 1:
354-
with layout_files[0].open("w") as file:
354+
with layout_files[0].open("r") as file:
355355
layout = file.read().strip()
356356
elif len(layout_files) > 1:
357357
raise ValueError(
@@ -367,7 +367,7 @@ async def _create_config_df(context_name: str) -> pd.DataFrame: # noqa: C901
367367
f"infer the strandedness when writing the counts matrix"
368368
)
369369
elif len(strand_files) == 1:
370-
with strand_files[0].open("w") as file:
370+
with strand_files[0].open("r") as file:
371371
strand = file.read().strip()
372372
elif len(strand_files) > 1:
373373
raise ValueError(
@@ -379,7 +379,7 @@ async def _create_config_df(context_name: str) -> pd.DataFrame: # noqa: C901
379379
if len(prep_files) == 0:
380380
logger.warning(f"No prep file found for {label}, assuming 'total' as in Total RNA library preparation")
381381
elif len(prep_files) == 1:
382-
with prep_files[0].open("w") as file:
382+
with prep_files[0].open("r") as file:
383383
prep = file.read().strip().lower()
384384
if prep not in ["total", "mrna"]:
385385
raise ValueError(f"Prep method must be either 'total' or 'mrna' for {label}")

pyproject.toml

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1+
[build-system]
2+
requires = ["hatchling"]
3+
build-backend = "hatchling.build"
4+
15
[project]
26
name = "COMO"
37
dynamic = ["version"]
48
requires-python = ">=3.10,<3.13"
59
dependencies = [
610
"cobra>=0.28.0",
711
"fast-bioservices>=0.3.9",
8-
"gurobipy>=11.0",
912
"kaleido==0.2.1",
1013
"loguru>=0.7.2",
1114
"pandas>=1.3.5",
@@ -21,9 +24,20 @@ dependencies = [
2124
"cobamp@git+https://github.com/JoshLoecker/cobamp@master",
2225
]
2326

24-
[build-system]
25-
requires = ["hatchling"]
26-
build-backend = "hatchling.build"
27+
[project.optional-dependencies]
28+
gurobi = [ "gurobipy>=10.0.0" ]
29+
interactive = [
30+
"jupyterlab>=4.0.0",
31+
"ipython>=7.0.0"
32+
]
33+
dev = [
34+
"commitlint>=1.3.0",
35+
"pytest-asyncio>=0.24.0",
36+
"pytest>=8.0.0",
37+
"ruff>=0.8.0",
38+
"hypothesis>=6.122.1",
39+
"pytest-cov>=6.0.0",
40+
]
2741

2842
[tool.hatch.version]
2943
path = "main/como/__init__.py"
@@ -35,14 +49,4 @@ packages = ["main/como"]
3549
allow-direct-references = true
3650

3751
[tool.pytest.ini_options]
38-
pythonpath = [ "main/src" ]
39-
40-
[tool.uv]
41-
dev-dependencies = [
42-
"commitlint>=1.3.0",
43-
"pytest-asyncio>=0.24.0",
44-
"pytest>=8.3.3",
45-
"ruff>=0.8.0",
46-
"hypothesis>=6.122.1",
47-
"pytest-cov>=6.0.0",
48-
]
52+
pythonpath = [ "main/src" ]

0 commit comments

Comments
 (0)