Skip to content

uniprot_extraction

UniProt extraction and mapping helpers for structures.

ChainUniprotPair = namedtuple('ChainUniprotPair', ['chain_id', 'uniprot_accession']) module-attribute

Pair of chain id and UniProt accession for mapping purposes.

UniprotSource = Literal['both', 'sifts', 'struct_ref_seq', 'fallback'] module-attribute

From which source to extract UniProt accessions from a structure.

FlattenedUniprotChainMapping dataclass

Collapsed _struct_ref_seq like alignment information for one chain.

Attributes:

uniprot_accession: The UniProt accession.
uniprot_start: The start position of the alignment on the UniProt sequence.
uniprot_end: The end position of the alignment on the UniProt sequence.
chain_id: The chain ID in the 'auth' [chain ID system][protein_quest.structure.chains.ChainIdSystem].
sequence_identity: The sequence identity of the alignment.
aligned_residue_count: The number of aligned residues in the alignment.

flatten_uniprot_chain_mappings(mappings)

Flatten a set of UniprotChainMapping.

Each (accession, chain) group is collapsed into one record with merged start/end and aligned_residue_count summed across all ranges.

Parameters:

Name Type Description Default
mappings UniprotChainMappings

Set of UniprotChainMapping.

required

Returns:

Type Description
set[FlattenedUniprotChainMapping]

Set of flattened per-(accession, chain) records with merged start/end,

set[FlattenedUniprotChainMapping]

summed aligned residue counts, and computed sequence identity.

structure2uniprot_accessions(structure_file)

Extract UniProt accessions from a structure file.

Logs a warning and returns an empty set if no accessions are found in structure.

Parameters:

Name Type Description Default
structure_file Path

Source mmCIF path to preserve raw SIFTS segment data.

required

Returns:

Type Description
set[str]

A set of UniProt accessions found in the structure.

structure_to_uniprot(structure_file, source='both', one_uniprot_per_chain=True, structure=None)

Extract UniProt chain mappings from a structure.

Parameters:

Name Type Description Default
structure_file Path

Source mmCIF path. When provided for .cif or .cif.gz files, SIFTS mappings are extracted from raw _pdbx_sifts_unp_segments rows as structure does not contain that info.

required
source UniprotSource

UniProt source to read from.

  • sifts: Read from _pdbx_sifts_unp_segments rows in the input mmCIF.
  • struct_ref_seq: Read from _struct_ref_seq filtered by _struct_ref records with db_name=UNP.
  • both: Merge SIFTS and struct_ref_seq results.
  • fallback: Return SIFTS when available, otherwise struct_ref_seq.
'both'
one_uniprot_per_chain bool

If True, return only the best UniProt per chain, based on highest aligned residue count, with ties broken alphabetically by accession. Otherwise, return all UniProt mappings for each chain.

True
structure Structure | None

The structure containing SIFTS and/or _struct_ref_seq data. Can be passed if caller already read structure. If not passed will use protein_quest.structure.formats.read_structure to read structure_file.

None

Returns:

Type Description
set[FlattenedUniprotChainMapping]

Set of flattened per-(accession, chain) records with merged start/end,

set[FlattenedUniprotChainMapping]

summed aligned residue counts, and computed sequence identity.

uniprot_chain_mappings_from_struct_ref_seq(structure)

Extract UniProt chain mappings from _struct_ref_seq rows.

Parameters:

Name Type Description Default
structure Structure

The structure containing _struct_ref and _struct_ref_seq records.

required

Returns:

Type Description
UniprotChainMappings

Set of UniProt chain mappings with ranges per chain. Empty if no UNP data found.