当前位置: 首页>>代码示例>>Python>>正文


Python RUtil.run_plotter_no_table方法代码示例

本文整理汇总了Python中RUtil.run_plotter_no_table方法的典型用法代码示例。如果您正苦于以下问题:Python RUtil.run_plotter_no_table方法的具体用法?Python RUtil.run_plotter_no_table怎么用?Python RUtil.run_plotter_no_table使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在RUtil的用法示例。


在下文中一共展示了RUtil.run_plotter_no_table方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_r_tikz_stub

# 需要导入模块: import RUtil [as 别名]
# 或者: from RUtil import run_plotter_no_table [as 别名]
def get_r_tikz_stub():
    user_script = RUtil.g_stub
    device_name = "tikz"
    retcode, r_out, r_err, tikz_code = RUtil.run_plotter_no_table(user_script, device_name)
    if retcode:
        raise RUtil.RError(r_err)
    return tikz_code
开发者ID:argriffing,项目名称:xgcode,代码行数:9,代码来源:20120122a.py

示例2: get_response_content

# 需要导入模块: import RUtil [as 别名]
# 或者: from RUtil import run_plotter_no_table [as 别名]
def get_response_content(fs):
    # define some fixed values
    N_diploid = 6
    N_hap = 2 * N_diploid
    plot_density = 8
    # define some mutation rates
    theta_values = [0.001, 0.01, 0.1, 1.0]
    # define some selection coefficients to plot
    Ns_low = 0.0
    Ns_high = 3.0
    Ns_values = np.linspace(Ns_low, Ns_high, 3 * plot_density + 1)
    # get the values for each h
    Nr_values = (0, 5)
    arr_0 = get_plot_array(N_diploid, Nr_values[0], theta_values, Ns_values)
    arr_1 = get_plot_array(N_diploid, Nr_values[1], theta_values, Ns_values)
    ylab = '"expected returns to AB"'
    # define x and y plot limits
    xlim = (Ns_low, Ns_high)
    ylim = (np.min((arr_0, arr_1)), np.max((arr_0, arr_1)))
    ylogstr = '""'
    # http://sphaerula.com/legacy/R/multiplePlotFigure.html
    out = StringIO()
    print >> out, mk_call_str("par", mfrow="c(1,2)", oma="c(0,0,2,0)")
    print >> out, get_plot("left", Nr_values[0], arr_0, theta_values, Ns_values, xlim, ylim, ylogstr, ylab)
    print >> out, get_plot("right", Nr_values[1], arr_1, theta_values, Ns_values, xlim, ylim, ylogstr, '""')
    print >> out, mk_call_str("title", '"expected number of returns to AB, 2N=%s"' % N_hap, outer="TRUE")
    script = out.getvalue().rstrip()
    # create the R plot image
    device_name = Form.g_imageformat_to_r_function[fs.imageformat]
    retcode, r_out, r_err, image_data = RUtil.run_plotter_no_table(script, device_name)
    if retcode:
        raise RUtil.RError(r_err)
    return image_data
开发者ID:argriffing,项目名称:xgcode,代码行数:35,代码来源:20120905d.py

示例3: get_response_content

