示例#1
0
def find_captures_4_unfolded_terminal_test():
    """Example capture window contains 1 long terminal capturethat has unfolded.

    Tests: find_captures returns 1 capture
    """
    data_file = "src/tests/data/capture_windows/test_data_capture_window_4.txt.gz"
    data = picoampere_signal_from_data_file(data_file)
    window = Window(5_511_887, 5_604_585)
    signal_threshold_frac = 0.7
    alt_open_channel_pA = 230
    terminal_capture_only = True
    filters = [filtering.LengthFilter(100, None)]
    delay = 0
    end_tol = 0
    channel_number = 2
    captures = segment.find_captures(
        data,
        channel_number,
        window,
        signal_threshold_frac,
        alt_open_channel_pA,
        terminal_capture_only=terminal_capture_only,
        filters=filters,
        delay=delay,
        end_tol=end_tol,
    )
    assert len(captures) == 1
示例#2
0
def find_captures_3_multicapture_nonterminal_test():
    """Example capture window contains 1 long terminal capture & 1 medium capture.

    Tests: find_captures returns...
    3 captures when terminal_capture_only = False
    """
    data_file = "src/tests/data/capture_windows/test_data_capture_window_3.txt.gz"
    data = picoampere_signal_from_data_file(data_file)
    window = Window(1_187_841, 1_280_674)
    actual_captures = [(1_200_088, 1_201_033, False), (1_252_611, 1_280_674, True)]
    signal_threshold_frac = 0.7
    alt_open_channel_pA = 230
    terminal_capture_only = False
    filters = [filtering.LengthFilter(100, None)]
    delay = 3
    end_tol = 0
    channel_number = 2
    captures = segment.find_captures(
        data,
        channel_number,
        window,
        signal_threshold_frac,
        alt_open_channel_pA,
        terminal_capture_only=terminal_capture_only,
        filters=filters,
        delay=delay,
        end_tol=end_tol,
    )
    assert len(captures) == len(actual_captures)
    for test_capture in captures:
        test_start = test_capture.window.start
        test_end = test_capture.window.end
        ejected = test_capture.ejected
        assert (test_start, test_end, ejected) in actual_captures
示例#3
0
def find_captures_3_multicapture_terminal_test():
    """Example capture window contains 1 long terminal capture & 2 medium/short captures.

    Tests: find_captures returns...
    1 capture when terminal_capture_only = True
    """
    data_file = "src/tests/data/capture_windows/test_data_capture_window_3.txt.gz"
    data = picoampere_signal_from_data_file(data_file)
    window = Window(1_187_841, 1_280_674)
    signal_threshold_frac = 0.7
    alt_open_channel_pA = 230
    terminal_capture_only = True
    filters = [filtering.LengthFilter(100, None)]
    delay = 0
    end_tol = 0
    channel_number = 2
    captures = segment.find_captures(
        data,
        channel_number,
        window,
        signal_threshold_frac,
        alt_open_channel_pA,
        terminal_capture_only=terminal_capture_only,
        filters=filters,
        delay=delay,
        end_tol=end_tol,
    )
    assert len(captures) == 1
示例#4
0
def find_captures_2_nocaptures_test():
    """Example capture window contains no captures.

    Test: find_captures returns no captures"""
    data_file = "src/tests/data/capture_windows/test_data_capture_window_2.txt.gz"
    data = picoampere_signal_from_data_file(data_file)
    window = Window(3_423_474, 3_516_439)
    signal_threshold_frac = 0.7
    alt_open_channel_pA = 230
    terminal_capture_only = False
    filters = [filtering.LengthFilter(100, None)]
    delay = 10
    end_tol = 0
    channel_number = 1
    captures = segment.find_captures(
        data,
        channel_number,
        window,
        signal_threshold_frac,
        alt_open_channel_pA,
        terminal_capture_only=terminal_capture_only,
        filters=filters,
        delay=delay,
        end_tol=end_tol,
    )
    assert len(captures) == 0
