-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathtest_3_utils.py
More file actions
53 lines (39 loc) · 1.7 KB
/
test_3_utils.py
File metadata and controls
53 lines (39 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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
from conftest import vcf_file, sample_5kb_fasta_file, example_intervals_bed
import pytest
import numpy as np
import pyranges
from kipoiseq.extractors import FastaStringExtractor, MultiSampleVCF
from kipoiseq.utils import parse_alphabet, parse_dtype, \
compare_chrom_annotation
def test_parse_alphabet():
assert parse_alphabet(['A', 'C']) == ['A', 'C']
assert parse_alphabet('AC') == ['A', 'C']
def test_parse_type():
with pytest.raises(Exception):
parse_dtype('string')
with pytest.raises(Exception):
parse_dtype('np.float322')
assert parse_dtype('float') == float
assert parse_dtype(float) == float
assert parse_dtype("np.float32") == np.float32
def test_compare_chrom_annotation():
sources = [
MultiSampleVCF(vcf_file),
FastaStringExtractor(sample_5kb_fasta_file),
pyranges.read_bed(example_intervals_bed)
]
with pytest.raises(ValueError):
assert compare_chrom_annotation([])
with pytest.raises(ValueError):
assert compare_chrom_annotation([object()])
assert compare_chrom_annotation(sources) == {'chr1'}
assert compare_chrom_annotation(sources, strategy='all') == {'chr1'}
with pytest.raises(AssertionError) as exception:
sources[1].fasta = {'chr1': '', 'chr2': '', 'chr3': ''}
compare_chrom_annotation(sources, strategy='all')
assert str(exception.value) == 'chroms annotations are not all same.'
assert compare_chrom_annotation(sources) == {'chr1'}
with pytest.raises(AssertionError) as exception:
sources[1].fasta = {'chr2': '', 'chr3': ''}
compare_chrom_annotation(sources)
assert str(exception.value) == 'there is not intersection between chromosomes.'