Data Loading API¶
Module for loading CellRanger VDJ and GEX outputs.
loader ¶
Data loading functions for TCRsift.
Handles loading CellRanger VDJ and GEX outputs into unified data structures.
load_cellranger_vdj ¶
load_cellranger_vdj(vdj_dir: str | Path, sample_name: str, annotations_filename: str = 'filtered_contig_annotations.csv', clonotypes_filename: str = 'clonotypes.csv', verbose: bool = True) -> pd.DataFrame
Load CellRanger VDJ output files.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vdj_dir
|
str or Path
|
Path to CellRanger VDJ output directory |
required |
sample_name
|
str
|
Name to assign to this sample |
required |
annotations_filename
|
str
|
Name of the contig annotations CSV file |
'filtered_contig_annotations.csv'
|
clonotypes_filename
|
str
|
Name of the clonotypes CSV file |
'clonotypes.csv'
|
verbose
|
bool
|
Print progress information |
True
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
DataFrame with VDJ annotations for all cells |
Source code in tcrsift/loader.py
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 | |
load_cellranger_gex ¶
load_cellranger_gex(gex_dir: str | Path, sample_name: str, min_genes: int = 250, max_genes: int = 15000, min_counts: int = 500, max_counts: int = 100000, max_mito_pct: float = 8.0, min_mito_pct: float = 2.0, verbose: bool = True) -> ad.AnnData
Load CellRanger gene expression output.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gex_dir
|
str or Path
|
Path to CellRanger count output directory |
required |
sample_name
|
str
|
Name to assign to this sample |
required |
min_genes
|
int
|
Minimum genes detected per cell |
250
|
max_genes
|
int
|
Maximum genes detected per cell |
15000
|
min_counts
|
int
|
Minimum UMI counts per cell |
500
|
max_counts
|
int
|
Maximum UMI counts per cell |
100000
|
max_mito_pct
|
float
|
Maximum mitochondrial percentage |
8.0
|
min_mito_pct
|
float
|
Minimum mitochondrial percentage |
2.0
|
verbose
|
bool
|
Print progress information |
True
|
Returns:
| Type | Description |
|---|---|
AnnData
|
AnnData object with gene expression data |
Source code in tcrsift/loader.py
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 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 | |
load_sample ¶
load_sample(sample: Sample, min_genes: int = 250, max_genes: int = 15000, min_counts: int = 500, max_counts: int = 100000, max_mito_pct: float = 8.0, min_mito_pct: float = 2.0) -> ad.AnnData | None
Load all data for a single sample.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sample
|
Sample
|
Sample object with paths and metadata |
required |
min_genes
|
int
|
QC filter parameters for GEX data |
250
|
max_genes
|
int
|
QC filter parameters for GEX data |
250
|
min_counts
|
int
|
QC filter parameters for GEX data |
250
|
max_counts
|
int
|
QC filter parameters for GEX data |
250
|
max_mito_pct
|
int
|
QC filter parameters for GEX data |
250
|
min_mito_pct
|
int
|
QC filter parameters for GEX data |
250
|
Returns:
| Type | Description |
|---|---|
AnnData or None
|
Combined AnnData with GEX and VDJ data, or None if sample has neither gex_dir nor vdj_dir. |
Source code in tcrsift/loader.py
540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 | |
load_samples ¶
load_samples(sample_sheet_path: str | Path | SampleSheet, min_genes: int = 250, max_genes: int = 15000, min_counts: int = 500, max_counts: int = 100000, max_mito_pct: float = 8.0, min_mito_pct: float = 2.0, verbose: bool = True, show_progress: bool = True, tmpdir: str | Path | None = None) -> ad.AnnData
Load all samples from a sample sheet into a single AnnData object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sample_sheet_path
|
str or Path or SampleSheet
|
Path to sample sheet (CSV or YAML), or a SampleSheet instance. |
required |
min_genes
|
int
|
QC filter parameters. |
250
|
max_genes
|
int
|
QC filter parameters. |
250
|
min_counts
|
int
|
QC filter parameters. |
250
|
max_counts
|
int
|
QC filter parameters. |
250
|
max_mito_pct
|
int
|
QC filter parameters. |
250
|
min_mito_pct
|
int
|
QC filter parameters. |
250
|
verbose
|
bool
|
Print detailed progress information. |
True
|
show_progress
|
bool
|
Show progress bar. |
True
|
tmpdir
|
str or Path or None
|
Parent directory for the spill tempdir (see Notes). Defaults to the system temp location ($TMPDIR / /tmp). Pass an explicit disk-backed directory when the system temp is on tmpfs. |
None
|
Returns:
| Type | Description |
|---|---|
AnnData
|
Combined AnnData with all samples. |
Notes
Memory: each per-sample AnnData is spilled to a tempfile h5ad after
load and the in-memory copy is freed, then merged with
anndata.experimental.concat_on_disk, which streams inputs and output
in bounded chunks (~400 MB default). The merged file is read back into
memory once. Peak memory ≈ max(one sample, output), versus the prior
in-memory ad.concat peak of ~2 × Σ(samples).
Temp disk: spilled per-sample h5ads plus the merged output, so ~2× the
total sparse dataset size. Redirect with tmpdir= when $TMPDIR is on
tmpfs.
VDJ-only samples: see _ensure_x — a zero-column placeholder is
synthesized to keep the merge path uniform, then stripped after the
merge so combined.X is None for VDJ-only loads.
Source code in tcrsift/loader.py
646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 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 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 | |