Skip to content

Commit

Permalink
Testing generate_lineages_from_taxa and added fixtures.
Browse files Browse the repository at this point in the history
  • Loading branch information
mmtechslv committed Jun 30, 2021
1 parent 9855ed0 commit 2201d21
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 5 deletions.
4 changes: 4 additions & 0 deletions pmaf/tests/_testing_shared.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import pandas as pd

def fix_nan_in_frame(frame):
return frame.applymap(lambda val: None if pd.isna(val) else val)
37 changes: 33 additions & 4 deletions pmaf/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,46 @@
import pytest
from pmaf.database import DatabaseGreengenes
import pandas as pd
from os import path
from ._testing_shared import fix_nan_in_frame

TEST_DATA_ROOT = "pmaf/tests/data/"


@pytest.fixture(scope="module")
def tdb_greengenes():
db = DatabaseGreengenes("pmaf/tests/data/tdbs/greengenes/gg_13_8_demo.hdf5")
db = DatabaseGreengenes(
path.join(TEST_DATA_ROOT, "tdbs/greengenes/gg_13_8_demo.hdf5")
)
yield db
db.close()


@pytest.fixture
def product_tids_tax_greengenes():
return pd.read_csv(
"pmaf/tests/data/tdbs/greengenes/products/product_tids_tax.csv", index_col=0, header=0
).replace({pd.NA: None})
return fix_nan_in_frame(
pd.read_csv(
path.join(TEST_DATA_ROOT, "tdbs/greengenes/products/product_tids_tax.csv"),
index_col=0,
header=0,
)
)


@pytest.fixture
def input_taxonomy_all_ranks():
return fix_nan_in_frame(
pd.read_json(
path.join(TEST_DATA_ROOT, "taxonomy/input_taxonomy_all_ranks_1.json")
)
)


