biocypher 0.5.39__tar.gz → 0.5.41__tar.gz
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.
Potentially problematic release.
This version of biocypher might be problematic. Click here for more details.
- {biocypher-0.5.39 → biocypher-0.5.41}/PKG-INFO +1 -1
- {biocypher-0.5.39 → biocypher-0.5.41}/biocypher/_config/biocypher_config.yaml +18 -8
- {biocypher-0.5.39 → biocypher-0.5.41}/biocypher/_connect.py +36 -9
- {biocypher-0.5.39 → biocypher-0.5.41}/biocypher/_core.py +7 -3
- {biocypher-0.5.39 → biocypher-0.5.41}/biocypher/_metadata.py +1 -1
- {biocypher-0.5.39 → biocypher-0.5.41}/biocypher/_misc.py +6 -2
- biocypher-0.5.41/biocypher/write/__init__.py +0 -0
- biocypher-0.5.39/biocypher/_write.py → biocypher-0.5.41/biocypher/write/_batch_writer.py +7 -944
- biocypher-0.5.41/biocypher/write/_write.py +105 -0
- biocypher-0.5.41/biocypher/write/graph/__init__.py +0 -0
- biocypher-0.5.41/biocypher/write/graph/_arangodb.py +241 -0
- biocypher-0.5.41/biocypher/write/graph/_neo4j.py +334 -0
- biocypher-0.5.41/biocypher/write/relational/__init__.py +0 -0
- biocypher-0.5.41/biocypher/write/relational/_postgresql.py +320 -0
- biocypher-0.5.41/biocypher/write/relational/_sqlite.py +51 -0
- {biocypher-0.5.39 → biocypher-0.5.41}/pyproject.toml +1 -1
- {biocypher-0.5.39 → biocypher-0.5.41}/LICENSE +0 -0
- {biocypher-0.5.39 → biocypher-0.5.41}/README.md +0 -0
- {biocypher-0.5.39 → biocypher-0.5.41}/biocypher/__init__.py +0 -0
- {biocypher-0.5.39 → biocypher-0.5.41}/biocypher/_config/__init__.py +0 -0
- {biocypher-0.5.39 → biocypher-0.5.41}/biocypher/_config/test_config.yaml +0 -0
- {biocypher-0.5.39 → biocypher-0.5.41}/biocypher/_config/test_schema_config.yaml +0 -0
- {biocypher-0.5.39 → biocypher-0.5.41}/biocypher/_config/test_schema_config_disconnected.yaml +0 -0
- {biocypher-0.5.39 → biocypher-0.5.41}/biocypher/_config/test_schema_config_extended.yaml +0 -0
- {biocypher-0.5.39 → biocypher-0.5.41}/biocypher/_create.py +0 -0
- {biocypher-0.5.39 → biocypher-0.5.41}/biocypher/_deduplicate.py +0 -0
- {biocypher-0.5.39 → biocypher-0.5.41}/biocypher/_get.py +0 -0
- {biocypher-0.5.39 → biocypher-0.5.41}/biocypher/_logger.py +0 -0
- {biocypher-0.5.39 → biocypher-0.5.41}/biocypher/_mapping.py +0 -0
- {biocypher-0.5.39 → biocypher-0.5.41}/biocypher/_ontology.py +0 -0
- {biocypher-0.5.39 → biocypher-0.5.41}/biocypher/_pandas.py +0 -0
- {biocypher-0.5.39 → biocypher-0.5.41}/biocypher/_translate.py +0 -0
|
@@ -3,7 +3,6 @@ Title: BioCypher python module configuration file
|
|
|
3
3
|
## Some options are not used by default. Uncomment them to use them.
|
|
4
4
|
|
|
5
5
|
biocypher:
|
|
6
|
-
|
|
7
6
|
### Required parameters ###
|
|
8
7
|
## DBMS type
|
|
9
8
|
|
|
@@ -51,18 +50,17 @@ biocypher:
|
|
|
51
50
|
|
|
52
51
|
# tail_ontologies:
|
|
53
52
|
# so:
|
|
54
|
-
# url: test/so.owl
|
|
53
|
+
# url: test/ontologies/so.owl
|
|
55
54
|
# head_join_node: sequence variant
|
|
56
55
|
# tail_join_node: sequence_variant
|
|
57
56
|
# mondo:
|
|
58
|
-
# url: test/mondo.owl
|
|
57
|
+
# url: test/ontologies/mondo.owl
|
|
59
58
|
# head_join_node: disease
|
|
60
59
|
# tail_join_node: disease
|
|
61
60
|
|
|
62
61
|
### DBMS configuration ###
|
|
63
62
|
|
|
64
63
|
neo4j:
|
|
65
|
-
|
|
66
64
|
### Neo4j configuration ###
|
|
67
65
|
## Database name
|
|
68
66
|
|
|
@@ -80,8 +78,8 @@ neo4j:
|
|
|
80
78
|
|
|
81
79
|
## Neo4j admin import batch writer settings
|
|
82
80
|
|
|
83
|
-
delimiter:
|
|
84
|
-
array_delimiter:
|
|
81
|
+
delimiter: ";"
|
|
82
|
+
array_delimiter: "|"
|
|
85
83
|
quote_character: "'"
|
|
86
84
|
|
|
87
85
|
## MultiDB functionality
|
|
@@ -104,8 +102,8 @@ postgresql:
|
|
|
104
102
|
|
|
105
103
|
# PostgreSQL connection credentials
|
|
106
104
|
database_name: postgres # DB name
|
|
107
|
-
user: postgres
|
|
108
|
-
password: postgres
|
|
105
|
+
user: postgres # user name
|
|
106
|
+
password: postgres # password
|
|
109
107
|
host: localhost # host
|
|
110
108
|
port: 5432 # port
|
|
111
109
|
|
|
@@ -114,3 +112,15 @@ postgresql:
|
|
|
114
112
|
delimiter: '\t'
|
|
115
113
|
# import_call_bin_prefix: '' # path to "psql"
|
|
116
114
|
# import_call_file_prefix: '/path/to/files'
|
|
115
|
+
|
|
116
|
+
sqlite:
|
|
117
|
+
### SQLite configuration ###
|
|
118
|
+
|
|
119
|
+
# SQLite connection credentials
|
|
120
|
+
database_name: sqlite.db # DB name
|
|
121
|
+
|
|
122
|
+
# SQLite import batch writer settings
|
|
123
|
+
quote_character: '"'
|
|
124
|
+
delimiter: '\t'
|
|
125
|
+
# import_call_bin_prefix: '' # path to "sqlite3"
|
|
126
|
+
# import_call_file_prefix: '/path/to/files'
|
|
@@ -11,11 +11,12 @@
|
|
|
11
11
|
"""
|
|
12
12
|
BioCypher 'online' mode. Handles connection and manipulation of a running DBMS.
|
|
13
13
|
"""
|
|
14
|
+
import subprocess
|
|
15
|
+
|
|
14
16
|
from ._logger import logger
|
|
15
17
|
|
|
16
18
|
logger.debug(f"Loading module {__name__}.")
|
|
17
19
|
|
|
18
|
-
from typing import Optional
|
|
19
20
|
from collections.abc import Iterable
|
|
20
21
|
import itertools
|
|
21
22
|
|
|
@@ -24,7 +25,6 @@ import neo4j_utils
|
|
|
24
25
|
from . import _misc
|
|
25
26
|
from ._config import config as _config
|
|
26
27
|
from ._create import BioCypherEdge, BioCypherNode
|
|
27
|
-
from ._ontology import Ontology
|
|
28
28
|
from ._translate import Translator
|
|
29
29
|
|
|
30
30
|
__all__ = ["_Neo4jDriver"]
|
|
@@ -137,16 +137,43 @@ class _Neo4jDriver:
|
|
|
137
137
|
|
|
138
138
|
logger.info("Creating constraints for node types in config.")
|
|
139
139
|
|
|
140
|
+
major_neo4j_version = int(self._get_neo4j_version().split(".")[0])
|
|
140
141
|
# get structure
|
|
141
142
|
for leaf in self.translator.ontology.mapping.extended_schema.items():
|
|
142
|
-
label = _misc.sentencecase_to_pascalcase(leaf[0])
|
|
143
|
+
label = _misc.sentencecase_to_pascalcase(leaf[0], sep=r"\s\.")
|
|
143
144
|
if leaf[1]["represented_as"] == "node":
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
145
|
+
if major_neo4j_version >= 5:
|
|
146
|
+
s = (
|
|
147
|
+
f"CREATE CONSTRAINT `{label}_id` "
|
|
148
|
+
f"IF NOT EXISTS FOR (n:`{label}`) "
|
|
149
|
+
"REQUIRE n.id IS UNIQUE"
|
|
150
|
+
)
|
|
151
|
+
self._driver.query(s)
|
|
152
|
+
else:
|
|
153
|
+
s = (
|
|
154
|
+
f"CREATE CONSTRAINT `{label}_id` "
|
|
155
|
+
f"IF NOT EXISTS ON (n:`{label}`) "
|
|
156
|
+
"ASSERT n.id IS UNIQUE"
|
|
157
|
+
)
|
|
158
|
+
self._driver.query(s)
|
|
159
|
+
|
|
160
|
+
def _get_neo4j_version(self):
|
|
161
|
+
"""Get neo4j version."""
|
|
162
|
+
try:
|
|
163
|
+
neo4j_version = self._driver.query(
|
|
164
|
+
"""
|
|
165
|
+
CALL dbms.components()
|
|
166
|
+
YIELD name, versions, edition
|
|
167
|
+
UNWIND versions AS version
|
|
168
|
+
RETURN version AS version
|
|
169
|
+
""",
|
|
170
|
+
)[0][0]["version"]
|
|
171
|
+
return neo4j_version
|
|
172
|
+
except Exception as e:
|
|
173
|
+
logger.warning(
|
|
174
|
+
f"Error detecting Neo4j version: {e} use default version 4.0.0."
|
|
175
|
+
)
|
|
176
|
+
return "4.0.0"
|
|
150
177
|
|
|
151
178
|
def add_nodes(self, id_type_tuples: Iterable[tuple]) -> tuple:
|
|
152
179
|
"""
|
|
@@ -26,8 +26,8 @@ from ._logger import logger
|
|
|
26
26
|
|
|
27
27
|
logger.debug(f"Loading module {__name__}.")
|
|
28
28
|
|
|
29
|
+
from biocypher.write._write import DBMS_TO_CLASS, get_writer
|
|
29
30
|
from ._get import Downloader
|
|
30
|
-
from ._write import get_writer
|
|
31
31
|
from ._config import config as _config
|
|
32
32
|
from ._config import update_from_file as _file_update
|
|
33
33
|
from ._create import BioCypherEdge, BioCypherNode, BioCypherRelAsNode
|
|
@@ -40,7 +40,7 @@ from ._deduplicate import Deduplicator
|
|
|
40
40
|
|
|
41
41
|
__all__ = ["BioCypher"]
|
|
42
42
|
|
|
43
|
-
SUPPORTED_DBMS =
|
|
43
|
+
SUPPORTED_DBMS = DBMS_TO_CLASS.keys()
|
|
44
44
|
|
|
45
45
|
REQUIRED_CONFIG = [
|
|
46
46
|
"dbms",
|
|
@@ -136,6 +136,10 @@ class BioCypher:
|
|
|
136
136
|
|
|
137
137
|
if not self._schema_config_path:
|
|
138
138
|
logger.warning("Running BioCypher without schema configuration.")
|
|
139
|
+
else:
|
|
140
|
+
logger.info(
|
|
141
|
+
f"Running BioCypher with schema configuration from {self._schema_config_path}."
|
|
142
|
+
)
|
|
139
143
|
|
|
140
144
|
self._head_ontology = head_ontology or self.base_config["head_ontology"]
|
|
141
145
|
|
|
@@ -476,7 +480,7 @@ class BioCypher:
|
|
|
476
480
|
if mt:
|
|
477
481
|
msg = (
|
|
478
482
|
"Input entities not accounted for due to them not being "
|
|
479
|
-
"present in the
|
|
483
|
+
f"present in the schema configuration file {self._schema_config_path} "
|
|
480
484
|
"(this is not necessarily a problem, if you did not intend "
|
|
481
485
|
"to include them in the database; see the log for details): \n"
|
|
482
486
|
)
|
|
@@ -205,7 +205,7 @@ def sentencecase_to_snakecase(s: str) -> str:
|
|
|
205
205
|
return stringcase.snakecase(s).lower()
|
|
206
206
|
|
|
207
207
|
|
|
208
|
-
def sentencecase_to_pascalcase(s: str) -> str:
|
|
208
|
+
def sentencecase_to_pascalcase(s: str, sep: str = r"\s") -> str:
|
|
209
209
|
"""
|
|
210
210
|
Convert sentence case to PascalCase.
|
|
211
211
|
|
|
@@ -215,7 +215,11 @@ def sentencecase_to_pascalcase(s: str) -> str:
|
|
|
215
215
|
Returns:
|
|
216
216
|
string in PascalCase form
|
|
217
217
|
"""
|
|
218
|
-
return re.sub(
|
|
218
|
+
return re.sub(
|
|
219
|
+
r"(?:^|[" + sep + "])([a-zA-Z])",
|
|
220
|
+
lambda match: match.group(1).upper(),
|
|
221
|
+
s,
|
|
222
|
+
)
|
|
219
223
|
|
|
220
224
|
|
|
221
225
|
def to_lower_sentence_case(s: str) -> str:
|
|
File without changes
|