API Reference¶
This API reference provides comprehensive documentation for all public classes and functions in the BAM Masterdata package. For more detailed examples and usage patterns, see the How-to Guides and Tutorial sections.
Warning
This documentation page is currently broken, as we shifted from MkDocs to Zensical for our documentation engine.
bam_masterdata.metadata.entities
¶
BaseEntity
¶
Bases: BaseModel
Base class used to define ObjectType and VocabularyType classes. It extends the BaseModel
adding new methods that are useful for interfacing with openBIS.
Source code in bam_masterdata/metadata/entities.py
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 | |
cls_name
property
¶
Returns the entity name of the class as a string to speed up checks. This is a property to be overwritten by each of the abstract entity types.
get_property_metadata()
¶
Dictionary containing the metadata of the properties assigned to the entity type.
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
A dictionary containing the keys of the |
dict
|
values of the definitions of |
|
dict
|
{ "name": PropertyTypeAssignment( code="$NAME", data_type=VARCHAR, mandatory=True, property_label="Name" ), "age": PropertyTypeAssignment( code="AGE", data_type=INTEGER, mandatory=False, property_label="Age" ), |
|
dict
|
} |
Source code in bam_masterdata/metadata/entities.py
model_to_dict()
¶
Returns the model as a dictionary storing the data defs and the property or vocabulary term
assignments.
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
The dictionary representation of the model. |
Source code in bam_masterdata/metadata/entities.py
model_to_json(indent=None)
¶
Returns the model as a string in JSON format storing the data defs and the property or
vocabulary term assignments.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
indent
|
Optional[int]
|
The indent to print in JSON. Defaults to None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The JSON representation of the model. |
Source code in bam_masterdata/metadata/entities.py
model_to_rdf(namespace, graph, logger)
¶
Convert the entity to RDF triples and add them to the graph. The function uses the
_add_properties_rdf method to convert the properties assigned to the entity to RDF triples.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
namespace
|
Namespace
|
The namespace to use for the RDF graph. |
required |
graph
|
Graph
|
The RDF graph to which the entity is added. |
required |
logger
|
BoundLoggerLazyProxy
|
The logger to log messages. |
required |
Source code in bam_masterdata/metadata/entities.py
to_dict()
¶
Returns the entity as a dictionary storing the value of the properties assigned to the entity.
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
The dictionary representation of the entity. |
Source code in bam_masterdata/metadata/entities.py
to_hdf5(hdf_file, group_name='')
¶
Serialize the entity to a HDF5 file under the group specified in the input.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hdf_file
|
File
|
The HDF5 file to store the entity. |
required |
group_name
|
str
|
The group name to serialize the data. |
''
|
Source code in bam_masterdata/metadata/entities.py
to_json(indent=None)
¶
Returns the entity as a string in JSON format storing the value of the properties assigned to the entity.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
indent
|
Optional[int]
|
The indent to print in JSON. Defaults to None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The JSON representation of the entity. |
Source code in bam_masterdata/metadata/entities.py
ObjectType
¶
Bases: BaseEntity
Base class used to define object types. All object types must inherit from this class. The
object types are defined in the module bam_masterdata/object_types.py.
The ObjectType class contains a list of all properties defined for a ObjectType, for
internally represent the model in other formats (e.g., JSON or Excel).
Note this is also used for CollectionType and DatasetType, as they also contain a list of
properties.
Source code in bam_masterdata/metadata/entities.py
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 | |
base_name
property
¶
Returns the entity name of the class as a string.
get_vocabulary_class(vocabulary_code, vocab_path)
¶
Get the class instance of the vocabulary type defined by vocabulary_code in the Python module
specified by vocab_path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vocabulary_code
|
str
|
Code of the vocabulary type to get. |
required |
vocab_path
|
str
|
Path to the module containing the vocabulary type definitions. |
required |
Returns:
| Type | Description |
|---|---|
VocabularyType | None
|
VocabularyType | None: The class of the vocabulary type if found, otherwise None. |
Source code in bam_masterdata/metadata/entities.py
model_validator_after_init(data)
classmethod
¶
Validate the model after instantiation of the class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Any
|
The data containing the fields values to validate. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
The data with the validated fields. |
Source code in bam_masterdata/metadata/entities.py
CollectionType
¶
Bases: ObjectType
Source code in bam_masterdata/metadata/entities.py
1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 | |
base_name
property
¶
Returns the entity name of the class as a string.
add(object_type)
¶
Add an object type to the collection type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
object_type
|
ObjectType
|
The object type to add to the collection type. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The unique identifier of the object type assigned in openBIS. |
Source code in bam_masterdata/metadata/entities.py
add_relationship(parent, child)
¶
Add a relationship between two object types in the collection type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parent
|
str | dict
|
Either the unique identifier of the parent object type or a dictionary representation of the parent object type. |
required |
child
|
str | dict
|
Either the unique identifier of the child object type or a dictionary representation of the child object type. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The unique identifier of the created relationship, generated from the resolved parent and child identifiers. |
Source code in bam_masterdata/metadata/entities.py
remove(object_id='')
¶
Remove an object type from the collection type by its unique identifier.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
object_id
|
str
|
The ID of the object type to be removed from the collection. |
''
|
Source code in bam_masterdata/metadata/entities.py
remove_relationship(relationship_id)
¶
Remove a relationship from the collection type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
relationship_id
|
str
|
The unique identifier of the relationship to remove. |
required |
Source code in bam_masterdata/metadata/entities.py
DatasetType
¶
Bases: ObjectType
Source code in bam_masterdata/metadata/entities.py
base_name
property
¶
Returns the entity name of the class as a string.
VocabularyType
¶
Bases: BaseEntity
Base class used to define vocabulary types. All vocabulary types must inherit from this class. The
vocabulary types are defined in the module bam_masterdata/vocabulary_types.py.
The VocabularyType class contains a list of all terms defined for a VocabularyType, for
internally represent the model in other formats (e.g., JSON or Excel).
Source code in bam_masterdata/metadata/entities.py
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 | |
base_name
property
¶
Returns the entity name of the class as a string.
model_validator_after_init(data)
classmethod
¶
Validate the model after instantiation of the class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Any
|
The data containing the fields values to validate. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
The data with the validated fields. |
Source code in bam_masterdata/metadata/entities.py
bam_masterdata.metadata.definitions
¶
EntityDef
¶
Bases: BaseModel
Abstract base class for all masterdata entity definitions. The entity definitions are immutable properties.
This class provides a common interface (with common attributes like code and
description.) for all entity definitions.
Source code in bam_masterdata/metadata/definitions.py
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 | |
excel_headers_map
property
¶
Maps the field keys of the Pydantic model into the openBIS Excel style headers.
excel_name
property
¶
Returns the name of the entity in a format suitable for the openBIS Excel file.
model_id(data)
classmethod
¶
Populate id based on the entity code and entity type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Any
|
The data containing the fields values to validate. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
The data with the validated fields. |
Source code in bam_masterdata/metadata/definitions.py
strip_description(value)
classmethod
¶
Strip leading and trailing whitespace from descriptions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
str
|
Description string. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The trimmed description. |
Source code in bam_masterdata/metadata/definitions.py
validate_code(value)
classmethod
¶
Validate entity codes against the allowed openBIS format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
str
|
Candidate code string. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The validated code. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the code is empty or contains invalid characters. |
Source code in bam_masterdata/metadata/definitions.py
validate_iri(value)
classmethod
¶
Validate the optional ontology IRI against the expected BAM pattern.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
str | None
|
Candidate IRI string, or None. |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
The validated IRI (or None). |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the IRI does not match the required pattern. |
Source code in bam_masterdata/metadata/definitions.py
ObjectTypeDef
¶
Bases: BaseObjectTypeDef
Definition class for an object type. It adds the fields of generated_code_prefix, auto_generate_codes,
and validation_script to the common attributes of a base object type definition. E.g.:
class Instrument(BaseModel):
defs = ObjectTypeDef(
code='INSTRUMENT',
description='
Measuring Instrument//Messgerät
',
generated_code_prefix='INS',
)
Source code in bam_masterdata/metadata/definitions.py
model_validator_after_init(data)
classmethod
¶
Ensure generated_code_prefix is set after initialization.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Any
|
The data containing the fields values to validate. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
The data with the validated fields. |
Source code in bam_masterdata/metadata/definitions.py
CollectionTypeDef
¶
Bases: BaseObjectTypeDef
Definition class for a collection type. E.g.:
class DefaultExperiment(BaseModel):
defs = CollectionTypeDef(
code='DEFAULT_EXPERIMENT',
description='...',
validation_script='DEFAULT_EXPERIMENT.date_range_validation',
)
Source code in bam_masterdata/metadata/definitions.py
DatasetTypeDef
¶
Bases: BaseObjectTypeDef
Definition class for a data set type. E.g.:
```python class RawData(BaseModel): defs = DatasetTypeDef( code='RAW_DATA', description='...', )
Source code in bam_masterdata/metadata/definitions.py
VocabularyTypeDef
¶
Bases: EntityDef
Definition class for a vocabulary type. It adds the fields of url_template to the common attributes of
an entity definition. E.g.:
class DocumentType(VocabularyType):
defs = VocabularyTypeDef(
code='DOCUMENT_TYPE',
description='Document type//Dokumententypen',
)
Source code in bam_masterdata/metadata/definitions.py
PropertyTypeDef
¶
Bases: EntityDef
Definition class for a property type. It adds the fields of property_label, data_type,
vocabulary_code, metadata, dynamic_script, and multivalued to the common attributes of
an entity definition.
This class is used as an abstract layer for PropertyTypeAssignment, as in openBIS a PropertyType
definition has less fields than when it is actually assigned to an entity type.
Source code in bam_masterdata/metadata/definitions.py
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 | |
apply_units_to_property_label(data)
classmethod
¶
Enforce the in [units] suffix in property_label when units are provided.
If the label already contains a bracketed unit, it must include the
exact in [units] format or validation fails. Otherwise, the suffix
is appended.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Any
|
The data containing the fields values to validate. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
The data with the updated label (if needed). |
Raises:
| Type | Description |
|---|---|
ValueError
|
If a bracketed unit exists without the |
Source code in bam_masterdata/metadata/definitions.py
validate_units(value)
classmethod
¶
Validate the optional units string using pint's unit registry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
str | None
|
Units string in pint format, or None. |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
The validated units string (or None). |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the units string is not recognized by pint. |
Source code in bam_masterdata/metadata/definitions.py
PropertyTypeAssignment
¶
Bases: PropertyTypeDef
Base class used to define properties inside ObjectType, CollectionType, or DatasetType.
This is used to construct these types by assigning property types to them. It adds the fields
of mandatory, show_in_edit_views, section, unique, and internal_assignment to the common
attributes of a property type definition. E.g.:
class Instrument(ObjectType):
defs = ObjectTypeDef(
code='INSTRUMENT',
description='
Measuring Instrument//Messgerät
',
generated_code_prefix='INS',
)
alias = PropertyTypeAssignment(
code='ALIAS',
data_type='VARCHAR',
property_label='Alternative name',
description='
e.g. abbreviation or nickname//z.B. Abkürzung oder Spitzname//z.B. Abkürzung oder Spitzname
',
mandatory=False,
show_in_edit_views=True,
section='General information',
)
# ... other property type assignments here ...
Source code in bam_masterdata/metadata/definitions.py
VocabularyTerm
¶
Bases: VocabularyTypeDef
Base class used to define terms inside a VocabularyType. This is used to construct the vocabulary types
by assigning vocabulary terms to them. It adds the fields of label and official to the common attributes
of a vocabulary type definition. E.g.:
```python class DocumentType(VocabularyType): defs = VocabularyTypeDef( code='DOCUMENT_TYPE', description='Document type//Dokumententypen', )
acceptance_certificate = VocabularyTerm(
code='ACCEPTANCE_CERTIFICATE',
label='Acceptance Certificate',
description='Acceptance Certificate//Abnahmezeugnis',
)
calibration_certificate = VocabularyTerm(
code='CALIBRATION_CERTIFICATE',
label='Calibration Certificate',
description='Calibration Certificate//Kalibrierschein',
)
# ... other vocabulary term definitions here ...
Source code in bam_masterdata/metadata/definitions.py
bam_masterdata.metadata.entities_dict
¶
EntitiesDict
¶
Class to convert the entities in the datamodel defined in Python to a dictionary. The entities are read from the Python
files defined in python_path.
Source code in bam_masterdata/metadata/entities_dict.py
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 | |
single_json()
¶
Returns a single dictionary containing all the entities in the datamodel defined in the Python files
in python_path. The format of this dictionary is:
{
"collection_type": {
"COLLECTION": {
"defs": {
"code": "COLLECTION",
"description": "",
...
},
"properties": [
{
"code": "$DEFAULT_COLLECTION_VIEW",
"description": "Default view for experiments of the type collection",
...
},
{...},
...
]
}
},
"object_type": {...},
...
}
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
A dictionary containing all the entities in the datamodel. |
Source code in bam_masterdata/metadata/entities_dict.py
to_dict(module_path)
¶
Returns a dictionary containing entities read from the module_path Python file. The Python modules
are imported using the function import_module and their contents are inspected (using inspect) to
find the classes in the datamodel containing defs and with a model_to_dict method defined.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
module_path
|
str
|
Path to the Python module file. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
A dictionary containing the entities in the datamodel defined in one Python module file. |
Source code in bam_masterdata/metadata/entities_dict.py
bam_masterdata.cli.fill_masterdata
¶
MasterdataCodeGenerator
¶
Class to generate Python code for the masterdata datamodel based on the entities existing in an openBIS instance.
Source code in bam_masterdata/cli/fill_masterdata.py
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 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 | |
add_properties(entities, parent_code, data, lines)
¶
Add the properties of the entity to the lines list. The properties are added as
PropertyTypeAssignment objects.
Note: the assigned properties do not have the information of code for the entity when
data_type is OBJECT or CONTROLLEDVOCABULARY. These are instead defined in property_types.py.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entities
|
dict
|
The dictionary of entities (objects, collections, datasets, vocabularies). |
required |
parent_code
|
code
|
The code of the parent class. |
required |
data
|
dict
|
The data information for the entity as obtained from openBIS. |
required |
lines
|
list
|
A list of strings to be printed to the Python module. |
required |
Source code in bam_masterdata/cli/fill_masterdata.py
determine_parent_class(code, class_names, default, lines)
¶
Determine the parent class information of the entity based on its code. It returns
the parent_code and parent class, as well as the class_name of the entity. The
class will inherit from parent_class.
If the parent class does not exist, a note is added to the lines list for debugging purposes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
code
|
str
|
The code of the entity. |
required |
class_names
|
dict
|
A dictionary with the class names of the entities. |
required |
default
|
str
|
The default parent class if the parent class does not exist. |
required |
lines
|
list
|
A list of strings to be printed to the Python module. |
required |
Returns: tuple: The parent code, parent class, and class name of the entity.
Source code in bam_masterdata/cli/fill_masterdata.py
generate_collection_types()
¶
Generate Python code for the collection types in the Openbis datamodel. The code is generated
as a string which is then printed out to the specific Python module in bam_masterdata/datamodel/collection_types.py.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Python code for the collection types. |
Source code in bam_masterdata/cli/fill_masterdata.py
generate_dataset_types()
¶
Generate Python code for the dataset types in the Openbis datamodel. The code is generated
as a string which is then printed out to the specific Python module in bam_masterdata/datamodel/dataset_types.py.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Python code for the dataset types. |
Source code in bam_masterdata/cli/fill_masterdata.py
generate_object_types()
¶
Generate Python code for the object types in the Openbis datamodel. The code is generated
as a string which is then printed out to the specific Python module in bam_masterdata/datamodel/object_types.py.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Python code for the object types. |
Source code in bam_masterdata/cli/fill_masterdata.py
generate_vocabulary_types()
¶
Generate Python code for the vocabulary types in the Openbis datamodel. The code is generated
as a string which is then printed out to the specific Python module in bam_masterdata/datamodel/vocabulary_types.py.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Python code for the vocabulary types. |
Source code in bam_masterdata/cli/fill_masterdata.py
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 | |
get_property_object_code(prop_data)
¶
Get the object code (or vocabulary code) used for reference for the assigned property with prop_code.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prop_data
|
dict
|
The data information for the property as obtained from openBIS. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The object/vocabulary code used for reference for the assigned property. |
Source code in bam_masterdata/cli/fill_masterdata.py
bam_masterdata.excel.excel_to_entities
¶
MasterdataExcelExtractor
¶
Source code in bam_masterdata/excel/excel_to_entities.py
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 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 | |
__init__(excel_path, **kwargs)
¶
Initialize the MasterdataExtractor.
Source code in bam_masterdata/excel/excel_to_entities.py
block_to_entity_dict(sheet, start_index_row, last_non_empty_row, complete_dict)
¶
Extracts entity attributes from an Excel sheet block and returns them as a dictionary.
Source code in bam_masterdata/excel/excel_to_entities.py
excel_to_entities()
¶
Extracts entities from an Excel file and returns them as a dictionary.
Returns:
| Type | Description |
|---|---|
dict[str, dict[str, Any]]
|
dict[str, dict[str, Any]]: A dictionary where each key is a normalized sheet name and the value is a dictionary |
dict[str, dict[str, Any]]
|
containing the extracted entities. Returns an empty dictionary if all sheets are empty. |
Source code in bam_masterdata/excel/excel_to_entities.py
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 | |
extract_value(sheet, row, column, validation_pattern=None, is_description=False, is_data=False, is_url=False)
¶
Extracts and validates a value from a specified cell in the Excel sheet.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sheet
|
Worksheet
|
The worksheet object. |
required |
row
|
int
|
The row number of the cell (1-based index). |
required |
column
|
int
|
The column number of the cell (1-based index). |
required |
validation_pattern
|
str
|
Optional regex pattern to validate the cell value. |
None
|
is_description
|
bool
|
Flag indicating if the value is a description. |
False
|
is_data
|
bool
|
Flag indicating if the value is a data type. |
False
|
is_url
|
bool
|
Flag indicating if the value is a URL. |
False
|
Returns:
| Type | Description |
|---|---|
str
|
The extracted and validated cell value as a string. Returns an empty string if the value is invalid or not provided. |
Source code in bam_masterdata/excel/excel_to_entities.py
get_and_check_property(value, term, coordinate, sheet_title, is_description=False, is_code=False, is_data=False, is_url=False)
¶
Gets a property and checks its format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
str | bool | None
|
The string to convert. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The property. |
Source code in bam_masterdata/excel/excel_to_entities.py
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 | |
get_last_non_empty_row(sheet, start_index)
¶
Finds the last non-empty row before encountering a completely empty row.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sheet
|
Worksheet
|
The worksheet object. |
required |
start_index
|
int
|
The row number to start checking from (1-based index). |
required |
Returns:
| Type | Description |
|---|---|
int | None
|
The row number of the last non-empty row before an empty row is encountered, |
int | None
|
or None if no non-empty rows are found starting from the given index. |
Source code in bam_masterdata/excel/excel_to_entities.py
index_to_excel_column(index)
¶
Converts a 1-based index to an Excel column name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index
|
int
|
The 1-based index to convert. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The corresponding Excel column name. |
Source code in bam_masterdata/excel/excel_to_entities.py
process_entity(sheet, start_index_row, header_terms, expected_terms, entity_type)
¶
Process an entity type block in the Excel sheet and return its attributes as a dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sheet
|
Worksheet
|
The worksheet object. |
required |
start_index_row
|
int
|
The row where the current entity type begins (1-based index). |
required |
header_terms
|
list[str]
|
List of header terms in the entity block. |
required |
expected_terms
|
list[str]
|
List of expected terms to extract from the entity block. |
required |
entity_type
|
str
|
The type of the entity (e.g., SAMPLE_TYPE, OBJECT_TYPE). |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
A dictionary containing the attributes of the entity. |
Source code in bam_masterdata/excel/excel_to_entities.py
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 | |
process_term(term, cell_value, coordinate, sheet_title)
¶
Processes a term by converting it to a boolean if necessary or checking its validity.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
term
|
str
|
The term being processed. |
required |
cell_value
|
Any
|
The value of the cell. |
required |
coordinate
|
str
|
The coordinate of the cell in the sheet. |
required |
sheet_title
|
str
|
The title of the sheet. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
The processed value, either as a boolean or the original value after validation. |
Source code in bam_masterdata/excel/excel_to_entities.py
properties_to_dict(sheet, start_index_row, last_non_empty_row)
¶
Extracts properties from an Entity type block in the Excel sheet and returns them as a dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sheet
|
Worksheet
|
The worksheet object. |
required |
start_index_row
|
int
|
Row where the current entity type begins (1-based index). |
required |
last_non_empty_row
|
int
|
Row where the current entity type finish (1-based index). |
required |
Returns:
| Type | Description |
|---|---|
dict[str, dict[str, Any]]
|
A dictionary where each key is a property code and the value is a dictionary |
dict[str, dict[str, Any]]
|
containing the attributes of the property. |
Source code in bam_masterdata/excel/excel_to_entities.py
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 | |
str_to_bool(value, term, coordinate, sheet_title)
¶
Converts a string to a boolean value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
str | bool | None
|
The string to convert. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
The boolean value. |
Source code in bam_masterdata/excel/excel_to_entities.py
terms_to_dict(sheet, start_index_row, last_non_empty_row)
¶
Extracts terms from a Vocabulary block in the Excel sheet and returns them as a dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sheet
|
Worksheet
|
The worksheet object. |
required |
start_index_row
|
int
|
Row where the current entity type begins (1-based index). |
required |
last_non_empty_row
|
int
|
Row where the current entity type finish (1-based index). |
required |
Returns:
| Type | Description |
|---|---|
dict[str, dict[str, Any]]
|
A dictionary where each key is a vocabulary term code and the value is a dictionary |
dict[str, dict[str, Any]]
|
containing the attributes of the vocabulary term. |
Source code in bam_masterdata/excel/excel_to_entities.py
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 | |
bam_masterdata.cli.entities_to_excel
¶
entities_to_excel(worksheet, module_path, definitions_module)
¶
Export entities to the Excel file. The Python modules are imported using the function import_module,
and their contents are inspected (using inspect) to find the classes in the datamodel containing
defs and with a model_to_json method defined. Each row is then appended to the worksheet.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
worksheet
|
Worksheet
|
The worksheet to append the entities. |
required |
module_path
|
str
|
Path to the Python module file. |
required |
definitions_module
|
Any
|
The module containing the definitions of the entities. This is used to match the header definitions of the entities. |
required |
Source code in bam_masterdata/cli/entities_to_excel.py
bam_masterdata.cli.entities_to_rdf
¶
entities_to_rdf(graph, module_path, logger)
¶
Convert the entities defined in the specified module to RDF triples and add them to the graph. The function
uses the model_to_rdf method defined in each class to convert the class attributes to RDF triples. The
function also adds the PropertyType and other entity types as placeholders in the graph.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
Graph
|
The RDF graph to which the entities are added. |
required |
module_path
|
str
|
The path to the module containing the entities to be converted. |
required |
logger
|
BoundLoggerLazyProxy
|
The logger to log messages. |
required |
Source code in bam_masterdata/cli/entities_to_rdf.py
rdf_graph_init(g)
¶
Initialize the RDF graph with base namespaces, annotation properties, and internal BAM properties. This
function also creates placeholders for PropertyType and other entity types. The graph is to be printed out
in RDF/XML format in the entities_to_rdf function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
g
|
Graph
|
The RDF graph to be initialized. |
required |
Source code in bam_masterdata/cli/entities_to_rdf.py
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 | |
bam_masterdata.cli.run_parser
¶
make_unique_code(code, seen_codes)
¶
Generate a unique code by appending a duplicate counter if the code has already been seen.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
code
|
str
|
The original code to make unique. |
required |
seen_codes
|
dict
|
A dictionary tracking codes and their occurrence counts. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The unique code, either the original code or the code with a duplicate suffix. |
Source code in bam_masterdata/cli/run_parser.py
run_parser(openbis=None, space_name='', project_name='PROJECT', collection_name='', files_parser={}, collection_type='COLLECTION')
¶
Run the parsers on the specified files and save objects immediately without using transactions.
This function parses files and creates/updates objects in openBIS individually, saving each object immediately after creation. This approach is simpler to debug but less efficient than transactions. After all objects are created, parent-child relationships are established.
Unlike run_parser_with_transactions(), this functions main difference is that it saves each object to openBIS immediately after creation, so objects-uploads are not dependent on others being successfully created.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
openbis
|
Openbis
|
An instance of the Openbis class from pyBIS, already logged in. |
None
|
space_name
|
str
|
The space in openBIS where the entities will be stored. |
''
|
project_name
|
str
|
The project in openBIS where the entities will be stored. |
'PROJECT'
|
collection_name
|
str
|
The collection in openBIS where the entities will be stored. |
''
|
files_parser
|
dict
|
A dictionary where keys are parser instances and values are lists of file paths to be parsed. E.g., {MasterdataParserExample(): ["path/to/file.json", "path/to/another_file.json"]} |
{}
|
collection_type
|
str
|
The type of collection to create in openBIS. Options are "COLLECTION" or "DEFAULT_EXPERIMENT". Defaults to "COLLECTION". |
'COLLECTION'
|
Source code in bam_masterdata/cli/run_parser.py
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 | |
run_parser_with_transactions(openbis=None, space_name='', project_name='PROJECT', collection_name='', files_parser={}, collection_type='COLLECTION')
¶
Run the parsers on the specified files and save objects using openBIS transactions.
This function parses files and creates/updates objects in openBIS using transactions for atomicity. Operations are batched and committed together, ensuring consistency. If any operation fails, all changes within that transaction are rolled back.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
openbis
|
Openbis
|
An instance of the Openbis class from pyBIS, already logged in. |
None
|
space_name
|
str
|
The space in openBIS where the entities will be stored. |
''
|
project_name
|
str
|
The project in openBIS where the entities will be stored. |
'PROJECT'
|
collection_name
|
str
|
The collection in openBIS where the entities will be stored. |
''
|
files_parser
|
dict
|
A dictionary where keys are parser instances and values are lists of file paths to be parsed. E.g., {MasterdataParserExample(): ["path/to/file.json", "path/to/another_file.json"]} |
{}
|
collection_type
|
str
|
The type of collection to create in openBIS. Options are "COLLECTION" or "DEFAULT_EXPERIMENT". Defaults to "COLLECTION". |
'COLLECTION'
|
Source code in bam_masterdata/cli/run_parser.py
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 | |
bam_masterdata.excel.excel_to_entities
¶
MasterdataExcelExtractor
¶
Source code in bam_masterdata/excel/excel_to_entities.py
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 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 | |
__init__(excel_path, **kwargs)
¶
Initialize the MasterdataExtractor.
Source code in bam_masterdata/excel/excel_to_entities.py
block_to_entity_dict(sheet, start_index_row, last_non_empty_row, complete_dict)
¶
Extracts entity attributes from an Excel sheet block and returns them as a dictionary.
Source code in bam_masterdata/excel/excel_to_entities.py
excel_to_entities()
¶
Extracts entities from an Excel file and returns them as a dictionary.
Returns:
| Type | Description |
|---|---|
dict[str, dict[str, Any]]
|
dict[str, dict[str, Any]]: A dictionary where each key is a normalized sheet name and the value is a dictionary |
dict[str, dict[str, Any]]
|
containing the extracted entities. Returns an empty dictionary if all sheets are empty. |
Source code in bam_masterdata/excel/excel_to_entities.py
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 | |
extract_value(sheet, row, column, validation_pattern=None, is_description=False, is_data=False, is_url=False)
¶
Extracts and validates a value from a specified cell in the Excel sheet.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sheet
|
Worksheet
|
The worksheet object. |
required |
row
|
int
|
The row number of the cell (1-based index). |
required |
column
|
int
|
The column number of the cell (1-based index). |
required |
validation_pattern
|
str
|
Optional regex pattern to validate the cell value. |
None
|
is_description
|
bool
|
Flag indicating if the value is a description. |
False
|
is_data
|
bool
|
Flag indicating if the value is a data type. |
False
|
is_url
|
bool
|
Flag indicating if the value is a URL. |
False
|
Returns:
| Type | Description |
|---|---|
str
|
The extracted and validated cell value as a string. Returns an empty string if the value is invalid or not provided. |
Source code in bam_masterdata/excel/excel_to_entities.py
get_and_check_property(value, term, coordinate, sheet_title, is_description=False, is_code=False, is_data=False, is_url=False)
¶
Gets a property and checks its format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
str | bool | None
|
The string to convert. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The property. |
Source code in bam_masterdata/excel/excel_to_entities.py
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 | |
get_last_non_empty_row(sheet, start_index)
¶
Finds the last non-empty row before encountering a completely empty row.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sheet
|
Worksheet
|
The worksheet object. |
required |
start_index
|
int
|
The row number to start checking from (1-based index). |
required |
Returns:
| Type | Description |
|---|---|
int | None
|
The row number of the last non-empty row before an empty row is encountered, |
int | None
|
or None if no non-empty rows are found starting from the given index. |
Source code in bam_masterdata/excel/excel_to_entities.py
index_to_excel_column(index)
¶
Converts a 1-based index to an Excel column name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index
|
int
|
The 1-based index to convert. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The corresponding Excel column name. |
Source code in bam_masterdata/excel/excel_to_entities.py
process_entity(sheet, start_index_row, header_terms, expected_terms, entity_type)
¶
Process an entity type block in the Excel sheet and return its attributes as a dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sheet
|
Worksheet
|
The worksheet object. |
required |
start_index_row
|
int
|
The row where the current entity type begins (1-based index). |
required |
header_terms
|
list[str]
|
List of header terms in the entity block. |
required |
expected_terms
|
list[str]
|
List of expected terms to extract from the entity block. |
required |
entity_type
|
str
|
The type of the entity (e.g., SAMPLE_TYPE, OBJECT_TYPE). |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
A dictionary containing the attributes of the entity. |
Source code in bam_masterdata/excel/excel_to_entities.py
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 | |
process_term(term, cell_value, coordinate, sheet_title)
¶
Processes a term by converting it to a boolean if necessary or checking its validity.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
term
|
str
|
The term being processed. |
required |
cell_value
|
Any
|
The value of the cell. |
required |
coordinate
|
str
|
The coordinate of the cell in the sheet. |
required |
sheet_title
|
str
|
The title of the sheet. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
The processed value, either as a boolean or the original value after validation. |
Source code in bam_masterdata/excel/excel_to_entities.py
properties_to_dict(sheet, start_index_row, last_non_empty_row)
¶
Extracts properties from an Entity type block in the Excel sheet and returns them as a dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sheet
|
Worksheet
|
The worksheet object. |
required |
start_index_row
|
int
|
Row where the current entity type begins (1-based index). |
required |
last_non_empty_row
|
int
|
Row where the current entity type finish (1-based index). |
required |
Returns:
| Type | Description |
|---|---|
dict[str, dict[str, Any]]
|
A dictionary where each key is a property code and the value is a dictionary |
dict[str, dict[str, Any]]
|
containing the attributes of the property. |
Source code in bam_masterdata/excel/excel_to_entities.py
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 | |
str_to_bool(value, term, coordinate, sheet_title)
¶
Converts a string to a boolean value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
str | bool | None
|
The string to convert. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
The boolean value. |
Source code in bam_masterdata/excel/excel_to_entities.py
terms_to_dict(sheet, start_index_row, last_non_empty_row)
¶
Extracts terms from a Vocabulary block in the Excel sheet and returns them as a dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sheet
|
Worksheet
|
The worksheet object. |
required |
start_index_row
|
int
|
Row where the current entity type begins (1-based index). |
required |
last_non_empty_row
|
int
|
Row where the current entity type finish (1-based index). |
required |
Returns:
| Type | Description |
|---|---|
dict[str, dict[str, Any]]
|
A dictionary where each key is a vocabulary term code and the value is a dictionary |
dict[str, dict[str, Any]]
|
containing the attributes of the vocabulary term. |
Source code in bam_masterdata/excel/excel_to_entities.py
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 | |
bam_masterdata.openbis.login
¶
ologin(url='')
¶
Connect to openBIS using the credentials stored in the environment variables.
If an existing Openbis session is provided, the session is returned.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
(str, Openbis)
|
The URL of the openBIS instance. Defaults to the value of the |
''
|
Returns:
| Name | Type | Description |
|---|---|---|
Openbis |
Openbis
|
Openbis object for the specific openBIS instance defined in |
Source code in bam_masterdata/openbis/login.py
bam_masterdata.openbis.get_entities
¶
OpenbisEntities
¶
Class to get openBIS entities and their attributes as dictionaries to be printed in the
Python modules of bam_masterdata/datamodel/.
Source code in bam_masterdata/openbis/get_entities.py
4 5 6 7 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 | |
get_collection_dict()
¶
Get the collection types from openBIS and return them as a dictionary where the keys
are the collection type code and the value is a dictionary of attributes assigned to that
collection type.
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
Dictionary of collection types with their attributes. |
Source code in bam_masterdata/openbis/get_entities.py
get_dataset_dict()
¶
Get the dataset types from openBIS and return them as a dictionary where the keys
are the dataset type code and the value is a dictionary of attributes assigned to that
dataset type.
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
Dictionary of dataset types with their attributes. |
Source code in bam_masterdata/openbis/get_entities.py
get_object_dict()
¶
Get the object types from openBIS and return them as a dictionary where the keys
are the object type code and the value is a dictionary of attributes assigned to that
object type.
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
Dictionary of object types with their attributes. |
Source code in bam_masterdata/openbis/get_entities.py
get_property_dict()
¶
Get the property types from openBIS and return them as a dictionary where the keys
are the property type code and the value is a dictionary of attributes assigned to that
property type.
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
Dictionary of property types with their attributes. |
Source code in bam_masterdata/openbis/get_entities.py
get_vocabulary_dict()
¶
Get the vocabulary types from openBIS and return them as a dictionary where the keys
are the vocabulary type code and the value is a dictionary of attributes assigned to that
vocabulary type.
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
Dictionary of vocabulary types with their attributes. |
Source code in bam_masterdata/openbis/get_entities.py
bam_masterdata.checker.checker
¶
MasterdataChecker
¶
Source code in bam_masterdata/checker/checker.py
__init__()
¶
Initialize the comparator with validation rules and set the datamodel directory.
check(mode='all')
¶
Run validations.
Modes: - "self" -> Validate only the current data model. - "incoming" -> Validate only the new entity structure. - "validate" -> Validate both the current model and new entities. - "compare" -> Compare new entities against the current model. - "all" -> Run both validation types. - "individual" -> Run individual repositories validations.
Before running, ensure that required models are loaded based on the mode.
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
Validation results. |
Source code in bam_masterdata/checker/checker.py
load_current_model(datamodel_dir='./bam_masterdata/datamodel/')
¶
Load and transform the current data model (Pydantic classes) into JSON.
Uses the default datamodel directory unless overridden.
Source code in bam_masterdata/checker/checker.py
load_new_entities(source)
¶
Load new entities from various sources (Python classes, Excel, etc.).
Source code in bam_masterdata/checker/checker.py
bam_masterdata.checker.masterdata_validator
¶
MasterdataValidator
¶
Source code in bam_masterdata/checker/masterdata_validator.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 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 | |
__init__(new_entities, current_model, validation_rules)
¶
Initialize the validator with new and current entity data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
new_entities
|
dict
|
The incoming datamodel. |
required |
current_model
|
dict
|
The existing datamodel. |
required |
validation_rules
|
dict
|
The validation rules to apply. |
required |
Source code in bam_masterdata/checker/masterdata_validator.py
validate(mode='all')
¶
Run validations based on mode: - "self": Validate current model structure and format. - "incoming": Validate new entities structure and format. - "validate": Validate both current and incoming models but do not compare. - "compare": Validate new entities against the current model. - "all": Run both. - "individual": Validate new entities and compare them with the current model.
Returns: dict: Validation results.
Source code in bam_masterdata/checker/masterdata_validator.py
bam_masterdata.checker.source_loader
¶
SourceLoader
¶
Load the entities from a source written in different formats (Python classes, Excel, etc.) as defined
in the source_path into a dictionary.
Source code in bam_masterdata/checker/source_loader.py
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 | |
entities_to_json()
¶
Transforms the dictionary of entities returned by the Excel extractor into a dictionary in JSON format for later check.
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
A dictionary containing the transformed entities. |
Source code in bam_masterdata/checker/source_loader.py
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 | |
load()
¶
Load entities from the source path into a dictionary.
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
A dictionary containing the entities. |
Source code in bam_masterdata/checker/source_loader.py
bam_masterdata.parsing.parsing
¶
AbstractParser
¶
Bases: ABC
Example Abstract base class for parsers. Each parser should inherit from this class and implement
the parse() method to populate collection.
Source code in bam_masterdata/parsing/parsing.py
parse(files, collection, logger)
abstractmethod
¶
Parse the input files and populate the provided collection with object types, their metadata,
and their relationships.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
files
|
list[str]
|
List of file paths to be parsed. |
required |
collection
|
CollectionType
|
Collection to be populated with parsed data. |
required |
logger
|
BoundLoggerLazyProxy
|
Logger for logging messages during parsing. |
required |
Source code in bam_masterdata/parsing/parsing.py
bam_masterdata.utils.utils
¶
code_to_class_name(code, logger=logger, entity_type='object')
¶
Converts an openBIS code to a class name by capitalizing each word and removing special characters. In
the special case the entity is a property type, it retains the full name separated by points instead of
only keeping the last name (e.g., "TEM.INSTRUMENT" -> "TemInstrument" instead of "Instrument").
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
code
|
str
|
The openBIS code to convert to a class name. |
required |
logger
|
BoundLoggerLazyProxy
|
The logger to log messages. Default is |
logger
|
entity_type
|
str
|
The type of entity to convert. Default is "object". |
'object'
|
Returns: str: The class name derived from the openBIS code.
Source code in bam_masterdata/utils/utils.py
delete_and_create_dir(directory_path, logger=logger, force_delete=False)
¶
Deletes the directory at directory_path and creates a new one in the same path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
directory_path
|
str
|
The directory path to delete and create the folder. |
required |
logger
|
BoundLoggerLazyProxy
|
The logger to log messages. Default is |
logger
|
force_delete
|
bool
|
If True, the directory will be forcibly deleted if it exists. |
False
|
Source code in bam_masterdata/utils/utils.py
duplicated_property_types(module_path, logger)
¶
Find the duplicated property types in a module specified by module_path and returns a dictionary
containing the duplicated property types class names as keys and the lines where they matched as values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
module_path
|
str
|
The path to the module containing the property types. |
required |
logger
|
BoundLoggerLazyProxy
|
The logger to log messages. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
A dictionary containing the duplicated property types class names as keys and the |
dict
|
lines where they matched as values. |
Source code in bam_masterdata/utils/utils.py
format_json_id(value)
¶
Converts snake_case or UPPER_CASE to PascalCase while keeping special cases like '$NAME' untouched.
Source code in bam_masterdata/utils/utils.py
import_module(module_path)
¶
Dynamically imports a module from the given file path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
module_path
|
str
|
Path to the Python module file. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
module |
Any
|
Imported module object. |
Source code in bam_masterdata/utils/utils.py
is_reduced_version(generated_code_value, code)
¶
Check if generated_code_value is a reduced version of code.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
generated_code_value
|
str
|
The potentially reduced code. |
required |
code
|
str
|
The original full code. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if generated_code_value is a reduced version of code, False otherwise. |
Source code in bam_masterdata/utils/utils.py
listdir_py_modules(directory_path, logger=logger)
¶
Recursively goes through the directory_path and returns a list of all .py files that do not start with '_'. If
directory_path is a single Python module file, it will return a list with that file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
directory_path
|
str
|
The directory path to search through. |
required |
logger
|
BoundLoggerLazyProxy
|
The logger to log messages. Default is |
logger
|
Returns:
| Type | Description |
|---|---|
list[str]
|
list[str]: A list of all .py files that do not start with '_' |
Source code in bam_masterdata/utils/utils.py
store_log_message(logger, entity_ref, message, level='error')
¶
Logs a message and stores it inside the entity's _log_msgs list.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entity_ref
|
dict
|
The entity dictionary where _log_msgs should be stored. |
required |
message
|
str
|
The log message. |
required |
level
|
str
|
Log level ('error', 'warning', 'critical', 'info'). |
'error'
|
Source code in bam_masterdata/utils/utils.py
bam_masterdata.utils.paths
¶
find_dir(possible_locations)
¶
Search for a valid directory in a list of possible locations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
possible_locations
|
list[Path]
|
A list of possible locations to search for a directory. |
required |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If no valid directory is found. |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The path of the valid directory. |
Source code in bam_masterdata/utils/paths.py
bam_masterdata.utils.users
¶
UserID
¶
Source code in bam_masterdata/utils/users.py
get_userid_from_fullname(name)
¶
Return the userId matching the given fullname (case-insensitive). It uses the _split_name function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Full name, e.g., "John Doe" or "Doe, John". |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
str | None: The userId if a match is found, otherwise None. |
Source code in bam_masterdata/utils/users.py
get_userid_from_names(firstname, lastname)
¶
Return the userId matching the given first and last name (case-insensitive).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
firstname
|
str
|
First name. |
required |
lastname
|
str
|
Last name. |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
str | None: The userId if a match is found, otherwise None. |
Source code in bam_masterdata/utils/users.py
get_bam_username(firstname, lastname)
¶
Tries to get the BAM username from the first and last names. The BAM username guess is defined by concatenating the first letter of the first name with the, max. 7 digits of the last name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
firstname
|
str
|
The first name. |
required |
lastname
|
str
|
The last name. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The guessed BAM username. |