Esempio n. 1
0
def kshv_pos_selection(base_path: str, generations: int = 50) -> float:
    """Simulate KSHV with and without positive selection and plot the results.

    Args:
        base_path (str): path into which the data should be saved
        pos_coefficient (float, optional): the nonzero positive selection coefficient to use. Defaults to 0.10.
        generations (int, optional): the number of generations to simulate. Defaults to 50.

    Returns:
        float: the fraction of cells with zero plasmids per cell after generations
    """
    kshv_pop = lpp.LatentPlasmidPopulation()
    kshv_pop.set_virus('kshv')
    # Set up a large population and burn in
    kshv_pop.population(5000, lambda_=0.02)
    kshv_pop.simulate(generations)
    ppc = kshv_pop.get_plasmids_per_cell()
    av_nonzero_ppc = np.average(np.arange(len(ppc) - 1) + 1, weights=ppc[1:])
    print(av_nonzero_ppc)

    ts = kshv_pop.save(base_path, {})
    plasmid_rep.plotting.standard_plots.plasmids_per_cell(
        kshv_pop,
        os.path.join(base_path, f'{ts}-kshv_complete.pdf'),
        xmax=50,
        add_text=f'KSHV {generations} gens both selections')

    return ppc[0]
def kshv_pos_selection(base_path: str, generations: int = 50) -> float:
    """Simulate KSHV with and without positive selection and plot the results.

    Args:
        base_path (str): path into which the data should be saved
        generations (int, optional): the number of generations to simulate. Defaults to 50.

    """
    for sel in [None]:
        kshv_pop = lpp.LatentPlasmidPopulation()
        kshv_pop.set_virus('kshv')
        kshv_pop.update_parameters({
            'negative_cluster_selection_coefficient': 0,
            's_phase_duplication_prob': 0.92,
            'positive_selection_coefficient': sel
        })
        sel = kshv_pop.positive_selection_coefficient  # In case of None, get default

        # Set up a large population and burn in
        kshv_pop.population(3000, lambda_=0.02)
        kshv_pop.simulate(generations)
        ppc = kshv_pop.get_plasmids_per_cell()
        av_nonzero_ppc = np.average(np.arange(len(ppc) - 1) + 1,
                                    weights=ppc[1:])
        print(av_nonzero_ppc)

        ts = kshv_pop.save(base_path, {})
        plasmid_rep.plotting.standard_plots.plasmids_per_cell(
            kshv_pop,
            os.path.join(base_path,
                         f'{ts}-kshv_sel{sel}_plasmids_oer_cell.pdf'),
            xmax=50,
            add_text=f'KSHV 50 gens positive sel: {sel}')
def ebv_pos_selection(base_path: str, generations: int = 50) -> float:
    """Simulate EBV with and without positive selection and plot the results.

    Args:
        base_path (str): path into which the data should be saved
        generations (int, optional): the number of generations to simulate. Defaults to 50.

    Returns:
        float: the fraction of cells with zero plasmids per cell after generations
    """
    for sel in [0, None]:
        ebv_pop = lpp.LatentPlasmidPopulation()
        ebv_pop.set_virus('ebv')
        ebv_pop.update_parameters({'positive_selection_coefficient': sel})
        sel = ebv_pop.positive_selection_coefficient  # In case of None, get default

        # Set up a large population and burn in
        ebv_pop.population(5000, lambda_=2)
        ebv_pop.simulate(generations)
        ppc = ebv_pop.get_plasmids_per_cell()
        av_nonzero_ppc = np.average(np.arange(len(ppc) - 1) + 1, weights=ppc[1:])
        print(av_nonzero_ppc)

        ts = ebv_pop.save(base_path, {})
        plasmid_rep.plotting.standard_plots.plasmids_per_cell(ebv_pop,
                                                            os.path.join(base_path, f'{ts}-ebv_sel{sel}_plasmids_oer_cell.pdf'))

    return ppc[0]
Esempio n. 4
0
def fraction_of_ebvpos_cells(pos_coefficient: float = 0.10,
                             generations: int = 100) -> float:

    ebv_pop = lpp.LatentPlasmidPopulation()
    ebv_pop.set_virus('ebv')
    ebv_pop.positive_selection_coefficient = pos_coefficient

    # Set up a large population and burn in
    ebv_pop.population(5000, lambda_=2)
    ebv_pop.simulate(generations)
    ppc = ebv_pop.get_plasmids_per_cell()
    av_nonzero_ppc = np.average(np.arange(len(ppc) - 1) + 1, weights=ppc[1:])
    print(av_nonzero_ppc)

    return ppc[0]
def kshv_pos_selection(base_path: str, generations: int = 50, turn_off_neg: bool = False) -> float:
    """Simulate KSHV with and without positive selection and plot the results.

    Args:
        base_path (str): path into which the data should be saved
        pos_coefficient (float, optional): the nonzero positive selection coefficient to use. Defaults to 0.10.
        generations (int, optional): the number of generations to simulate. Defaults to 50.

    Returns:
        float: the fraction of cells with zero plasmids per cell after generations
    """
    # kshv_pop = lpp.LatentPlasmidPopulation()
    # kshv_pop.set_virus('kshv')
    # if turn_off_neg:
    #     kshv_pop.update_parameters({'negative_cluster_selection_coefficient': 0,
    #                                 's_phase_duplication_prob': 0.92})
    # # Set up a large population and burn in
    # kshv_pop.population(2000, mu=1, sd=0)
    # kshv_pop.simulate(generations)

    # ts = kshv_pop.save(base_path, {})

    big_pop = lpp.LatentPlasmidPopulation()
    big_pop.set_virus('kshv')
    if turn_off_neg:
        big_pop.update_parameters({'negative_cluster_selection_coefficient': 0,
                                   's_phase_duplication_prob': 0.92})
    # Set up a large population and burn in
    big_pop.population(2000, mu=2, sd=0)
    big_pop.simulate(generations)

    ts2 = big_pop.save(base_path, {})
    neg_text = 'noneg' if turn_off_neg else 'neg'
    plasmid_rep.plotting.standard_plots.multi_plasmids_per_cell([big_pop],
                                                                os.path.join(base_path, f'{ts2}-{neg_text}-kshv_small_big.pdf'), 
                                                                xmax=50, 
                                                                add_text=f'KSHV {generations} gens both selections')
    # ts = kshv_pop.save(base_path, {})

    big_pop = lpp.LatentPlasmidPopulation()
    big_pop.set_virus('kshv')
    if turn_off_neg:
        big_pop.update_parameters({'negative_cluster_selection_coefficient': 0,
                                   's_phase_duplication_prob': 0.92})
    # Set up a large population and burn in
    big_pop.population(2000, mu=2, sd=0)
    big_pop.simulate(generations)

    ts2 = big_pop.save(base_path, {})
    neg_text = 'noneg' if turn_off_neg else 'neg'
    plasmid_rep.plotting.standard_plots.multi_plasmids_per_cell([big_pop],
                                                                os.path.join(base_path, f'{ts2}-{neg_text}-kshv_small_big.pdf'), 
                                                                xmax=50, 
                                                                add_text=f'KSHV {generations} gens both selections')


if __name__ == '__main__':
    import logging
    logging.basicConfig(
        format='%(asctime)s %(levelname)-8s %(message)s',
        level=logging.INFO,
        datefmt='%Y-%m-%d %H:%M:%S')
    
    pop = lpp.LatentPlasmidPopulation()
    base_path = pop.load_config()['base_path']
    kshv_pos_selection(base_path)