Pydantic Models¶
VirtualDB Configuration Models¶
tfbpapi.models.MetadataConfig
¶
Bases: BaseModel
Configuration for building standardized metadata tables.
Specifies optional alias mappings for normalizing factor levels across heterogeneous datasets, plus property path mappings for each repository.
Attributes: factor_aliases: Optional mappings of standardized names to actual values. Example: {“carbon_source”: {“glucose”: [“D-glucose”, “dextrose”]}} missing_value_labels: Labels for missing values by property name description: Human-readable descriptions for each property repositories: Dict mapping repository IDs to their configurations
Example:
repositories:
BrentLab/harbison_2004:
dataset:
harbison_2004:
carbon_source:
field: condition
path: media.carbon_source
BrentLab/kemmeren_2014:
temperature:
path: temperature_celsius
dataset:
kemmeren_2014:
carbon_source:
path: media.carbon_source
factor_aliases:
carbon_source:
glucose: ["D-glucose", "dextrose"]
galactose: ["D-galactose", "Galactose"]
missing_value_labels:
carbon_source: "unspecified"
description:
carbon_source: "Carbon source in growth media"
Source code in tfbpapi/models.py
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 | |
from_yaml(path)
classmethod
¶
Load and validate configuration from YAML file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path | str
|
Path to YAML configuration file |
required |
Returns:
| Type | Description |
|---|---|
MetadataConfig
|
Validated MetadataConfig instance |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If file doesn’t exist |
ValueError
|
If configuration is invalid |
Source code in tfbpapi/models.py
get_property_mappings(repo_id, config_name)
¶
Get merged property mappings for a repo/dataset combination.
Merges repo-wide and dataset-specific mappings, with dataset-specific taking precedence.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
repo_id
|
str
|
Repository ID |
required |
config_name
|
str
|
Dataset/config name |
required |
Returns:
| Type | Description |
|---|---|
dict[str, PropertyMapping]
|
Dict mapping property names to PropertyMapping objects |
Source code in tfbpapi/models.py
get_repository_config(repo_id)
¶
Get configuration for a specific repository.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
repo_id
|
str
|
Repository ID (e.g., “BrentLab/harbison_2004”) |
required |
Returns:
| Type | Description |
|---|---|
RepositoryConfig | None
|
RepositoryConfig instance or None if not found |
Source code in tfbpapi/models.py
parse_repositories(data)
classmethod
¶
Parse repository configurations from ‘repositories’ key.
Source code in tfbpapi/models.py
validate_description(v)
classmethod
¶
Validate description structure, filtering out None values.
Source code in tfbpapi/models.py
validate_factor_aliases(v)
classmethod
¶
Validate factor alias structure.
Source code in tfbpapi/models.py
validate_missing_value_labels(v)
classmethod
¶
Validate missing value labels structure, filtering out None values.
Source code in tfbpapi/models.py
tfbpapi.models.RepositoryConfig
¶
Bases: BaseModel
Configuration for a single repository. Eg BrentLab/harbison_2004.
Attributes: properties: Repo-wide property mappings that apply to all datasets dataset: Dataset-specific configurations including sample_id, comparative_analyses, and property mappings
Example:
config = RepositoryConfig(
properties={
"temperature_celsius": PropertyMapping(path="temperature_celsius")
},
dataset={
"dataset_name": DatasetVirtualDBConfig(
sample_id=PropertyMapping(field="sample_id"),
comparative_analyses=[
ComparativeAnalysis(
repo="BrentLab/yeast_comparative_analysis",
dataset="dto",
via_field="binding_id"
)
],
# Additional property mappings via extra fields
**{"carbon_source": PropertyMapping(
field="condition",
path="media.carbon_source"
)}
)
}
)
Source code in tfbpapi/models.py
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 | |
parse_structure(data)
classmethod
¶
Parse raw dict structure into typed objects.
Source code in tfbpapi/models.py
tfbpapi.models.PropertyMapping
¶
Bases: BaseModel
Mapping specification for a single property.
Attributes: path: Optional dot-notation path to the property value. For repo/config-level: relative to experimental_conditions For field-level: relative to field definitions When omitted with field specified, creates a column alias. field: Optional field name for field-level properties. When specified, looks in this field’s definitions. When omitted, looks in repo/config-level experimental_conditions. expression: Optional SQL expression for derived/computed fields. When specified, creates a computed column. Cannot be used with field or path. dtype: Optional data type specification for type conversion. Supported values: ‘string’, ‘numeric’, ‘bool’. When specified, extracted values are converted to this type.
Examples: Field-level property with path: PropertyMapping(field=”condition”, path=”media.carbon_source”)
Repo/config-level property:
PropertyMapping(path="temperature_celsius")
Field-level column alias (no path):
PropertyMapping(field="condition")
Derived field with expression:
PropertyMapping(expression="dto_fdr < 0.05")
Source code in tfbpapi/models.py
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 | |
validate_at_least_one_specified()
¶
Ensure at least one field type is specified and mutually exclusive.
Source code in tfbpapi/models.py
validate_expression(v)
classmethod
¶
Ensure expression is not empty string if provided.
Source code in tfbpapi/models.py
validate_field(v)
classmethod
¶
Ensure field is not empty string if provided.
Source code in tfbpapi/models.py
validate_path(v)
classmethod
¶
Ensure path is not just whitespace if provided.
Source code in tfbpapi/models.py
DataCard Models¶
tfbpapi.models.DatasetCard
¶
Bases: BaseModel
Complete dataset card model.
Uses extra=”allow” to accept arbitrary top-level metadata and experimental_conditions.
Source code in tfbpapi/models.py
at_most_one_default(v)
classmethod
¶
Ensure at most one config is marked as default.
Source code in tfbpapi/models.py
configs_not_empty(v)
classmethod
¶
Ensure at least one config is present.
get_config_by_name(name)
¶
get_configs_by_type(dataset_type)
¶
Get all configurations of a specific type.
get_data_configs()
¶
get_default_config()
¶
Get the default configuration if one exists.
get_metadata_configs()
¶
unique_config_names(v)
classmethod
¶
Ensure config names are unique.
Source code in tfbpapi/models.py
tfbpapi.models.DatasetConfig
¶
Bases: BaseModel
Configuration for a dataset within a repository.
Uses extra=”allow” to accept arbitrary experimental_conditions and other fields.
Source code in tfbpapi/models.py
applies_to_only_for_metadata(v, info)
classmethod
¶
Validate that applies_to is only used for metadata or comparative configs.
Source code in tfbpapi/models.py
metadata_fields_validation(v)
classmethod
¶
Validate metadata_fields usage.
Source code in tfbpapi/models.py
tfbpapi.models.DatasetType
¶
Supported dataset types.
Source code in tfbpapi/models.py
tfbpapi.models.FeatureInfo
¶
Bases: BaseModel
Information about a dataset feature/column.
Minimal required fields with flexible dtype handling.
Source code in tfbpapi/models.py
tfbpapi.models.MetadataRelationship
¶
Bases: BaseModel
Relationship between a data config and its metadata.
Source code in tfbpapi/models.py
tfbpapi.models.ExtractedMetadata
¶
Bases: BaseModel
Metadata extracted from datasets.