filter
CCSliceFilter
¶
Bases: SliceFilter
Perform Capture-C slice filtering (inplace) and reporter identification.
SliceFilter tuned specifically for Capture-C data. This class has addtional methods to remove common artifacts in Capture-C data i.e. multi-capture fragments, non-reporter fragments, multi-capture reporters. The default filter order is as follows:
- remove_unmapped_slices
- remove_orphan_slices
- remove_multi_capture_fragments
- remove_excluded_slices
- remove_blacklisted_slices
- remove_non_reporter_fragments
- remove_viewpoint_adjacent_restriction_fragments
- remove_slices_without_re_frag_assigned
- remove_duplicate_re_frags
- remove_duplicate_slices
- remove_duplicate_slices_pe
- remove_non_reporter_fragments
See the individual methods for further details.
Attributes:
Name | Type | Description |
---|---|---|
slices |
DataFrame
|
Annotated slices dataframe. |
fragments |
DataFrame
|
Slices dataframe aggregated by parental read. |
reporters |
DataFrame
|
Slices identified as reporters. |
filter_stages |
dict
|
Dictionary containg stages and a list of class methods (str) required to get to this stage. |
slice_stats |
DataFrame
|
Provides slice level statistics. |
read_stats |
DataFrame
|
Provides statistics of slice filtering at the parental read level. |
filter_stats |
DataFrame
|
Provides statistics of read filtering. |
Source code in capcruncher/api/filter.py
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 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 |
|
capture_site_stats: pd.Series
property
¶
Extracts the number of unique capture sites.
captures: pd.DataFrame
property
¶
Extracts capture slices from slices dataframe
i.e. slices that do not have a null capture name
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame: Capture slices |
cis_or_trans_stats: pd.DataFrame
property
¶
Extracts reporter cis/trans statistics from slices.
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame: Reporter cis/trans statistics |
frag_stats: pd.DataFrame
property
¶
Statistics aggregated at the fragment level.
As this involves slice aggregation it can be rather slow for large datasets. It is recomended to only use this property if it is required.
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame: Fragment level statistics |
fragments: pd.DataFrame
property
¶
Summarises slices at the fragment level.
Uses pandas groupby to aggregate slices by their parental read name (shared by all slices from the same fragment). Also determines the number of reporter slices for each fragment.
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame: Slices aggregated by parental read name. |
merged_captures_and_reporters: pd.DataFrame
property
¶
Merges captures and reporters sharing the same parental id.
Capture slices and reporter slices with the same parental read id are merged together. The prefixes 'capture' and 'reporter' are used to identify slices marked as either captures or reporters.
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame: Merged capture and reporter slices |
remove_multi_capture_fragments()
¶
Removes double capture fragments.
All slices (i.e. the entire fragment) are removed if more than one capture probe is present i.e. a double capture (V. Common)
Source code in capcruncher/api/filter.py
719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 |
|
remove_non_reporter_fragments()
¶
Removes the fragment if it has no reporter slices present (Common)
Source code in capcruncher/api/filter.py
697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 |
|
remove_viewpoint_adjacent_restriction_fragments(n_adjacent=1)
¶
Deals with an odd situation in which a reporter spanning two adjacent capture sites is not removed.
Example
------Capture 1----/------Capture 2------ -----REP--------
In this case the "reporter" slice is not considered either a capture or exclusion.
These cases are dealt with by explicitly removing reporters on restriction fragments adjacent to capture sites.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n_adjacent |
int
|
Number of adjacent restriction fragments to remove |
1
|
Source code in capcruncher/api/filter.py
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 |
|
SliceFilter
¶
Perform slice filtering (inplace) and reporter identification.
The SliceFilter classes e.g. CCSliceFilter, TriCSliceFilter, TiledCSliceFilter perform all of the filtering (inplace) and reporter identification whilst also providing statistics of the numbers of slices/reads removed at each stage.
Attributes:
Name | Type | Description |
---|---|---|
slices |
DataFrame
|
Annotated slices dataframe. |
fragments |
DataFrame
|
Slices dataframe aggregated by parental read. |
reporters |
DataFrame
|
Slices identified as reporters. |
filter_stages |
dict
|
Dictionary containg stages and a list of class methods (str) required to get to this stage. |
slice_stats |
DataFrame
|
Provides slice level statistics. |
read_stats |
DataFrame
|
Provides statistics of slice filtering at the parental read level. |
filter_stats |
DataFrame
|
Provides statistics of read filtering. |
Source code in capcruncher/api/filter.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 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 |
|
filter_stats: pd.DataFrame
property
¶
Statistics for each filter stage.
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame: Statistics of the number of slices removed at each stage. |
filters: list
property
¶
A list of the callable filters present within the slice filterer instance.
Returns:
Name | Type | Description |
---|---|---|
list |
list
|
All filters present in the class. |
fragments: pd.DataFrame
property
¶
Summarises slices at the fragment level.
Uses pandas groupby to aggregate slices by their parental read name (shared by all slices from the same fragment). Also determines the number of reporter slices for each fragment.
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame: Slices aggregated by parental read name. |
read_stats: pd.DataFrame
property
¶
Gets statistics at a read level.
Aggregates slices by parental read id and calculates stats.
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame: Statistics of the slices/fragments removed aggregated by read id. |
reporters: pd.DataFrame
property
¶
Extracts reporter slices from slices dataframe i.e. non-capture slices
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame: All non-capture slices |
slice_stats: pd.DataFrame
property
¶
Statistics at the slice level.
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame: Statistics per slice. |
__init__(slices, filter_stages=None, sample_name='', read_type='')
¶
Base for all slice filter objects.
Slices DataFrame must have the following columns:
- slice_name: Unique aligned read identifier (e.g. XZKG:889:11|flashed|1)
- parent_read: Identifier shared by slices from same fragment (e.g.XZKG:889:11)
- pe: Read combined by FLASh or not (i.e. "flashed" or "pe")
- mapped: Alignment is mapped (e.g. 0/1)
- multimapped: Alignment is mapped (e.g. 0/1)
- slice: Slice number (e.g. 0)
- chrom: Chromosome e.g. chr1
- start: Start coord
- end: End coord
- capture: Capture site intersecting slice (e.g. Slc25A37)
- capture_count: Number of capture probes overlapping slice (e.g. 1)
- exclusion: Read present in excluded region (e.g. Slc25A37)
- exclusion_count: Number of excluded regions overlapping slice (e.g. 1)
- blacklist: Read present in excluded region (e.g. 0)
- coordinates: Genome coordinates (e.g. chr1:1000-2000)
Filtering to be performed can be left as the default (all start with 'remove') or a custom filtering order can be supplied with a yaml file. This must have the format:
FILTER_STAGE_NAME: - FILTER 1 - FILTER 2 FILTER_STAGE_NAME2: - FILTER 3 - FILTER 1
All filters present in the file must be defined within the SliceFilter class.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
slices |
DataFrame
|
DatFrame containing annotated slices |
required |
filter_stages |
dict
|
Dictionary defining order of slice filtering. Defaults to None. |
None
|
sample_name |
str
|
Name of sample being processed e.g. DOX-treated_1. Defaults to "". |
''
|
read_type |
str
|
Combined (flashed) or not-combined (pe). Defaults to "". |
''
|
Raises:
Type | Description |
---|---|
ValueError
|
Filter stages must be provided. This is done automatically by all subclasses |
AttributeError
|
All filters must be defined in the SliceFilter. |
Source code in capcruncher/api/filter.py
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 |
|
filter_slices(output_slices=False, output_location='.')
¶
Performs slice filtering.
Filters are applied to the slices dataframe in the order specified by filter_stages. Filtering stats aggregated at the slice and fragment level are also printed.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
output_slices |
bool
|
Determines if slices are to be output to a specified location after each filtering step. Useful for debugging. Defaults to False. |
False
|
output_location |
str
|
Location to output slices at each stage. Defaults to ".". |
'.'
|
Source code in capcruncher/api/filter.py
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 |
|
get_unfiltered_slices()
¶
Does not modify slices.
Source code in capcruncher/api/filter.py
298 299 300 301 302 |
|
remove_blacklisted_slices()
¶
Removes slices marked as being within blacklisted regions
Source code in capcruncher/api/filter.py
422 423 424 425 426 |
|
remove_duplicate_re_frags()
¶
Prevent the same restriction fragment being counted more than once (Uncommon).
Example:
--RE_FRAG1------Capture-------RE_FRAG1----
Source code in capcruncher/api/filter.py
322 323 324 325 326 327 328 329 330 331 332 333 |
|
remove_duplicate_slices()
¶
Remove all slices if the slice coordinates and slice order are shared.
This method is designed to remove a fragment if it is a PCR duplicate (Common).
Example:
| Frag 1: chr1:1000-1250 chr1:1500-1750 | Frag 2: chr1:1000-1250 chr1:1500-1750 | Frag 3: chr1:1050-1275 chr1:1600-1755 | Frag 4: chr1:1500-1750 chr1:1000-1250
Frag 2 removed. Frag 1,3,4 retained
Source code in capcruncher/api/filter.py
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 |
|
remove_duplicate_slices_pe()
¶
Removes PCR duplicates from non-flashed (PE) fragments (Common).
Sequence quality is often lower at the 3' end of reads leading to variance in mapping coordinates. PCR duplicates are removed by checking that the fragment start and end are not duplicated in the dataframe.
Source code in capcruncher/api/filter.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 404 405 406 407 |
|
remove_excluded_slices()
¶
Removes any slices in the exclusion region (default 1kb) (V. Common)
Source code in capcruncher/api/filter.py
409 410 411 412 413 414 415 416 417 418 419 420 |
|
remove_orphan_slices()
¶
Remove fragments with only one aligned slice (Common)
Source code in capcruncher/api/filter.py
310 311 312 313 314 315 316 317 318 319 320 |
|
remove_slices_without_re_frag_assigned()
¶
Removes slices if restriction_fragment column is N/A
Source code in capcruncher/api/filter.py
335 336 337 |
|
remove_unmapped_slices()
¶
Removes slices marked as unmapped (Uncommon)
Source code in capcruncher/api/filter.py
304 305 306 307 308 |
|
TiledCSliceFilter
¶
Bases: SliceFilter
Perform Tiled-C slice filtering (inplace) and reporter identification.
SliceFilter tuned specifically for Tiled-C data. This class has addtional methods to remove common artifacts in Tiled-C data i.e. non-capture fragments, multi-capture (with different tiled regions) fragments. A reporter is defined differently in a Tiled-C analysis as a reporter slice can also be a capture slice.
The default filter order is as follows:
- remove_unmapped_slices
- remove_orphan_slices
- remove_blacklisted_slices
- remove_non_capture_fragments
- remove_dual_capture_fragments
- remove_slices_without_re_frag_assigned
- remove_duplicate_re_frags
- remove_duplicate_slices
- remove_duplicate_slices_pe
- remove_orphan_slices
See the individual methods for further details.
Attributes:
Name | Type | Description |
---|---|---|
slices |
DataFrame
|
Annotated slices dataframe. |
fragments |
DataFrame
|
Slices dataframe aggregated by parental read. |
reporters |
DataFrame
|
Slices identified as reporters. |
filter_stages |
dict
|
Dictionary containg stages and a list of class methods (str) required to get to this stage. |
slice_stats |
DataFrame
|
Provides slice level statistics. |
read_stats |
DataFrame
|
Provides statistics of slice filtering at the parental read level. |
filter_stats |
DataFrame
|
Provides statistics of read filtering. |
Source code in capcruncher/api/filter.py
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 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 |
|
captures: pd.DataFrame
property
¶
Extracts capture slices from slices dataframe
i.e. slices that do not have a null capture name
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame: Capture slices |
cis_or_trans_stats: pd.DataFrame
property
¶
Extracts reporter cis/trans statistics from slices.
Unlike Capture-C/Tri-C reporter slice can also be capture slices as all slices within the capture region are considered as reporters. To extract cis/trans statistics, one capture slice in each fragment is considered to be the "primary capture" this then enables merging of this "primary capture" with the other reporters both inside and outside of the tiled region.
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame: Reporter cis/trans statistics |
remove_dual_capture_fragments()
¶
Removes a fragment with multiple different capture sites.
Modified for TiledC filtering as the fragment dataframe is generated slightly differently.
Source code in capcruncher/api/filter.py
1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 |
|
remove_non_capture_fragments()
¶
Removes fragments without a capture assigned
Source code in capcruncher/api/filter.py
1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 |
|
remove_slices_outside_capture()
¶
Removes slices outside of capture region(s)
Source code in capcruncher/api/filter.py
1047 1048 1049 |
|
TriCSliceFilter
¶
Bases: CCSliceFilter
Perform Tri-C slice filtering (inplace) and reporter identification.
SliceFilter tuned specifically for Tri-C data. Whilst the vast majority of filters are inherited from CCSliceFilter, this class has addtional methods for Tri-C analysis i.e. remove_slices_with_one_reporter. The default filtering order is:
- remove_unmapped_slices
- remove_slices_without_re_frag_assigned
- remove_orphan_slices
- remove_multi_capture_fragments
- remove_blacklisted_slices
- remove_non_reporter_fragments
- remove_viewpoint_adjacent_restriction_fragments
- remove_duplicate_re_frags
- remove_duplicate_slices
- remove_duplicate_slices_pe
- remove_non_reporter_fragments
- remove_slices_with_one_reporter
See the individual methods for further details.
Attributes:
Name | Type | Description |
---|---|---|
slices |
DataFrame
|
Annotated slices dataframe. |
fragments |
DataFrame
|
Slices dataframe aggregated by parental read. |
reporters |
DataFrame
|
Slices identified as reporters. |
filter_stages |
dict
|
Dictionary containg stages and a list of class methods (str) required to get to this stage. |
slice_stats |
DataFrame
|
Provides slice level statistics. |
read_stats |
DataFrame
|
Provides statistics of slice filtering at the parental read level. |
filter_stats |
DataFrame
|
Provides statistics of read filtering. |
Source code in capcruncher/api/filter.py
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 |
|
remove_slices_with_one_reporter()
¶
Removes fragments if they do not contain at least two reporters.
Source code in capcruncher/api/filter.py
856 857 858 859 860 861 |
|