# 需要导入模块: import RUtil [as 别名]
# 或者: from RUtil import run_plotter_no_table [as 别名]
def get_response_content(fs):
    # define the initial frequency
    p = 0.1
    # define some selection coefficients to plot
    h_low = 0.2
    h_high = 0.8
    h_values = np.linspace(h_low, h_high, 6*10 + 1)
    # define some dominance coefficients
    hs_values = [-0.2, -0.05, 0, 0.05, 0.2]
    colors = ['blue', 'green', 'black', 'orange', 'red']
    # get the values for each h
    arr = []
    for hs in hs_values:
        v = [kimura.get_fixation_probability_chen(p, hs/h, h) for h in h_values]
        arr.append(v)
    #
    # define the r script
    out = StringIO()
    print >> out, 'h.values <- c', str(tuple(h_values))
    print >> out, 'ha <- c', str(tuple(arr[0]))
    print >> out, 'hb <- c', str(tuple(arr[1]))
    print >> out, 'hc <- c', str(tuple(arr[2]))
    print >> out, 'hd <- c', str(tuple(arr[3]))
    print >> out, 'he <- c', str(tuple(arr[4]))
    print >> out, mk_call_str('plot', 'h.values', 'ha',
            type='"l"',
            xlab='"h"',
            ylab='"probability of eventual fixation"',
            main=(
                '"fixation probabilities for various h*s ; '
                's = 2*N*sigma ; p0 = %s"' % p),
            ylim='c(0, 0.2)',
            col='"%s"' % colors[0],
            )
    print >> out, mk_call_str('lines', 'h.values', 'hb', col='"%s"' % colors[1])
    print >> out, mk_call_str('lines', 'h.values', 'hc', col='"%s"' % colors[2])
    print >> out, mk_call_str('lines', 'h.values', 'hd', col='"%s"' % colors[3])
    print >> out, mk_call_str('lines', 'h.values', 'he', col='"%s"' % colors[4])
    script = out.getvalue().rstrip()
    # create the R plot image
    device_name = Form.g_imageformat_to_r_function[fs.imageformat]
    retcode, r_out, r_err, image_data = RUtil.run_plotter_no_table(
            script, device_name)
    if retcode:
        raise RUtil.RError(r_err)
    return image_data
开发者ID:argriffing,项目名称:xgcode,代码行数:48,代码来源:20120829a.py

示例4: get_response_content

# 需要导入模块: import RUtil [as 别名]
# 或者: from RUtil import run_plotter_no_table [as 别名]
def get_response_content(fs):
    # define the initial frequency
    p = 0.8
    # define some selection coefficients to plot
    low = -5
    high = 5
    s_values = np.linspace(low, high, (high - low) * 20 + 1)
    # define some dominance coefficients
    h_values = [2, 3, 5, 7]
    # get the values for each h
    arr = []
    for h in h_values:
        v = [kimura.get_fixation_probability_chen(p, s, h) for s in s_values]
        arr.append(v)
    #
    # define the r script
    out = StringIO()
    print >> out, 'title.string <- "my title"'
    print >> out, "s.values <- c", str(tuple(s_values))
    print >> out, "ha <- c", str(tuple(arr[0]))
    print >> out, "hb <- c", str(tuple(arr[1]))
    print >> out, "hc <- c", str(tuple(arr[2]))
    print >> out, "hd <- c", str(tuple(arr[3]))
    print >> out, mk_call_str(
        "plot",
        "s.values",
        "ha",
        type='"l"',
        xlab='"selection coefficient (s)"',
        ylab='"probability of eventual fixation"',
        main='"fixation probabilities for various h ; p0 = 0.8"',
        ylim="c(0.5,1)",
    )
    print >> out, mk_call_str("lines", "s.values", "hb", col='"red"')
    print >> out, mk_call_str("lines", "s.values", "hc", col='"green"')
    print >> out, mk_call_str("lines", "s.values", "hd", col='"blue"')
    script = out.getvalue().rstrip()
    # create the R plot image
    device_name = Form.g_imageformat_to_r_function[fs.imageformat]
    retcode, r_out, r_err, image_data = RUtil.run_plotter_no_table(script, device_name)
    if retcode:
        raise RUtil.RError(r_err)
    return image_data
开发者ID:argriffing,项目名称:xgcode,代码行数:45,代码来源:20120828b.py

示例5: get_response_content

