-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Methods to split
GenomicRanges
to GenomicRangesList
and vice-versa (
#109) - Method to split `GenomicRanges` by a list of groups. - Coerce `GenomicRangesList` to `GenomicRanges`. - Add tests and documentation.
- Loading branch information
Showing
5 changed files
with
174 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import pytest | ||
import pandas as pd | ||
import numpy as np | ||
from genomicranges import GenomicRanges, GenomicRangesList | ||
from biocframe import BiocFrame | ||
from iranges import IRanges | ||
from random import random | ||
import genomicranges | ||
|
||
__author__ = "jkanche" | ||
__copyright__ = "jkanche" | ||
__license__ = "MIT" | ||
|
||
subject = GenomicRanges( | ||
seqnames=[ | ||
"chr1", | ||
"chr2", | ||
"chr2", | ||
"chr2", | ||
"chr1", | ||
"chr1", | ||
"chr3", | ||
"chr3", | ||
"chr3", | ||
"chr3", | ||
], | ||
ranges=IRanges(range(101, 111), range(121, 131)), | ||
strand=["*", "-", "-", "*", "*", "+", "+", "+", "-", "-"], | ||
mcols=BiocFrame( | ||
{ | ||
"score": range(0, 10), | ||
"GC": [random() for _ in range(10)], | ||
} | ||
), | ||
) | ||
|
||
|
||
def test_split(): | ||
assert subject is not None | ||
|
||
splits = subject.split( | ||
[ | ||
"chr1", | ||
"chr2", | ||
"chr2", | ||
"chr2", | ||
"chr1", | ||
"chr1", | ||
"chr3", | ||
"chr3", | ||
"chr3", | ||
"chr3", | ||
] | ||
) | ||
|
||
assert splits is not None | ||
assert isinstance(splits, GenomicRangesList) | ||
assert len(splits) == 3 | ||
print(splits.element_nrows()) | ||
assert sum(splits.get_range_lengths()) == len(subject) | ||
|
||
|
||
def test_to_granges(): | ||
assert subject is not None | ||
|
||
splits = subject.split( | ||
[ | ||
"chr1", | ||
"chr2", | ||
"chr2", | ||
"chr2", | ||
"chr1", | ||
"chr1", | ||
"chr3", | ||
"chr3", | ||
"chr3", | ||
"chr3", | ||
] | ||
) | ||
|
||
roundtrip = splits.to_genomic_ranges() | ||
|
||
assert roundtrip is not None | ||
assert isinstance(roundtrip, GenomicRanges) | ||
assert len(roundtrip) == len(subject) |