Annotation API¶
Module for annotating clonotypes with public TCR databases.
annotate ¶
TCR annotation using public databases for TCRsift.
Matches TCRs against VDJdb, IEDB, and CEDAR to identify known specificities.
VIRAL_SPECIES_PATTERNS
module-attribute
¶
VIRAL_SPECIES_PATTERNS = ['cmv', 'cytomegalovirus', 'ebv', 'epstein-barr', 'hiv', 'human immunodeficiency', 'flu', 'influenza', 'sars', 'coronavirus', 'herpes', 'hsv', 'hpv', 'papilloma', 'hepatitis', 'hbv', 'hcv', 'dengue', 'zika', 'yellow fever']
load_vdjdb ¶
Load VDJdb database.
VDJdb ships two on-disk shapes with different row semantics:
vdjdb_full.txt— paired-chain format: one row per clonotype, withcdr3.alphaandcdr3.betaas separate columns. This is what αβ matching needs.vdjdb.txt— long/slim format: one row per chain, keyed bycomplex.idandgene(TRA/TRB). Thecdr3column holds an α-CDR3 whengene == TRAand a β-CDR3 whengene == TRB. A naivecdr3 → cdr3_betarename mixes the two and matches alpha sequences as if they were beta. To avoid that, the long-format path is filtered togene == TRBrows socdr3_betaonly carries actual β-CDR3s; α rows are dropped (would need acomplex.idpivot to recover αβ pairs, which is best deferred to the full file).
When given a directory, looks for one of three canonical filenames
in priority order: vdjdb_full.txt, vdjdb.txt,
vdjdb.slim.txt. Other files in the directory (metadata
sidecars, processed views, etc.) are ignored — a directory that
has none of these names raises with a hint to re-run
tcrsift data download or pass the file path explicitly.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str or Path
|
Path to VDJdb directory or single file. |
required |
verbose
|
bool
|
Print progress information. |
True
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
VDJdb entries with standardized columns ( |
Source code in tcrsift/annotate.py
689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 | |
load_iedb ¶
Load IEDB TCR database.
Handles two on-disk shapes:
- The current
receptor_full_v3.zipexport (cached astcr_full_v3.csv): comma-separated with a two-row hierarchical header — top row is the section (Receptor/Epitope/Assay/Chain 1/Chain 2…), second row is the field (e.g.CDR3 Curated,Source Organism). - Older flat-TSV exports kept around for compatibility.
The format is sniffed from the first byte of the file rather than the extension, so a user-supplied path is treated correctly regardless of suffix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str or Path
|
Path to IEDB receptor file (v3 CSV or legacy flat TSV). |
required |
epitope_path
|
str or Path
|
Path to the IEDB epitope-level CSV
( |
None
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
IEDB entries with standardized columns ( |
Source code in tcrsift/annotate.py
load_cedar ¶
Load the CEDAR TCR database.
Handles two on-disk shapes, sniffed from the file's first line (not the extension):
- The bulk receptor export (
doc/receptor_full_v3.zip→tcr_full_v3.csv, cached bytcrsift data download --db cedar): comma-separated with the same v3 two-row hierarchical header as IEDB, so it is parsed by the shared :func:_load_iedb_v3. - A manual web-UI export
cedar.tsv— tab-separated, flat header with fields likecdr3_b_aa/epitope_sequence(the original supported shape; kept for back-compat).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str or Path
|
Path to a CEDAR receptor file (bulk v3 CSV or manual flat TSV). |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
CEDAR entries with standardized columns ( |
Source code in tcrsift/annotate.py
load_databases ¶
load_databases(vdjdb_path: str | Path | None = None, iedb_path: str | Path | None = None, cedar_path: str | Path | None = None, iedb_epitope_path: str | Path | None = None) -> pd.DataFrame
Load and combine multiple TCR databases.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vdjdb_path
|
str or Path
|
Path to VDJdb |
None
|
iedb_path
|
str or Path
|
Path to IEDB receptor table |
None
|
cedar_path
|
str or Path
|
Path to CEDAR |
None
|
iedb_epitope_path
|
str or Path
|
Path to IEDB epitope-level table (companion to |
None
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Combined database with standardized columns |
Source code in tcrsift/annotate.py
match_clonotypes ¶
match_clonotypes(clonotypes: DataFrame, database: DataFrame, match_by: str = 'CDR3ab', match_strictness: str | None = None, match_mode: str = 'exact', max_distance: int = 1, verbose: bool = True, show_progress: bool = True) -> pd.DataFrame
Match clonotypes against public database.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
clonotypes
|
DataFrame
|
Clonotype DataFrame |
required |
database
|
DataFrame
|
Combined database from load_databases |
required |
match_by
|
str
|
Legacy matching strategy. |
'CDR3ab'
|
match_strictness
|
str
|
Explicit matching strictness. When set, takes precedence over
|
None
|
match_mode
|
str
|
Distance regime for the β-only match (#57). When |
``"exact"``
|
max_distance
|
int
|
Maximum edit distance for fuzzy β matching (only used when
|
1
|
verbose
|
bool
|
Print progress information |
True
|
show_progress
|
bool
|
Show progress bar |
True
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Clonotypes with match annotations: |
Source code in tcrsift/annotate.py
1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 | |
annotate_clonotypes ¶
annotate_clonotypes(clonotypes: DataFrame, vdjdb_path: str | Path | None = None, iedb_path: str | Path | None = None, cedar_path: str | Path | None = None, iedb_epitope_path: str | Path | None = None, match_by: str = 'CDR3ab', match_strictness: str | None = None, match_mode: str = 'exact', max_distance: int = 1, exclude_viral: bool = False, flag_only: bool = False, *, add_publicness: bool = False, publicness_cdr3_col: str = 'CDR3_beta', publicness_v_gene_col: str = 'beta_v_gene', publicness_j_gene_col: str = 'beta_j_gene') -> pd.DataFrame
Main annotation function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
clonotypes
|
DataFrame
|
Clonotype DataFrame |
required |
vdjdb_path
|
str or Path
|
Paths to databases |
None
|
iedb_path
|
str or Path
|
Paths to databases |
None
|
cedar_path
|
str or Path
|
Paths to databases |
None
|
iedb_epitope_path
|
str or Path
|
Path to the IEDB epitope-level table (companion to
|
None
|
match_by
|
str
|
Legacy matching strategy. Prefer |
'CDR3ab'
|
match_strictness
|
str
|
Explicit matching strictness — |
None
|
exclude_viral
|
bool
|
Remove clones matching viral epitopes |
False
|
flag_only
|
bool
|
Just flag viral, don't remove |
False
|
add_publicness
|
bool
|
When True, add |
False
|
publicness_cdr3_col
|
str
|
Columns Pgen estimator should read. |
'CDR3_beta'
|
publicness_v_gene_col
|
str
|
Columns Pgen estimator should read. |
'CDR3_beta'
|
publicness_j_gene_col
|
str
|
Columns Pgen estimator should read. |
'CDR3_beta'
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Annotated clonotypes |
Source code in tcrsift/annotate.py
1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 | |
get_annotation_summary ¶
Get summary of annotation results.
Returns:
| Type | Description |
|---|---|
dict
|
Summary statistics |