immunum
immunum.__version__ is the version of immunum that is installed, such as "2.0.0".
immunum.Annotator(chains, scheme, min_confidence=None)
Annotates antibody and T-cell receptor sequences with scheme-specific position numbers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
chains
|
list[str]
|
Chain types to consider during auto-detection. Each entry is a case-insensitive string. Accepted values:
A group of chains is accepted too: |
required |
scheme
|
str
|
Numbering scheme to use for output positions. Accepted values (case-insensitive):
Note: only IMGT supports TCR chains. Kabat, Chothia, Martin and AHo are restricted to antibody chains (IGH, IGK, IGL). |
required |
min_confidence
|
float | None
|
Minimum alignment confidence threshold in the range |
None
|
Raises:
| Type | Description |
|---|---|
Error
|
A |
Source code in immunum/__init__.py
number(sequence)
Assign scheme-specific position numbers to every residue in a sequence.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sequence
|
str
|
Amino-acid sequence string (single-letter codes). |
required |
Returns:
| Type | Description |
|---|---|
NumberingResult
|
A |
Source code in immunum/__init__.py
number_domains(sequence)
Number every variable domain in a sequence, such as both domains of an scFv.
A domain that lacks its first IMGT positions (a light chain starting at position 2, say) and directly follows other residues, such as a linker, can have the residue just before it numbered as its first position: IMGT position 1 is so variable that the sequence alone can't tell a linker residue from the domain's own first residue.
from immunum import Annotator
heavy = "QVQLVQSGAEVKRPGSSVTVSCKASGGSFSTYALSWVRQAPGRGLEWMGGVIPLLTITNYAPRFQGRITITADRSTSTAYLELNSLRPEDTAVYYCAREGTTGKPIGAFAHWGQGTLVTVSS"
kappa = "DIQMTQSPSSLSASVGDRVTITCRASQDVNTAVAWYQQKPGKAPKLLIYSASFLYSGVPSRFSGSRSGTDFTLTISSLQPEDFATYYCQQHYTTPPTFGQGTKVEIK"
scfv = heavy + "GGGGSGGGGSGGGGS" + kappa
annotator = Annotator(
chains=["ig"], scheme="imgt"
)
domains = annotator.number_domains(scfv)
assert [d.chain for d in domains] == [
"H",
"K",
]
assert (
domains[1].query_start
== len(heavy) + 15
)
assert domains[1].numbering["1"] == "D"
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sequence
|
str
|
Amino-acid sequence string (single-letter codes). |
required |
Returns:
| Type | Description |
|---|---|
list[NumberingResult]
|
One |
Source code in immunum/__init__.py
segment(sequence)
Split a sequence into FR/CDR regions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sequence
|
str
|
Amino-acid sequence string (single-letter codes). |
required |
Returns:
| Type | Description |
|---|---|
SegmentationResult
|
A |
Source code in immunum/__init__.py
segment_domains(sequence)
Split every variable domain in a sequence into FR/CDR regions.
Every residue lands in exactly one domain's regions: a domain's prefix holds
the residues since the previous domain (or the start of the sequence), and only
the last domain has the residues after it as its postfix. All domains'
regions in order rebuild the sequence.
from immunum import Annotator
heavy = "QVQLVQSGAEVKRPGSSVTVSCKASGGSFSTYALSWVRQAPGRGLEWMGGVIPLLTITNYAPRFQGRITITADRSTSTAYLELNSLRPEDTAVYYCAREGTTGKPIGAFAHWGQGTLVTVSS"
kappa = "DIQMTQSPSSLSASVGDRVTITCRASQDVNTAVAWYQQKPGKAPKLLIYSASFLYSGVPSRFSGSRSGTDFTLTISSLQPEDFATYYCQQHYTTPPTFGQGTKVEIK"
linker = "GGGGSGGGGSGGGGS"
annotator = Annotator(
chains=["ig"], scheme="imgt"
)
heavy_regions, kappa_regions = (
annotator.segment_domains(
heavy + linker + kappa
)
)
assert (
heavy_regions.cdr3
== "AREGTTGKPIGAFAH"
)
assert kappa_regions.prefix == linker
assert kappa_regions.cdr3 == "QQHYTTPPT"
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sequence
|
str
|
Amino-acid sequence string (single-letter codes). |
required |
Returns:
| Type | Description |
|---|---|
list[SegmentationResult]
|
One |
Source code in immunum/__init__.py
immunum.regions_for(scheme, chain)
Look up the FR/CDR region boundaries a scheme uses for a chain.
from immunum import regions_for
kabat_heavy = regions_for("kabat", "H")
assert kabat_heavy["cdr1"] == (31, 35)
assert kabat_heavy["fr4"] == (103, 113)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scheme
|
str
|
Numbering scheme — |
required |
chain
|
str
|
A single chain (not a group such as |
required |
Returns:
| Type | Description |
|---|---|
dict[str, tuple[int, int]]
|
|
Raises:
| Type | Description |
|---|---|
Error
|
If the scheme or chain is unrecognised ( |
Source code in immunum/__init__.py
immunum.scheme_supports_chain(scheme, chain)
Tell whether a scheme numbers a chain, before building an Annotator for them.
from immunum import (
scheme_supports_chain,
)
assert scheme_supports_chain(
"kabat", "H"
)
assert not scheme_supports_chain(
"kabat", "B"
) # only IMGT numbers TCR chains
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scheme
|
str
|
Numbering scheme, as for |
required |
chain
|
str
|
A single chain, as for |
required |
Returns:
| Type | Description |
|---|---|
bool
|
|
Raises:
| Type | Description |
|---|---|
Error
|
If the scheme or chain is unrecognised ( |
Source code in immunum/__init__.py
immunum.Error
Bases: ValueError
immunum was set up or called wrongly, such as with an unknown chain name.
kind
instance-attribute
What went wrong, as a stable code: "invalid_chain", "invalid_scheme",
"unsupported_chain" or "invalid_min_confidence".
immunum.NumberingResult(chain, scheme, confidence, numbering, query_start, query_end, error, error_kind)
dataclass
The numbering of a sequence. Read a field as an attribute, such as result.chain
or result.numbering:
from immunum import Annotator
annotator = Annotator(
chains=["H", "K", "L"],
scheme="imgt",
)
sequence = "QVQLVQSGAEVKRPGSSVTVSCKASGGSFSTYALSWVRQAPGRGLEWMGGVIPLLTITNYAPRFQGRITITADRSTSTAYLELNSLRPEDTAVYYCAREGTTGKPIGAFAHWGQGTLVTVSS"
result = annotator.number(sequence)
assert result.chain == "H"
assert result.scheme == "IMGT"
assert isinstance(
result.confidence, float
)
assert result.numbering["1"] == "Q"
for (
position,
amino_acid,
) in result.numbering.items():
print(f"{position}: {amino_acid}")
# 1: Q
# 2: V
# 3: Q
# ...
chain
instance-attribute
Detected chain: "H", "K", "L", "A", "B", "G" or "D".
None on failure.
scheme
instance-attribute
Scheme the positions are in: "IMGT", "Kabat", "Chothia", "Martin"
or "Aho". None on failure.
confidence
instance-attribute
Alignment confidence, between 0 and 1. None on failure.
numbering
instance-attribute
Position to residue, in sequence order. Positions are strings because insertions
carry a letter, such as "111A". None on failure.
query_start
instance-attribute
0-based index of the first numbered residue in the sequence. None on failure.
query_end
instance-attribute
0-based index of the last numbered residue in the sequence, inclusive: the
numbered residues are sequence[query_start : query_end + 1]. None on
failure.
error
instance-attribute
Why the sequence couldn't be numbered, or None on success.
error_kind
instance-attribute
What went wrong, as a stable code, or None on success: "invalid_sequence"
(shorter than 30 or longer than 10,000 residues, or holding a character that isn't a
letter), "low_confidence" (no alignment reached min_confidence) or, from
number_domains only, "domain_too_short" (the best alignment is confident but
too short to be a domain).
immunum.SegmentationResult(prefix, fr1, cdr1, fr2, cdr2, fr3, cdr3, fr4, postfix, error, error_kind)
dataclass
FR/CDR regions of a sequence, plus the residues before and after the domain. Read a
region as an attribute, such as result.fr1, or all of them in sequence order with
as_dict():
from immunum import Annotator
annotator = Annotator(
chains=["H", "K", "L"],
scheme="imgt",
)
sequence = "QVQLVQSGAEVKRPGSSVTVSCKASGGSFSTYALSWVRQAPGRGLEWMGGVIPLLTITNYAPRFQGRITITADRSTSTAYLELNSLRPEDTAVYYCAREGTTGKPIGAFAHWGQGTLVTVSS"
result = annotator.segment(sequence)
assert (
result.fr1
== "QVQLVQSGAEVKRPGSSVTVSCKAS"
)
assert result.cdr1 == "GGSFSTYA"
assert result.fr2 == "LSWVRQAPGRGLEWMGG"
assert result.cdr2 == "VIPLLTIT"
assert (
result.fr3
== "NYAPRFQGRITITADRSTSTAYLELNSLRPEDTAVYYC"
)
assert result.cdr3 == "AREGTTGKPIGAFAH"
assert result.fr4 == "WGQGTLVTVSS"
assert (
"".join(result.as_dict().values())
== sequence
)
for (
segment,
aminoacids,
) in result.as_dict().items():
print(f"{segment}: {aminoacids}")
# prefix:
# fr1: QVQLVQSGAEVKRPGSSVTVSCKAS
# cdr1: GGSFSTYA
# fr2: LSWVRQAPGRGLEWMGG
# cdr2: VIPLLTIT
# fr3: NYAPRFQGRITITADRSTSTAYLELNSLRPEDTAVYYC
# cdr3: AREGTTGKPIGAFAH
# fr4: WGQGTLVTVSS
# postfix:
prefix
instance-attribute
Residues before FR1, such as a leader or the linker after a previous domain; often
empty. None on failure.
fr1
instance-attribute
Framework region 1. None on failure.
cdr1
instance-attribute
CDR1. None on failure.
fr2
instance-attribute
Framework region 2. None on failure.
cdr2
instance-attribute
CDR2. None on failure.
fr3
instance-attribute
Framework region 3. None on failure.
cdr3
instance-attribute
CDR3. None on failure.
fr4
instance-attribute
Framework region 4. None on failure.
postfix
instance-attribute
Residues after FR4, such as a constant region; often empty. None on failure.
error
instance-attribute
Why the sequence couldn't be segmented, or None on success.
error_kind
instance-attribute
What went wrong, as a stable code, or None on success: "invalid_sequence"
(shorter than 30 or longer than 10,000 residues, or holding a character that isn't a
letter), "low_confidence" (no alignment reached min_confidence) or, from
segment_domains only, "domain_too_short" (the best alignment is confident but
too short to be a domain).
as_dict()
Map each region name to its residues, in sequence order.
Returns:
| Type | Description |
|---|---|
dict[str, Optional[str]]
|
|