napistu 0.3.5__py3-none-any.whl → 0.3.7__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. napistu/__main__.py +38 -27
  2. napistu/consensus.py +22 -27
  3. napistu/constants.py +91 -65
  4. napistu/context/filtering.py +2 -1
  5. napistu/identifiers.py +3 -6
  6. napistu/indices.py +3 -1
  7. napistu/ingestion/bigg.py +6 -6
  8. napistu/ingestion/sbml.py +298 -295
  9. napistu/ingestion/string.py +16 -19
  10. napistu/ingestion/trrust.py +22 -27
  11. napistu/ingestion/yeast.py +2 -1
  12. napistu/matching/interactions.py +4 -4
  13. napistu/matching/species.py +1 -1
  14. napistu/modify/uncompartmentalize.py +1 -1
  15. napistu/network/net_create.py +1 -1
  16. napistu/network/paths.py +1 -1
  17. napistu/ontologies/dogma.py +2 -1
  18. napistu/ontologies/genodexito.py +5 -1
  19. napistu/ontologies/renaming.py +4 -0
  20. napistu/sbml_dfs_core.py +1343 -2167
  21. napistu/sbml_dfs_utils.py +1086 -143
  22. napistu/utils.py +52 -41
  23. {napistu-0.3.5.dist-info → napistu-0.3.7.dist-info}/METADATA +2 -2
  24. {napistu-0.3.5.dist-info → napistu-0.3.7.dist-info}/RECORD +40 -40
  25. tests/conftest.py +113 -13
  26. tests/test_consensus.py +161 -4
  27. tests/test_context_filtering.py +2 -2
  28. tests/test_gaps.py +26 -15
  29. tests/test_network_net_create.py +1 -1
  30. tests/test_network_precompute.py +1 -1
  31. tests/test_ontologies_genodexito.py +3 -0
  32. tests/test_ontologies_mygene.py +3 -0
  33. tests/test_ontologies_renaming.py +28 -24
  34. tests/test_sbml_dfs_core.py +260 -211
  35. tests/test_sbml_dfs_utils.py +194 -36
  36. tests/test_utils.py +19 -0
  37. {napistu-0.3.5.dist-info → napistu-0.3.7.dist-info}/WHEEL +0 -0
  38. {napistu-0.3.5.dist-info → napistu-0.3.7.dist-info}/entry_points.txt +0 -0
  39. {napistu-0.3.5.dist-info → napistu-0.3.7.dist-info}/licenses/LICENSE +0 -0
  40. {napistu-0.3.5.dist-info → napistu-0.3.7.dist-info}/top_level.txt +0 -0
tests/test_gaps.py CHANGED
@@ -3,21 +3,32 @@ import numpy as np
3
3
  import warnings
4
4
 
5
5
  from napistu.sbml_dfs_core import SBML_dfs
6
- from napistu.constants import SBML_DFS
7
- from napistu.constants import MINI_SBO_FROM_NAME
8
6
  from napistu.identifiers import Identifiers
9
-
7
+ from napistu.source import Source
10
8
  from napistu.modify import gaps
9
+ from napistu.constants import BQB
10
+ from napistu.constants import IDENTIFIERS
11
+ from napistu.constants import ONTOLOGIES
12
+ from napistu.constants import MINI_SBO_FROM_NAME
13
+ from napistu.constants import SBML_DFS
14
+ from napistu.ingestion.constants import EXCHANGE_COMPARTMENT, COMPARTMENTS
11
15
 
12
16
 
13
17
  # Minimal compartments table
14
18
  def _create_sbml_dfs_missing_transport_rxns():
15
19
 
