def test_write(self): qfile = io.QFile() qfile.add("A", [1, 1, 1]) qfile.add("B", [1, 1, 1]) qfile.add("C", [1, 1, 1]) stream = StringIO("") qfile.write(stream) expected = "A\t1\t1\t1\nB\t1\t1\t1\nC\t1\t1\t1\n" assert stream.getvalue() == expected
def test_barplot(self): qfile = io.QFile() qfile.add("A", [1, 1, 1]) qfile.add("B", [2, 2, 2]) qfile.add("C", [3, 3, 3]) barplot = qfile.to_barplot() expected = [ dict(x=["A", "B", "C"], y=[1, 2, 3], type="bar", name="Pop #000"), dict(x=["A", "B", "C"], y=[1, 2, 3], type="bar", name="Pop #001"), dict(x=["A", "B", "C"], y=[1, 2, 3], type="bar", name="Pop #002") ] for i in range(3): assert barplot[i] == expected[i]
def test_summarise(self): qfile = io.QFile() qfile.add("A", [1, 1, 1]) qfile.add("B", [1, 1, 1]) qfile.add("C", [1, 1, 1]) qfile.add("D", [1, 1, 1]) qfile.add("E", [1, 1, 1]) qfile.add("F", [1, 1, 1]) qfile = qfile.summarise(["GA", "GB"], [(1, 3), (4, 6)]) assert qfile.samples == ["A", "D", "GA", "GB"] assert qfile.get_ancestry(0) == [1, 1, 1, 1] assert qfile.get_ancestry(1) == [1, 1, 1, 1] assert qfile.get_ancestry(2) == [1, 1, 1, 1]
def test_iterate_ancestry(self): qfile = io.QFile() qfile.add("X", [0, 1, 2]) for sample, ancestry in qfile: assert sample == "X" assert ancestry == [0, 1, 2]
def test_add(self): qfile = io.QFile() qfile.add("X", [0, 1, 2]) assert qfile.n_ancestries == 3 assert qfile.n_samples == 1
def test_get_ancestry_raise_error(self): qfile = io.QFile() with pytest.raises(IndexError): qfile.get_ancestry(1)
def test_create_empty(self): qfile = io.QFile() assert qfile.n_samples == 0 assert qfile.n_ancestries == 0