Skip to content

Commit 06c6976

Browse files
authored
Merge pull request #199 from HelikarLab/remove-hardcoded-paths/rnaseq-gen
Remove hardcoded paths in RNA-seq Gen
2 parents a36d05d + bad5a8a commit 06c6976

10 files changed

Lines changed: 1055 additions & 1221 deletions

main/COMO.ipynb

Lines changed: 185 additions & 124 deletions
Large diffs are not rendered by default.

main/como/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from como.utils import stringlist_to_list
55

66
__all__ = ["stringlist_to_list", "Config"]
7-
__version__ = "1.10.0"
7+
__version__ = "1.11.1"
88

99

1010
def return_placeholder_data() -> pd.DataFrame:

main/como/create_context_specific_model.py

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -308,9 +308,16 @@ def _build_with_imat(
308308
expr_vector: npt.NDArray,
309309
expr_thesh: tuple[float, float],
310310
force_gene_ids: Sequence[int],
311+
solver: str,
311312
) -> (cobra.Model, pd.DataFrame):
312313
expr_vector = np.array(expr_vector)
313-
properties = IMATProperties(exp_vector=expr_vector, exp_thresholds=expr_thesh, core=force_gene_ids, epsilon=0.01)
314+
properties = IMATProperties(
315+
exp_vector=expr_vector,
316+
exp_thresholds=expr_thesh,
317+
core=force_gene_ids,
318+
epsilon=0.01,
319+
solver=solver.upper(),
320+
)
314321
algorithm = IMAT(s_matrix, np.array(lb), np.array(ub), properties)
315322
context_rxns: npt.NDArray = algorithm.run()
316323
fluxes: pd.Series = algorithm.sol.to_series()
@@ -507,7 +514,14 @@ def _build_model( # noqa: C901
507514
elif recon_algorithm == Algorithm.IMAT:
508515
context_model_cobra: cobra.Model
509516
context_model_cobra, flux_df = _build_with_imat(
510-
reference_model, s_matrix, lb, ub, expr_vector, exp_thresh, idx_force
517+
reference_model,
518+
s_matrix,
519+
lb,
520+
ub,
521+
expr_vector,
522+
exp_thresh,
523+
idx_force,
524+
solver=solver,
511525
)
512526
imat_reactions = flux_df.rxn
513527
model_reactions = [reaction.id for reaction in context_model_cobra.reactions]
@@ -550,6 +564,7 @@ def _collect_boundary_reactions(path: Path) -> _BoundaryReactions:
550564
df = _create_df(path)
551565
for column in df.columns:
552566
if column not in [
567+
"boundary",
553568
"reaction",
554569
"abbreviation",
555570
"compartment",
@@ -561,31 +576,25 @@ def _collect_boundary_reactions(path: Path) -> _BoundaryReactions:
561576
f"'Minimum Reaction Rate', and 'Maximum Reaction Rate'. Found: {column}"
562577
)
563578

564-
reactions: list[str] = []
579+
reactions: list[str] = [""] * len(df)
565580
boundary_type: list[str] = df["reaction"].tolist()
566581
reaction_abbreviation: list[str] = df["abbreviation"].tolist()
567582
reaction_compartment: list[str] = df["compartment"].tolist()
568-
lower_bounds = df["minimum reaction rate"].tolist()
569-
upper_bounds = df["maximum reaction rate"].tolist()
583+
lower_bound = df["minimum reaction rate"].tolist()
584+
upper_bound = df["maximum reaction rate"].tolist()
585+
boundary_map = {"exchange": "EX", "demand": "DM", "sink": "SK"}
570586
for i in range(len(boundary_type)):
571-
current_type: str = boundary_type[i]
572-
temp_reaction: str = ""
573-
574-
match current_type.lower():
575-
case "exchange":
576-
temp_reaction += "EX_"
577-
case "demand":
578-
temp_reaction += "DM_"
579-
case "sink":
580-
temp_reaction += "SK_"
587+
boundary: str = boundary_type[i].lower()
588+
if boundary not in boundary_map:
589+
raise ValueError(f"Boundary reaction type must be 'Exchange', 'Demand', or 'Sink'. Found: {boundary[i]}")
581590

582591
shorthand_compartment = Compartments.get(reaction_compartment[i])
583-
temp_reaction += f"{reaction_abbreviation[i]}[{shorthand_compartment}]"
584-
reactions.append(temp_reaction)
592+
reactions[i] = f"{boundary_map.get(boundary)}_{reaction_abbreviation[i]}[{shorthand_compartment}]"
593+
585594
return _BoundaryReactions(
586595
reactions=reactions,
587-
lower_bounds=lower_bounds,
588-
upper_bounds=upper_bounds,
596+
lower_bounds=lower_bound,
597+
upper_bounds=upper_bound,
589598
)
590599

591600

@@ -631,10 +640,10 @@ def create_context_specific_model( # noqa: C901
631640
raise ValueError(f"Output file type {output_type} not recognized. Must be one of: 'xml', 'mat', 'json'")
632641

633642
if algorithm not in Algorithm:
634-
raise ValueError(f"Algorithm {algorithm} not supported. Please use one of: GIMME, FASTCORE, or IMAT")
643+
raise ValueError(f"Algorithm {algorithm} not supported. Use one of {', '.join(a.value for a in Algorithm)}")
635644

636645
if solver not in Solver:
637-
raise ValueError(f"Solver '{solver}' not supported. Use 'GLPK' or 'GUROBI'")
646+
raise ValueError(f"Solver '{solver}' not supported. Use one of {', '.join(s.value for s in Solver)}")
638647

639648
if boundary_rxns_filepath:
640649
boundary_reactions = _collect_boundary_reactions(boundary_rxns_filepath)
@@ -667,7 +676,7 @@ def create_context_specific_model( # noqa: C901
667676
bound_ub=boundary_reactions.upper_bounds,
668677
exclude_rxns=exclude_rxns,
669678
force_rxns=force_rxns,
670-
solver=solver.value,
679+
solver=solver.value.lower(),
671680
low_thresh=low_threshold,
672681
high_thresh=high_threshold,
673682
)

0 commit comments

Comments
 (0)