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
|
Measure the three CDRs of a numbered domain. |
|
Extract the three CDR sequences of a numbered domain. |
|
Calculate the sequence identity between numbered sequences. |
|
Split a numbered domain into its framework and CDR sequences. |
|
Calculate the BLOSUM62 similarity between numbered sequences. |
- antibody_utils.sequence.cdr_lengths(numbered, definition)[source]¶
Measure the three CDRs of a numbered domain.
- Parameters:
numbered (
NumberedSequence) – The numbered domain.definition (
Definition|str) – The CDR definition to apply.
- Return type:
- 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:
numbered (
NumberedSequence) – The numbered domain.definition (
Definition|str) – The CDR definition to apply.
- Return type:
- 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:
a (
NumberedSequence|Iterable[NumberedSequence]) – The first sequence, or sequences.b (
NumberedSequence|Iterable[NumberedSequence]) – The second sequence, or sequences.definition (
Definition|str) – The region definition used to select positions.regions (
Iterable[Region|str] |None) – The regions, or region groups such as “cdrs”, to compare over. By default, the whole variable domain (“fv”).
- Return type:
- 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:
numbered (
NumberedSequence) – The numbered domain.definition (
Definition|str) – The region definition to apply.
- Return type:
- 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:
a (
NumberedSequence|Iterable[NumberedSequence]) – The first sequence, or sequences.b (
NumberedSequence|Iterable[NumberedSequence]) – The second sequence, or sequences.definition (
Definition|str) – The region definition used to select positions.regions (
Iterable[Region|str] |None) – The regions, or region groups such as “cdrs”, to compare over. By default, the whole variable domain (“fv”).normalise (
bool) – Divide the total score by the number of positions compared.
- Return type:
- 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.