def it_computes_zero_pr_for_subset(): p, r, s, a = cb_all_wrong.pr_curve(pep_iz_subset=[1], n_steps=2) assert utils.np_array_same([p, r, s, a], zero_pr_result) p, r, s, a = cb_all_wrong.pr_curve(pep_iz_subset=[2], n_steps=2) assert utils.np_array_same([p, r, s, a], zero_pr_result) # peptide 2 does not show up in true/pred at all so should get zero pr curve p, r, s, a = cb_all_right.pr_curve(pep_iz_subset=[2], n_steps=2) assert utils.np_array_same([p, r, s, a], zero_pr_result)
def it_can_mock(): # A mock cycle is the same as a edman_failure no matter what (p_edman_failure=0.0) # and yet I should still see failure behavior result = sim_v1_worker._step_3a_cycle_edman(samples, is_mock=True, p_edman_failure=0.0) assert np_array_same(samples, result)
def it_bleaches_channels_independently(): result = sim_v1_worker._step_3b_photobleach( samples, p_bleach_by_channel=[1.0, 0.0]) expected = npf([ [[0, 0, 0], [0, 1, 0]], [[n, 0, 0], [n, 0, 1]], ]) assert np_array_same(expected, result)
def it_returns_train_dyepeps(): sim_v2_result, sim_v2_params = _sim() # The order of dyts is not guaranteed, so remove them assert utils.np_array_same( sim_v2_result.train_dyepeps[:, (0, 2)], np.array([[0, 0], [1, 5000], [2, 5000], [3, 5000],], dtype=np.uint64), )
def it_detach(): result = sim_v1_worker._step_3c_detach(samples, 1.0) expected = np.full_like(samples, n) assert np_array_same(expected, result) def it_make_a_copy(): # The original should not have changed assert samples[0, 0, 0] == 1.0 zest()
def it_proceeds_with_no_error(): evolution = sim_v1_worker._step_3_evolve_cycles(samples, sim_params) # fmt: off n = np.nan expected = npf([ [ [[1, 1, 0], [0, 1, 0]], [[0, 1, 1], [0, 0, 1]], ], [ [[n, 1, 0], [n, 1, 0]], [[n, 1, 1], [n, 0, 1]], ], ]) # fmt: on if not np_array_same(evolution, expected): debug(evolution) debug(sim_params) assert np_array_same(evolution, expected)
def it_degrades_at_first_non_nan(): samples = npf([ [[n, 1, 0], [n, 1, 0]], [[0, 1, 1], [0, 0, 1]], ]) result = sim_v1_worker._step_3a_cycle_edman(samples, is_mock=False, p_edman_failure=0.0) expected = npf([ [[n, n, 0], [n, n, 0]], [[n, 1, 1], [n, 0, 1]], ]) assert np_array_same(expected, result)
def it_proceeds_with_errors(): # Example error: detach 100% sim_params.error_model.p_detach = 1.0 sim_params._build_join_dfs() evolution = sim_v1_worker._step_3_evolve_cycles(samples, sim_params) expected = np.full_like(evolution, np.nan) assert np_array_same(evolution, expected) def it_makes_a_copy(): assert samples[0, 0, 0] == 1.0 zest()
def it_bleaches_all(): result = sim_v1_worker._step_3b_photobleach( samples, p_bleach_by_channel=[1.0, 1.0]) expected = npf([ [[0, 0, 0], [0, 0, 0]], [[n, 0, 0], [n, 0, 0]], ]) assert np_array_same(expected, result) def it_makes_a_copy(): # The original should not have changed assert samples[0, 0, 0] == 1.0 zest()
def it_gets_flat_test_radmat(): flat_test_radmat = result.flat_test_radmat() assert flat_test_radmat.shape == ( n_peps * n_test_samples, n_channels * n_cycles, ) expected = npf([ [4.0, 2.0, 1.0, 1.0, 1.0, 0.0], [5.0, 2.0, 1.0, 1.0, 1.0, 1.0], [6.0, 3.0, 0.9, 1.0, 0.0, 1.0], [0.4, 0.2, 0.1, 0.3, 0.2, 0.1], [0.5, 0.2, 0.1, 0.3, 0.2, 0.1], [0.6, 0.3, 2.9, 0.3, 0.2, 0.1], ]) assert np_array_same(flat_test_radmat, expected)
def it_returns_train_dyemat(): # Because it has no errors, there's only a perfect dyemats sim_v2_result, sim_v2_params = _sim() assert sim_v2_result.train_dyemat.shape == (4, 5 * 2) # 5 cycles, 2 channels assert utils.np_array_same( sim_v2_result.train_dyemat, np.array( [ [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 2, 1, 0, 0, 0], [0, 0, 0, 0, 0, 2, 1, 1, 0, 0], [1, 0, 0, 0, 0, 1, 1, 0, 0, 0], ], dtype=np.uint8, ), )
def it_can_degrade_one_sample_and_not_another(): samples = npf([ [[n, 1, 0], [n, 1, 0]], [[0, 1, 1], [0, 0, 1]], ]) n_samples = 2 with zest.mock(sim_v1_worker._rand1, returns=np.full((n_samples, ), [0.0, 1.0])): result = sim_v1_worker._step_3a_cycle_edman(samples, is_mock=False, p_edman_failure=0.5) expected = npf([ [[n, 1, 0], [n, 1, 0]], [[n, 1, 1], [n, 0, 1]], ]) assert np_array_same(expected, result)
def it_can_edman_degrade(): # Degrade = Edman success; thus p_edman_failure=0.0 result = sim_v1_worker._step_3a_cycle_edman(samples, is_mock=False, p_edman_failure=0.0) expected = npf([ [[n, 1, 0], [n, 1, 0]], [[n, 1, 1], [n, 0, 1]], ]) assert np_array_same(expected, result) def it_makes_a_copy(): # The original should not have changed assert samples[0, 0, 0] == 1.0 zest()
def it_zeros_nans(): # fmt: off evolution = npf([ [ [[n, n, n], [n, n, n]], [[n, n, n], [n, n, n]], ], ]) dyemat = sim_v1_worker._step_4_make_dyemat(evolution) expected = npf([ [ [0, 0], [0, 0], ], ]) # fmt: on assert np_array_same(dyemat, expected)
def it_makes_pcbs(): # fmt: off params = SimV2Params( is_survey=False, dyes=[ Munch(dye_name="dye1", channel_name="640"), Munch(dye_name="dye2", channel_name="549"), ], labels=[ Munch(aa="A", dye_name="dye1", label_name="A", ptm_only=False), Munch(aa="B", dye_name="dye2", label_name="B", ptm_only=False), ], priors_desc={ "p_non_fluorescent.dye1": dict(class_name="MLEPrior", params=dict(value=0.5)), "p_non_fluorescent.dye2": dict(class_name="MLEPrior", params=dict(value=0.3)), }, channels={ "640": 0, "549": 1, }, ) # fmt: on pep_seq = pd.DataFrame( dict( pep_i=[1, 1, 1, 2, 2], aa=["X", "A", "X", "B", "X"], pep_offset_in_pro=[0, 1, 2, 0, 1], )) pcbs = params.pcbs(pep_seq) assert utils.np_array_same( pcbs, [ [1.0, np.nan, np.nan], [1.0, 0.0, 0.5], [1.0, np.nan, np.nan], [2.0, 1.0, 1.0 - 0.3], [2.0, np.nan, np.nan], ], )
def it_returns_train_dyemat_for_uncleaved_cterm_labels(): prep_cterm = prep_fixtures.result_cterm_label_fixture() # dyemat when allow_edman_cterm is False (default) sim_v2_result, sim_v2_params = _sim( _prep_result=prep_cterm, sim_kwargs=Munch(allow_edman_cterm=False) ) assert sim_v2_result.train_dyemat.shape == (3, 5 * 2) # 5 cycles, 2 channels assert utils.np_array_same( sim_v2_result.train_dyemat, np.array( [ [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 1, 0, 0, 0, 0], [0, 0, 0, 0, 0, 1, 1, 1, 1, 1], ], dtype=np.uint8, ), )
def it_makes_a_flu(): assert np_array_same(compact_flu, [1, n, 0, 1])
def it_pads_an_array(): assert utils.np_array_same(utils.np_1d_end_pad(a, 4), np.array([1, 2, 3, 0]))
def it_repl_2d_vecs_1_col(): r = utils.repl_vec_over_cols(np.array([[1, 2, 3]]).T, 2) assert utils.np_array_same(r, expected)
def it_repl_1d_vecs(): r = utils.repl_vec_over_cols(np.array([1, 2, 3]), 2) assert utils.np_array_same(r, expected)
def it_matches_beyond_100_epsilon(): assert not utils.np_array_same( [1 + 100 * np.finfo(np.float32).eps, np.nan], [1, np.nan] )
def it_matches_epsilon(): assert utils.np_array_same([1 + np.finfo(np.float32).eps, np.nan], [1, np.nan])
def it_matches_nan(): assert utils.np_array_same([1, np.nan], [1, np.nan])
def it_can_edman_fail(): # Failure means Edman did not happen; p_edman_failure=1.0 and we no change result = sim_v1_worker._step_3a_cycle_edman(samples, is_mock=False, p_edman_failure=1.0) assert np_array_same(samples, result)
def it_fail_to_detach(): result = sim_v1_worker._step_3c_detach(samples, 0.0) assert np_array_same(samples, result)
def it_sums(): # fmt: off # Using a huge array here to make sure all my axes # are getting set properly evolution = npf([ [ [[1, 1, 0], [0, 1, 0]], [[0, 1, 1], [0, 0, 1]], [[1, 1, 1], [1, 0, 1]], [[1, 1, 1], [1, 0, 1]], ], [ [[n, 1, 0], [n, 1, 0]], [[n, 1, 1], [n, 0, 1]], [[n, n, 1], [n, n, 1]], [[n, 1, 1], [n, 0, 1]], ], [ [[n, 1, 0], [n, 1, 0]], [[n, 1, 1], [n, 0, 1]], [[n, n, 1], [n, n, 1]], [[n, 1, 1], [n, 0, 1]], ], [ [[n, 1, 0], [n, 1, 0]], [[n, 1, 1], [n, 0, 1]], [[n, n, 1], [n, n, 1]], [[n, 1, 1], [n, 0, 1]], ], [ [[n, 3, 0], [n, 4, 0]], [[n, 1, 5], [n, 0, 1]], [[n, n, 9], [n, n, 1]], [[n, 1, 1], [n, 0, 2]], ], ]) dyemat = sim_v1_worker._step_4_make_dyemat(evolution) # The axes are now rearranged so that there's # 4 samples, 2 channels, 5 cycles # I've thrown enough noise in to make sure I've got # the dimensions as I want expected = npf([ [ [2, 1, 1, 1, 3], [1, 1, 1, 1, 4], ], [ [2, 2, 2, 2, 6], [1, 1, 1, 1, 1], ], [ [3, 1, 1, 1, 9], [2, 1, 1, 1, 1], ], [ [3, 2, 2, 2, 2], [2, 1, 1, 1, 2], ], ]) # fmt: on assert np_array_same(dyemat, expected)
def it_makes_remainder(): assert np_array_same(remainder_flu, [1, 2])
def it_np_signal_radmat(): assert np_array_same(res.signal_radmat(), props.signal_radmat)
def it_np_noise_radmat(): assert np_array_same(res.noise_radmat(), props.noise_radmat)
def it_computes_zero_pr(): p, r, s, a = cb_all_wrong.pr_curve(n_steps=2) assert utils.np_array_same([p, r, s, a], zero_pr_result)