20
+ blank_id = Identifiers([])
21
+ blank_source = Source(init=True)
22
+
16
23
  compartments = pd.DataFrame(
17
24
  {
18
- SBML_DFS.C_NAME: ["mitochondria", "nucleus", "cytosol"],
19
- SBML_DFS.C_IDENTIFIERS: [None],
20
- SBML_DFS.C_SOURCE: [None],
25
+ SBML_DFS.C_NAME: [
26
+ COMPARTMENTS.MITOCHONDRIA,
27
+ COMPARTMENTS.NUCLEUS,
28
+ EXCHANGE_COMPARTMENT,
29
+ ],
30
+ SBML_DFS.C_IDENTIFIERS: [blank_id],
31
+ SBML_DFS.C_SOURCE: [blank_source],
21
32
  },
22
33
  index=["c_mito", "c_nucl", "c_cytosol"],
23
34
  ).rename_axis(SBML_DFS.C_ID)
@@ -30,15 +41,15 @@ def _create_sbml_dfs_missing_transport_rxns():
30
41
  Identifiers(
31
42
  [
32
43
  {
33
- "ontology": "uniprot",
34
- "identifier": "PFAKE1",
35
- "bqb": "BQB_IS",
36
- "url": None,
44
+ IDENTIFIERS.ONTOLOGY: ONTOLOGIES.UNIPROT,
45
+ IDENTIFIERS.IDENTIFIER: "PFAKE1",
46
+ IDENTIFIERS.BQB: BQB.IS,
47
+ IDENTIFIERS.URL: None,
37
48
  }
38
49
  ]
39
50
  )
40
51
  ],
41
- SBML_DFS.S_SOURCE: [None],
52
+ SBML_DFS.S_SOURCE: [blank_source],
42
53
  },
43
54
  index=["s_A"],
44
55
  ).rename_axis(SBML_DFS.S_ID)
@@ -49,7 +60,7 @@ def _create_sbml_dfs_missing_transport_rxns():
49
60
  SBML_DFS.SC_NAME: ["A [mitochondria]", "A [nucleus]"],
50
61
  SBML_DFS.S_ID: ["s_A", "s_A"],
51
62
  SBML_DFS.C_ID: ["c_mito", "c_nucl"],
52
- SBML_DFS.SC_SOURCE: [None],
63
+ SBML_DFS.SC_SOURCE: [blank_source],
53
64
  },
54
65
  index=["sc_A_mito", "sc_A_nucl"],
55
66
  ).rename_axis(SBML_DFS.SC_ID)
