예제 #1
0
def test_fetch_bed():
    import os

    filenames = [
        "chrom22_subsample20_maf0.10.bed",
        "chrom22_subsample20_maf0.10.fam",
        "chrom22_subsample20_maf0.10.bim",
    ]

    with limix.file_example(filenames) as filepaths:
        folder = os.path.dirname(filepaths[0])
        filepath = os.path.join(folder, "chrom22_subsample20_maf0.10")

        specs = [
            f"{filepath}",
            f"{filepath}:bed:row=candidate,col=sample",
            f"{filepath}:bed:col=sample",
            f"{filepath}:bed",
            f"{filepath}",
            f"{filepath}:",
            f"{filepath}::",
            f"{filepath}:bed:",
            f"{filepath}::row=candidate",
        ]

        for spec in specs:
            G = fetch("genotype", spec, verbose=False)

            assert_string_equal(G.name, "genotype")
            assert_array_equal(G["sample"], _samples)
            assert_equal(G.shape, (274, 49008))
            assert_array_equal(G.dims, ["sample", "candidate"])
예제 #2
0
def test_fetch_csv():

    with limix.file_example("expr.csv") as filepath:

        spec = f"{filepath}:csv:row=trait,trait[gene1]"
        y = fetch("trait", spec, verbose=False)

        assert_string_equal(y.name, "trait")
        assert_array_equal(y["sample"], _samples)
        assert_equal(y.shape, (274, 1))
        assert_allclose(y.values[:2, 0],
                        [-3.752_345_147_31, -0.421_128_991_488])
        assert_array_equal(y.coords, ["trait", "sample"])

        spec = f"{filepath}:csv:row=trait,trait[gene11]"
        y = fetch("trait", spec, verbose=False)

        assert_string_equal(y.name, "trait")
        assert_array_equal(y["sample"], _samples)
        assert_equal(y.shape, (274, 1))
        assert_allclose(y.values[:2, 0], [0.798_312_717_19, 0.237_496_587_19])

        spec = f"{filepath}:csv:row=trait"
        y = fetch("trait", spec, verbose=False)

        assert_string_equal(y.name, "trait")
        assert_array_equal(y["sample"], _samples)
        assert_equal(y.shape, (274, 11))

        spec = f"{filepath}:csv:row=trait,col=sample"
        y = fetch("trait", spec, verbose=False)
        assert_equal(y.shape, (274, 11))
        assert_equal(y.dims, ("sample", "trait"))

        spec = f"{filepath}:csv:row=sample,col=trait"
        y = fetch("trait", spec, verbose=False)
        assert_equal(y.shape, (11, 274))
        assert_equal(y.dims, ("sample", "trait"))

        spec = f"{filepath}:csv:"
        y = fetch("trait", spec, verbose=False)

        spec = f"{filepath}:csv"
        y = fetch("trait", spec, verbose=False)

        spec = f"{filepath}:csv:row=samples"
        with pytest.raises(ValueError):
            y = fetch("trait", spec, verbose=False)

        spec = "wrong_filepath:csv:row=sample"
        with pytest.raises(FileNotFoundError):
            y = fetch("trait", spec, verbose=False)

        spec = f"{filepath}:csv:row=sample,col=trait"
        with pytest.raises(ValueError):
            y = fetch("traits", spec, verbose=False)

        spec = f"{filepath}:csvs:row=sample,col=trait"
        with pytest.raises(ValueError):
            y = fetch("trait", spec, verbose=False)
예제 #3
0
def test_io_gen():
    with file_example(["example.gen", "example.sample"]) as filepaths:
        df = io.gen.read(filepaths[0][:-4], verbose=False)
        assert_equal(df["sample"]["sample_id"][1], "1A1")
        assert_equal(df["sample"]["age"][0], 4)
        assert_allclose(df["genotype"]["1A4"]["AB"][0], 0.0207)
예제 #4
0
def test_io_hdf5():
    with file_example("data.h5.bz2") as filepath:
        filepath = extract(filepath, verbose=False)
        with io.hdf5.fetcher(filepath) as df:
            X = df.fetch("/genotype/chrom20/SNP")
            assert_allclose(X[0, 0], [1.0])
예제 #5
0
def test_io_csv():
    with file_example("pheno.csv") as filepath:
        assert_equal(io.csv.read(filepath, verbose=False)["attr1"][0], "string")