Database Annotation API¶
Match clonotypes against VDJdb, IEDB, and CEDAR epitope references, separate
canonical protein/antigen labels (db_protein_canonical, e.g. NY-ESO-1,
LAGE-1, MART-1, TRP-2, CEA) from official HGNC/MGI encoding gene symbols
(db_antigen_gene, e.g. CTAG1A/CTAG1B, CTAG2, MLANA/Mlana,
DCT/Dct, CEACAM5; None for viral or exogenous proteins such as chicken
OVA), and track donor host species (db_host_species, host_species_filter).
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', 'mcmv', 'ebv', 'epstein-barr', 'epstein barr', 'hiv', 'human immunodeficiency', 'htlv', 'flu', 'influenza', 'sars', 'coronavirus', 'herpes', 'hsv', 'hpv', 'papilloma', 'hepatitis', 'hbv', 'hcv', 'dengue', 'zika', 'yellow fever', 'west nile', 'lcmv', 'lymphocytic choriomeningitis', 'mammarenavirus choriomeningitidis', 'vesicular stomatitis', 'vsv', 'sendai', 'murine respirovirus', 'respirovirus', 'vaccinia', 'ectromelia', 'murine leukemia', 'mulv', 'polyomavirus', 'adenovirus', 'norovirus', 'rotavirus', 'parvovirus']
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). Output rows are restricted togene == TRBsocdr3_betaonly carries actual β-CDR3s; whencomplex.id > 0links aTRBrow to a pairedTRArow,cdr3_alphaandv_alphaare reconstructed onto that row (unpairedcomplex.id == 0rows keepcdr3_alpha = pd.NA).
When given a directory, looks for canonical filenames in priority
order (vdjdb_full.txt, vdjdb.txt, vdjdb.slim.txt, or a
date-stamped vdjdb-YYYY-MM-DD.txt). Other sidecar files in the
directory (.meta.txt, .scored.txt, etc.) are ignored.
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
1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 | |
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, verbose: bool = True) -> 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
|
verbose
|
bool
|
Print progress information. |
True
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Combined database with standardized columns |
Source code in tcrsift/annotate.py
canonicalize_antigen ¶
Map a raw antigen/protein string to its canonical protein/antigen label.
Strictly word-bounded and organism-aware:
- Distinguishes proteins/proteoforms from encoding genes: both
CTAG1AandCTAG1Bcanonicalize to"NY-ESO-1", whereasCTAG2canonicalizes to"LAGE-1";CEACAM5andCarcinoembryonic antigencanonicalize to"CEA"whileCEACAM1/CEACAM6stay untouched;ERBB2→"HER2"whileERBB2IPstays untouched;MAGE-A10/MAGEA12keep their exact paralog numbers rather than collapsing intoMAGE-A1. - Disambiguates shared viral protein names (
Nucleoprotein,Nucleocapsid,NS3,Spike,IE1) usingspecies(or an inline[organism]suffix), and never maps host self proteins such as humanSmall nuclear ribonucleoprotein G(SNRPG) onto viral labels.
Source code in tcrsift/annotate.py
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 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 | |
resolve_antigen_gene ¶
resolve_antigen_gene(antigen: str | None, canonical_protein: str | None = None, species: str | None = None) -> str | None
Resolve the official encoding gene symbol (HGNC/MGI) for an endogenous antigen.
Returns None for viral, bacterial, and foreign exogenous antigens (such as
chicken OVA or CMV pp65) so db_antigen_gene strictly holds host
or tumor gene symbols while db_protein_canonical holds the protein or
antigen name.
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, *, species: str = 'human', host_species_filter: str = 'all') -> 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
2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 | |
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, *, verbose: bool = True, show_progress: bool = True, 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', species: str = 'human', host_species_filter: str = 'all') -> pd.DataFrame
Main annotation function.
Source code in tcrsift/annotate.py
2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 | |
get_annotation_summary ¶
Get summary of annotation results.
Returns:
| Type | Description |
|---|---|
dict
|
Summary statistics |