# 需要导入模块: import RUtil [as 别名]
# 或者: from RUtil import run_plotter_no_table [as 别名]
def get_response_content(fs):
    # define the initial frequency
    p = 0.1
    # define some selection coefficients to plot
    low = -20
    high = 20
    s_values = np.linspace(low, high, (high-low)*10 + 1)
    # define some dominance coefficients
    h_values = [-3, 0, 1, 2]
    # get the values for each h
    arr = []
    for h in h_values:
        v = [kimura.get_fixation_probability_chen(p, s, h) for s in s_values]
        arr.append(v)
    #
    # define the r script
    out = StringIO()
    print >> out, 's.values <- c', str(tuple(s_values))
    print >> out, 'ha <- c', str(tuple(arr[0]))
    print >> out, 'hb <- c', str(tuple(arr[1]))
    print >> out, 'hc <- c', str(tuple(arr[2]))
    print >> out, 'hd <- c', str(tuple(arr[3]))
    print >> out, mk_call_str('plot', 's.values', 'ha',
            type='"l"',
            xlab='"selection coefficient (s)"',
            ylab='"probability of eventual fixation"',
            main='"fixation probabilities for various h ; p0 = 0.1"',
            ylim='c(0,1)',
            )
    print >> out, mk_call_str('lines', 's.values', 'hb', col='"red"')
    print >> out, mk_call_str('lines', 's.values', 'hc', col='"green"')
    print >> out, mk_call_str('lines', 's.values', 'hd', col='"blue"')
    script = out.getvalue().rstrip()
    # create the R plot image
    device_name = Form.g_imageformat_to_r_function[fs.imageformat]
    retcode, r_out, r_err, image_data = RUtil.run_plotter_no_table(
            script, device_name)
    if retcode:
        raise RUtil.RError(r_err)
    return image_data
开发者ID:argriffing,项目名称:xgcode,代码行数:42,代码来源:20120828c.py

示例6: get_response_content

# 需要导入模块: import RUtil [as 别名]
# 或者: from RUtil import run_plotter_no_table [as 别名]
def get_response_content(fs):
    # define some fixed values
    N_diploid = 8
    N_hap = 2 * N_diploid
    plot_density = 8
    # get the user-defined theta
    if fs.theta_1em0:
        theta = 1.0
    elif fs.theta_1em1:
        theta = 0.1
    elif fs.theta_1em2:
        theta = 0.01
    # define some mutation rates
    Nr_values = [0.0, 5.0]
    # define some selection coefficients to plot
    Ns_low = 0.0
    Ns_high = 2.5
    Ns_values = np.linspace(Ns_low, Ns_high, 3*plot_density + 1)
    # get the values for each h
    arr = get_plot_array(N_diploid, theta, Nr_values, Ns_values)
    #ylab='"log(Type1 / Type2)"'
    ylab='"normalized time (Type1 - Type2)"'
    # define x and y plot limits
    xlim = (Ns_low, Ns_high)
    ylim = (np.min(arr), np.max(arr))
    ylogstr = '""'
    out = StringIO()
    print >> out, get_plot(
            N_hap, theta, arr, Nr_values, Ns_values,
            xlim, ylim, ylogstr, ylab)
    script = out.getvalue().rstrip()
    # create the R plot image
    device_name = Form.g_imageformat_to_r_function[fs.imageformat]
    retcode, r_out, r_err, image_data = RUtil.run_plotter_no_table(
            script, device_name)
    if retcode:
        raise RUtil.RError(r_err)
    return image_data
开发者ID:argriffing,项目名称:xgcode,代码行数:40,代码来源:20120905c.py

示例7: get_response_content

# 需要导入模块: import RUtil [as 别名]
# 或者: from RUtil import run_plotter_no_table [as 别名]

