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_more_columns(tmpdir):
bed_file = write_tmp(
'chr1\t1\t2\tinterval1\t1\t0\nchr2\t1\t3\tinterval2\t0\t1', tmpdir)
with pytest.raises(Exception):
bt = BedDataset(bed_file, label_dtype=bool)
bt = BedDataset(bed_file, bed_columns=4, label_dtype=bool)
assert bt[0][0].name == 'interval1'
assert bt[1][0].name == 'interval2'
with pytest.raises(Exception):
bt = BedDataset(bed_file)
def test_ambiguous_mask(tmpdir):
bed_file = write_tmp(
'chr1\t1\t2\t1\t0\nchr2\t1\t3\t0\t1\nchr3\t1\t3\t0\t-1', tmpdir)
bt = BedDataset(bed_file)
assert len(bt) == 3
assert np.all(bt[2][1] == np.array([0, -1]))
# same as before
bt = BedDataset(bed_file, ambiguous_mask=-1)
assert len(bt) == 3
assert np.all(bt[2][1] == np.array([0, -1]))
assert np.all(bt.get_targets().max(axis=1) >= 0)
def test_ambiguous_mask2(tmpdir):
# only ambigous regions are present
bed_file = write_tmp(
'chr1\t1\t2\t1\t0\nchr2\t1\t3\t0\t1\nchr3\t1\t3\t-1\t-1', tmpdir)
bt = BedDataset(bed_file, ambiguous_mask=-1)
assert len(bt) == 2
assert np.all(bt.get_targets().max(axis=1) >= 0)
def test_more_columns(tmpdir):
bed_file = write_tmp(
'chr1\t1\t2\tinterval1\t1\t0\nchr2\t1\t3\tinterval2\t0\t1', tmpdir)
with pytest.raises(Exception):
bt = BedDataset(bed_file, label_dtype=bool)
bt = BedDataset(bed_file, bed_columns=4, label_dtype=bool)
assert bt[0][0].name == 'interval1'
assert bt[1][0].name == 'interval2'
with pytest.raises(Exception):
bt = BedDataset(bed_file)
def test_more_columns(tmpdir):
bed_file = write_tmp(
'chr1\t1\t2\tinterval1\t1\t0\nchr2\t1\t3\tinterval2\t0\t1', tmpdir)
with pytest.raises(Exception):
bt = BedDataset(bed_file, label_dtype=bool)
bt = BedDataset(bed_file, bed_columns=4, label_dtype=bool)
assert bt[0][0].name == 'interval1'
assert bt[1][0].name == 'interval2'
with pytest.raises(Exception):
bt = BedDataset(bed_file)
def test_tsvreader(tsv_file, num_chr, label_dtype):
ds = BedDataset(tsv_file, label_dtype=label_dtype, num_chr=num_chr)
interval, labels = ds[0]
assert isinstance(interval, Interval)
if not num_chr:
assert interval.chrom.startswith("chr")
assert isinstance(labels[0], label_dtype)
assert interval.start == 2
assert interval.end == 4
def test_label_dtype(tmpdir):
bed_file = write_tmp('chr1\t1\t2\t1\t0\nchr2\t1\t3\t0\t1', tmpdir)
bt = BedDataset(bed_file, label_dtype=bool)
assert len(bt) == 2
assert bt[0][1].dtype == bool
assert bt.get_targets().dtype == bool
def test_num_chr(tmpdir):
bed_file = write_tmp(
'chr1\t1\t2\t1\t0\nchr2\t1\t3\t0\t1\nchr3\t1\t3\t0\t-1', tmpdir)
bt = BedDataset(bed_file, num_chr=True)
assert len(bt) == 3
assert bt[0][0].chrom == '1'
def test_incl_excl_chromosomes(tmpdir):
bed_file = write_tmp(
'chr1\t1\t2\t1\t0\nchr2\t1\t3\t0\t1\nchr3\t1\t3\t0\t1', tmpdir)
bt = BedDataset(bed_file)
assert len(bt) == 3
bt = BedDataset(bed_file, incl_chromosomes=['chr1'])
assert len(bt) == 1
assert bt[0][0] == Interval("chr1", 1, 2)
bt = BedDataset(bed_file, excl_chromosomes=['chr1'])
assert len(bt) == 2
assert bt[0][0] == Interval("chr2", 1, 3)
def test_incl_excl_chromosomes(tmpdir):
bed_file = write_tmp(
'chr1\t1\t2\t1\t0\nchr2\t1\t3\t0\t1\nchr3\t1\t3\t0\t1', tmpdir)
bt = BedDataset(bed_file)
assert len(bt) == 3
bt = BedDataset(bed_file, incl_chromosomes=['chr1'])
assert len(bt) == 1
assert bt[0][0] == Interval("chr1", 1, 2)
bt = BedDataset(bed_file, excl_chromosomes=['chr1'])
assert len(bt) == 2
assert bt[0][0] == Interval("chr2", 1, 3)