Exemple #1
0
def test_families_instance_type_assertion():
    error_message = "families must be an instance of FamiliesData!"
    with pytest.raises(AssertionError) as excinfo:
        DenovoLoader.flexible_denovo_load(
            None,
            None,
            denovo_location="foo",
            denovo_variant="bar",
            denovo_person_id="baz",
            families="bla",
        )
    assert str(excinfo.value) == error_message
Exemple #2
0
def test_read_variants_genome_assertion(fixture_dirname, fake_families):
    filename = fixture_dirname("denovo_import/variants_DAE_style.tsv")

    with pytest.raises(AssertionError) as excinfo:
        DenovoLoader.flexible_denovo_load(
            filename,
            None,
            families=fake_families,
            denovo_location="location",
            denovo_variant="variant",
            denovo_family_id="familyId",
            denovo_best_state="bestState",
        )

    assert str(excinfo.value) == "You must provide a genome object!"
Exemple #3
0
def test_read_variants_DAE_style(genome_2013, fixture_dirname, fake_families):
    filename = fixture_dirname("denovo_import/variants_DAE_style.tsv")
    res_df = DenovoLoader.flexible_denovo_load(
        filename,
        genome_2013,
        families=fake_families,
        denovo_location="location",
        denovo_variant="variant",
        denovo_family_id="familyId",
        denovo_best_state="bestState",
    )

    expected_df = pd.DataFrame({
        "chrom": ["1", "2", "2", "3", "4"],
        "position": [123, 234, 234, 345, 456],
        "reference": ["A", "T", "G", "G", "G"],
        "alternative": ["G", "A", "A", "A", "A"],
        "family_id": ["f1", "f1", "f2", "f3", "f4"],
        "genotype": [None, None, None, None, None],
        "best_state": [
            np.array([[2, 2, 1, 2, 1], [0, 0, 1, 0, 1]]),
            np.array([[2, 2, 1, 2, 2], [0, 0, 1, 0, 0]]),
            np.array([[2, 2, 2, 1], [0, 0, 0, 1]]),
            np.array([[1], [1]]),
            np.array([[1, 1], [1, 1]]),
        ],
    })

    assert compare_variant_dfs(res_df, expected_df)
Exemple #4
0
def test_read_variants_person_ids(genome_2013, filename, fake_families,
                                  fixture_dirname):
    filename = fixture_dirname(filename)
    res_df = DenovoLoader.flexible_denovo_load(
        filename,
        genome_2013,
        families=fake_families,
        denovo_chrom="chrom",
        denovo_pos="pos",
        denovo_ref="ref",
        denovo_alt="alt",
        denovo_person_id="personId",
    )

    expected_df = pd.DataFrame({
        "chrom": ["1", "2", "2", "3", "4"],
        "position": [123, 234, 235, 345, 456],
        "reference": ["A", "T", "G", "G", "G"],
        "alternative": ["G", "A", "A", "A", "A"],
        "family_id": ["f1", "f1", "f2", "f3", "f4"],
        "genotype": [
            np.array([[0, 0, 0, 0, 0], [0, 0, 1, 0, 1]]),
            np.array([[0, 0, 0, 0, 0], [0, 0, 1, 0, 0]]),
            np.array([[0, 0, 0, 0], [0, 0, 0, 1]]),
            np.array([[0], [1]]),
            np.array([[0, 0], [1, 1]]),
        ],
        "best_state": [None, None, None, None, None],
    })

    print(res_df)
    print(expected_df)

    res_df = res_df.sort_values(["chrom", "position", "reference"])
    res_df = res_df.reset_index(drop=True)
    expected_df = expected_df.sort_values(["chrom", "position", "reference"])
    expected_df = expected_df.reset_index(drop=True)

    print(res_df)
    print(expected_df)

    assert compare_variant_dfs(res_df, expected_df)