#.........这里部分代码省略.........
        v = MatrixUtil.get_stationary_distribution(P)
        for state_index, counts in enumerate(kaizeng.gen_states(
            N_big_haploid, k)):
            if counts[0] and counts[1]:
                allele_histograms[i, counts[0]] += v[state_index]
    # Define the r table.
    # There are nine columns each corresponding to an allele frequency.
    # There are three rows each corresponding to a configuration.
    arr = []
    # Use the two allele approximation
    # from mcvean and charlesworth 1999 referred to by zeng 2011.
    # I'm not sure if I am using the right equation.
    g0 = fs.gamma_0
    g1 = fs.gamma_1
    """
    s_0 = -gamma_0 / float(N_big)
    s_1 = -gamma_1 / float(N_big)
    hist = np.zeros(N_small+1)
    for i in range(1, N_small):
        x = i / float(N_small)
        hist[i] = math.exp(1*N_big*(s_0 - s_1)*x) / (x*(1-x))
    h = hist[1:-1]
    h /= np.sum(h)
    arr.append(h.tolist())
    """
    arr.append(diallelic_approximation(N_small, g0, g1).tolist())
    # Use the exact two allele distribution.
    # Well, it is exact if I understand the right scaling
    # of the population size and fitnesses.
    f0 = 1.0
    f1 = 1.0 - gamma / N_big_haploid
    #f0 = 1.0 + gamma / N
    #f1 = 1.0
    #f0 = 1.0 + 1.5 / (4*N)
    #f1 = 1.0 - 1.5 / (4*N)
    h = get_two_allele_distribution(
            N_big_haploid, N_small, f0, f1, f_subsample)
    arr.append(h.tolist())
    # Get frequencies for the other two configurations
    for hist in allele_histograms:
        # Get probabilities conditional on dimorphism.
        hist[0] = 0
        hist[-1] = 0
        hist /= np.sum(hist)
        # Get the subsampled pmf.
        distn = f_subsample(hist, N_small)
        MatrixUtil.assert_distribution(distn)
        # Get probabiities conditional on dimorphism of the sample.
        distn[0] = 0
        distn[-1] = 0
        distn /= np.sum(distn)
        # Add to the table of densities.
        arr.append(distn[1:-1].tolist())
    # Get a large population approximation
    # when there is mutational bias.
    params = (0.008, 2, 1, fs.gamma_0, fs.gamma_1, fs.gamma_2)
    mutation, fitness = kaizeng.params_to_mutation_fitness(
            N_big_haploid, params)
    gammas = np.array([fs.gamma_0, fs.gamma_1, fs.gamma_2, 0])
    h = kaizeng.get_large_population_approximation(N_small, k, gammas, mutation)
    arr.append(h.tolist())
    # define the r script
    out = StringIO()
    print >> out, 'title.string <- "allele 1 vs allele 2"'
    print >> out, 'mdat <-', RUtil.matrix_to_R_string(arr)
    print >> out, mk_call_str(
            'barplot',
            'mdat',
            'legend.text=' + mk_call_str(
                'c',
                '"two-allele large N limit"',
                '"two-allele"',
                '"four-allele without mutational bias"',
                '"four-allele with mutational bias (kappa_{1,2}=2)"',
                '"four-allele with mutational bias, large N limit"',
                ),
            'args.legend = list(x="topleft", bty="n")',
            'names.arg = c(1,2,3,4,5,6,7,8,9)',
            main='title.string',
            xlab='"frequency of allele 1"',
            ylab='"frequency"',
            col=mk_call_str(
                'c',
                '"red"',
                '"white"',
                '"black"',
                '"gray"',
                '"blue"',
                ),
            beside='TRUE',
            )
    #print >> out, 'box()'
    script = out.getvalue().rstrip()
    # create the R plot image
    device_name = Form.g_imageformat_to_r_function[fs.imageformat]
    retcode, r_out, r_err, image_data = RUtil.run_plotter_no_table(
            script, device_name)
    if retcode:
        raise RUtil.RError(r_err)
    return image_data
开发者ID:argriffing,项目名称:xgcode,代码行数:104,代码来源:20120820a.py

示例8: get_response_content

