Mapping and Translation
Class responsible for exacting the translation process.
Translation is configured in the schema_config.yaml file. Creates a mapping dictionary from that file, and, given nodes and edges, translates them into BioCypherNodes and BioCypherEdges. During this process, can also filter the properties of the entities if the schema_config.yaml file specifies a property whitelist or blacklist.
Provides utility functions for translating between input and output labels and cypher queries.
Source code in biocypher/_translate.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 |
|
__init__(ontology, strict_mode=False)
Initialise the translator.
leaves:
Dictionary detailing the leaves of the hierarchy
tree representing the structure of the graph; the leaves are
the entities that will be direct components of the graph,
while the intermediary nodes are additional labels for
filtering purposes.
strict_mode:
If True, the translator will raise an error if input data do not
carry source, licence, and version information.
Source code in biocypher/_translate.py
_add_translation_mappings(original_name, biocypher_name)
Add translation mappings for a label and name.
We use here the PascalCase version of the BioCypher name, since sentence case is not useful for Cypher queries.
Source code in biocypher/_translate.py
_filter_props(bl_type, props)
Filter properties for those specified in schema_config if any.
If the properties are not specified in the schema_config.yaml file, return the original properties.
Source code in biocypher/_translate.py
_get_ontology_mapping(label)
Find the ontology class for the given input type.
For each given input type ("input_label" or "label_in_input"), find the
corresponding ontology class in the leaves dictionary (from the
schema_config.yam
).
label:
The input type to find (`input_label` or `label_in_input` in
`schema_config.yaml`).
Source code in biocypher/_translate.py
_get_preferred_id(_bl_type)
Return the preferred id for the given Biolink type.
If the preferred id is not specified in the schema_config.yaml file, return "id".
Source code in biocypher/_translate.py
_record_no_type(_type, what)
Record the type of a non-represented node or edge.
In case of an entity that is not represented in the schema_config, record the type and the entity.
Source code in biocypher/_translate.py
_update_ontology_types()
Create a dictionary to translate from input to ontology labels.
If multiple input labels, creates mapping for each.
Source code in biocypher/_translate.py
get_missing_biolink_types()
Return a dictionary of non-represented types.
The dictionary contains the type as the key and the number of occurrences as the value.
name_sentence_to_pascal(name)
staticmethod
Convert a name in sentence case to pascal case.
Source code in biocypher/_translate.py
reverse_translate(query)
Reverse translate a cypher query.
Only translates labels as of now.
Source code in biocypher/_translate.py
reverse_translate_term(term)
translate(query)
Translate a cypher query.
Only translates labels as of now.
translate_edges(edge_tuples)
Translate input edge representation.
Translate the edge tuples to a representation that conforms to the schema of the given BioCypher graph. For now requires explicit statement of edge type on pass.
edge_tuples (list of tuples):
collection of tuples representing source and target of
an interaction via their unique ids as well as the type
of interaction in the original database notation, which
is translated to BioCypher notation using the `leaves`.
Can optionally possess its own ID.
Source code in biocypher/_translate.py
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 |
|
translate_nodes(node_tuples)
Translate input node representation.
Translate the node tuples to a representation that conforms to the schema of the given BioCypher graph. For now requires explicit statement of node type on pass.
node_tuples (list of tuples): collection of tuples
representing individual nodes by their unique id and a type
that is translated from the original database notation to
the corresponding BioCypher notation.