示例#5
0
def find_captures_1_double_capture_noterminal_2_test():
    """Example capture window contains 2 long captures, neither terminal.
    Also contains a few short blips.

    Test: terminal_capture_only = False returns 2 captures"""
    data_file = "src/tests/data/capture_windows/test_data_capture_window_1.txt.gz"
    data = picoampere_signal_from_data_file(data_file)
    window = Window(4_765_695, 4_858_482)
    signal_threshold_frac = 0.7
    alt_open_channel_pA = 230
    terminal_capture_only = False
    filters = [filtering.LengthFilter(100, None)]
    delay = 0
    end_tol = 0
    channel_number = 1
    captures = segment.find_captures(
        data,
        channel_number,
        window,
        signal_threshold_frac,
        alt_open_channel_pA,
        terminal_capture_only=terminal_capture_only,
        filters=filters,
        delay=delay,
        end_tol=end_tol,
    )
    assert len(captures) == 2
示例#6
0
def find_captures_0_single_capture_terminal_test():
    data_file = "src/tests/data/capture_windows/test_data_capture_window_0.txt.gz"
    window = Window(3_572_989, 3_665_680)
    data = picoampere_signal_from_data_file(data_file)
    actual_captures = [(33822 + window.start, 92691 + window.start, True)]
    signal_threshold_frac = 0.7
    alt_open_channel_pA = 230
    terminal_capture_only = True
    filters = [filtering.LengthFilter(100, None)]
    delay = 0
    end_tol = 0
    channel_number = 1
    captures = segment.find_captures(
        data,
        channel_number,
        window,
        signal_threshold_frac,
        alt_open_channel_pA,
        terminal_capture_only=terminal_capture_only,
        filters=filters,
        delay=delay,
        end_tol=end_tol,
    )

    assert len(captures) == len(actual_captures)
    for test_capture in captures:
        test_start = test_capture.window.start
        test_end = test_capture.window.end
        ejected = test_capture.ejected
        assert (test_start, test_end, ejected) in actual_captures
示例#7
0
def find_captures_7_capture_no_open_channel_test():
    """Example capture window contains 1 long terminal capture. Open pore region
    is extremely, extremely short. Test by cutting off the open pore region.

    Tests: find_captures returns 1 capture; open pore returns alt value.
    """
    data_file = "src/tests/data/capture_windows/test_data_capture_window_7.txt.gz"
    data = picoampere_signal_from_data_file(data_file)[100:]
    window = Window(2_919_913, 3_013_723)
    signal_threshold_frac = 0.7
    alt_open_channel_pA = 230
    terminal_capture_only = False
    filters = [filtering.LengthFilter(100, None)]
    delay = 100
    end_tol = 0
    channel_number = 2
    captures = segment.find_captures(
        data,
        channel_number,
        window,
        signal_threshold_frac,
        alt_open_channel_pA,
        terminal_capture_only=terminal_capture_only,
        filters=filters,
        delay=delay,
        end_tol=end_tol,
    )
    assert len(captures) == 1
    # Rough check; should be ~229.05 & anything close is okay.
    # The function is nondeterministic & should return this exact value, but if
    # future changes are made, some tolerance can be allowed.
    expected_open_channel_pA = 230

    open_channel_pA = np.array([capture.open_channel_pA_calculated for capture in captures])
    all_currents_within_bounds = all(
        (np.isclose(open_channel_pA, expected_open_channel_pA, atol=0.5))
    )

    assert (
        all_currents_within_bounds
    ), f"All captures should have calculated an open channel current close to {expected_open_channel_pA}."