# 需要导入模块: import RUtil [as 别名]
# 或者: from RUtil import run_plotter_no_table [as 别名]
def get_response_content(fs):
    # define the initial frequency
    p = 0.1
    # define some selection coefficients to plot
    h_low = 0.2
    h_high = 0.8
    h_values = np.linspace(h_low, h_high, 6*10 + 1)
    # define some dominance coefficients
    hs_values = [-0.2, -0.1, -0.04, 0, 0.04, 0.1, 0.2]
    #colors = ['blue', 'green', 'black', 'orange', 'red']
    colors = ['darkviolet', 'blue', 'green', 'black', 'yellow', 'orange', 'red']
    # get the values for each h
    arr = []
    xaxis = []
    for hs in hs_values:
        s_values = hs / h_values
        v = [kimura.get_fixation_probability_chen(p, hs/h, h) for h in h_values]
        xaxis.append(s_values)
        arr.append(v)
    #
    # define the r script
    out = StringIO()
    print >> out, 'h.values <- c', str(tuple(h_values))
    print >> out, 'ha <- c', str(tuple(arr[0]))
    print >> out, 'hb <- c', str(tuple(arr[1]))
    print >> out, 'hc <- c', str(tuple(arr[2]))
    print >> out, 'hd <- c', str(tuple(arr[3]))
    print >> out, 'he <- c', str(tuple(arr[4]))
    print >> out, 'hf <- c', str(tuple(arr[5]))
    print >> out, 'hg <- c', str(tuple(arr[6]))
    print >> out, 'ha.x <- c', str(tuple(xaxis[0]))
    print >> out, 'hb.x <- c', str(tuple(xaxis[1]))
    print >> out, 'hc.x <- c', str(tuple(xaxis[2]))
    print >> out, 'hd.x <- c', str(tuple(xaxis[3]))
    print >> out, 'he.x <- c', str(tuple(xaxis[4]))
    print >> out, 'hf.x <- c', str(tuple(xaxis[5]))
    print >> out, 'hg.x <- c', str(tuple(xaxis[6]))
    print >> out, mk_call_str('plot', 'ha.x', 'ha',
            type='"l"',
            xlab='"selection coefficient (s)"',
            ylab='"probability of eventual fixation"',
            main=(
                '"fixation probabilities for various h*s ; '
                's = 2*N*sigma ; p0 = %s"' % p),
            xlim='c(-1, 1)',
            ylim='c(0.05, 0.15)',
            col='"%s"' % colors[0],
            )
    print >> out, mk_call_str('lines', 'hb.x', 'hb', col='"%s"' % colors[1])
    print >> out, mk_call_str('lines', 'hc.x', 'hc', col='"%s"' % colors[2])
    print >> out, mk_call_str('lines', 'hd.x', 'hd', col='"%s"' % colors[3])
    print >> out, mk_call_str('lines', 'he.x', 'he', col='"%s"' % colors[4])
    print >> out, mk_call_str('lines', 'hf.x', 'hf', col='"%s"' % colors[5])
    print >> out, mk_call_str('lines', 'hg.x', 'hg', col='"%s"' % colors[6])
    print >> out, mk_call_str(
            'legend',
            '"topleft"',
            'c' + str(rev('hs = %s' % x for x in hs_values)),
            lty='c' + str(rev([1]*7)),
            lwd='c' + str(rev([2.5]*7)),
            col='c' + str(rev(colors)),
            )
    script = out.getvalue().rstrip()
    # create the R plot image
    device_name = Form.g_imageformat_to_r_function[fs.imageformat]
    retcode, r_out, r_err, image_data = RUtil.run_plotter_no_table(
            script, device_name)
    if retcode:
        raise RUtil.RError(r_err)
    return image_data
开发者ID:argriffing,项目名称:xgcode,代码行数:72,代码来源:20120829b.py

示例9: get_response_content

# 需要导入模块: import RUtil [as 别名]
# 或者: from RUtil import run_plotter_no_table [as 别名]
def get_response_content(fs):
    N_diploid = 10
    N_mutants = 1
    N_haploid = N_diploid * 2
    p = N_mutants / float(N_haploid)
    t1_exact = []
    t1_approx = []
    Nes_values = range(1, 9)
    for Nes in Nes_values:
        s = Nes / float(N_diploid)
        t1_exact.append(get_t1_exact(N_mutants, N_diploid, s))
        t1_approx.append(get_t1_approx(p, N_diploid, s))
    # define the r script
    out = StringIO()
    print >> out, 'title.string <- "my title"'
    print >> out, 'Nes <- c', str(tuple(Nes_values))
    print >> out, 't1 <- c', str(tuple(t1_exact))
    print >> out, 't1.approx <- c', str(tuple(t1_approx))
    print >> out, mk_call_str('plot', 'Nes', 't1',
            #col='"red"', type='"l"', xaxp='c(0,1,10)',
            ylim='c(0,%s)' % (N_diploid*4))
    print >> out, mk_call_str('lines', 'Nes', 't1.approx', col='"red"')
    #print >> out, mk_call_str('points', 'p.20', 't1.20.exact',
            #col='"blue"')
    #
    """
    print >> out, 't1.10.approx <- c', str(tuple(t1_10_approx))
    print >> out, 't1.10.exact <- c', str(tuple(t1_10_exact))
    print >> out, 'p.10 <- c', str(tuple(proportions_10.tolist()))
    print >> out, mk_call_str('lines', 'p.10', 't1.10.approx',
            col='"red"')
    print >> out, mk_call_str('points', 'p.10', 't1.10.exact',
            col='"blue"')
    """
    #
    """
            'barplot',
            'mdat',
            'legend.text=' + mk_call_str(
                'c',
                '"exact discrete distribution"',
                '"continuous approximation"',
                #'"two-allele large N limit"',
                #'"two-allele"',
                #'"four-allele without mutational bias"',
                #'"four-allele with mutational bias (kappa_{1,2}=2)"',
                #'"four-allele with mutational bias, large N limit"',
                ),
            'args.legend = list(x="topright", bty="n")',
            'names.arg = 1:%s' % (N-1),
            main='title.string',
            xlab='"frequency of allele 1"',
            ylab='"frequency"',
            col=mk_call_str(
                'c',
                #'"red"',
                #'"white"',
                '"black"',
                #'"gray"',
                '"red"',
                ),
            beside='TRUE',
            border='NA',
            )
    #print >> out, 'box()'
    """
    script = out.getvalue().rstrip()
    # create the R plot image
    device_name = Form.g_imageformat_to_r_function[fs.imageformat]
    retcode, r_out, r_err, image_data = RUtil.run_plotter_no_table(
            script, device_name)
    if retcode:
        raise RUtil.RError(r_err)
    return image_data