@pytest.fixture
def product_generate_lineages_from_taxa_default():
return pd.read_json(
path.join(
TEST_DATA_ROOT, "taxonomy/product_taxonomy_all_ranks_1_GLFT_default.json"
),
typ="series",
)
1 change: 1 addition & 0 deletions pmaf/tests/data/taxonomy/input_taxonomy_all_ranks_1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"k":{"2424":"Bacteria","2514":"Bacteria","313":"Bacteria","975":"Bacteria","1656":"Bacteria","3139":"Bacteria","2796":"Bacteria","1020":"Bacteria","58":"Archaea","2821":"Bacteria","1385":"Bacteria","2831":"Bacteria","2153":"Bacteria","1637":"Bacteria","1621":"Bacteria","2637":"Bacteria","1968":"Bacteria","1676":"Bacteria","1173":"Bacteria","646":"Bacteria"},"p":{"2424":"Proteobacteria","2514":"Proteobacteria","313":"Actinobacteria","975":"Chlorobi","1656":"Gemmatimonadetes","3139":"Verrucomicrobia","2796":"Proteobacteria","1020":"Chloroflexi","58":"Crenarchaeota","2821":"Proteobacteria","1385":"Firmicutes","2831":"Proteobacteria","2153":"Proteobacteria","1637":"Firmicutes","1621":"Firmicutes","2637":"Proteobacteria","1968":"Proteobacteria","1676":"Gn02","1173":"Cyanobacteria","646":"Armatimonadetes"},"c":{"2424":"Betaproteobacteria","2514":"Deltaproteobacteria","313":"Actinobacteria","975":"Ignavibacteria","1656":"Gemm-2","3139":"Pedosphaerae","2796":"Gammaproteobacteria","1020":"Chloroflexi","58":"Thermoprotei","2821":"Gammaproteobacteria","1385":"Bacilli","2831":"Gammaproteobacteria","2153":"Alphaproteobacteria","1637":"Erysipelotrichi","1621":"Clostridia","2637":"Gammaproteobacteria","1968":"Alphaproteobacteria","1676":"Gks2-174","1173":"Oscillatoriophycideae","646":null},"o":{"2424":"Rhodocyclales","2514":"Desulfuromonadales","313":"Actinomycetales","975":"Ignavibacteriales","1656":null,"3139":null,"2796":"Marinicellales","1020":"Akiw781","58":"Ynpffa","2821":"Oceanospirillales","1385":"Lactobacillales","2831":"Oceanospirillales","2153":"Rickettsiales","1637":"Erysipelotrichales","1621":"Thermoanaerobacterales","2637":"Alteromonadales","1968":"Rhodobacterales","1676":null,"1173":"Chroococcales","646":null},"f":{"2424":"Rhodocyclaceae","2514":"Geobacteraceae","313":"Actinospicaceae","975":null,"1656":null,"3139":null,"2796":"Marinicellaceae","1020":null,"58":"A13","2821":"Hoc21","1385":"Carnobacteriaceae","2831":"Oceanospirillaceae","2153":"Mitochondria","1637":"Erysipelotrichaceae","1621":null,"2637":"Alteromonadaceae","1968":"Hyphomonadaceae","1676":null,"1173":"Microcystaceae","646":null},"g":{"2424":"Propionivibrio","2514":"Geobacter","313":"Actinospica","975":null,"1656":null,"3139":null,"2796":"Marinicella","1020":null,"58":null,"2821":null,"1385":"Isobaculum","2831":"Oceaniserpentilla","2153":"Hedyosmum","1637":"Psb-m-3","1621":null,"2637":"Hb2-32-21","1968":"Robiginitomaculum","1676":null,"1173":"Microcystis","646":null},"d":{"2424":null,"2514":null,"313":null,"975":null,"1656":null,"3139":null,"2796":null,"1020":null,"58":null,"2821":null,"1385":null,"2831":null,"2153":null,"1637":null,"1621":null,"2637":null,"1968":null,"1676":null,"1173":null,"646":null}}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"2424":"k__Bacteria; p__Proteobacteria; c__Betaproteobacteria; o__Rhodocyclales; f__Rhodocyclaceae; g__Propionivibrio","2514":"k__Bacteria; p__Proteobacteria; c__Deltaproteobacteria; o__Desulfuromonadales; f__Geobacteraceae; g__Geobacter","313":"k__Bacteria; p__Actinobacteria; c__Actinobacteria; o__Actinomycetales; f__Actinospicaceae; g__Actinospica","975":"k__Bacteria; p__Chlorobi; c__Ignavibacteria; o__Ignavibacteriales","1656":"k__Bacteria; p__Gemmatimonadetes; c__Gemm-2","3139":"k__Bacteria; p__Verrucomicrobia; c__Pedosphaerae","2796":"k__Bacteria; p__Proteobacteria; c__Gammaproteobacteria; o__Marinicellales; f__Marinicellaceae; g__Marinicella","1020":"k__Bacteria; p__Chloroflexi; c__Chloroflexi; o__Akiw781","58":"k__Archaea; p__Crenarchaeota; c__Thermoprotei; o__Ynpffa; f__A13","2821":"k__Bacteria; p__Proteobacteria; c__Gammaproteobacteria; o__Oceanospirillales; f__Hoc21","1385":"k__Bacteria; p__Firmicutes; c__Bacilli; o__Lactobacillales; f__Carnobacteriaceae; g__Isobaculum","2831":"k__Bacteria; p__Proteobacteria; c__Gammaproteobacteria; o__Oceanospirillales; f__Oceanospirillaceae; g__Oceaniserpentilla","2153":"k__Bacteria; p__Proteobacteria; c__Alphaproteobacteria; o__Rickettsiales; f__Mitochondria; g__Hedyosmum","1637":"k__Bacteria; p__Firmicutes; c__Erysipelotrichi; o__Erysipelotrichales; f__Erysipelotrichaceae; g__Psb-m-3","1621":"k__Bacteria; p__Firmicutes; c__Clostridia; o__Thermoanaerobacterales","2637":"k__Bacteria; p__Proteobacteria; c__Gammaproteobacteria; o__Alteromonadales; f__Alteromonadaceae; g__Hb2-32-21","1968":"k__Bacteria; p__Proteobacteria; c__Alphaproteobacteria; o__Rhodobacterales; f__Hyphomonadaceae; g__Robiginitomaculum","1676":"k__Bacteria; p__Gn02; c__Gks2-174","1173":"k__Bacteria; p__Cyanobacteria; c__Oscillatoriophycideae; o__Chroococcales; f__Microcystaceae; g__Microcystis","646":"k__Bacteria; p__Armatimonadetes"}
10 changes: 10 additions & 0 deletions pmaf/tests/unit/test__shared.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import pytest
from pmaf.internal._shared import generate_lineages_from_taxa


def test_generate_lineages_from_taxa(
input_taxonomy_all_ranks, product_generate_lineages_from_taxa_default
):
product = generate_lineages_from_taxa(input_taxonomy_all_ranks)
should_product = product_generate_lineages_from_taxa_default
assert product.equals(should_product)
2 changes: 1 addition & 1 deletion pmaf/tests/unit/test__tax_base.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest


def test_get_lineage_by_tid(tdb_greengenes,product_tids_tax_greengenes):
def test_get_lineage_by_tid(tdb_greengenes, product_tids_tax_greengenes):
tids_tax = tdb_greengenes.get_taxonomy_by_tid()
assert tids_tax.equals(product_tids_tax_greengenes)

0 comments on commit 2201d21

Please sign in to comment.