Пример #1
0
    def it_returns_the_fraction_of_all_dark_samples():
        with tmp.tmp_folder(chdir=True):
            n_samples = 5000
            sim_params = _stub_sim_params(
                ErrorModel.from_defaults(n_channels=2), n_samples)
            prep_result = PrepResult.stub_prep_result(
                pros=[".", "ABCDEFGHI"],
                pro_is_decoys=[False, False],
                peps=[".", "ABB"],
                pep_pro_iz=[0, 1],
            )

            pep_seq_df = prep_result.pepseqs()

            dyemat, radmat, recall = _make_arrays("test1",
                                                  n_peps=2,
                                                  n_samples=n_samples)
            sim_worker._do_pep_sim(
                pep_seq_df[pep_seq_df.pep_i == 1],
                sim_params,
                n_samples=n_samples,
                output_dyemat=dyemat,
                output_radmat=radmat,
                output_recall=recall,
            )
            assert np.all((0.9 < recall[1]) & (recall[1] < 1.0))
Пример #2
0
    def it_computes_p_bright_from_product():
        error_model = ErrorModel.no_errors(n_channels=2)
        error_model.labels[0].p_failure_to_bind_amino_acid = 0.9
        error_model.labels[1].p_failure_to_bind_amino_acid = 0.8
        error_model.labels[0].p_failure_to_attach_to_dye = 0.7
        error_model.labels[1].p_failure_to_attach_to_dye = 0.6
        error_model.dyes[0].p_non_fluorescent = 0.5
        error_model.dyes[1].p_non_fluorescent = 0.4

        sim_params = SimParams.construct_from_aa_list(("A", "C"),
                                                      error_model=error_model,
                                                      n_edmans=3)
        flu, p_bright = sim_worker._step_1_create_flu_and_p_bright(
            pep_seq_df, sim_params)
        assert flu.shape == (2, 4)
        expected = np.array([
            [
                ((1 - 0.9) * (1 - 0.7) * (1 - 0.5)),
                0,
                0,
                0,
            ],
            [
                0,
                0,
                ((1 - 0.8) * (1 - 0.6) * (1 - 0.4)),
                0,
            ],
        ])
        assert np.allclose(p_bright, expected)
Пример #3
0
def zest_step_5_make_radmat():
    # fmt: off
    dyemat = npf([
        [
            [2, 1],
            [2, 1],
        ],
        [
            [0, 0],
            [0, 0],
        ],
    ])

    sim_params = SimParams.construct_from_aa_list(
        ["DE", "C"],
        error_model=ErrorModel.no_errors(n_channels=2, beta=7500.0,
                                         sigma=0.16),
        n_pres=1,
        n_mocks=0,
        n_edmans=1,
    )

    radmat = sim_worker._step_5_make_radmat(dyemat, sim_params)

    def it_makes_radmat():
        assert np.all(radmat[0] > 4000.0)

    def it_deals_with_zeros():
        assert np.all(radmat[1] == 0.0)

    # fmt: on
    zest()
Пример #4
0
 def it_labels_in_tail():
     sim_params = SimParams.construct_from_aa_list(
         ("A", "C"),
         error_model=ErrorModel.no_errors(n_channels=2),
         n_edmans=6,
     )
     pep_seq_df = pd.DataFrame(
         [
             (1, "B", 0),
             (1, "B", 1),
             (1, "B", 2),
             (1, "B", 3),
             (1, "A", 4),
             (1, "C", 5),
         ],
         columns=PrepResult.pep_seqs_columns,
     )
     flu, p_bright = sim_worker._step_1_create_flu_and_p_bright(
         pep_seq_df, sim_params)
     assert np.all(flu == [
         [0, 0, 0, 0, 1, 0, 0],
         [0, 0, 0, 0, 0, 1, 0],
     ])
     assert np.all(p_bright == [
         [0, 0, 0, 0, 1, 0, 0],
         [0, 0, 0, 0, 0, 1, 0],
     ])
Пример #5
0
 def _before():
     nonlocal sim_params
     sim_params = SimParams.construct_from_aa_list(
         ["DE", "C"],
         error_model=ErrorModel.no_errors(n_channels=2, beta=7500.0),
         n_pres=0,
         n_mocks=1,
         n_edmans=1,
     )
Пример #6
0
 def it_extends_short_peptides():
     sim_params = SimParams.construct_from_aa_list(
         ("A", "C"),
         error_model=ErrorModel.no_errors(n_channels=2),
         n_edmans=6,
     )
     flu, p_bright = sim_worker._step_1_create_flu_and_p_bright(
         pep_seq_df, sim_params)
     assert flu.shape == (2, 7)
     assert np.all(flu[:, 3:] == 0.0)
Пример #7
0
 def it_copies():
     error_model = ErrorModel.from_defaults(n_channels=2)
     src_params = SimParams.construct_from_aa_list(["DE", "Y"],
                                                   error_model=error_model)
     src_params._build_join_dfs()
     src_bleach = src_params.error_model.dyes[0].p_bleach_per_cycle
     dst_params = src_params.copy()
     dst_params.error_model.set_dye_param("p_bleach_per_cycle", 1.0)
     _src_bleach = src_params.error_model.dyes[0].p_bleach_per_cycle
     _dst_bleach = dst_params.error_model.dyes[0].p_bleach_per_cycle
     assert _src_bleach == src_bleach
     assert _dst_bleach == 1.0
Пример #8
0
    def copy(self):
        # REMOVE everything that _build_join_dfs put in
        utils.safe_del(self, "df")
        utils.safe_del(self, "by_channel")
        utils.safe_del(self, "ch_by_aa")
        utils.safe_del(self, "channel_i_to_gain")
        utils.safe_del(self, "channel_i_to_vpd")

        dst = utils.munch_deep_copy(self, klass_set={SimParams})
        dst.error_model = ErrorModel(**dst.error_model)
        assert isinstance(dst, SimParams)
        return dst