开发者ID:argriffing,项目名称:xgcode,代码行数:76,代码来源:20120827b.py

示例10: get_response_content

# 需要导入模块: import RUtil [as 别名]
# 或者: from RUtil import run_plotter_no_table [as 别名]
def get_response_content(fs):
    N_diploid = fs.N_diploid
    N = N_diploid * 2
    k = 2
    gamma = fs.gamma
    # define the fitnesses and the selection value
    f0 = 1.0
    f1 = 1.0 - gamma / N
    s = 1 - f1 / f0
    if f1 <= 0:
        raise ValueError('the extreme selection caused a non-positive fitness')
    # get a wright fisher transition matrix
    P = np.exp(wfengine.create_genic_diallelic(N_diploid, s))
    """
    # condition on no fixation
    for i in range(N):
        P[i] /= 1 - P[i, N]
    # remove the fixed state from the transition matrix
    P = P[:N, :N]
    """
    # add mutations
    P[0, 0] = 0
    P[0, 1] = 1
    P[N, N] = 0
    P[N, 1] = 1
    # compute the stationary distribution
    v = MatrixUtil.get_stationary_distribution(P)
    # get the distribution over dimorphic states
    h = v[1:-1]
    h /= np.sum(h)
    # look at continuous approximations
    w = np.zeros(N+1)
    for i in range(1, N):
        x = i / float(N)
        #x0 = i / float(N)
        #x1 = (i + 1) / float(N)
        #value = sojourn_definite(x0, x1, gamma)
        value = sojourn_kernel(x, gamma)
        w[i] = value
    w = w[1:-1]
    w /= np.sum(w)
    # get the array for the R plot
    arr = [h.tolist(), w.tolist()]
    # define the r script
    out = StringIO()
    print >> out, 'title.string <- "allele 1 vs allele 2"'
    print >> out, 'mdat <-', RUtil.matrix_to_R_string(arr)
    print >> out, mk_call_str(
            'barplot',
            'mdat',
            'legend.text=' + mk_call_str(
                'c',
                '"exact discrete distribution"',
                '"continuous approximation"',
                #'"two-allele large N limit"',
                #'"two-allele"',
                #'"four-allele without mutational bias"',
                #'"four-allele with mutational bias (kappa_{1,2}=2)"',
                #'"four-allele with mutational bias, large N limit"',
                ),
            'args.legend = list(x="topright", bty="n")',
            'names.arg = 1:%s' % (N-1),
            main='title.string',
            xlab='"frequency of allele 1"',
            ylab='"frequency"',
            col=mk_call_str(
                'c',
                #'"red"',
                #'"white"',
                '"black"',
                #'"gray"',
                '"red"',
                ),
            beside='TRUE',
            border='NA',
            )
    #print >> out, 'box()'
    script = out.getvalue().rstrip()
    # create the R plot image
    device_name = Form.g_imageformat_to_r_function[fs.imageformat]
    retcode, r_out, r_err, image_data = RUtil.run_plotter_no_table(
            script, device_name)
    if retcode:
        raise RUtil.RError(r_err)
    return image_data