@@ -58,8 +69,8 @@ def _create_sbml_dfs_missing_transport_rxns():
58
69
  reactions = pd.DataFrame(
59
70
  {
60
71
  SBML_DFS.R_NAME: ["A [mito] -> A [mito]", "A [nucl] -> A [nucl]"],
61
- SBML_DFS.R_IDENTIFIERS: [None],
62
- SBML_DFS.R_SOURCE: [None],
72
+ SBML_DFS.R_IDENTIFIERS: [blank_id],
73
+ SBML_DFS.R_SOURCE: [blank_source],
63
74
  SBML_DFS.R_ISREVERSIBLE: [True, True],
64
75
  },
65
76
  index=["r_A_mito", "r_A_nucl"],
@@ -105,7 +116,7 @@ def test_add_transportation_reactions():
105
116
 
106
117
  sbml_dfs = _create_sbml_dfs_missing_transport_rxns()
107
118
  sbml_dfs_w_transport = gaps.update_sbml_df_with_exchange(
108
- np.array(["s_A"]), sbml_dfs, exchange_compartment="cytosol"
119
+ np.array(["s_A"]), sbml_dfs, exchange_compartment=EXCHANGE_COMPARTMENT
109
120
  )
110
121
  assert sbml_dfs_w_transport.reactions.shape[0] == 4, "Should add 2 reactions"
111
122
  assert sbml_dfs_w_transport.reactions[
@@ -20,7 +20,7 @@ test_path = os.path.abspath(os.path.join(__file__, os.pardir))
20
20
  test_data = os.path.join(test_path, "test_data")
21
21
 
22
22
  sbml_path = os.path.join(test_data, "R-HSA-1237044.sbml")
23
- sbml_model = sbml.SBML(sbml_path).model
23
+ sbml_model = sbml.SBML(sbml_path)
24
24
  sbml_dfs = sbml_dfs_core.SBML_dfs(sbml_model)
25
25
 
26
26
 
@@ -18,7 +18,7 @@ sbml_path = os.path.join(test_path, "test_data", "reactome_glucose_metabolism.sb
18
18
  if not os.path.isfile(sbml_path):
19
19
  raise ValueError(f"{sbml_path} not found")
20
20
 
21
- sbml_model = sbml.SBML(sbml_path).model
21
+ sbml_model = sbml.SBML(sbml_path)
22
22
  sbml_dfs = sbml_dfs_core.SBML_dfs(sbml_model)
23
23
  sbml_dfs.validate()
24
24
 
@@ -1,4 +1,6 @@
1
1
  import pandas as pd
2
+ import pytest
3
+
2
4
  from napistu.ontologies.genodexito import Genodexito
3
5
  from napistu.ontologies.constants import (
4
6
  GENODEXITO_DEFS,
@@ -7,6 +9,7 @@ from napistu.ontologies.constants import (
7
9
  )
8
10
 
9
11
 
12
+ @pytest.skip_on_timeout(5)
10
13
  def test_genodexito_mapping_operations():
11
14
  """Test Genodexito mapping table creation and operations."""
12
15
  # Initialize with test mode and Python method to avoid R dependencies
@@ -1,7 +1,10 @@
1
+ import pytest
2
+
1
3
  from napistu.ontologies.mygene import create_python_mapping_tables
2
4
  from napistu.ontologies.constants import INTERCONVERTIBLE_GENIC_ONTOLOGIES
3
5
 
4
6
 
7
+ @pytest.skip_on_timeout(5)
5
8
  def test_create_python_mapping_tables_yeast():
6
9
  """Test create_python_mapping_tables with yeast species."""
7
10
  # Test with a subset of mappings to keep test runtime reasonable
@@ -1,14 +1,16 @@
1
1
  """Tests for the ontology aliases module."""
2
2
 
3
+ from unittest.mock import patch
4
+
3
5
  import pytest
4
6
  import pandas as pd
5
7
  from napistu import identifiers
6
- from napistu.constants import IDENTIFIERS, SBML_DFS
8
+ from napistu.constants import IDENTIFIERS, SBML_DFS, ONTOLOGIES
7
9
  from napistu.ontologies import renaming
8
10
 
9
11
 
10
12
  @pytest.fixture
11
- def mock_sbml_dfs():
13
+ def mock_sbml_dfs(sbml_dfs):
12
14
  """Create a mock SBML_dfs object for testing."""
13
15
  # Create a simple species DataFrame with identifiers
14
16
  s1_ids = identifiers.Identifiers(
@@ -39,32 +41,27 @@ def mock_sbml_dfs():
39
41
  ]
40
42
  )
41
43
 
44
+ s3_ids = identifiers.Identifiers([])
45
+
42
46
  species_df = pd.DataFrame(
43
- {"s_name": ["gene1", "gene2"], SBML_DFS.S_IDENTIFIERS: [s1_ids, s2_ids]}
47
+ {
48
+ SBML_DFS.S_NAME: ["gene1", "gene2", "gene3"],
49
+ SBML_DFS.S_IDENTIFIERS: [s1_ids, s2_ids, s3_ids],
50
+ }
44
51
  )
45
52
 
46
- # Create mock SBML_dfs object
47
- class MockSBMLDfs:
48
- def __init__(self):
49
- self.species = species_df
50
- self.schema = {"species": {"pk": "s_id", "id": SBML_DFS.S_IDENTIFIERS}}
51
-
52
- def get_identifiers(self, table_name):
53
- if table_name == SBML_DFS.SPECIES:
54
- all_ids = []
55
- for idx, row in self.species.iterrows():
56
- for id_dict in row[SBML_DFS.S_IDENTIFIERS].ids:
57
- all_ids.append({"s_id": idx, **id_dict})
58
- return pd.DataFrame(all_ids)
59
- return pd.DataFrame()
60
-
61
- return MockSBMLDfs()
53
+ # Patch the species attribute only for the duration of the test
54
+ with patch.object(sbml_dfs, "species", new=species_df):
55
+ yield sbml_dfs # All methods are real, only .species is patched
62
56
 
63
57
 
64
58
  def test_rename_species_ontologies_basic(mock_sbml_dfs):
65
59
  """Test basic alias updating functionality."""
66
60
  # Define test aliases
67
- test_aliases = {"ncbi_entrez_gene": {"ncbigene"}, "uniprot": {"uniprot_id"}}
61
+ test_aliases = {
62
+ ONTOLOGIES.NCBI_ENTREZ_GENE: {"ncbigene"},
63
+ ONTOLOGIES.UNIPROT: {"uniprot_id"},
64
+ }
68
65
 
69
66
  # Update aliases
70
67
  renaming.rename_species_ontologies(mock_sbml_dfs, test_aliases)
@@ -73,11 +70,18 @@ def test_rename_species_ontologies_basic(mock_sbml_dfs):
73
70
  updated_ids = mock_sbml_dfs.get_identifiers(SBML_DFS.SPECIES)
74
71
 
75
72
  # Check that ontologies were updated correctly
76
- assert "ncbi_entrez_gene" in set(updated_ids[IDENTIFIERS.ONTOLOGY])
77
- assert "uniprot" in set(updated_ids[IDENTIFIERS.ONTOLOGY])
73
+ assert ONTOLOGIES.NCBI_ENTREZ_GENE in set(updated_ids[IDENTIFIERS.ONTOLOGY])
74
+ assert ONTOLOGIES.UNIPROT in set(updated_ids[IDENTIFIERS.ONTOLOGY])
78
75
  assert "ncbigene" not in set(updated_ids[IDENTIFIERS.ONTOLOGY])
79
76
  assert "uniprot_id" not in set(updated_ids[IDENTIFIERS.ONTOLOGY])
80
77
 
78
+ # verify that all the species have Identifiers object
79
+ for row in mock_sbml_dfs.species.itertuples():
80
+ val = getattr(row, SBML_DFS.S_IDENTIFIERS)
81
+ assert val is not None and isinstance(
82
+ val, identifiers.Identifiers
83
+ ), f"Bad value: {val} in row {row}"
84
+
81
85
 
82
86
  def test_rename_species_ontologies_no_overlap(mock_sbml_dfs):
83
87
  """Test that error is raised when no aliases overlap with data."""
@@ -93,7 +97,7 @@ def test_rename_species_ontologies_partial_update(mock_sbml_dfs):
93
97
  """Test that partial updates work correctly."""
94
98
  # Define aliases that only update some ontologies
95
99
  test_aliases = {
96
- "ncbi_entrez_gene": {"ncbigene"}
100
+ ONTOLOGIES.NCBI_ENTREZ_GENE: {"ncbigene"}
97
101
  # Don't include uniprot_id mapping
98
102
  }
99
103
 
@@ -104,7 +108,7 @@ def test_rename_species_ontologies_partial_update(mock_sbml_dfs):
104
108
  updated_ids = mock_sbml_dfs.get_identifiers(SBML_DFS.SPECIES)
105
109
 
106
110
  # Check that only ncbigene was updated
107
- assert "ncbi_entrez_gene" in set(updated_ids[IDENTIFIERS.ONTOLOGY])
111
+ assert ONTOLOGIES.NCBI_ENTREZ_GENE in set(updated_ids[IDENTIFIERS.ONTOLOGY])
108
112
  assert "uniprot_id" in set(
109
113
  updated_ids[IDENTIFIERS.ONTOLOGY]
110
114
  ) # Should remain unchanged