Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_read_bed():
pr.read_bed("pyranges/example_data/chipseq.bed")
def test_read_bed():
pr.read_bed("pyranges/example_data/chipseq.bed")
def test_pyranges_to_intervals():
pranges = pyranges.read_gtf(gtf_file)
intervals = list(pyranges_to_intervals(pranges, interval_attrs=[
'gene_id', 'gene_name', 'transcript_id', 'exon_id']))
assert len(intervals) == 5
assert intervals[4].attrs['gene_id'] == 'ENSG00000012048'
assert intervals[4].attrs['gene_name'] == 'BRCA1'
assert intervals[4].attrs['transcript_id'] == 'ENST00000357654'
assert intervals[4].attrs['exon_id'] == 'ENSE00003510592'
pranges = pyranges.read_bed(example_intervals_bed)
intervals = list(pyranges_to_intervals(pranges))
assert len(intervals) == 4
assert intervals[0].start == 2
assert pranges.Chromosome.tolist() == ['chr1'] * 4
assert pranges.Start.tolist() == [2, 2, 2, 602]
assert pranges.End.tolist() == [1000, 5000, 1002, 604]
>>> # | chr2 | 0 | 243199373 |
>>> # | chr3 | 0 | 198022430 |
>>> # | chr4 | 0 | 191154276 |
>>> # | ... | ... | ... |
>>> # | chrY | 0 | 59373566 |
>>> # | chrX | 0 | 155270560 |
>>> # | chrM | 0 | 16571 |
>>> # | chr22 | 0 | 51304566 |
>>> # +--------------+-----------+-----------+
>>> # Unstranded PyRanges object has 25 rows and 3 columns from 25 chromosomes.
>>> # For printing, the PyRanges was sorted on Chromosome.
"""
full_path = get_example_path("chromsizes.bed")
return pr.read_bed(full_path)
>>> # | chrX | 135574120 | 135574598 | NM_001727_exon_2_0_chrX_135574121_f | 0 | + |
>>> # | chrX | 47868945 | 47869126 | NM_205856_exon_4_0_chrX_47868946_f | 0 | + |
>>> # | chrX | 77294333 | 77294480 | NM_000052_exon_17_0_chrX_77294334_f | 0 | + |
>>> # | ... | ... | ... | ... | ... | ... |
>>> # | chrY | 15409586 | 15409728 | NR_047633_exon_3_0_chrY_15409587_r | 0 | - |
>>> # | chrY | 15478146 | 15478273 | NR_047634_exon_18_0_chrY_15478147_r | 0 | - |
>>> # | chrY | 15360258 | 15361762 | NR_047601_exon_0_0_chrY_15360259_r | 0 | - |
>>> # | chrY | 15467254 | 15467278 | NM_001258270_exon_13_0_chrY_15467255_r | 0 | - |
>>> # +--------------+-----------+-----------+----------------------------------------+-----------+--------------+
>>> # Stranded PyRanges object has 1,000 rows and 6 columns from 2 chromosomes.
>>> # For printing, the PyRanges was sorted on Chromosome and Strand.
"""
full_path = get_example_path("exons.bed")
return pr.read_bed(full_path)
>>> # | chr1 | 9953 | 10152 | H3K27me3 | 5 | + |
>>> # | chr1 | 10024 | 10223 | H3K27me3 | 1 | + |
>>> # | chr1 | 10246 | 10445 | H3K27me3 | 4 | + |
>>> # | ... | ... | ... | ... | ... | ... |
>>> # | chr1 | 9978 | 10177 | H3K27me3 | 7 | - |
>>> # | chr1 | 10001 | 10200 | H3K27me3 | 5 | - |
>>> # | chr1 | 10127 | 10326 | H3K27me3 | 1 | - |
>>> # | chr1 | 10241 | 10440 | H3K27me3 | 6 | - |
>>> # +--------------+-----------+-----------+------------+-----------+--------------+
>>> # Stranded PyRanges object has 11 rows and 6 columns from 1 chromosomes.
>>> # For printing, the PyRanges was sorted on Chromosome and Strand.
"""
full_path = get_example_path("aorta.bed")
return pr.read_bed(full_path)
>>> # | chr1 | 169887529 | 169887554 | U0 | 0 | + |
>>> # | chr1 | 216711011 | 216711036 | U0 | 0 | + |
>>> # | chr1 | 144227079 | 144227104 | U0 | 0 | + |
>>> # | ... | ... | ... | ... | ... | ... |
>>> # | chrY | 15224235 | 15224260 | U0 | 0 | - |
>>> # | chrY | 13517892 | 13517917 | U0 | 0 | - |
>>> # | chrY | 8010951 | 8010976 | U0 | 0 | - |
>>> # | chrY | 7405376 | 7405401 | U0 | 0 | - |
>>> # +--------------+-----------+-----------+------------+-----------+--------------+
>>> # Stranded PyRanges object has 10,000 rows and 6 columns from 24 chromosomes.
>>> # For printing, the PyRanges was sorted on Chromosome and Strand.
"""
full_path = get_example_path("chipseq.bed")
return pr.read_bed(full_path)
def _read_intervals(gtf_path=None, bed_path=None, pranges=None,
intervals=None, interval_attrs=None, duplicate_attr=False):
alternatives = [bed_path, pranges, intervals, gtf_path]
if sum(i is not None for i in alternatives) != 1:
raise ValueError('only one of `gth_path`, `bed_path`, `pranges`,'
'`intervals` or should given as input.')
if gtf_path:
import pyranges
pranges = pyranges.read_gtf(gtf_path, duplicate_attr=duplicate_attr)
elif bed_path:
import pyranges
pranges = pyranges.read_bed(bed_path)
elif intervals:
if interval_attrs is not None:
raise ValueError(
'`interval_attrs` is not valid with `intervals`')
pranges = intervals_to_pyranges(intervals)
pranges.intervals = intervals
return pranges