Exemplo n.º 1
0
def _run_one(simu_id, result_path, paramtree, measuretree, verbose):
    """
    This function need to be outisde Launcher class to allow
    multiprocessing module to work
    """
    queue = _run_one.q

    queue.put({"id": simu_id, "state": "start"})
    meta = Metaphase(verbose=False,
                     paramtree=paramtree,
                     measuretree=measuretree,
                     reduce_p=True)
    meta.simul()
    meta.evaluate()

    # Build filename
    simu_path = os.path.join(result_path, "simu_%06d.zip" % simu_id)

    # Write simulation result
    io = SimuIO(meta)
    io.save(simufname=simu_path, verbose=False)

    queue.put({"id" : simu_id, "state" : "stop" })

    del meta
    del io
    gc.collect()
    return True
Exemplo n.º 2
0
    def __init__(self, paramtree, measuretree,
                 initial_plug=None, parent=None):

        Metaphase.__init__(self, paramtree, measuretree,
                           initial_plug=initial_plug)
        QtGui.QWidget.__init__(self, parent)

        self.date = 0
Exemplo n.º 3
0
def _run_one_simulation(args):
    """
    """
    simu_parameters, simu_path, i, digits = args

    fname = "simu_%s.h5" % (str(i).zfill(digits))
    fpath = os.path.join(simu_path, fname)
    meta = Metaphase(**simu_parameters)
    meta.simul()
    SimuIO(meta).save(fpath, save_tree=False)
    return (i, fname)
Exemplo n.º 4
0
    MEASUREFILE = parameters.MEASUREFILE

    # Arguments parser
    parser = argparse.ArgumentParser(description="KtSimu Animator")
    parser.add_argument("--new", "-n", action="store_true", default=False, help="Run a new simulation")
    parser.add_argument(
        "--results",
        "-r",
        type=str,
        default="simu.h5",
        help="Specified results hdf5 file for new or already runned simulation",
    )
    args = parser.parse_args()

    results_file = args.results

    if args.new:

        meta = Metaphase(paramfile=PARAMFILE, measurefile=MEASUREFILE, verbose=True)
        meta.simul()
        io = SimuIO(meta)
        io.save(results_file)

    else:

        meta = SimuIO().read(results_file)

    # Run animation
    anim = Animator(meta)
    anim.play()
Exemplo n.º 5
0
    measuretree = ParamTree(MEASUREFILE, adimentionalized=False)

    # Arguments parser
    parser = argparse.ArgumentParser(description='KtSimu Launcher')
    parser.add_argument('--new', '-n', action='store_true', default=False,
                         help="Run a new simulation")
    parser.add_argument('--results', '-r', type=str, default="simu.h5",
                         help="Specified results hdf5 file for new or already runned simulation")
    args = parser.parse_args()

    results_file = args.results

    if args.new:

        # Init simu
        meta = Metaphase(verbose=True, paramtree=paramtree, measuretree=measuretree, initial_plug='random')

        # Launch simu
        meta.simul()

        # Save results
        SimuIO(meta).save(results_file)

        # Show trajectories (matplotlib needed)
        meta.show()

    else:

        meta = SimuIO().read(results_file)
        meta.show()
