Fragments
chromatinhd.data.fragments.Fragments
Bases: Flow
Fragments positioned within regions. Fragments are sorted by the region, position within the region (left cut site) and cell.
The object can also store several precalculated tensors that are used for efficient loading of fragments. See create_regionxcell_indptr for more information.
Source code in src/chromatinhd/data/fragments/fragments.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 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 179 180 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 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 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 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 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 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 |
|
coordinates: TensorstoreInstance = Tensorstore(dtype='<i4', chunks=[100000, 2], compression=None, shape=[0, 2])
class-attribute
instance-attribute
Coordinates of the two cut sites.
counts
property
Counts of fragments per cell x region
mapping: TensorstoreInstance = Tensorstore(dtype='<i4', chunks=[100000, 2], compression='blosc', shape=[0, 2])
class-attribute
instance-attribute
Mapping of a fragment to a cell (first column) and a region (second column)
n_cells
cached
property
Number of cells
n_regions
cached
property
Number of regions
obs: pd.DataFrame = TSV()
class-attribute
instance-attribute
DataFrame containing information about cells.
regions: Regions = Linked()
class-attribute
instance-attribute
The regions in which (part of) the fragments are located and centered.
regionxcell_indptr: np.ndarray = Tensorstore(dtype='<i8', chunks=[100000], compression='blosc')
class-attribute
instance-attribute
Index pointers to the regionxcell fragment positions
var: pd.DataFrame = TSV()
class-attribute
instance-attribute
DataFrame containing information about regions.
create_regionxcell_indptr(overwrite=False)
Creates pointers to each individual region x cell combination from the mapping tensor.
Returns:
Type | Description |
---|---|
Fragments
|
The same object with |
Source code in src/chromatinhd/data/fragments/fragments.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
|
filter_cells(cells, path=None)
Filter based on new cells
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cells
|
Cells to filter. |
required |
Returns: A new Fragments object
Source code in src/chromatinhd/data/fragments/fragments.py
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 |
|
filter_regions(regions, path=None, overwrite=True)
Filter based on new regions
Parameters:
Name | Type | Description | Default |
---|---|---|---|
regions
|
Regions
|
Regions to filter. |
required |
Returns: A new Fragments object
Source code in src/chromatinhd/data/fragments/fragments.py
537 538 539 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 |
|
from_alignments(obs, regions, file_column='path', alignment_column=None, remove_duplicates=None, path=None, overwrite=False, reuse=True, batch_size=10000000.0, paired=True)
Create a Fragments object from multiple alignment (bam/sam) files, each pertaining to a single cell or sample
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obs
|
DataFrame
|
DataFrame containing information about cells/samples. The index will be used as the name of the cell for future reference. The DataFrame should contain a column with the path to the alignment file (specified in the file_column) or a column with the alignment object itself (specified in the alignment_column). Any additional data about cells/samples can be stored in this dataframe as well. |
required |
regions
|
Regions
|
Regions from which the fragments will be extracted. |
required |
file_column
|
str
|
Column name in the |
'path'
|
alignment_column
|
str
|
Column name in the |
None
|
remove_duplicates
|
bool
|
Whether to remove duplicate fragments within a sample or cell. This is commonly done for single-cell data, but not necessarily for bulk data. If the data is paired, duplicates will be removed by default. If the data is single-end, duplicates will not be removed by default. |
None
|
path
|
PathLike
|
Folder in which the fragments data will be stored. |
None
|
overwrite
|
bool
|
Whether to overwrite the data if it already exists. |
False
|
reuse
|
bool
|
Whether to reuse existing data if it exists. |
True
|
batch_size
|
int
|
Number of fragments to process before saving. Lower this number if you run out of memory. Increase the number if you want to speed up the process, particularly if disk I/O is slow. |
10000000.0
|
paired
|
bool
|
Whether the reads are paired-end or single-end. If paired, the coordinates of the two cut sites will be stored. If single-end, only the coordinate of only one cut site will be stored. Note that this also affects the default value of |
True
|
Source code in src/chromatinhd/data/fragments/fragments.py
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 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 |
|
from_fragments_tsv(fragments_file, regions, obs, cell_column=None, path=None, overwrite=False, reuse=True, batch_size=1000000.0)
Create a Fragments object from a fragments tsv file
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fragments_file
|
PathLike
|
Location of the fragments tab-separate file created by e.g. CellRanger or sinto |
required |
obs
|
DataFrame
|
DataFrame containing information about cells.
The index should be the cell names as present in the fragments file.
Alternatively, the column containing cell ids can be specified using the |
required |
regions
|
Regions
|
Regions from which the fragments will be extracted. |
required |
cell_column
|
str
|
Column name in the |
None
|
path
|
PathLike
|
Folder in which the fragments data will be stored. |
None
|
overwrite
|
bool
|
Whether to overwrite the data if it already exists. |
False
|
reuse
|
bool
|
Whether to reuse existing data if it exists. |
True
|
batch_size
|
int
|
Number of fragments to process before saving. Lower this number if you run out of memory. |
1000000.0
|
Returns: A new Fragments object
Source code in src/chromatinhd/data/fragments/fragments.py
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 179 180 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 |
|
from_multiple_fragments_tsv(fragments_files, regions, obs, cell_column='cell_original', batch_column='batch', path=None, overwrite=False, reuse=True, batch_size=1000000.0)
Create a Fragments object from multiple fragments tsv file
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fragments_files
|
[PathLike]
|
Location of the fragments tab-separate file created by e.g. CellRanger or sinto |
required |
obs
|
DataFrame
|
DataFrame containing information about cells.
The index should be the cell names as present in the fragments file.
Alternatively, the column containing cell ids can be specified using the |
required |
regions
|
Regions
|
Regions from which the fragments will be extracted. |
required |
cell_column
|
str
|
Column name in the |
'cell_original'
|
batch_column
|
str
|
Column name in the |
'batch'
|
path
|
PathLike
|
Folder in which the fragments data will be stored. |
None
|
overwrite
|
bool
|
Whether to overwrite the data if it already exists. |
False
|
reuse
|
bool
|
Whether to reuse existing data if it exists. |
True
|
batch_size
|
int
|
Number of fragments to process before saving. Lower this number if you run out of memory. |
1000000.0
|
Returns: A new Fragments object
Source code in src/chromatinhd/data/fragments/fragments.py
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 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 |
|
chromatinhd.data.fragments.FragmentsView
Bases: Flow
A view of fragments based on regions that are a subset of the parent fragments. In a typical use case, the parent contains fragments for all chromosomes, while this the view focuses on specific regions.
Only fragments that are fully inclusive (i.e., both left and right cut sites) within a region will be selected.
Source code in src/chromatinhd/data/fragments/view.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 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 179 180 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 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 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 |
|
coordinates
property
Coordinates of the fragments, equal to the parent coordinates
counts
property
Number of fragments per region and cell
mapping
property
Mapping of the fragments, equal to the parent mapping
n_cells
cached
property
Number of cells
n_regions
cached
property
Number of regions
obs: pd.DataFrame = TSV()
class-attribute
instance-attribute
DataFrame containing information about cells.
parent: Fragments = Linked()
class-attribute
instance-attribute
The parent fragments object from which this view is created
regions: Regions = Linked()
class-attribute
instance-attribute
The regions object
regionxcell_indptr: TensorstoreInstance = Tensorstore(dtype='<i8', chunks=[100000], compression='blosc', shape=(0, 2))
class-attribute
instance-attribute
Index of fragments in the parent fragments object
var: pd.DataFrame = TSV()
class-attribute
instance-attribute
DataFrame containing information about regions.
create_regionxcell_indptr(inclusive=(True, False), overwrite=True)
Create index pointers (left and right) for the fragments associated to each regionxcell combination
Parameters:
Name | Type | Description | Default |
---|---|---|---|
batch_size
|
Number of regions to wait before saving the intermediate results and freeing up memory. Reduce this number to avoid running out of memory. |
required | |
inclusive
|
tuple
|
Whether to only include fragments that are only partially overlapping with the region. Must be a tuple indicating left and/or right inclusivity. |
(True, False)
|
overwrite
|
Whether to overwrite the existing index pointers. |
True
|
Returns:
Type | Description |
---|---|
FragmentsView
|
Same object but with the |
Source code in src/chromatinhd/data/fragments/view.py
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 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
|
create_regionxcell_indptr2(inclusive=(True, False), overwrite=True)
Create index pointers (left and right) for the fragments associated to each regionxcell combination. This implementation is faster if there are many samples with a lot of fragments (e.g. minibulk data)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
batch_size
|
Number of regions to wait before saving the intermediate results and freeing up memory. Reduce this number to avoid running out of memory. |
required | |
inclusive
|
tuple
|
Whether to only include fragments that are only partially overlapping with the region. Must be a tuple indicating left and/or right inclusivity. |
(True, False)
|
overwrite
|
Whether to overwrite the existing index pointers. |
True
|
Returns:
Type | Description |
---|---|
FragmentsView
|
Same object but with the |
Source code in src/chromatinhd/data/fragments/view.py
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 |
|
estimate_fragment_per_cellxregion()
Estimate the expected number of fragments per regionxcell combination. This is used to estimate the buffer size for loading fragments.
Source code in src/chromatinhd/data/fragments/view.py
339 340 341 342 343 |
|
filter_regions(regions, path=None, overwrite=True)
Filter based on new regions
Parameters:
Name | Type | Description | Default |
---|---|---|---|
regions
|
Regions
|
Regions to filter. |
required |
Returns: A new Fragments object
Source code in src/chromatinhd/data/fragments/view.py
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 |
|
from_fragments(parent, regions, parentregion_column='chrom', obs=None, var=None, path=None, overwrite=False)
classmethod
Creates a fragments view from a parent fragments object and a regions object
Parameters:
Name | Type | Description | Default |
---|---|---|---|
parent
|
Fragments
|
Parent fragments object. If a fragments view is provided, the parent of the parent will be used. |
required |
regions
|
Regions
|
Regions object |
required |
obs
|
DataFrame
|
DataFrame containing information about cells, will be copied from the fragments object if not provided |
None
|
parentregion_column
|
str
|
Column in the regions coordinates that links each new region to the regions of the original fragments. This is typically the chromosome column. This column should be present in both |
'chrom'
|
path
|
PathLike
|
Path to store the fragments view |
None
|
Source code in src/chromatinhd/data/fragments/view.py
36 37 38 39 40 41 42 43 44 45 46 47 48 49 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 |
|
get_cache(region_oi)
Get the cache for a specific region
Source code in src/chromatinhd/data/fragments/view.py
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 |
|