Пример #9
0
def sim(aa_list, err_set, **sim_kws):
    if isinstance(err_set, ErrorModel):
        error_model = err_set
    else:
        error_model = ErrorModel.from_err_set(err_set)
    assert sim_kws.get("n_edmans", 0) > 1
    n_pres = sim_kws.get("n_pres", 0)
    n_mocks = sim_kws.get("n_mocks", 0)
    assert (
        n_pres + n_mocks >= 1
    ), "You must include at least 1 pre or mock cycle to capture the initial image"
    return Munch(
        sim=Munch(
            version="1.0",
            inputs=Munch(prep="../prep"),
            parameters=Munch(
                **SimParams.construct_from_aa_list(
                    aa_list, error_model=error_model, include_dfs=False, **sim_kws
                )
            ),
        )
    )
Пример #10
0
)
from plaster.tools.schema import check


def _stub_sim_params(error_model, n_samples):
    return SimParams.construct_from_aa_list(
        ["A", "C"],
        error_model=error_model,
        n_samples=n_samples,
        n_pres=1,
        n_mocks=0,
        n_edmans=2,
    )


some_error_model = ErrorModel.no_errors(n_channels=2, sigma=0.16)

no_error_model = ErrorModel.no_errors(n_channels=2)


def _stub_dyemat_and_true():
    dyemat = np.array([
        [[2.0, 1.0, 0.0], [1.0, 1.0, 1.0]],
        [[2.0, 1.0, 0.0], [1.0, 1.0, 1.0]],
        [[2.0, 1.0, 0.0], [1.0, 1.0, 1.0]],
        [[3.0, 2.0, 1.0], [2.0, 1.0, 0.0]],
        [[3.0, 2.0, 1.0], [2.0, 1.0, 0.0]],
        [[2.0, 1.0, 0.0], [1.0, 1.0, 1.0]],
        [[0.1, 0.1, 0.0], [0.1, 0.1, 0.1]],
    ])
Пример #11
0
 def __init__(self, include_dfs=True, **kwargs):
     kwargs["error_model"] = kwargs.pop("error_model", ErrorModel())
     super().__init__(**kwargs)
     if include_dfs:
         self._build_join_dfs()
Пример #12
0
def zest_step_1_create_flu():
    sim_params = SimParams.construct_from_aa_list(
        ("A", "C"),
        error_model=ErrorModel.no_errors(n_channels=2),
    )

    pep_seq_df = pd.DataFrame([
        (1, "A", 0),
        (1, "B", 1),
        (1, "C", 2),
    ],
                              columns=PrepResult.pep_seqs_columns)

    def it_return_flu_and_p_bright():
        flu, p_bright = sim_worker._step_1_create_flu_and_p_bright(
            pep_seq_df, sim_params)
        assert np.all(flu == [
            [
                1,
                0,
                0,
            ],
            [
                0,
                0,
                1,
            ],
        ])
        assert np.all(p_bright == [
            [
                1,
                0,
                0,
            ],
            [
                0,
                0,
                1,
            ],
        ])

    def it_extends_short_peptides():
        sim_params = SimParams.construct_from_aa_list(
            ("A", "C"),
            error_model=ErrorModel.no_errors(n_channels=2),
            n_edmans=6,
        )
        flu, p_bright = sim_worker._step_1_create_flu_and_p_bright(
            pep_seq_df, sim_params)
        assert flu.shape == (2, 7)
        assert np.all(flu[:, 3:] == 0.0)

    def it_computes_p_bright_from_product():
        error_model = ErrorModel.no_errors(n_channels=2)
        error_model.labels[0].p_failure_to_bind_amino_acid = 0.9
        error_model.labels[1].p_failure_to_bind_amino_acid = 0.8
        error_model.labels[0].p_failure_to_attach_to_dye = 0.7
        error_model.labels[1].p_failure_to_attach_to_dye = 0.6
        error_model.dyes[0].p_non_fluorescent = 0.5
        error_model.dyes[1].p_non_fluorescent = 0.4

        sim_params = SimParams.construct_from_aa_list(("A", "C"),
                                                      error_model=error_model,
                                                      n_edmans=3)
        flu, p_bright = sim_worker._step_1_create_flu_and_p_bright(
            pep_seq_df, sim_params)
        assert flu.shape == (2, 4)
        expected = np.array([
            [
                ((1 - 0.9) * (1 - 0.7) * (1 - 0.5)),
                0,
                0,
                0,
            ],
            [
                0,
                0,
                ((1 - 0.8) * (1 - 0.6) * (1 - 0.4)),
                0,
            ],
        ])
        assert np.allclose(p_bright, expected)

    def it_labels_in_tail():
        sim_params = SimParams.construct_from_aa_list(
            ("A", "C"),
            error_model=ErrorModel.no_errors(n_channels=2),
            n_edmans=6,
        )
        pep_seq_df = pd.DataFrame(
            [
                (1, "B", 0),
                (1, "B", 1),
                (1, "B", 2),
                (1, "B", 3),
                (1, "A", 4),
                (1, "C", 5),
            ],
            columns=PrepResult.pep_seqs_columns,
        )
        flu, p_bright = sim_worker._step_1_create_flu_and_p_bright(
            pep_seq_df, sim_params)
        assert np.all(flu == [
            [0, 0, 0, 0, 1, 0, 0],
            [0, 0, 0, 0, 0, 1, 0],
        ])
        assert np.all(p_bright == [
            [0, 0, 0, 0, 1, 0, 0],
            [0, 0, 0, 0, 0, 1, 0],
        ])

    zest()