开发者ID:argriffing,项目名称:xgcode,代码行数:87,代码来源:20120824a.py

示例11: get_response_content

# 需要导入模块: import RUtil [as 别名]
# 或者: from RUtil import run_plotter_no_table [as 别名]
def get_response_content(fs):
    N_diploid = 5
    N_haploid = N_diploid * 2
    k = 4
    gamma = 1.5
    params_list = [
            (0.008, 1, 1, 0, gamma, 1),
            (0.008, 2, 1, 0, gamma, 1)]
    allele_histograms = np.zeros((2, N_haploid+1))
    for i, params in enumerate(params_list):
        mutation, fitnesses = kaizeng.params_to_mutation_fitness(
                N_haploid, params)
        P = kaizeng.get_transition_matrix(
                N_diploid, k, mutation, fitnesses)
        v = MatrixUtil.get_stationary_distribution(P)
        for state_index, counts in enumerate(kaizeng.gen_states(N_haploid, k)):
            if counts[0] and counts[1]:
                allele_histograms[i, counts[0]] += v[state_index]
    # Define the r table.
    # There are nine columns each corresponding to an allele frequency.
    # There are three rows each corresponding to a configuration.
    arr = []
    # Use the exact two allele distribution.
    # Well, it is exact if I understand the right scaling
    # of the population size and fitnesses.
    f0 = 1.0
    f1 = 1.0 - gamma / N_haploid
    #f0 = 1.0 + gamma / N
    #f1 = 1.0
    #f0 = 1.0 + 1.5 / (4*N)
    #f1 = 1.0 - 1.5 / (4*N)
    h = get_two_allele_distribution(N_diploid, f0, f1)
    arr.append(h.tolist())
    # Use the two allele approximation
    # from mcvean and charlesworth 1999 referred to by zeng 2011.
    # I'm not sure if I am using the right equation.
    """
    gamma_0 = 0
    gamma_1 = 1.5
    s_0 = -gamma_0 / float(N)
    s_1 = -gamma_1 / float(N)
    hist = np.zeros(N+1)
    for i in range(1, N):
        x = i / float(N)
        hist[i] = math.exp(1*N*(s_0 - s_1)*x) / (x*(1-x))
    h = hist[1:-1]
    h /= np.sum(h)
    arr.append(h.tolist())
    """
    # Get frequencies for the other two configurations
    for hist in allele_histograms:
        h = hist[1:-1]
        h /= np.sum(h)
        arr.append(h.tolist())
    # define the r script
    out = StringIO()
    print >> out, 'title.string <- "allele 1 vs allele 2, gamma = 1.5"'
    print >> out, 'mdat <-', RUtil.matrix_to_R_string(arr)
    print >> out, mk_call_str(
            'barplot',
            'mdat',
            'legend.text=' + mk_call_str(
                'c',
                '"two-allele"',
                '"four-allele without mutational bias"',
                '"four-allele with mutational bias kappa_{1,2}=2"',
                ),
            'args.legend = list(x="topleft", bty="n")',
            'names.arg = c(1,2,3,4,5,6,7,8,9)',
            main='title.string',
            xlab='"frequency of allele 1"',
            ylab='"frequency"',
            col=mk_call_str(
                'c',
                #'"red"',
                '"white"',
                '"black"',
                '"gray"',
                ),
            beside='TRUE',
            )
    #print >> out, 'box()'
    script = out.getvalue().rstrip()
    # create the R plot image
    device_name = Form.g_imageformat_to_r_function[fs.imageformat]
    retcode, r_out, r_err, image_data = RUtil.run_plotter_no_table(
            script, device_name)
    if retcode:
        raise RUtil.RError(r_err)
    return image_data
开发者ID:argriffing,项目名称:xgcode,代码行数:92,代码来源:20120817b.py


注:本文中的RUtil.run_plotter_no_table方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。