-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #249 from jeromekelleher/test_metadata
Test metadata
- Loading branch information
Showing
5 changed files
with
148 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import pathlib | ||
import shutil | ||
import gzip | ||
|
||
import pytest | ||
|
||
import sc2ts | ||
|
||
|
||
@pytest.fixture | ||
def data_cache(): | ||
cache_path = pathlib.Path("tests/data/cache") | ||
if not cache_path.exists(): | ||
cache_path.mkdir() | ||
return cache_path | ||
|
||
|
||
@pytest.fixture | ||
def alignments_fasta(data_cache): | ||
cache_path = data_cache / "alignments.fasta" | ||
if not cache_path.exists(): | ||
with gzip.open("tests/data/alignments.fasta.gz") as src: | ||
with open(cache_path, "wb") as dest: | ||
shutil.copyfileobj(src, dest) | ||
return cache_path | ||
|
||
|
||
@pytest.fixture | ||
def alignments_store(data_cache, alignments_fasta): | ||
cache_path = data_cache / "alignments.db" | ||
if not cache_path.exists(): | ||
with sc2ts.AlignmentStore(cache_path, "a") as a: | ||
fasta = sc2ts.core.FastaReader(alignments_fasta) | ||
a.append(fasta, show_progress=False) | ||
return sc2ts.AlignmentStore(cache_path) | ||
|
||
@pytest.fixture | ||
def metadata_db(data_cache): | ||
cache_path = data_cache / "metadata.db" | ||
tsv_path = "tests/data/metadata.tsv" | ||
if not cache_path.exists(): | ||
sc2ts.MetadataDb.import_csv(tsv_path, cache_path) | ||
return sc2ts.MetadataDb(cache_path) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import pytest | ||
import pandas as pd | ||
|
||
|
||
class TestMetadataDb: | ||
def test_known(self, metadata_db): | ||
record = metadata_db["SRR11772659"] | ||
assert record["strain"] == "SRR11772659" | ||
assert record["date"] == "2020-01-19" | ||
assert record["Viridian_pangolin"] == "A" | ||
|
||
def test_missing_sequence(self, metadata_db): | ||
# We include sequence that's not in the alignments DB | ||
assert "ERR_MISSING" in metadata_db | ||
|
||
def test_keys(self, metadata_db): | ||
keys = list(metadata_db.keys()) | ||
assert "SRR11772659" in keys | ||
assert len(set(keys)) == len(keys) | ||
df = pd.read_csv("tests/data/metadata.tsv", sep="\t") | ||
assert set(keys) == set(df["strain"]) | ||
|
||
def test_in(self, metadata_db): | ||
assert "SRR11772659" in metadata_db | ||
assert "DEFO_NOT_IN_DB" not in metadata_db | ||
|
||
def test_get_all_days(self, metadata_db): | ||
results = metadata_db.get_days() | ||
assert results == [ | ||
"2020-01-01", | ||
"2020-01-19", | ||
"2020-01-24", | ||
"2020-01-25", | ||
"2020-01-28", | ||
"2020-01-29", | ||
"2020-01-30", | ||
"2020-01-31", | ||
"2020-02-01", | ||
"2020-02-02", | ||
"2020-02-03", | ||
"2020-02-04", | ||
"2020-02-05", | ||
"2020-02-06", | ||
"2020-02-07", | ||
"2020-02-08", | ||
"2020-02-09", | ||
"2020-02-10", | ||
"2020-02-11", | ||
"2020-02-13", | ||
] | ||
|
||
def test_get_days_greater(self, metadata_db): | ||
results = metadata_db.get_days("2020-02-06") | ||
assert results == [ | ||
"2020-02-07", | ||
"2020-02-08", | ||
"2020-02-09", | ||
"2020-02-10", | ||
"2020-02-11", | ||
"2020-02-13", | ||
] | ||
|
||
def test_get_days_none(self, metadata_db): | ||
assert metadata_db.get_days("2022-02-06") == [] | ||
|
||
def test_get_first(self, metadata_db): | ||
results = list(metadata_db.get("2020-01-01")) | ||
assert len(results) == 1 | ||
assert results[0] == metadata_db["SRR14631544"] | ||
|
||
def test_get_multi(self, metadata_db): | ||
results = list(metadata_db.get("2020-02-11")) | ||
assert len(results) == 2 | ||
for result in results: | ||
assert result["date"] == "2020-02-11" |