moleculekit.uniprot module#

Sequence lookups against the UniProt REST API.

Use this when the RCSB cannot give the full target sequence of a chain – moleculekit.rcsb.resolveFullSequences() has no entry for it, or the structure is not a PDB deposition at all – and a reference sequence is still needed to tell which residues a structure is missing.

UniProt entries are full-length precursors: they include signal peptides, propeptides and, for engineered constructs, sequence the crystallised protein never had. Passing one straight to moleculekit.tools.modelling.detectSequenceGaps() therefore reports a long terminal “gap” that is not missing density but a region excised by design, so trim it to the observed span with trimPrecursorSequences() first.

moleculekit.uniprot.trimPrecursorSequences(mol, sequences, chains=None, tol=2.0, return_offsets=False)#

Trim reference sequences down to the span a structure actually covers.

A UniProt precursor typically starts before, and can end after, the construct in the structure: a signal peptide, an activation peptide, a purification tag. Those residues are absent by design, not unresolved, so they must not be presented as gaps to model. This aligns each reference against the observed sequence and drops the leading and trailing reference residues that align to nothing, leaving internal gaps and the residue numbering untouched.

Only apply this to references that came from UniProt. On an RCSB entity sequence a terminal overhang is missing density (a disordered terminus) and dropping it would silently discard a real, modellable gap – hence chains.

Parameters:
  • mol (Molecule) – The structure the sequences are references for.

  • sequences (dict) – {chain: full_sequence}. Not modified; a trimmed copy is returned.

  • chains (list of str, optional) – The chains to trim. Defaults to every chain in sequences; pass the UniProt-derived chains explicitly when the mapping mixes sources.

  • tol (float) – Maximum C-N distance (Angstrom) still counted as a peptide bond when locating the structure’s backbone breaks, which is what tells the aligner where residues can legitimately be missing.

  • return_offsets (bool) – Also return {chain: n_leading_trimmed}. Reference position p (1-based) in a trimmed sequence is UniProt position p + offset, which is how a caller maps a terminus back to precursor numbering.

Return type:

dict | tuple[dict, dict[str, int]]

Returns:

  • trimmed (dict) – {chain: sequence}, with untrimmed chains carried through unchanged.

  • offsets (dict) – Only when return_offsets is True: the number of leading reference residues dropped per trimmed chain (0 for chains carried through).

Examples

>>> from moleculekit.uniprot import trimPrecursorSequences, uniprotSequence
>>> seqs = trimPrecursorSequences(mol, {"A": uniprotSequence("P00760")})
>>> seqs["A"][:4]      # the mature chain, signal + activation peptide gone
'IVGG'
moleculekit.uniprot.uniprotMatureChains(accession)#

The mature chain spans of a UniProt entry, in precursor numbering.

A structure’s terminus is a real biological end only if it coincides with a boundary of one of these spans: everything else is a cut through the backbone. Entries can carry several spans (bovine trypsin P00760 lists the mature chain 24-246 and its two alpha-trypsin autolysis products), so all of them are returned and the caller records which one matched.

Parameters:

accession (str) – A UniProtKB accession, e.g. "P00760".

Returns:

spans{"start", "end", "type", "description"} per span, in precursor numbering (1-based, inclusive), sorted by start then end. When the entry declares no Chain/Peptide feature, a single span is synthesised from the precursor minus any leading signal, transit or propeptide (type="synthesised").

Return type:

list

Examples

>>> from moleculekit.uniprot import uniprotMatureChains
>>> uniprotMatureChains("P00533")[0]["start"]
25
moleculekit.uniprot.uniprotSearch(query, size=5)#

Search UniProtKB and return the top hits as plain dicts.

Parameters:
Returns:

hits{"accession", "name", "organism", "length", "reviewed"} per hit, best match first. reviewed marks a Swiss-Prot (manually curated) entry. Ranking is UniProt’s own relevance, which is not sequence identity to any structure – present the candidates and let the user pick rather than taking the first hit.

Return type:

list

Examples

>>> from moleculekit.uniprot import uniprotSearch
>>> hits = uniprotSearch('trypsin AND organism_name:"Bos taurus"')
>>> hits[0]["accession"]
'P00760'
moleculekit.uniprot.uniprotSequence(accession)#

The full-length precursor sequence of a UniProt entry.

Parameters:

accession (str) – A UniProtKB accession, e.g. "P00760".

Returns:

sequence – The one-letter sequence, signal peptide and propeptides included. Trim it to a structure with trimPrecursorSequences() before using it as a gap-detection reference.

Return type:

str

Examples

>>> from moleculekit.uniprot import uniprotSequence
>>> len(uniprotSequence("P00760"))
246