コード例 #1
0
    def __init__(self, pipeline, fixed_params, variable_param_options,
                 eval_metrics, n_repeat, working_directory):
        self.pipeline = pipeline
        self.fixed_params = OrderedDict(fixed_params)
        self.variable_param_options = OrderedDict(variable_param_options)
        self.eval_metrics = eval_metrics
        self.working_directory = working_directory
        self.n_repeat = n_repeat
        mkpath(working_directory)

        # Handle repetitions as a variable parameter
        self.variable_param_options['i_repeat'] = list(range(n_repeat))
コード例 #2
0
def animate_walk(simulation, alpha=0.3, anim_folder=ANIM_FOLDER):
    mkpath(anim_folder)
    walk = simulation.get_location_history()
    n = walk.shape[0]
    n_steps, n_sites, n_dim = walk.shape
    assert n_sites == simulation.n_sites
    assert n_dim == 2

    x_min, y_min, x_max, y_max = bounding_box(walk.reshape(-1, 2), margin=0.05)

    fig = plt.figure()
    ax = fig.add_axes([0, 0, 1, 1])
    plt.tight_layout(pad=0)
    ax.set_xlim(x_min, x_max), ax.set_xticks([])
    ax.set_ylim(y_min, y_max), ax.set_yticks([])
    w, h = fig.get_size_inches()
    h *= 15 / w
    w = 15
    fig.set_size_inches(w, h)

    paths = []
    for i in range(simulation.n_sites):
        p, = ax.plot([], [], color=COLOR_PATH, lw=PATH_WIDTH, zorder=0)
        paths.append(p)

    root = ax.scatter(*walk[0, :, :].T, marker='*', c=COLOR_ROOT_TRUE, s=500, zorder=5)
    scat = ax.scatter(*walk[0, :, :].T, color=COLOR_SCATTER, s=30, lw=0, zorder=4)

    def update(frame):
        if frame > n+1:
            return

        scat.set_offsets(walk[frame-2:frame+3, :, :].mean(axis=0))
        for i, p in enumerate(paths):
            p.set_data(walk[:frame, i, 0], walk[:frame, i, 1])
        # plt.savefig(anim_folder + 'step_%i.png' % frame)

    anim = animation.FuncAnimation(fig, update, frames=n_steps-1 + 20,
                                   interval=60)
    anim.save('results/animation.gif', dpi=100, writer='imagemagick')
    plt.show()
コード例 #3
0
    ADAPT_HEIGHT = False
    FIX_ROOT = False

    # SUFFIX = '_missingClades'

    WORKING_DIR = 'data/bantu_{model}_outgroup_{og}_adapttree_{at}_' + \
                  'adaptheight_{ah}_hpd_{hpd}{fixroot}{suffix}/'
    WORKING_DIR = WORKING_DIR.format(
        model=MODEL, og=USE_OUTGROUP, at=ADAPT_TREE, ah=ADAPT_HEIGHT, hpd=HPD,
        fixroot='_fixroot' if FIX_ROOT else '', suffix=SUFFIX
    )
    BANTU_XML_PATH = WORKING_DIR + 'nowhere.xml'
    GEOJSON_PATH = 'africa.geojson'
    GEO_TREE_PATH = WORKING_DIR + 'nowhere.tree'
    GEO_TREES_PATH = WORKING_DIR + 'nowhere.trees'
    mkpath(WORKING_DIR)

    HOMELAND = np.array([10.5, 6.5])
    ax.scatter(*HOMELAND, marker='*', c=TURQUOISE, s=200, zorder=3)

    write_bantu_xml(BANTU_XML_PATH, CHAIN_LENGTH,
                   root=HOMELAND if FIX_ROOT else None,
                   exclude_outgroup=not USE_OUTGROUP,
                   adapt_tree=ADAPT_TREE,
                   adapt_height=ADAPT_HEIGHT,
                   movement_model=MODEL)

    # Run the BEAST analysis
    run_beast(WORKING_DIR)
    run_treeannotator(HPD, BURNIN, WORKING_DIR)
コード例 #4
0
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from __future__ import absolute_import, division, print_function, unicode_literals
import os
import subprocess
import logging
import time

from src.beast_xml_templates import *
from src.tree import Tree
from src.util import str_concat_array, extract_newick_from_nexus, SubprocessException, mkpath

BEAST_LOGGER_PATH = 'logs/beast.log'
mkpath(BEAST_LOGGER_PATH)

EXPERIMENT_LOGGER = logging.getLogger('experiment')

BEAST_LOGGER = logging.getLogger('beast')
BEAST_LOGGER.setLevel(logging.DEBUG)
BEAST_LOGGER.addHandler(logging.FileHandler(BEAST_LOGGER_PATH))
BEAST_LOGGER.info('=' * 100)
BEAST_LOGGER.info('New Run')
BEAST_LOGGER.info('=' * 100)

def write_nexus(simulation, path, fossils=None):
    data_str = ''

    for i, state in enumerate(simulation.societies):
        name = state.name
        fs = state.featureState.features.astype(int)