TIL Matching API¶
Module for matching clonotypes against tumor-infiltrating lymphocyte data.
til ¶
TIL (Tumor-Infiltrating Lymphocyte) matching for TCRsift.
Identifies culture-validated TCRs in TIL samples. Supports loading TIL data from multiple formats: - h5ad: Pre-processed AnnData files - CSV: Simple CSV with CDR3_alpha, CDR3_beta columns - vdj_dir: CellRanger VDJ output directory
load_til_data ¶
Load TIL data from various formats into a standard DataFrame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source_type
|
str
|
Type of source: "h5ad", "csv", or "vdj_dir" |
required |
path
|
str or Path
|
Path to the data source |
required |
sample_name
|
str
|
Name to assign to this sample (used in output) |
None
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
DataFrame with at least CDR3_alpha, CDR3_beta, and sample columns. Each row represents one cell. |
Raises:
| Type | Description |
|---|---|
TCRsiftValidationError
|
If the file doesn't exist or has invalid format |
Source code in tcrsift/til.py
load_til_samples ¶
Load TIL data from multiple samples.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
samples
|
list[Sample] or SampleSheet
|
Samples to load (only TIL samples will be processed) |
required |
Returns:
| Type | Description |
|---|---|
dict[str, DataFrame]
|
Dictionary mapping sample names to DataFrames |
Source code in tcrsift/til.py
load_til_specs ¶
Load TIL data from repeatable --til-sample specs.
Spec format: - NAME=TYPE:PATH - TYPE:PATH (sample name inferred from PATH stem)
Example: - T1=csv:/path/to/til_t1.csv - T2=vdj:/path/to/cellranger_vdj_outs
Source code in tcrsift/til.py
summarize_til_clonotypes ¶
summarize_til_clonotypes(til_data: AnnData | DataFrame | dict[str, DataFrame], match_by: str = 'CDR3ab', min_cells: int = 1) -> pd.DataFrame
Summarize TIL-only data into clonotype-level counts/frequencies across samples.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
til_data
|
AnnData, DataFrame, or dict[str, DataFrame]
|
TIL data source(s) |
required |
match_by
|
str
|
"CDR3ab" (alpha+beta) or "CDR3b_only" (beta only) |
'CDR3ab'
|
min_cells
|
int
|
Minimum total cells across all TIL samples to retain a clonotype |
1
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
One row per clonotype with total/per-sample TIL counts and frequencies. |
Source code in tcrsift/til.py
246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 | |
match_til ¶
match_til(culture_clonotypes: DataFrame, til_data: AnnData | DataFrame | dict[str, DataFrame], match_by: str = 'CDR3ab', min_til_cells: int = 1) -> pd.DataFrame
Match culture-validated clonotypes against TIL data.
Supports single TIL sample (AnnData or DataFrame) or multiple TIL samples (dict mapping sample names to DataFrames).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
culture_clonotypes
|
DataFrame
|
Filtered clonotypes from culture experiments |
required |
til_data
|
AnnData, DataFrame, or dict[str, DataFrame]
|
TIL data with TCR information. Can be: - AnnData: Single TIL sample (uses .obs) - DataFrame: Single TIL sample with CDR3_alpha, CDR3_beta columns - dict: Multiple TIL samples mapping name -> DataFrame |
required |
match_by
|
str
|
Matching strategy: "CDR3ab" or "CDR3b_only" |
'CDR3ab'
|
min_til_cells
|
int
|
Minimum TIL cells to count as present (per sample for multi-sample) |
1
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Culture clonotypes with TIL match information: - til_match: Found in any TIL sample - til_samples: Comma-separated list of matching TIL samples - til_cell_count: Total cells across all TIL samples - til_frequency: Combined frequency - til_cell_count.{sample}: Cells in specific sample (multi-sample only) - til_frequency.{sample}: Frequency in specific sample (multi-sample only) |
Source code in tcrsift/til.py
364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 | |
get_til_summary ¶
Get summary of TIL matching results.
Returns:
| Type | Description |
|---|---|
dict
|
Summary statistics |
Source code in tcrsift/til.py
identify_til_specific_clones ¶
identify_til_specific_clones(til_data: AnnData, culture_clonotypes: DataFrame | None = None, min_cells: int = 2) -> pd.DataFrame
Identify clones that are abundant in TILs but not in culture.
These could be tumor-reactive TCRs not captured in the culture system.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
til_data
|
AnnData
|
TIL data |
required |
culture_clonotypes
|
DataFrame
|
Culture clonotypes to exclude |
None
|
min_cells
|
int
|
Minimum cells in TIL to consider |
2
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
TIL-specific clones |