Skip to content

Commit f097305

Browse files
authored
Cobra Types (#237)
1 parent 9597584 commit f097305

69 files changed

Lines changed: 1095 additions & 8 deletions

Some content is hidden

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

main/como/rnaseq_gen.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,11 @@ async def _build_matrix_results(
168168
"""
169169
matrix.dropna(subset="ensembl_gene_id", inplace=True)
170170
conversion = await ensembl_to_gene_id_and_symbol(ids=matrix["ensembl_gene_id"].tolist(), taxon=taxon)
171+
172+
# If any one column was
173+
if any(conversion[col].eq("-").all() for col in conversion.columns):
174+
logger.critical(f"Conversion of Ensembl Gene IDs to Entrez IDs and Gene Symbols was empty - is '{taxon}' the correct taxon ID for this data?")
175+
171176
conversion["ensembl_gene_id"] = conversion["ensembl_gene_id"].str.split(",")
172177
conversion = conversion.explode("ensembl_gene_id")
173178
conversion.reset_index(inplace=True, drop=True)

main/como/rnaseq_preprocess.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,6 @@ async def _write_counts_matrix(
367367
final_matrix = final_matrix[["ensembl_gene_id", *rna_specific_sample_names]]
368368

369369
output_counts_matrix_filepath.parent.mkdir(parents=True, exist_ok=True)
370-
final_matrix.dropna(inplace=True)
371370
final_matrix.to_csv(output_counts_matrix_filepath, index=False)
372371
logger.success(f"Wrote gene count matrix for '{rna.value}' RNA at '{output_counts_matrix_filepath}'")
373372
return final_matrix
@@ -460,6 +459,7 @@ async def _create_config_df( # noqa: C901
460459

461460
fragment_label = f"{context_name}_{label}_fragment_size.txt"
462461
frag_paths = [p for p in aux_lookup["fragment"].values() if p.name == fragment_label]
462+
print(f"HERE: {prep}")
463463
if not frag_paths and prep.lower() != RNAType.TRNA.value.lower():
464464
logger.warning(f"No fragment file for '{label}'; defaulting to 100 bp (needed for zFPKM).")
465465
mean_frag = 100.0
@@ -682,7 +682,7 @@ async def read_counts(file: Path) -> list[str]:
682682
)
683683

684684
# Remove NA values from entrez_gene_id dataframe column
685-
return conversion["entrez_gene_id"].dropna().tolist()
685+
return conversion["entrez_gene_id"].tolist()
686686

687687
logger.info("Fetching gene info - this can take up to 5 minutes depending on the number of genes and your internet connection")
688688
genes = set(chain.from_iterable(await asyncio.gather(*[read_counts(f) for f in counts_matrix_filepaths])))
@@ -706,10 +706,7 @@ async def read_counts(file: Path) -> list[str]:
706706
gene_info.at[i, "entrez_gene_id"] = data.get("entrezgene", pd.NA)
707707
gene_info.at[i, "ensembl_gene_id"] = ensembl_ids
708708
gene_info.at[i, "size"] = end_pos - start_pos
709-
710-
gene_info = gene_info[((~gene_info["entrez_gene_id"].isna()) & (~gene_info["ensembl_gene_id"].isna()) & (~gene_info["gene_symbol"].isna()))]
711709
gene_info.sort_values(by="ensembl_gene_id", inplace=True)
712-
gene_info.dropna(inplace=True)
713710

714711
output_filepath.parent.mkdir(parents=True, exist_ok=True)
715712
gene_info.to_csv(output_filepath, index=False)
@@ -857,10 +854,10 @@ async def rnaseq_preprocess(
857854
async def _main():
858855
context_name = "notreatment"
859856
taxon = 9606
860-
como_context_dir = Path("/Users/joshl/Projects/COMO/main/data/COMO_input/notreatment")
861-
output_gene_info_filepath = Path("/Users/joshl/Projects/COMO/main/data/results/notreatment/gene_info.csv")
857+
como_context_dir = Path("/Users/joshl/Projects/COMO/main/data/COMO_input/naiveB")
858+
output_gene_info_filepath = Path("/Users/joshl/Projects/COMO/main/data/results/naiveB/gene_info_fixed.csv")
862859
output_trna_metadata_filepath = Path("/Users/joshl/Projects/COMO/main/data/config_sheets/trna_config.xlsx")
863-
output_trna_count_matrix_filepath = Path("/Users/joshl/Projects/COMO/main/data/results/notreatment/total-rna/totalrna_notreatment.csv")
860+
output_trna_count_matrix_filepath = Path("/Users/joshl/Projects/COMO/main/data/results/naiveB/total-rna/totalrna_naiveB.csv")
864861

865862
await rnaseq_preprocess(
866863
context_name=context_name,

stubs/cobra/__init__.pyi

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from cobra import flux_analysis as flux_analysis, io as io, medium as medium, sampling as sampling, summary as summary
2+
from cobra.core import Configuration as Configuration, DictList as DictList, Gene as Gene, Metabolite as Metabolite, Model as Model, Object as Object, Reaction as Reaction, Solution as Solution, Species as Species
3+
from cobra.util import show_versions as show_versions
4+
5+
__version__: str

stubs/cobra/core/__init__.pyi

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from cobra.core.configuration import Configuration as Configuration
2+
from cobra.core.dictlist import DictList as DictList
3+
from cobra.core.gene import GPR as GPR, Gene as Gene
4+
from cobra.core.group import Group as Group
5+
from cobra.core.metabolite import Metabolite as Metabolite
6+
from cobra.core.model import Model as Model
7+
from cobra.core.object import Object as Object
8+
from cobra.core.reaction import Reaction as Reaction
9+
from cobra.core.solution import Solution as Solution, get_solution as get_solution
10+
from cobra.core.species import Species as Species

stubs/cobra/core/configuration.pyi

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import pathlib
2+
import types
3+
from numbers import Number
4+
5+
from _typeshed import Incomplete
6+
7+
from .singleton import Singleton
8+
9+
__all__ = ["Configuration"]
10+
11+
12+
class Configuration(metaclass=Singleton):
13+
tolerance: float
14+
lower_bound: Incomplete
15+
upper_bound: Incomplete
16+
processes: Incomplete
17+
max_cache_size: Incomplete
18+
cache_expiration: Incomplete
19+
20+
def __init__(self, **kwargs) -> None: ...
21+
@property
22+
def solver(self) -> types.ModuleType: ...
23+
@solver.setter
24+
def solver(self, value) -> None: ...
25+
@property
26+
def bounds(self) -> tuple[Number | None, Number | None]: ...
27+
@bounds.setter
28+
def bounds(self, bounds: tuple[Number | None, Number | None]) -> None: ...
29+
@property
30+
def cache_directory(self) -> pathlib.Path: ...
31+
@cache_directory.setter
32+
def cache_directory(self, path: pathlib.Path | str) -> None: ...

stubs/cobra/core/dictlist.pyi

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
from .object import Object as Object
2+
from typing import Any, Callable, Iterable, Iterator, Pattern
3+
4+
class DictList(list):
5+
def __init__(self, *args) -> None: ...
6+
def has_id(self, id: Object | str) -> bool: ...
7+
def get_by_id(self, id: Object | str) -> Object: ...
8+
def list_attr(self, attribute: str) -> list: ...
9+
def get_by_any(self, iterable: list[str | Object | int]) -> list: ...
10+
def query(self, search_function: str | Pattern | Callable, attribute: str | None = None) -> DictList: ...
11+
def append(self, entity: Object) -> None: ...
12+
def union(self, iterable: Iterable[Object]) -> None: ...
13+
def extend(self, iterable: Iterable[Object]) -> None: ...
14+
def __sub__(self, other: Iterable[Object]) -> DictList: ...
15+
def __isub__(self, other: Iterable[Object]) -> DictList: ...
16+
def __add__(self, other: Iterable[Object]) -> DictList: ...
17+
def __iadd__(self, other: Iterable[Object]) -> DictList: ...
18+
def __reduce__(self) -> tuple[type['DictList'], tuple, dict, Iterator]: ...
19+
def index(self, id: str | Object, *args) -> int: ...
20+
def __contains__(self, entity: str | Object) -> bool: ...
21+
def __copy__(self) -> DictList: ...
22+
def insert(self, index: int, entity: Object) -> None: ...
23+
def pop(self, *args) -> Object: ...
24+
def add(self, x: Object) -> None: ...
25+
def remove(self, x: str | Object) -> None: ...
26+
def reverse(self) -> None: ...
27+
def sort(self, cmp: Callable = None, key: Callable = None, reverse: bool = False) -> None: ...
28+
def __getitem__(self, i: int | slice | Iterable | Object | DictList) -> DictList | Object: ...
29+
def __setitem__(self, i: slice | int, y: list | Object) -> None: ...
30+
def __delitem__(self, index: int) -> None: ...
31+
def __getslice__(self, i: int, j: int) -> DictList: ...
32+
def __setslice__(self, i: int, j: int, y: list | Object) -> None: ...
33+
def __delslice__(self, i: int, j: int) -> None: ...
34+
def __getattr__(self, attr: Any) -> Any: ...
35+
def __dir__(self) -> list: ...

stubs/cobra/core/formula.pyi

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from .object import Object as Object
2+
from _typeshed import Incomplete
3+
4+
element_re: Incomplete
5+
6+
class Formula(Object):
7+
formula: Incomplete
8+
elements: Incomplete
9+
def __init__(self, formula: str | None = None, **kwargs) -> None: ...
10+
def __add__(self, other_formula: Formula | str) -> Formula: ...
11+
def parse_composition(self) -> None: ...
12+
@property
13+
def weight(self) -> float: ...
14+
15+
elements_and_molecular_weights: Incomplete

stubs/cobra/core/gene.pyi

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import sympy.logic.boolalg as spl
2+
from ..util import resettable as resettable
3+
from ..util.util import format_long_string as format_long_string
4+
from .dictlist import DictList as DictList
5+
from .species import Species as Species
6+
from _typeshed import Incomplete
7+
from ast import AST, BoolOp, Expression, Module, Name, NodeTransformer, NodeVisitor
8+
from sympy import Symbol
9+
from typing import Iterable
10+
11+
logger: Incomplete
12+
keywords: Incomplete
13+
keyword_re: Incomplete
14+
number_start_re: Incomplete
15+
replacements: Incomplete
16+
17+
class GPRWalker(NodeVisitor):
18+
gene_set: Incomplete
19+
def __init__(self, **kwargs) -> None: ...
20+
def visit_Name(self, node: Name) -> None: ...
21+
def visit_BoolOp(self, node: BoolOp) -> None: ...
22+
23+
class GPRCleaner(NodeTransformer):
24+
gene_set: Incomplete
25+
def __init__(self, **kwargs) -> None: ...
26+
def visit_Name(self, node: Name) -> Name: ...
27+
def visit_BinOp(self, node: BoolOp) -> None: ...
28+
29+
def parse_gpr(str_expr: str) -> tuple: ...
30+
31+
class Gene(Species):
32+
def __init__(self, id: str = None, name: str = '', functional: bool = True) -> None: ...
33+
@property
34+
def functional(self) -> bool: ...
35+
@functional.setter
36+
@resettable
37+
def functional(self, value: bool) -> None: ...
38+
def knock_out(self) -> None: ...
39+
40+
class GPR(Module):
41+
body: list | None
42+
def __init__(self, gpr_from: Expression | Module | AST = None, **kwargs) -> None: ...
43+
@classmethod
44+
def from_string(cls, string_gpr: str) -> GPR: ...
45+
@property
46+
def genes(self) -> frozenset: ...
47+
def update_genes(self) -> None: ...
48+
def eval(self, knockouts: DictList | set | str | Iterable = None) -> bool: ...
49+
def to_string(self, names: dict = None) -> str: ...
50+
def copy(self) -> GPR: ...
51+
def __copy__(self) -> GPR: ...
52+
def as_symbolic(self, names: dict = None) -> spl.Or | spl.And | Symbol: ...
53+
@classmethod
54+
def from_symbolic(cls, sympy_gpr: spl.BooleanFunction | Symbol) -> GPR: ...
55+
def __eq__(self, other) -> bool: ...
56+
57+
def eval_gpr(expr: Expression | GPR, knockouts: DictList | set) -> bool: ...
58+
def ast2str(expr: Expression | GPR, level: int = 0, names: dict = None) -> str: ...

stubs/cobra/core/group.pyi

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from .object import Object as Object
2+
from _typeshed import Incomplete
3+
from typing import Iterable
4+
5+
class Group(Object):
6+
KIND_TYPES: Incomplete
7+
def __init__(self, id: str, name: str = '', members: Iterable | None = None, kind: str | None = None) -> None: ...
8+
def __len__(self) -> int: ...
9+
@property
10+
def members(self) -> set: ...
11+
@property
12+
def kind(self) -> str: ...
13+
@kind.setter
14+
def kind(self, kind: str) -> None: ...
15+
def add_members(self, new_members: list) -> None: ...
16+
def remove_members(self, to_remove: list) -> None: ...

stubs/cobra/core/metabolite.pyi

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
from ..exceptions import OptimizationError as OptimizationError
2+
from ..util.solver import check_solver_status as check_solver_status
3+
from ..util.util import format_long_string as format_long_string
4+
from .formula import elements_and_molecular_weights as elements_and_molecular_weights
5+
from .species import Species as Species
6+
from _typeshed import Incomplete
7+
from cobra.core import Solution as Solution
8+
from cobra.summary.metabolite_summary import MetaboliteSummary as MetaboliteSummary
9+
from optlang.interface import Container as Container
10+
from pandas import DataFrame as DataFrame
11+
12+
element_re: Incomplete
13+
14+
class Metabolite(Species):
15+
formula: Incomplete
16+
compartment: Incomplete
17+
charge: Incomplete
18+
def __init__(self, id: str | None = None, formula: str | None = None, name: str | None = '', charge: float | None = None, compartment: str | None = None) -> None: ...
19+
@property
20+
def constraint(self) -> Container: ...
21+
@property
22+
def elements(self) -> dict[str, int | float] | None: ...
23+
@elements.setter
24+
def elements(self, elements_dict: dict[str, int | float]) -> None: ...
25+
@property
26+
def formula_weight(self) -> int | float: ...
27+
@property
28+
def y(self) -> float: ...
29+
@property
30+
def shadow_price(self) -> float: ...
31+
def remove_from_model(self, destructive: bool = False) -> None: ...
32+
def summary(self, solution: Solution | None = None, fva: float | DataFrame | None = None) -> MetaboliteSummary: ...

0 commit comments

Comments
 (0)