示例#1
0
def test__rebuild_map(test_data):
    """
    Test private _rebuild_map method.
    """

    for d in test_data:

        gpm = GenotypePhenotypeMap(wildtype=d["wildtype"],
                                   genotype=d["genotype"])

        # Trash all the stuff that _rebuild_map builds from scratch
        gpm._encoding_table = None
        gpm._data = gpm.data.drop(["binary"], axis=1)
        gpm._mutant = None
        gpm._data = gpm.data.drop(["n_mutations"], axis=1)
        gpm._data = gpm.data.drop(["name"], axis=1)

        gpm._rebuild_map()

        # Lazy check of encoding table. The encoding table is a pretty
        # complicated object.  See test_utils.test_get_encoding_table for test
        # of its creation.
        assert type(gpm._encoding_table) is pd.DataFrame
        assert np.array_equal(d["binary"], gpm.binary)
        assert gpm.mutant == d["mutant"]
        assert np.array_equal(d["n_mutations"], gpm.n_mutations)
        assert np.array_equal(d["name"], gpm.name)
示例#2
0
def test__trim_neighbors(test_data):

    for d in test_data:

        # Build map again.
        gpm = GenotypePhenotypeMap(genotype=d["genotype"])

        # Get the neighbors
        gpm.get_neighbors()
        num_neighbors_initial = len(gpm.neighbors)

        # Delete a node
        gpm._data = gpm._data.iloc[np.arange(len(gpm._data) - 1, dtype=int)]

        # Since we removed a node, we should have rebuilt neighbors. The length
        # of the neighbors will thus be shorter
        assert len(gpm.neighbors) < num_neighbors_initial
示例#3
0
def test__add_n_mutations(test_data):
    """
    Test private _add_n_mutations method.
    """

    for d in test_data:

        gpm = GenotypePhenotypeMap(wildtype=d["wildtype"],
                                   genotype=d["genotype"])

        # This is a hack to nuke the n_mutations column
        gpm._data = gpm.data.drop(["n_mutations"], axis=1)

        with pytest.raises(AttributeError):
            gpm.n_mutations

        gpm._add_n_mutations()

        assert np.array_equal(gpm.n_mutations, d["n_mutations"])
示例#4
0
def test__add_binary(test_data):
    """
    Test private _add_binary method.
    """

    for d in test_data:

        gpm = GenotypePhenotypeMap(wildtype=d["wildtype"],
                                   genotype=d["genotype"])

        # This is a hack to nuke the binary column
        gpm._data = gpm.data.drop(["binary"], axis=1)

        with pytest.raises(AttributeError):
            gpm.binary

        gpm._add_binary()

        assert np.array_equal(gpm.binary, d["binary"])