Output Writing
Writer Retrieval
Return the writer class based on the selection in the config file.
dbms: the database management system; for options, see DBMS_TO_CLASS.
translator: the Translator object.
deduplicator: the Deduplicator object.
output_directory: the directory to output.write the output files to.
strict_mode: whether to use strict mode.
instance: an instance of the selected writer class.
Source code in biocypher/output/write/_get_writer.py
Writer Base Class
Bases: ABC
Abstract class for writing node and edge representations to disk. Specifics of the different writers (e.g. neo4j, postgresql, csv, etc.) are implemented in the child classes. Any concrete writer needs to implement at least: - _write_node_data - _write_edge_data - _construct_import_call - _get_import_script_name
translator (Translator): Instance of :py:class:`Translator` to enable translation of
nodes and manipulation of properties.
deduplicator (Deduplicator): Instance of :py:class:`Deduplicator` to enable deduplication
of nodes and edges.
output_directory (str, optional): Path for exporting CSV files. Defaults to None.
strict_mode (bool, optional): Whether to enforce source, version, and license properties. Defaults to False.
NotImplementedError: Writer implementation must override '_write_node_data'
NotImplementedError: Writer implementation must override '_write_edge_data'
NotImplementedError: Writer implementation must override '_construct_import_call'
NotImplementedError: Writer implementation must override '_get_import_script_name'
Source code in biocypher/output/write/_writer.py
14 15 16 17 18 19 20 21 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 |
|
__init__(translator, deduplicator, output_directory=None, strict_mode=False, *args, **kwargs)
Abstract class for writing node and edge representations to disk.
translator (Translator): Instance of :py:class:`Translator` to enable translation of
nodes and manipulation of properties.
deduplicator (Deduplicator): Instance of :py:class:`Deduplicator` to enable deduplication
of nodes and edges.
output_directory (str, optional): Path for exporting CSV files. Defaults to None.
strict_mode (bool, optional): Whether to enforce source, version, and license properties. Defaults to False.
Source code in biocypher/output/write/_writer.py
_construct_import_call()
abstractmethod
Function to construct the import call detailing folder and individual node and edge headers and data files, as well as delimiters and database name. Built after all data has been processed to ensure that nodes are called before any edges.
Returns
str: command for importing the output files into a DBMS.
Source code in biocypher/output/write/_writer.py
_get_import_script_name()
abstractmethod
Returns the name of the import script.
Returns
str: The name of the import script (ending in .sh)
Source code in biocypher/output/write/_writer.py
_write_edge_data(edges)
abstractmethod
Implement how to output.write edges to disk.
edges (Iterable): An iterable of BioCypherNode / BioCypherEdge / BioCypherRelAsNode objects.
bool: The return value. True for success, False otherwise.
Source code in biocypher/output/write/_writer.py
_write_node_data(nodes)
abstractmethod
Implement how to output.write nodes to disk.
nodes (Iterable): An iterable of BioCypherNode / BioCypherEdge / BioCypherRelAsNode objects.
bool: The return value. True for success, False otherwise.
Source code in biocypher/output/write/_writer.py
write_edges(edges, batch_size=int(1000000.0), force=False)
Wrapper for writing edges.
nodes (BioCypherNode): a list or generator of nodes in
:py:class:`BioCypherNode` format
batch_size (int): The batch size for writing nodes.
force (bool): Whether to force writing nodes even if their type is
not present in the schema.
bool: The return value. True for success, False otherwise.
Source code in biocypher/output/write/_writer.py
write_import_call()
Function to output.write the import call detailing folder and individual node and edge headers and data files, as well as delimiters and database name, to the export folder as txt.
Returns
str: The path of the file holding the import call.
Source code in biocypher/output/write/_writer.py
write_nodes(nodes, batch_size=int(1000000.0), force=False)
Wrapper for writing nodes.
nodes (BioCypherNode): a list or generator of nodes in
:py:class:`BioCypherNode` format
batch_size (int): The batch size for writing nodes.
force (bool): Whether to force writing nodes even if their type is
not present in the schema.
bool: The return value. True for success, False otherwise.
Source code in biocypher/output/write/_writer.py
Batch Writer Base Class
Bases: _Writer
, ABC
Abstract batch writer class.
Source code in biocypher/output/write/_batch_writer.py
20 21 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 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 |
|
import_call_file_prefix
property
Property for output directory path.
__init__(translator, deduplicator, delimiter, array_delimiter=',', quote='"', output_directory=None, db_name='neo4j', import_call_bin_prefix=None, import_call_file_prefix=None, wipe=True, strict_mode=False, skip_bad_relationships=False, skip_duplicate_nodes=False, db_user=None, db_password=None, db_host=None, db_port=None, file_format=None, rdf_namespaces={}, labels_order='Ascending', **kwargs)
Write node and edge representations to disk.
Abstract parent class for writing node and edge representations to disk using the format specified by each database type. The database-specific functions are implemented by the respective child-classes. This abstract class contains all methods expected by a bach writer instance, some of which need to be overwritten by the child classes.
Each batch writer instance has a fixed representation that needs to be
passed at instantiation via the attr:
schema
argument. The instance
also expects an ontology adapter via attr:
ontology_adapter
to be
able to convert and extend the hierarchy.
Requires the following methods to be overwritten by database-specific writer classes:
- _write_node_headers
- _write_edge_headers
- _construct_import_call
- _write_array_string
- _get_import_script_name
translator:
Instance of :py:class:`Translator` to enable translation of
nodes and manipulation of properties.
deduplicator:
Instance of :py:class:`Deduplicator` to enable deduplication
of nodes and edges.
delimiter:
The delimiter to use for the CSV files.
array_delimiter:
The delimiter to use for array properties.
quote:
The quote character to use for the CSV files.
output_directory:
Path for exporting CSV files.
db_name:
Name of the database that will be used in the generated
commands.
import_call_bin_prefix:
Path prefix for the admin import call binary.
import_call_file_prefix:
Path prefix for the data files (headers and parts) in the import
call.
wipe:
Whether to force import (removing existing DB content).
(Specific to Neo4j.)
strict_mode:
Whether to enforce source, version, and license properties.
skip_bad_relationships:
Whether to skip relationships that do not have a valid
start and end node. (Specific to Neo4j.)
skip_duplicate_nodes:
Whether to skip duplicate nodes. (Specific to Neo4j.)
db_user:
The database user.
db_password:
The database password.
db_host:
The database host. Defaults to localhost.
db_port:
The database port.
file_format:
The format of RDF.
rdf_namespaces:
The namespaces for RDF.
labels_order:
The order of labels, to reflect the hierarchy (or not).
Default: "Ascending" (from more specific to more generic).
Source code in biocypher/output/write/_batch_writer.py
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 |
|
_construct_import_call()
abstractmethod
Construct the import call.
Construct the import call detailing folder and individual node and edge headers and data files, as well as delimiters and database name. Built after all data has been processed to ensure that nodes are called before any edges.
Returns
str: A bash command for csv import.
Source code in biocypher/output/write/_batch_writer.py
_get_default_import_call_bin_prefix()
abstractmethod
Provide the default string for the import call bin prefix.
Returns
str: The database-specific string for the path to the import call bin prefix
Source code in biocypher/output/write/_batch_writer.py
_get_import_script_name()
abstractmethod
Return the name of the import script.
The name will be chosen based on the used database.
Returns
str: The name of the import script (ending in .sh)
Source code in biocypher/output/write/_batch_writer.py
_process_delimiter(delimiter)
Process a delimited to escape correctly.
delimiter (str): The delimiter to process.
tuple: The delimiter and its escaped representation.
Source code in biocypher/output/write/_batch_writer.py
_quote_string(value)
abstractmethod
Quote a string.
Escaping is handled by the database-specific writer.
Source code in biocypher/output/write/_batch_writer.py
_write_array_string(string_list)
abstractmethod
Write the string representation of an array into a .csv file.
Different databases require different formats of array to optimize import speed.
string_list (list): list of ontology strings
str: The database-specific string representation of an array
Source code in biocypher/output/write/_batch_writer.py
_write_edge_data(edges, batch_size)
Write biocypher edges to CSV.
Writes biocypher edges to CSV conforming to the headers created
with _write_edge_headers()
, and is actually required to be run
before calling _write_node_headers()
to set the
attr:
self.edge_property_dict
for passing the edge
properties to the instance. Expects list or generator of edges
from the class:
BioCypherEdge
class.
edges (BioCypherEdge): a list or generator of edges in
:py:class:`BioCypherEdge` format
bool: The return value. True for success, False otherwise.
Todo:
- currently works for mixed edges but in practice often is
called on one iterable containing one type of edge only
Source code in biocypher/output/write/_batch_writer.py
698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 |
|
_write_edge_headers()
abstractmethod
Write a database import-file for an edge.
Write a database import-file for an edge as per the definition in
the schema_config.yaml
, containing only the header for this type
of edge.
Returns
bool: The return value. True for success, False otherwise.
Source code in biocypher/output/write/_batch_writer.py
_write_next_part(label, lines)
Write a list of strings to a new part file.
label (str): the label (type) of the edge; internal
representation sentence case -> needs to become PascalCase
for disk representation
lines (list): list of strings to be written
bool: The return value. True for success, False otherwise.
Source code in biocypher/output/write/_batch_writer.py
_write_node_data(nodes, batch_size, force=False)
Write biocypher nodes to CSV.
Conforms to the headers created with _write_node_headers()
, and
is actually required to be run before calling _write_node_headers()
to set the attr:
self.node_property_dict
for passing the node
properties to the instance. Expects list or generator of nodes from
the class:
BioCypherNode
class.
nodes (BioCypherNode): a list or generator of nodes in
:py:class:`BioCypherNode` format
bool: The return value. True for success, False otherwise.
Source code in biocypher/output/write/_batch_writer.py
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 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 |
|
_write_node_headers()
abstractmethod
Write header files for nodes.
Write header files (node properties) for nodes as per the
definition in the schema_config.yaml
.
Returns
bool: The return value. True for success, False otherwise.
Source code in biocypher/output/write/_batch_writer.py
_write_single_edge_list_to_file(edge_list, label, prop_dict)
Write a list of biocypher edges to a CSV file.
This function takes one list of biocypher edges and writes them to a Neo4j admin import compatible CSV file.
edge_list (list): list of BioCypherEdges to be written
label (str): the label (type) of the edge
prop_dict (dict): properties of node class passed from parsing
function and their types
bool: The return value. True for success, False otherwise.
Source code in biocypher/output/write/_batch_writer.py
844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 |
|
_write_single_node_list_to_file(node_list, label, prop_dict, labels)
Write a list of biocypher nodes to a CSV file.
This function takes one list of biocypher nodes and writes them to a Neo4j admin import compatible CSV file.
node_list (list): list of BioCypherNodes to be written
label (str): the primary label of the node
prop_dict (dict): properties of node class passed from parsing
function and their types
labels (str): string of one or several concatenated labels
for the node class
bool: The return value. True for success, False otherwise.
Source code in biocypher/output/write/_batch_writer.py
606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 |
|
get_import_call()
Eeturn the import call.
Return the import call detailing folder and individual node and edge headers and data files, as well as delimiters and database name.
Returns
str: a bash command for the database import
Source code in biocypher/output/write/_batch_writer.py
write_edges(edges, batch_size=int(1000000.0))
Write edges and their headers.
edges (BioCypherEdge): a list or generator of edges in
:py:class:`BioCypherEdge` or :py:class:`BioCypherRelAsNode`
format
bool: The return value. True for success, False otherwise.
Source code in biocypher/output/write/_batch_writer.py
write_import_call()
Write the import call.
Function to write the import call detailing folder and individual node and edge headers and data files, as well as delimiters and database name, to the export folder as txt.
Returns
str: The path of the file holding the import call.
Source code in biocypher/output/write/_batch_writer.py
write_nodes(nodes, batch_size=int(1000000.0), force=False)
Write nodes and their headers.
nodes (BioCypherNode): a list or generator of nodes in
:py:class:`BioCypherNode` format
batch_size (int): The batch size for writing nodes.
force (bool): Whether to force writing nodes even if their type is
not present in the schema.
bool: The return value. True for success, False otherwise.
Source code in biocypher/output/write/_batch_writer.py
Neo4j Batch Writer
Bases: _BatchWriter
Class for writing node and edge representations to disk using the
format specified by Neo4j for the use of admin import. Each batch
writer instance has a fixed representation that needs to be passed
at instantiation via the attr:
schema
argument. The instance
also expects an ontology adapter via attr:
ontology_adapter
to be able
to convert and extend the hierarchy.
This class inherits from the abstract class "_BatchWriter" and implements the Neo4j-specific methods:
- _write_node_headers
- _write_edge_headers
- _construct_import_call
- _write_array_string
Source code in biocypher/output/write/graph/_neo4j.py
9 10 11 12 13 14 15 16 17 18 19 20 21 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 |
|
__init__(*args, **kwargs)
Constructor.
Check the version of Neo4j and adds a command scope if version >= 5.
Returns
_Neo4jBatchWriter: An instance of the writer.
Source code in biocypher/output/write/graph/_neo4j.py
_construct_import_call()
Function to construct the import call detailing folder and individual node and edge headers and data files, as well as delimiters and database name. Built after all data has been processed to ensure that nodes are called before any edges.
Returns
str: a bash command for neo4j-admin import
Source code in biocypher/output/write/graph/_neo4j.py
_get_default_import_call_bin_prefix()
Method to provide the default string for the import call bin prefix.
Returns
str: The default location for the neo4j admin import location
_get_import_call(import_cmd, database_cmd, wipe_cmd)
Get parametrized import call for Neo4j 4 or 5+.
import_cmd (str): The import command to use.
database_cmd (str): The database command to use.
wipe_cmd (str): The wipe command to use.
str: The import call.
Source code in biocypher/output/write/graph/_neo4j.py
_get_import_script_name()
Returns the name of the neo4j admin import script
Returns
str: The name of the import script (ending in .sh)
_quote_string(value)
Quote a string. Quote character is escaped by doubling it.
_write_array_string(string_list)
Abstract method to output.write the string representation of an array into a .csv file as required by the neo4j admin-import.
string_list (list): list of ontology strings
str: The string representation of an array for the neo4j admin import
Source code in biocypher/output/write/graph/_neo4j.py
_write_edge_headers()
Writes single CSV file for a graph entity that is represented
as an edge as per the definition in the schema_config.yaml
,
containing only the header for this type of edge.
Returns
bool: The return value. True for success, False otherwise.
Source code in biocypher/output/write/graph/_neo4j.py
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 |
|
_write_node_headers()
Writes single CSV file for a graph entity that is represented
as a node as per the definition in the schema_config.yaml
,
containing only the header for this type of node.
Returns
bool: The return value. True for success, False otherwise.
Source code in biocypher/output/write/graph/_neo4j.py
ArangoDB Batch Writer
Bases: _Neo4jBatchWriter
Class for writing node and edge representations to disk.
Uses the format specified by ArangoDB for the use of "arangoimport". Output files are similar to Neo4j, but with a different header format.
Source code in biocypher/output/write/graph/_arangodb.py
9 10 11 12 13 14 15 16 17 18 19 20 21 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 |
|
_construct_import_call()
Construct the import call.
Details folder and individual node and edge headers and data files, as well as delimiters and database name. Built after all data has been processed to ensure that nodes are called before any edges.
Returns
str: a bash command for arangoimport
Source code in biocypher/output/write/graph/_arangodb.py
_get_default_import_call_bin_prefix()
Provide the default string for the import call bin prefix.
Returns
str: The default location for the neo4j admin import location
_get_import_script_name()
Return the name of the neo4j admin import script.
Returns
str: The name of the import script (ending in .sh)
_write_edge_headers()
Write single CSV file for a graph entity.
The graph entity is represented as an edge as per the definition
in the schema_config.yaml
, containing only the header for this type
of edge.
Returns
bool: The return value. True for success, False otherwise.
Source code in biocypher/output/write/graph/_arangodb.py
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 |
|
_write_node_headers()
Write single CSV file for a graph entity.
The graph entity is represented as a node as per the definition
in the schema_config.yaml
, containing only the header for this type
of node.
Returns
bool: The return value. True for success, False otherwise.
Source code in biocypher/output/write/graph/_arangodb.py
RDF Writer
Bases: _BatchWriter
Write BioCypher's property graph into an RDF format.
Uses rdflib
and all the extensions it supports (RDF/XML, N3, NTriples,
N-Quads, Turtle, TriX, Trig and JSON-LD). By default, the conversion
is done keeping only the minimum information about node and edges,
skipping all properties.
Source code in biocypher/output/write/graph/_rdf.py
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 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 |
|
_construct_import_call()
Write the import call.
This function is not applicable for RDF.
Returns
bool: The return value. True for success, False otherwise.
_get_default_import_call_bin_prefix()
Provide the default string for the import call bin prefix.
Returns
str: The default location for the RDF admin import location
_get_import_script_name()
Return the name of the RDF admin import script.
This function is used for RDF export.
Returns
str: The name of the import script (ending in .sh)
Source code in biocypher/output/write/graph/_rdf.py
_init_namespaces(graph)
Initialise the namespaces for the RDF graph.
This function adds the biocypher standard namespace to the namespaces
attribute of the class. If namespaces
is empty, it sets it to the
biocypher standard namespace. Otherwise, it merges the biocypher
standard namespace with the namespaces defined in the
biocypher_config.yaml.
graph (RDFLib.Graph): The RDF graph to bind the namespaces to.
None
Source code in biocypher/output/write/graph/_rdf.py
_is_rdf_format_supported(file_format)
Check if the specified RDF format is supported.
file_format (str): The RDF format to check.
bool: Returns True if rdf format supported, False otherwise.
Source code in biocypher/output/write/graph/_rdf.py
_quote_string(value)
_write_array_string(string_list)
Write the string representation of an array into a .csv file.
This function is not applicable for RDF.
string_list (list): list of ontology strings
str: The string representation of an array for the neo4j admin import
Source code in biocypher/output/write/graph/_rdf.py
_write_edge_headers()
Write a database import-file for a graph entity.
This function is not applicable for RDF.
Returns
bool: The return value. True for success, False otherwise.
Source code in biocypher/output/write/graph/_rdf.py
_write_node_headers()
Import properties of a graph entity.
This function is not applicable for RDF.
Returns
bool: The return value. True for success, False otherwise.
_write_single_edge_list_to_file(edge_list, label, prop_dict)
Write a list of BioCypherEdges to an RDF file.
edge_list (list): list of BioCypherEdges to be written
label (str): the label (type) of the edge
prop_dict (dict): properties of node class passed from parsing
function and their types
bool: The return value. True for success, False otherwise.
Source code in biocypher/output/write/graph/_rdf.py
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 |
|
_write_single_node_list_to_file(node_list, label, prop_dict, labels)
Write a list of BioCypherNodes to an RDF file.
node_list (list): A list of BioCypherNodes to be written.
label (str): The label (type) of the nodes.
prop_dict (dict): A dictionary of properties and their types for the node class.
labels (str): string of one or several concatenated labels
bool: True if the writing is successful, False otherwise.
Source code in biocypher/output/write/graph/_rdf.py
add_property_to_graph(graph, rdf_subject, rdf_object, rdf_predicate)
Add the properties to an RDF node.
It takes the graph, the subject, object, and predicate of the RDF triple. It checks if the property is a list and adds it to the graph accordingly. Otherwise it checks if the string represents a list. If it does, it transforms it to a list and adds it to the graph. If not, it adds the property to the graph as a literal. If the property is neither a list or string, it will also be added as a literal.
graph (RDFLib.Graph): The RDF graph to add the nodes to.
rdf_subject (str): The subject of the RDF triple.
rdf_object (str): The object of the RDF triple.
rdf_predicate (str): The predicate of the RDF triple.
None
Source code in biocypher/output/write/graph/_rdf.py
as_uri(name, namespace='')
Return an RDFlib object with the given namespace as a URI.
There is often a default for empty namespaces, which would have been
loaded with the ontology, and put in self.namespace
by
self._init_namespaces
.
name (str): The name to be transformed.
namespace (str): The namespace to be used.
str: The URI for the given name and namespace.
Source code in biocypher/output/write/graph/_rdf.py
property_to_uri(property_name)
Convert a property name to its corresponding URI.
This function takes a property name and searches for its corresponding URI in various namespaces. It first checks the core namespaces for rdflib, including owl, rdf, rdfs, xsd, and xml.
property_name (str): The property name to be converted to a URI.
str: The corresponding URI for the input property name.
Source code in biocypher/output/write/graph/_rdf.py
to_uri(subject)
Extract the namespace from the given subject.
Split the subject's string on ":". Then convert the subject to a proper URI, if the namespace is known. If namespace is unknown, defaults to the default prefix of the ontology.
subject (str): The subject to be converted to a URI.
str: The corresponding URI for the subject.
Source code in biocypher/output/write/graph/_rdf.py
transform_string_to_list(string_list)
Transform a string representation of a list into a list.
string_list (str): The string representation of the list.
list: The list representation of the input string.
Source code in biocypher/output/write/graph/_rdf.py
write_edges(edges, batch_size=int(1000000.0))
Write edges in RDF format.
edges (BioCypherEdge): a list or generator of edges in
:py:class:`BioCypherEdge` format
batch_size (int): The number of edges to write in each batch.
bool: The return value. True for success, False otherwise.
Source code in biocypher/output/write/graph/_rdf.py
write_nodes(nodes, batch_size=int(1000000.0), force=False)
Write nodes in RDF format.
nodes (list or generator): A list or generator of nodes in
BioCypherNode format.
batch_size (int): The number of nodes to write in each batch.
force (bool): Flag to force the writing even if the output file
already exists.
bool: True if the writing is successful, False otherwise.
Source code in biocypher/output/write/graph/_rdf.py
NetworkX Writer
Bases: _Writer
Class for writing the in-memory networkx DiGraph to file.
Call _construct_import_call
to write the networkx DiGraph to a pickle
file and return the Python call to load it.
TODO: this is a non-intuitive name, should be adjusted.
Source code in biocypher/output/write/graph/_networkx.py
_construct_import_call()
Dump networkx graph to a pickle file and return Python call.
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
Python code to load the networkx graph from a pickle file. |
Source code in biocypher/output/write/graph/_networkx.py
_get_import_script_name()
_write_edge_data(edges)
Add edges to the networkx graph.
TODO: this is not strictly writing, should be refactored.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
edges
|
list
|
List of edges to add to the networkx graph. |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if the edges were added successfully, False otherwise. |
Source code in biocypher/output/write/graph/_networkx.py
_write_node_data(nodes)
Add nodes to the networkx graph.
TODO: this is not strictly writing, should be refactored.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
nodes
|
list
|
List of nodes to add to the networkx graph. |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if the nodes were added successfully, False otherwise. |
Source code in biocypher/output/write/graph/_networkx.py
PostgreSQL Batch Writer
Bases: _BatchWriter
Write node and edge representations for PostgreSQL.
Class for writing node and edge representations to disk using the
format specified by PostgreSQL for the use of "COPY FROM...". Each batch
writer instance has a fixed representation that needs to be passed
at instantiation via the attr:
schema
argument. The instance
also expects an ontology adapter via attr:
ontology_adapter
to be able
to convert and extend the hierarchy.
This class inherits from the abstract class "_BatchWriter" and implements the PostgreSQL-specific methods:
- _write_node_headers
- _write_edge_headers
- _construct_import_call
- _write_array_string
Source code in biocypher/output/write/relational/_postgresql.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 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 |
|
_construct_import_call()
Function to construct the import call detailing folder and individual node and edge headers and data files, as well as delimiters and database name. Built after all data has been processed to ensure that nodes are called before any edges.
Returns
str: a bash command for postgresql import
Source code in biocypher/output/write/relational/_postgresql.py
_get_default_import_call_bin_prefix()
Provide the default string for the import call bin prefix.
Returns
str: The default location for the psql command
_get_import_script_name()
Return the name of the psql import script.
Returns
str: The name of the import script (ending in .sh)
_quote_string(value)
_write_array_string(string_list)
Write the string representation of an array into a .csv file.
Abstract method to output.write the string representation of an array into a .csv file as required by the postgresql COPY command, with '{','}' brackets and ',' separation.
string_list (list): list of ontology strings
str: The string representation of an array for postgres COPY
Source code in biocypher/output/write/relational/_postgresql.py
_write_edge_headers()
Writes single CSV file for a graph entity that is represented
as an edge as per the definition in the schema_config.yaml
,
containing only the header for this type of edge.
Returns
bool: The return value. True for success, False otherwise.
Source code in biocypher/output/write/relational/_postgresql.py
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 |
|
_write_node_headers()
Write node header files for PostgreSQL.
Writes single CSV file for a graph entity that is represented
as a node as per the definition in the schema_config.yaml
,
containing only the header for this type of node.
Returns
bool: The return value. True for success, False otherwise.
Source code in biocypher/output/write/relational/_postgresql.py
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 |
|
SQLite Batch Writer
Bases: _PostgreSQLBatchWriter
Class for writing node and edge representations to a SQLite database. It uses the _PostgreSQLBatchWriter class under the hood, which already implements the logic to write the nodes/edges to a relational DBMS. Only the import bash script differs between PostgreSQL and SQLite and is therefore implemented in this class.
- _construct_import_call
Source code in biocypher/output/write/relational/_sqlite.py
_construct_import_call()
Function to construct the import call detailing folder and individual node and edge headers and data files, as well as delimiters and database name. Built after all data has been processed to ensure that nodes are called before any edges.
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
a bash command for sqlite import |
Source code in biocypher/output/write/relational/_sqlite.py
Pandas CSV Writer
Bases: _Writer
Class for writing node and edge representations to CSV files.
Source code in biocypher/output/write/relational/_csv.py
_construct_import_call()
Function to construct the Python code to load all node and edge csv files again into Pandas dfs.
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
Python code to load the csv files into Pandas dfs. |
Source code in biocypher/output/write/relational/_csv.py
_get_import_script_name()
_write_entities_to_file(entities)
Function to write the entities to a CSV file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
entities
|
iterable
|
An iterable of BioCypherNode / BioCypherEdge / BioCypherRelAsNode objects. |
required |