Exemple #1
0
    def test_merge_genotypes(self):
        expected = dict(X=dict(A=('1', '1'), B=('1', '2'), C=('2', '2')),
                        Y=dict(A=('1', '1'), D=('1', '2'), E=('2', '2')))
        one = io.Genotype()
        one.add('X', ['A', 'B', 'C'], [('1', '1'), ('1', '2'), ('2', '2')])
        other = io.Genotype()
        other.add('Y', ['A', 'D', 'E'], [('1', '1'), ('1', '2'), ('2', '2')])

        one.merge(other)
        assert one.n_loci == 5
        assert one.n_samples == 2
        for sample, geno in one:
            assert sample in expected
            assert geno == expected[sample]
Exemple #2
0
    def test_add_unique_loci(self):
        genotype = io.Genotype()
        loci = ["A", "B", "C", "D"]

        genotype.add_loci(loci)
        genotype.add_loci(loci)
        assert genotype.n_loci == 4
Exemple #3
0
    def test_add_loci(self):
        genotype = io.Genotype()
        loci = ["A", "B", "C", "D"]

        genotype.add_loci(loci)
        # Check includes all
        for locus in loci:
            assert locus in genotype.loci
Exemple #4
0
    def test_combine(self):
        expected = dict(X=dict(A=('1', '1'), B=('1', '2'), C=('2', '2')),
                        Y=dict(A=('1', '1'), D=('1', '2'), E=('2', '2')))
        one = io.Genotype()
        one.add('X', ['A', 'B', 'C'], [('1', '1'), ('1', '2'), ('2', '2')])
        other = io.Genotype()
        other.add('Y', ['A', 'D', 'E'], [('1', '1'), ('1', '2'), ('2', '2')])

        merged = io.Genotype.combine(one, other)
        # Check for side effects
        assert one.n_loci == 3 and other.n_loci == 3
        assert one.n_samples == 1 and other.n_samples == 1
        assert merged.n_loci == 5
        assert merged.n_samples == 2
        for sample, geno in merged:
            assert sample in expected
            assert geno == expected[sample]
Exemple #5
0
    def test_add(self):
        genotype = io.Genotype()
        sample = "S0"
        loci = ["A", "B", "C", "D"]
        data = [[0, 1], [0, 2], [0, 1], [0, 2]]

        genotype.add(sample, loci, data)
        assert genotype.n_samples == 1
        assert genotype.n_loci == 4
Exemple #6
0
 def test_write(self):
     genotype = io.Genotype()
     loci = ["A", "B", "C", "D", "E"]
     genotype.add("X", loci, [('1', '1'), ('1', '1'), ('2', '2'),
                              ('1', '2'), ('-9', '-9')])
     genotype.add("Y", loci, [('2', '2'), ('1', '1'), ('1', '2'),
                              ('-9', '-9'), ('1', '2')])
     stream = StringIO("")
     expected = "".join(STR_STREAM)
     genotype.write(stream)
     assert stream.getvalue() == expected
Exemple #7
0
    def test_iterate_genotypes(self):
        genotype = io.Genotype()
        name = "S0"
        loci = ["A", "B", "C", "D"]
        data = [[1, 1], [1, 2], [1, 1], [2, 2]]
        genotype.add(name, loci, data)

        count = 0
        for sample, genotype in genotype:
            assert sample == name  # assert sample is the given
            assert genotype == dict(A=[1, 1], B=[1, 2], C=[1, 1], D=[2, 2])
            count += 1
        assert count == 1  # Iterates over one item
Exemple #8
0
 def test_create_empty(self):
     genotype = io.Genotype()
     assert genotype.n_loci == 0
     assert genotype.n_samples == 0
Exemple #9
0
 def test_create_empty(self):
     reference = io.Reference(io.Genotype(), [], [])
     assert reference.genotype.n_loci == 0
     assert reference.genotype.n_samples == 0
     assert reference.groups == []
     assert reference.ranges == []
Exemple #10
0
 def test_merge_genotype_raises_error(self):
     genotype = io.Genotype()
     with pytest.raises(ValueError):
         genotype.merge(1)