antibody_utils.sequence

Extract regions from numbered antibody sequences, and compare them.

Comparisons work position by position on numbered sequences, so they need no alignment: residues at the same position in the same numbering scheme are compared. Only like chains are compared (heavy with heavy, light with light).

Functions

cdr_lengths(numbered, definition)

Measure the three CDRs of a numbered domain.

cdr_sequences(numbered, definition)

Extract the three CDR sequences of a numbered domain.

identity(a, b, *, definition[, regions])

Calculate the sequence identity between numbered sequences.

region_sequences(numbered, definition)

Split a numbered domain into its framework and CDR sequences.

similarity(a, b, *, definition[, regions, ...])

Calculate the BLOSUM62 similarity between numbered sequences.

antibody_utils.sequence.cdr_lengths(numbered, definition)[source]

Measure the three CDRs of a numbered domain.

Parameters:
Return type:

dict[Region, int]

Returns:

The number of residues in each of CDRs 1, 2 and 3, in order.

antibody_utils.sequence.cdr_sequences(numbered, definition)[source]

Extract the three CDR sequences of a numbered domain.

Parameters:
Return type:

dict[Region, str]

Returns:

CDRs 1, 2 and 3 of the domain’s chain, in order. A CDR with no residues (for example, in a truncated sequence) maps to “”.

antibody_utils.sequence.identity(a, b, *, definition, regions=None)[source]

Calculate the sequence identity between numbered sequences.

Each of a and b is one domain, or several (such as a VH and its VL). Like chains are compared, and the identity is pooled over all the positions compared. A position counts only if both sequences have a residue there.

Region membership is decided position by position (as by antibody_utils.regions.get_region), so that both sequences are compared over the same positions.

Parameters:
Return type:

float

Returns:

The fraction of compared positions with the same residue, or 0.0 if no positions are compared.

Raises:

ValueError – If the sequences are numbered in different schemes, or if a or b contains two domains of the same chain.

>>> from antibody_utils.numbering import NumberedSequence, Position
>>> def heavy(sequence):
...     return NumberedSequence(
...         name=sequence,
...         chain_type="H",
...         scheme="imgt",
...         positions=tuple(Position(n) for n in (1, 2, 27, 28)),
...         sequence=sequence,
...         score=30.0,
...         start=0,
...         end=4,
...     )
>>> identity(heavy("EVGF"), heavy("QVGF"), definition="imgt")
0.75
>>> identity(heavy("EVGF"), heavy("QVGF"), definition="imgt", regions=["cdrs"])
1.0
>>> identity(heavy("EVGF"), heavy("QVGF"), definition="imgt", regions=["fwh1"])
0.5
antibody_utils.sequence.region_sequences(numbered, definition)[source]

Split a numbered domain into its framework and CDR sequences.

Parameters:
Return type:

dict[Region, str]

Returns:

The sequence of each region present, in sequence order. Residues beyond the numbered variable domain are left out.

>>> from antibody_utils.numbering import NumberedSequence, Position
>>> numbered = NumberedSequence(
...     name="example",
...     chain_type="H",
...     scheme="imgt",
...     positions=tuple(map(Position.parse, ["1", "2", "27", "28", "39"])),
...     sequence="EVGFW",
...     score=30.0,
...     start=0,
...     end=5,
... )
>>> {
...     str(region): residues
...     for region, residues in region_sequences(numbered, "imgt").items()
... }
{'fwh1': 'EV', 'cdrh1': 'GF', 'fwh2': 'W'}
antibody_utils.sequence.similarity(a, b, *, definition, regions=None, normalise=False)[source]

Calculate the BLOSUM62 similarity between numbered sequences.

Positions are selected as for identity. Residues with no BLOSUM62 score (anything other than the 20 amino acids, B, Z, X and *) are skipped.

Parameters:
Return type:

float

Returns:

The total BLOSUM62 score over the compared positions, or its mean if normalise is set; 0.0 if no positions are compared.

Raises:

ValueError – If the sequences are numbered in different schemes, or if a or b contains two domains of the same chain.