Exemplo n.º 6
0
    def read(self, simufname="results.zip", verbose=False):
        """
        Creates a simul_spindle.Metaphase from a results.zip file.

        :param simufname: The .zip file where results from the existing
                          simulation are (zip which contains xml and npy)
        :type simufname: string, optional

        :param verbose: Set Metaphase verbose
        :type verbose: bool

        :return: a Metaphase instance
        """

        # Unzip results.xml and data.npy and put it in
        # tempfile
        try:
            zipf = zipfile.ZipFile(simufname, "r")
        except:
            logger.info("%s does not appear to be a Zipfile" % simufname)
            return False

        # Test if simu results file are in the archive
        if "results.xml" not in zipf.namelist() or "data.npy" not in zipf.namelist():
            logger.info("%s does not contain results.xml and data.npy" % simufname)
            return False

        xmltemp = StringIO.StringIO(zipf.read("results.xml"))
        datatemp = StringIO.StringIO(zipf.read("data.npy"))

        restree = ResultTree(xmltemp, datatemp)

        param_root = restree.root.find('parameters')
        paramtree = ParamTree(root=param_root)
        params = paramtree.relative_dic
        measure_root = restree.root.find('measures')
        measuretree = ParamTree(root=measure_root,
                                adimentionalized=False)

        metaphase = Metaphase(paramtree=paramtree,
                              measuretree=measuretree,
                              verbose=verbose)

        traj_matrix = restree.get_all_trajs()
        correct_matrix = restree.get_all_correct()
        erroneous_matrix = restree.get_all_erroneous()
        state_hist_matrix = restree.get_all_plug_state()
        KD = KinetoDynamics(params)
        KD.spbR.traj = traj_matrix[:, 0]
        KD.spbL.traj = traj_matrix[:, 1]
        col_num = 2
        state_num = 0
        for n, ch in enumerate(KD.chromosomes):
            ch.cen_A.traj = traj_matrix[:, col_num]
            ch.cen_A.pos = ch.cen_A.pos
            col_num += 1
            ch.cen_B.traj = traj_matrix[:, col_num]
            ch.cen_B.pos = ch.cen_B.pos
            col_num += 1
            ch.erroneous_history = (erroneous_matrix[:, n * 2: n * 2 + 2])
            ch.correct_history = (correct_matrix[:, n * 2: n * 2 + 2])
            for plugsite in ch.cen_A.plugsites:
                plugsite.traj = traj_matrix[:, col_num]
                col_num += 1
                plugsite.state_hist = state_hist_matrix[:, state_num]
                plugsite.plug_state = plugsite.state_hist[-1]
                state_num += 1
            for plugsite in ch.cen_B.plugsites:
                plugsite.traj = traj_matrix[:, col_num]
                col_num += 1
                plugsite.state_hist = state_hist_matrix[:, state_num]
                plugsite.plug_state = plugsite.state_hist[-1]
                state_num += 1

        metaphase.KD = KD

        metaphase.KD.simulation_done = True

        return metaphase
Exemplo n.º 7
0
    def read(self, simufname, paramtree=None, measuretree=None, verbose=False):
        """
        Creates a simul_spindle.Metaphase from a results.zip file.

        Parameters
        ----------
        simufname : string, optional
            The .zip file where results from the existing simulation are
            (zip which contains xml and npy)

        verbose : bool
            Set Metaphase verbose

        Returns
        -------
        :class:`~kt_simul.core.simul_spindle.Metaphase`

        """

        store = pd.HDFStore(simufname)

        if not paramtree:
            param_root = build_tree(store['params'])
            paramtree = ParamTree(root=param_root)
        params = paramtree.relative_dic

        if not measuretree:
            measure_root = build_tree(store['measures'])
            measuretree = ParamTree(root=measure_root,
                                    adimentionalized=False)

        meta = Metaphase(paramtree=paramtree, measuretree=measuretree, verbose=False)
        KD = KinetoDynamics(params)

        spbs = store['spbs']

        KD.spbL.traj = spbs.xs('A', level='side').values.T[0]
        KD.spbR.traj = spbs.xs('B', level='side').values.T[0]

        kts = store['kts']
        plug_sites = store['plug_sites']
        store.close()

        for ch, (ch_id, ch_df) in zip(KD.chromosomes, kts.groupby(level="id")):
            ch.cen_A.traj = ch_df.xs('A', level='side')['x'].values.T
            ch.cen_B.traj = ch_df.xs('B', level='side')['x'].values.T
            ch.cen_A.tag = 'A'
            ch.cen_B.tag = 'B'

            for i, plugsite in enumerate(ch.cen_A.plugsites):
                ps = plug_sites.xs((ch_id, 'A', i), level=['id', 'side', 'plug_id'])
                plugsite.traj = ps['x'].values
                plugsite.state_hist = ps['state_hist'].values
                plugsite.plug_state = plugsite.state_hist[-1]
                plugsite.tag = 'A'

            for i, plugsite in enumerate(ch.cen_B.plugsites):
                ps = plug_sites.xs((ch_id, 'B', i), level=['id', 'side', 'plug_id'])
                plugsite.traj = ps['x'].values
                plugsite.state_hist = ps['state_hist'].values
                plugsite.plug_state = plugsite.state_hist[-1]
                plugsite.tag = 'B'

            ch.cen_A.calc_plug_vector()
            ch.cen_B.calc_plug_vector()

            ch.calc_erroneous_history()
            ch.calc_correct_history()

        meta.KD = KD
        meta.KD.simulation_done = True

        return meta