uniprot
UniProt extraction and injection 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.
add_uniprot_accessions2structure(structure, pdb2uniprot, *, chain_system='auth')
Add UniProt accessions to a structure if they are missing, based on the provided pdb2uniprot mapping.
If structure has UniProt accession that is not in pdb2uniprot, it will be left unchanged.
If structure has chain extraction provenance, the chain names from pdb2uniprot
will be renamed to match the output chain name in the provenance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
structure
|
Structure
|
The gemmi Structure object to add UniProt accessions to. |
required |
pdb2uniprot
|
Pdb2UniprotChainsMapping | None
|
Dictionary mapping PDB ID to structured UniProt chain mappings. If provided, will be used to inject UniProt accessions into the structure if they are missing. If None, the structure is returned unchanged. |
required |
chain_system
|
ChainIdSystem
|
System of chain ids in |
'auth'
|
Returns:
| Type | Description |
|---|---|
Structure
|
A gemmi Structure object with UniProt accessions added if they were missing |
Structure
|
or the structure unchanged if all accessions were already present. |
apply_chain_provenance_to_uniprot_mappings(mappings, chain_provenance)
Apply chain extraction provenance to a set of UniprotChainMapping.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mappings
|
set[UniprotChainMapping]
|
Set of UniprotChainMapping to apply provenance to. |
required |
chain_provenance
|
ChainExtractionProvenance
|
ChainExtractionProvenance to apply to mappings. |
required |
Returns:
| Type | Description |
|---|---|
set[UniprotChainMapping]
|
Set of UniprotChainMapping with chain ids updated based on provenance. |
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
|
set[UniprotChainMapping]
|
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)
Extract UniProt accessions from a gemmi Structure object.
Logs a warning and returns an empty set if no accessions are found in structure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
structure
|
Structure
|
The gemmi Structure object to extract UniProt accessions from. |
required |
Returns:
| Type | Description |
|---|---|
set[str]
|
A set of UniProt accessions found in the structure. |
structure_to_uniprot(structure, source='both', one_uniprot_per_chain=True)
Extract UniProt chain mappings from a structure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
structure
|
Structure
|
The structure containing SIFTS and/or |
required |
source
|
UniprotSource
|
UniProt source to read from.
|
'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
|
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_sifts(structure)
Extract UniProt chain mappings from SIFTS data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
structure
|
Structure
|
The structure containing SIFTS data. |
required |
Returns:
| Type | Description |
|---|---|
set[UniprotChainMapping]
|
Set of UniProt chain mappings with ranges per chain. Empty if no SIFTS data found. |
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 |
required |
Returns:
| Type | Description |
|---|---|
set[UniprotChainMapping]
|
Set of UniProt chain mappings with ranges per chain. Empty if no UNP data found. |