示例#8
0
def find_captures_5_unfolded_terminal_test():
    """Example capture window contains 1 long terminal capture. It was captured
    almost immediately, causing a very short open pore region.

    Tests: find_captures returns 1 capture
    """
    data_file = "src/tests/data/capture_windows/test_data_capture_window_5.txt.gz"
    data = picoampere_signal_from_data_file(data_file)
    window = Window(965_676, 1_059_216)
    signal_threshold_frac = 0.7
    alt_open_channel_pA = 230
    terminal_capture_only = True
    filters = [filtering.LengthFilter(100, None)]
    delay = 0
    end_tol = 0
    channel_number = 1
    captures = segment.find_captures(
        data,
        channel_number,
        window,
        signal_threshold_frac,
        alt_open_channel_pA,
        terminal_capture_only=terminal_capture_only,
        filters=filters,
        delay=delay,
        end_tol=end_tol,
    )
    assert len(captures) == 1
    open_channel_pA = np.array([capture.open_channel_pA_calculated for capture in captures])
    low_expected_open_channel_pA = 228.5
    high_expected_open_channel_pA = 230
    # Rough check; should be ~229.05 & anything close is okay.
    # The function is nondeterministic & should return this exact value, but if
    # future changes are made, some tolerance can be allowed.
    all_currents_within_bounds = all(
        (open_channel_pA > low_expected_open_channel_pA)
        & (open_channel_pA < high_expected_open_channel_pA)
    )
    assert (
        all_currents_within_bounds
    ), f"Expect all capture open channel currents to be between '{low_expected_open_channel_pA}' and '{high_expected_open_channel_pA}'."
示例#9
0
def find_captures_8_capture_no_open_channel_test():
    """Example capture window contains 2 captures: both long, 1 terminal.
    Test non-terminal long capture.

    Tests: find_captures returns 2 captures.
           Checks exact capture boundaries with delay = 3
    """
    data_file = "src/tests/data/capture_windows/test_data_capture_window_8.txt.gz"
    data = picoampere_signal_from_data_file(data_file)
    window = Window(4_875_289, 4_969_337)
    signal_threshold_frac = 0.7
    alt_open_channel_pA = 230
    terminal_capture_only = False
    filters = [filtering.LengthFilter(100, None)]
    delay = 3
    end_tol = 0
    channel_number = 2
    captures = segment.find_captures(
        data,
        channel_number,
        window,
        signal_threshold_frac,
        alt_open_channel_pA,
        terminal_capture_only=terminal_capture_only,
        filters=filters,
        delay=delay,
        end_tol=end_tol,
    )
    assert len(captures) == 2
    actual_captures = [
        (11310 + window.start, 22098 + window.start, False),
        (26617 + window.start, 94048 + window.start, True),
    ]
    for test_capture in captures:
        test_start = test_capture.window.start
        test_end = test_capture.window.end
        ejected = test_capture.ejected
        assert (test_start, test_end, ejected) in actual_captures
示例#10
0
def find_captures_6_clog_no_open_channel_test():
    """Example capture window contains 1 long terminal capture. Open pore region
    is extremely, extremely short. Test by cutting off the open pore region.

    Tests: find_captures returns 1 capture; open pore returns alt value.
    """
    data_file = "src/tests/data/capture_windows/test_data_capture_window_6.txt.gz"
    data = picoampere_signal_from_data_file(data_file)[100:]
    window = Window(2_769_436, 2_863_265)
    signal_threshold_frac = 0.7
    alt_open_channel_pA = 230
    terminal_capture_only = False
    filters = [filtering.LengthFilter(100, None)]
    delay = 100
    end_tol = 0
    channel_number = 1
    captures = segment.find_captures(
        data,
        channel_number,
        window,
        signal_threshold_frac,
        alt_open_channel_pA,
        terminal_capture_only=terminal_capture_only,
        filters=filters,
        delay=delay,
        end_tol=end_tol,
    )
    assert len(captures) == 1
    open_channel_pA = np.array([capture.open_channel_pA_calculated for capture in captures])
    expected_open_channel_pA = 230
    all_currents_within_bounds = all(
        (np.isclose(open_channel_pA, expected_open_channel_pA, atol=0.5))
    )

    assert (
        all_currents_within_bounds
    ), f"All calculated open channel currents should be close to {expected_open_channel_pA}"