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:
| Name | Type | Description |
|---|---|---|
factor_aliases |
FactorAliases
|
Optional mappings of standardized names to actual values. Example: {“carbon_source”: {“glucose”: [“D-glucose”, “dextrose”]}} |
missing_value_labels |
dict[str, str]
|
Labels for missing values by property name |
description |
dict[str, str]
|
Human-readable descriptions for each property |
repositories |
dict[str, RepositoryConfig]
|
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 # Comparative dataset with aliases and links BrentLab/yeast_comparative_analysis: dataset: dto: dto_fdr: field: dto_fdr aliases: dto_pvalue: dto_empirical_pvalue links: binding_id: - [BrentLab/harbison_2004, harbison_2004] 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
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 | |
filter_none_values(v)
classmethod
¶
Filter out None values that may come from empty YAML values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
v
|
dict[str, str] | None
|
Dictionary that may contain None values |
required |
Returns:
| Type | Description |
|---|---|
dict[str, str]
|
Dictionary with None values filtered out |
Source code in tfbpapi/models.py
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 |
|---|---|
ValidationError
|
If configuration is invalid |
FileNotFoundError
|
If file doesn’t exist |
ValueError
|
If YAML file does not contain a dictionary |
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
get_sample_id_field(repo_id, config_name)
¶
Resolve the actual column name for the sample identifier.
Checks dataset-level sample_id first, then repo-level,
falling back to "sample_id" if neither is configured.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
repo_id
|
str
|
Repository ID |
required |
config_name
|
str
|
Dataset/config name |
required |
Returns:
| Type | Description |
|---|---|
str
|
Column name for the sample identifier |
Source code in tfbpapi/models.py
get_tags(repo_id, config_name)
¶
Get merged tags for a repo/dataset combination.
Merges repo-level and dataset-level tags, with dataset-level tags taking precedence for the same key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
repo_id
|
str
|
Repository ID |
required |
config_name
|
str
|
Dataset/config name |
required |
Returns:
| Type | Description |
|---|---|
dict[str, str]
|
Dict of merged tags |
Source code in tfbpapi/models.py
parse_config(data)
classmethod
¶
Parse and validate all top-level sections of the VirtualDB configuration.
Handles the four top-level sections: repositories (required),
factor_aliases, missing_value_labels, and description
(all optional). Logs an INFO message for each optional section that
is absent from the configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Any
|
Raw configuration data |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Processed configuration dict ready for Pydantic field validation |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in tfbpapi/models.py
validate_factor_aliases(v)
classmethod
¶
Validate factor alias structure and value types.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
v
|
FactorAliases
|
Factor aliases dictionary |
required |
Returns:
| Type | Description |
|---|---|
FactorAliases
|
Validated factor aliases |
Raises:
| Type | Description |
|---|---|
ValueError
|
If any alias has an empty value list |
Source code in tfbpapi/models.py
validate_repositories_have_datasets()
¶
Validate that every repository defines at least one dataset.
Returns:
| Type | Description |
|---|---|
MetadataConfig
|
The validated MetadataConfig instance |
Raises:
| Type | Description |
|---|---|
ValueError
|
If any repository has no datasets defined |
Source code in tfbpapi/models.py
validate_unique_db_names()
¶
Validate that all resolved db_names are unique across datasets.
Each dataset resolves to db_name or config_name. These must be unique to avoid SQL view name collisions.
Returns:
| Type | Description |
|---|---|
MetadataConfig
|
The validated MetadataConfig instance |
Raises:
| Type | Description |
|---|---|
ValueError
|
If duplicate db_names are found |
Source code in tfbpapi/models.py
tfbpapi.models.RepositoryConfig
¶
Bases: BaseModel
Configuration for a single repository.
For example: BrentLab/harbison_2004
Attributes:
| Name | Type | Description |
|---|---|---|
properties |
dict[str, PropertyMapping]
|
Repo-wide property mappings that apply to all datasets |
dataset |
dict[str, DatasetVirtualDBConfig] | None
|
Dataset-specific configurations including sample_id, comparative_analyses, and property mappings Example:: BrentLab/harbison_2004: temperature_celsius: path: temperature_celsius dataset: harbison_2004: sample_id: field: sample_id carbon_source: field: condition path: media.carbon_source |
Source code in tfbpapi/models.py
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 | |
parse_structure(data)
classmethod
¶
Parse raw dict structure into typed objects.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Any
|
Raw input data |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Processed data with typed objects |
Raises:
| Type | Description |
|---|---|
ValueError
|
If validation fails |
Source code in tfbpapi/models.py
tfbpapi.models.PropertyMapping
¶
Bases: BaseModel
Mapping specification for a single property.
Attributes:
| Name | Type | Description |
|---|---|---|
field |
str | None
|
Optional field name for field-level properties. When specified, looks in this field’s definitions. When omitted, uses repo/config-level resolution. |
path |
str | None
|
Optional dot-notation path to the property value. For repo/config-level: relative to datacard/config root (e.g., “experimental_conditions.media.carbon_source” or “description”) For field-level: relative to the field’s definitions dict (e.g., “temperature_celsius” resolves within each sample’s definition) When omitted with field specified, creates a column alias. |
expression |
str | None
|
Optional SQL expression for derived/computed fields. When specified, creates a computed column. Cannot be used with field or path. |
dtype |
str | None
|
Optional data type specification for type conversion. Supported values: ‘string’, ‘numeric’, ‘bool’. When specified, extracted values are converted to this type. Examples:: # Repo/config-level property (explicit path from datacard root) PropertyMapping(path=”experimental_conditions.media.carbon_source.compound”) # Repo/config-level property outside experimental_conditions PropertyMapping(path=”description”) # Field-level property with path (relative to field definitions) PropertyMapping(field=”condition”, 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
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 | |
strip_whitespace(v)
classmethod
¶
Strip whitespace and validate non-empty strings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
v
|
str | None
|
String value to validate |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
Stripped string or None |
Raises:
| Type | Description |
|---|---|
ValueError
|
If string is empty or only whitespace |
Source code in tfbpapi/models.py
validate_field_types()
¶
Ensure at least one field type is specified and mutually exclusive.
Also validates dtype=’factor’ requires a field (not expression or path-only).
Returns:
| Type | Description |
|---|---|
PropertyMapping
|
The validated PropertyMapping instance |
Raises:
| Type | Description |
|---|---|
ValueError
|
If validation constraints are violated |
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
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 | |
config_names
cached
property
¶
default_config
cached
property
¶
Get the default configuration if one exists.
Returns:
| Type | Description |
|---|---|
DatasetConfig | None
|
The default DatasetConfig or None if no default is set |
get_config_by_name(name)
¶
Get a configuration by name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The configuration name to search for |
required |
Returns:
| Type | Description |
|---|---|
DatasetConfig | None
|
The matching DatasetConfig or None if not found |
Source code in tfbpapi/models.py
get_configs_by_type(dataset_type)
¶
Get all configurations of a specific type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset_type
|
DatasetType
|
The DatasetType to filter by |
required |
Returns:
| Type | Description |
|---|---|
list[DatasetConfig]
|
List of matching DatasetConfig objects |
Source code in tfbpapi/models.py
get_data_configs()
¶
Get all non-metadata configurations.
Returns:
| Type | Description |
|---|---|
list[DatasetConfig]
|
List of DatasetConfig objects excluding metadata types |
Source code in tfbpapi/models.py
get_metadata_configs()
¶
Get all metadata configurations.
Returns:
| Type | Description |
|---|---|
list[DatasetConfig]
|
List of DatasetConfig objects with metadata type |
Source code in tfbpapi/models.py
validate_configs(v)
classmethod
¶
Validate configs list.
Ensures at least one config exists, all config names are unique, and at most one config is marked as default.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
v
|
list[DatasetConfig]
|
The list of DatasetConfig objects |
required |
Returns:
| Type | Description |
|---|---|
list[DatasetConfig]
|
The validated list of configs |
Raises:
| Type | Description |
|---|---|
ValueError
|
If validation fails |
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.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
v
|
list[str] | None
|
The applies_to field value |
required |
info
|
Validation info containing other field values |
required |
Returns:
| Type | Description |
|---|---|
list[str] | None
|
The validated applies_to value |
Raises:
| Type | Description |
|---|---|
ValueError
|
If applies_to is used with invalid dataset type |
Source code in tfbpapi/models.py
metadata_fields_not_empty(v)
classmethod
¶
Validate metadata_fields is not an empty list.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
v
|
list[str] | None
|
The metadata_fields value |
required |
Returns:
| Type | Description |
|---|---|
list[str] | None
|
The validated metadata_fields value |
Raises:
| Type | Description |
|---|---|
ValueError
|
If metadata_fields is an empty list |
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.