Models
Data models extending sssom-schema for secondary-to-primary mappings.
Mapping Sets
- class BaseMappingSet(*args, _if_missing: Callable[[JsonObj, str], Tuple[bool, Any]] = None, **kwargs)[source]
Bases:
MappingSetA MappingSet with helpers for cardinality computation and export.
- _ambiguity_mode
Which field pair
_find_ambiguous()checks for conflicts:"id"(subject_id/object_id) or"label"(subject_label/object_label). Label-based subclasses override this to"label".- Type:
ClassVar[str]
Initialise the mapping set and the private primary-IDs store.
- to_sssom(output_path: Path | str | None = None) sssom_document.MappingSetDocument[source]
Return an SSSOM
MappingSetDocument, optionally writing to TSV.- Parameters:
output_path – If given, the document is also serialised to an SSSOM TSV file at this path
- Returns:
sssom.sssom_document.MappingSetDocumentfor the mapping set.
- to_rdf(output_path: Path | str | None = None, serialisation: str = 'turtle') rdflib.Graph[source]
Return an RDFLib graph, optionally writing it to a file.
When output_path is given (or auto-generated via the
savedispatcher), the graph is also serialised to disk. Either way therdflib.Graphis returned so callers can query or manipulate it directly.- Parameters:
output_path – Destination path. Pass a path (or
Noneto auto-generate one) to persist the graph. If you only want the in-memory graph without touching the file-system, callto_rdf()with no arguments and ignore the path attribute.serialisation – RDFLib serialisation format (default:
"turtle").
- Returns:
rdflib.Graphcontaining all mappings as RDF triples.
- to_json(output_path: Path | str | None = None) dict[str, Any][source]
Return the mapping set as a JSON-compatible
dict, optionally writing to file.- Parameters:
output_path – If given, the JSON is also written to this path.
- Returns:
dictrepresentation of the mapping set in SSSOM JSON format.
- to_owl(output_path: Path | str | None = None, serialisation: str = 'turtle') rdflib.Graph[source]
Return an OWL
rdflib.Graph, optionally writing to file.- Parameters:
output_path – If given, the graph is also serialised to this path.
serialisation – RDFLib serialisation format (default:
"turtle").
- Returns:
rdflib.Graphcontaining OWL axioms for the mapping set.
- save(fmt: str, output_path: Path | str | None = None, **kwargs: object) Path[source]
Write to any supported format by name.
Shared formats:
"sssom","rdf","json","owl". Subclasses override this to add type-specific formats.- Parameters:
fmt – Format key (see above).
output_path – Destination path. Auto-generated if
None.**kwargs – Forwarded to the format-specific writer.
- Returns:
Path to the written file.
- Raises:
ValueError – For unknown format keys.
- class IdMappingSet(*args, _if_missing: Callable[[JsonObj, str], Tuple[bool, Any]] = None, **kwargs)[source]
Bases:
BaseMappingSetMapping set for ID-based (secondary to primary identifier) mappings.
Initialise the mapping set and the private primary-IDs store.
- to_pri_ids(output_path: Path | str | None = None) list[str][source]
Return a sorted list of unique primary IDs, optionally writing to TXT.
When
_primary_idsis populated (e.g. from the HGNC complete set) that set is used. Otherwise primary IDs are derived from the uniqueobject_idvalues in the mappings.- Parameters:
output_path – If given, the IDs are also written one-per-line to a text file.
- Returns:
Sorted list of unique primary ID strings.
- save(fmt: str, output_path: Path | str | None = None, **kwargs: object) Path[source]
Write to any supported format by name.
Formats:
"sssom","rdf","json","owl","sec2pri","pri_ids".- Parameters:
fmt – Format key (see above).
output_path – Destination path. Auto-generated if
None.**kwargs – Forwarded to the format-specific writer.
- Returns:
Path to the written file.
- Raises:
ValueError – For unknown format keys.
- class LabelMappingSet(*args, _if_missing: Callable[[JsonObj, str], Tuple[bool, Any]] = None, **kwargs)[source]
Bases:
BaseMappingSetMapping set for label-based (previous/alias label to current label) mappings.
Initialise the mapping set and the private primary-IDs store.
- to_label_sec2pri(output_path: Path | str | None = None) pd.DataFrame[source]
Return a
DataFrameof previous/alias label to current label mappings.Columns:
secondary_id(subject_id),secondary_label(subject_label: alias or previous label),primary_id(object_id),primary_label(object_label: current approved label),predicate_id,mapping_cardinality.- Parameters:
output_path – If given, the DataFrame is also written as a TSV file.
- Returns:
pandas.DataFramewith one row per label mapping.
- to_pri_labels(output_path: Path | str | None = None) list[tuple[str, str]][source]
Return a sorted list of unique
(primary_id, label)pairs.When
_primary_labelsis populated (e.g. from the HGNC complete set) that dict is used. Otherwise pairs are derived from the unique(object_id, object_label)values in the mappings.- Parameters:
output_path – If given, the pairs are also written as a two-column TSV file (
id\\tlabel).- Returns:
Sorted list of
(primary_id, label)tuples.
- to_name2synonym(output_path: Path | str | None = None) pd.DataFrame[source]
Return a name to synonym
DataFrame, optionally writing to TSV.Columns:
primary_id,name(primary / canonical name),synonym(secondary / alternative name).Only
oboInOwl:hasExactSynonymrows are included. Rows withIAO:0100001("term replaced by") are deprecation mappings and belong in thelabel_sec2prioutput, not here.The direction follows the sec:pri structure, where the secondary (synonym/alternative) term is the subject and the primary (canonical) term is the object.
- Parameters:
output_path – If given, the DataFrame is also written as a TSV file.
- Returns:
pandas.DataFramewith synonym-only label mapping rows.
- save(fmt: str, output_path: Path | str | None = None, **kwargs: object) Path[source]
Write to any supported format by name.
Formats:
"sssom","rdf","json","owl","label_sec2pri"("label2prev"is a deprecated alias),"pri_labels","name2synonym".- Parameters:
fmt – Format key (see above).
output_path – Destination path. Auto-generated if
None.**kwargs – Forwarded to the format-specific writer.
- Returns:
Path to the written file.
- Raises:
ValueError – For unknown format keys.
Configuration
- class DatasourceConfig(*, name: str, prefix: str, curie_base_url: str, config_id: str = '', datasource_id: str = '', parser_class: str = '', entity_types: list[str] = <factory>, parse_options: dict[str, ~typing.Any] = <factory>, mapping_sets: dict[str, ~typing.Any] = <factory>, available_outputs: list[str] = <factory>, default_output_filename: str = '', download_urls: dict[str, ~typing.Any] = <factory>, primary_file_key: str = '', id_pattern: str = '', archive_url: str | None = '', input_file_types: list[str] = <factory>, source: str = '', homepage: str = '', data_license: str = '', sparql_endpoint: str = '', queries: dict[str, str] = <factory>, version_query: str = '', new_format_version: int | None = None, distribution_eras: list[~mapkgsutils.parsers.config.DistributionEra] = <factory>, xref_sources: list[~mapkgsutils.parsers.config.XrefSource] = <factory>, products: list[str] = <factory>, species: dict[str, ~typing.Any] = <factory>, subset: dict[str, ~typing.Any] = <factory>, mappingset: dict[str, ~typing.Any] = <factory>, mapping: dict[str, ~typing.Any] = <factory>, **extra_data: ~typing.Any)[source]
Configuration for a biological database datasource loaded from YAML.
Required fields (
name,prefix,curie_base_url) have no default; every other key is optional. Unrecognized top-level keys are tolerated (a warning is emitted byvalidate_config_dict()).Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- model_config: ClassVar[ConfigDict] = {'extra': 'allow', 'populate_by_name': True, 'validate_by_alias': True, 'validate_by_name': True}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- products: list[str]
Products split a release into disjoint datasets, e.g.
["species"]. Each names an attribute of the parser; their values become the product slug
- species_token(taxon_id: str | int) str[source]
Resolve a canonical NCBI taxon ID to this datasource’s species token.
Reads the
species.availableblock (seeensembl.yaml), which maps each supported taxon ID to the datasource-specific token used to build download paths/filters (e.g. Ensembl’shomo_sapiens).- Parameters:
taxon_id – Canonical NCBI taxon ID, e.g.
9606or"9606".- Returns:
The datasource-specific species token.
- Raises:
ValueError – If no
speciesblock is configured, or taxon_id is not one of its declared entries.
- default_species() str | int[source]
Return the configured default species taxon ID (
9606if unset).
- default_subset() str | None[source]
Return the configured default subset, or
Noneif this datasource has none.
- xref_source(source_id: str) XrefSource | None[source]
Return the configured
XrefSourcewith id source_id, if any.
- formats_for(kind: str) Any[source]
Return the list of supported output formats for a mapping-set kind.
- Parameters:
kind – Mapping-set key, e.g.
"ids"or"labels".- Returns:
List of format strings, or an empty list when the kind is absent.
- era_for(version: str | None) DistributionEra | None[source]
Return the first configured era whose bounds contain version.
- Parameters:
version – Version string to match, or
None.- Returns:
The matching
DistributionEra, orNoneif no eras are configured or none match (callers should fall back to the top-leveldownload_urls/new_format_versionbehavior).
Constants
Pre-loaded datasource configurations.
Constants for supported datasources.
Datasource configs are built on access.
Base Parser
- class BaseParser(version: str | None = None, show_progress: bool = True, config_name: str | None = None)[source]
Abstract base class for all pysec2pri datasource parsers.
Initialize the parser.
- Parameters:
version – Version/release identifier for the datasource.
show_progress – Whether to show progress bars during parsing.
config_name – Name of config file to load (defaults to class name).
- config_package: ClassVar[str] = 'pysec2pri.config'
Importable package holding this datasource family’s
*.yamlconfig files. Set by the concrete framework subclass.
- mapping_set_classes: ClassVar[dict[str, type[BaseMappingSet]]] = {'id': <class 'pysec2pri.parsers.base.IdMappingSet'>, 'label': <class 'pysec2pri.parsers.base.LabelMappingSet'>}
Which
BaseMappingSetsubclasscreate_mapping_set()instantiates for eachmapping_type.