You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
102 lines
2.5 KiB
102 lines
2.5 KiB
1 year ago
|
import pytest
|
||
|
|
||
|
|
||
|
@pytest.fixture()
|
||
|
def example_data():
|
||
|
import pandas as pd
|
||
|
|
||
|
data = [
|
||
|
("A", "a", 1, 1, 100, 5),
|
||
|
("A", "a", 1, 2, 100, 2),
|
||
|
("A", "a", 1, 3, 100, 0),
|
||
|
("A", "b", 1, 1, 200, 0),
|
||
|
("A", "b", 1, 2, 200, 3),
|
||
|
("A", "b", 1, 3, 200, 0),
|
||
|
("B", "a", 1, 1, 300, 0),
|
||
|
("B", "a", 1, 2, 300, 2),
|
||
|
("B", "a", 1, 3, 300, 0),
|
||
|
]
|
||
|
columns = [
|
||
|
"Analysis.Name",
|
||
|
"Well.Name",
|
||
|
"Pos.Id",
|
||
|
"Exposure.Id",
|
||
|
"Spot.Mean",
|
||
|
"Spot.Saturation",
|
||
|
]
|
||
|
return pd.DataFrame(data, columns=columns)
|
||
|
|
||
|
|
||
|
@pytest.mark.parametrize(
|
||
|
("analysis", "expected_cy3"), [("dry1", 100), ("hyb", 200)]
|
||
|
)
|
||
|
def test_add_exposure_info(example_data, analysis, expected_cy3):
|
||
|
from conda_helpers.mbp import add_exposure_info
|
||
|
|
||
|
result = add_exposure_info(example_data, analysis=analysis)
|
||
|
|
||
|
assert "Exposure.Channel" in result.columns
|
||
|
assert "Exposure.Time" in result.columns
|
||
|
assert "Exposure.Time.Normalized" in result.columns
|
||
|
|
||
|
for i, channel, time in [
|
||
|
(1, "Cy3", expected_cy3),
|
||
|
(2, "Cy5", 150),
|
||
|
(3, "Cy5", 15),
|
||
|
]:
|
||
|
selection = result["Exposure.Id"] == i
|
||
|
selected = result[selection].copy()
|
||
|
assert list(selected["Exposure.Channel"].unique()) == [channel]
|
||
|
assert list(selected["Exposure.Time"].unique()) == [time]
|
||
|
|
||
|
|
||
|
def test_test_overflow(example_data):
|
||
|
from conda_helpers.mbp import TEST_OVERFLOW_COLUMN, test_overflow
|
||
|
|
||
|
result = test_overflow(example_data)
|
||
|
|
||
|
assert list(result[TEST_OVERFLOW_COLUMN]) == [
|
||
|
True,
|
||
|
False,
|
||
|
False,
|
||
|
False,
|
||
|
True,
|
||
|
False,
|
||
|
False,
|
||
|
False,
|
||
|
False,
|
||
|
]
|
||
|
|
||
|
|
||
|
def test_select_xdr_data(example_data):
|
||
|
from conda_helpers.mbp import (
|
||
|
add_exposure_info,
|
||
|
select_xdr_data,
|
||
|
test_overflow,
|
||
|
)
|
||
|
|
||
|
tmp = add_exposure_info(example_data)
|
||
|
tmp = test_overflow(tmp)
|
||
|
result = select_xdr_data(tmp)
|
||
|
|
||
|
assert list(result["Exposure.Channel"]) == ["Cy3"] * 3 + ["Cy5"] * 3
|
||
|
assert list(result["Exposure.Time"]) == [200] * 3 + [150, 150, 15]
|
||
|
assert list(result["Analysis.Name"]) == list("AABABA")
|
||
|
assert list(result["Well.Name"]) == list("abaaab")
|
||
|
|
||
|
|
||
|
def test_normalize(example_data):
|
||
|
from conda_helpers.mbp import normalize
|
||
|
|
||
|
result = normalize(example_data)
|
||
|
assert "Spot.Mean.Normalized" in result.columns
|
||
|
|
||
|
assert list(result["Spot.Mean.Normalized"]) == [
|
||
|
100,
|
||
|
200,
|
||
|
300,
|
||
|
100 * 25 / 150,
|
||
|
300 * 25 / 150,
|
||
|
200 * 25 / 15,
|
||
|
]
|