本文整理汇总了Python中RUtil.run_plotter方法的典型用法代码示例。如果您正苦于以下问题:Python RUtil.run_plotter方法的具体用法?Python RUtil.run_plotter怎么用?Python RUtil.run_plotter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RUtil
的用法示例。
在下文中一共展示了RUtil.run_plotter方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: import RUtil [as 别名]
# 或者: from RUtil import run_plotter [as 别名]
def main(args):
# get the end positions,
# forcing the first end position to be 5
# and the last end position to be 898.
incr = (g_nchar - 5) / float(args.nlengths - 1)
stop_positions = [5 + int(i * incr) for i in range(args.nlengths)]
stop_positions[-1] = g_nchar
# run BEAST and create the R stuff
table_string, scripts = get_table_string_and_scripts(
stop_positions, args.nsamples)
# create the comboscript
out = StringIO()
print >> out, 'library(ggplot2)'
print >> out, 'par(mfrow=c(3,1))'
for script in scripts:
print >> out, script
comboscript = out.getvalue()
# create the R output image
device_name = Form.g_imageformat_to_r_function['pdf']
retcode, r_out, r_err, image_data = RUtil.run_plotter(
table_string, comboscript, device_name)
if retcode:
raise RUtil.RError(r_err)
# write the image data
with open(args.outfile, 'wb') as fout:
fout.write(image_data)
示例2: get_response_content
# 需要导入模块: import RUtil [as 别名]
# 或者: from RUtil import run_plotter [as 别名]
def get_response_content(fs):
f_info = ctmcmi.get_mutual_info_known_distn
# define the R table headers
headers = ['log.probability.ratio', 'mutual.information']
# make the array
arr = []
for x in np.linspace(fs.x_min, fs.x_max, 101):
row = [x]
proc = evozoo.AlternatingHypercube_d_1(3)
X = np.array([x])
distn = proc.get_distn(X)
Q = proc.get_rate_matrix(X)
info = f_info(Q, distn, fs.t)
row.append(info)
arr.append(row)
# create the R table string and scripts
# get the R table
table_string = RUtil.get_table_string(arr, headers)
# get the R script
script = get_ggplot()
# 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(
table_string, script, device_name)
if retcode:
raise RUtil.RError(r_err)
return image_data
示例3: get_response_content
# 需要导入模块: import RUtil [as 别名]
# 或者: from RUtil import run_plotter [as 别名]
def get_response_content(fs):
M, R = get_input_matrices(fs)
# create the R table string and scripts
headers = [
't',
'mi.true.mut',
'mi.true.mutsel',
'mi.analog.mut',
'mi.analog.mutsel']
npoints = 100
t_low = 0.0
t_high = 5.0
t_incr = (t_high - t_low) / (npoints - 1)
t_values = [t_low + t_incr*i for i in range(npoints)]
# get the data for the R table
arr = []
for t in t_values:
mi_mut = ctmcmi.get_mutual_information(M, t)
mi_mutsel = ctmcmi.get_mutual_information(R, t)
mi_analog_mut = ctmcmi.get_ll_ratio_wrong(M, t)
mi_analog_mutsel = ctmcmi.get_ll_ratio_wrong(R, t)
row = [t, mi_mut, mi_mutsel, mi_analog_mut, mi_analog_mutsel]
arr.append(row)
# get the R table
table_string = RUtil.get_table_string(arr, headers)
# get the R script
script = get_ggplot()
# 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(
table_string, script, device_name)
if retcode:
raise RUtil.RError(r_err)
return image_data
示例4: get_response_content
# 需要导入模块: import RUtil [as 别名]
# 或者: from RUtil import run_plotter [as 别名]
def get_response_content(fs):
# validate and store user input
if fs.x_max <= fs.x_min:
raise ValueError('check the min and max logs')
f_info = divtime.get_fisher_info_known_distn_fast
# define the R table headers
headers = ['log.probability.ratio', 'fisher.information']
# make the array
arr = []
for x in np.linspace(fs.x_min, fs.x_max, 101):
row = [x]
proc = evozoo.DistinguishedCornerPairHypercube_d_1(3)
X = np.array([x])
distn = proc.get_distn(X)
Q = proc.get_rate_matrix(X)
info = f_info(Q, distn, fs.t)
row.append(info)
arr.append(row)
# create the R table string and scripts
# get the R table
table_string = RUtil.get_table_string(arr, headers)
# get the R script
script = get_ggplot()
# 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(
table_string, script, device_name)
if retcode:
raise RUtil.RError(r_err)
return image_data
示例5: get_response_content
# 需要导入模块: import RUtil [as 别名]
# 或者: from RUtil import run_plotter [as 别名]
def get_response_content(fs):
# precompute some transition matrices
P_drift_selection = pgmsinglesite.create_drift_selection_transition_matrix(
fs.npop, fs.selection_ratio)
MatrixUtil.assert_transition_matrix(P_drift_selection)
P_mutation = pgmsinglesite.create_mutation_transition_matrix(
fs.npop, fs.mutation_ab, fs.mutation_ba)
MatrixUtil.assert_transition_matrix(P_mutation)
# define the R table headers
headers = ['generation', 'number.of.mutants']
# compute the path samples
P = np.dot(P_drift_selection, P_mutation)
mypath = PathSampler.sample_endpoint_conditioned_path(
fs.nmutants_initial, fs.nmutants_final, fs.ngenerations, P)
arr = [[i, nmutants] for i, nmutants in enumerate(mypath)]
# create the R table string and scripts
# get the R table
table_string = RUtil.get_table_string(arr, headers)
# get the R script
script = get_ggplot()
# 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(
table_string, script, device_name)
if retcode:
raise RUtil.RError(r_err)
return image_data
示例6: main
# 需要导入模块: import RUtil [as 别名]
# 或者: from RUtil import run_plotter [as 别名]
def main(args):
# set up the logger
f = logging.getLogger('toplevel.logger')
h = logging.StreamHandler()
h.setFormatter(logging.Formatter('%(message)s %(asctime)s'))
f.addHandler(h)
if args.verbose:
f.setLevel(logging.DEBUG)
else:
f.setLevel(logging.WARNING)
f.info('(local) permute columns of the alignment')
header_seq_pairs = beasttut.get_456_col_permuted_header_seq_pairs()
f.info('(local) run BEAST serially locally and build the R stuff')
table_string, scripts = get_table_string_and_scripts(
g_start_stop_pairs, args.nsamples, header_seq_pairs)
f.info('(local) create the composite R script')
out = StringIO()
print >> out, 'library(ggplot2)'
print >> out, 'par(mfrow=c(3,1))'
for script in scripts:
print >> out, script
comboscript = out.getvalue()
f.info('(local) run R to create the pdf')
device_name = Form.g_imageformat_to_r_function['pdf']
retcode, r_out, r_err, image_data = RUtil.run_plotter(
table_string, comboscript, device_name, keep_intermediate=True)
if retcode:
raise RUtil.RError(r_err)
f.info('(local) write the .pdf file')
with open(args.outfile, 'wb') as fout:
fout.write(image_data)
f.info('(local) return from toplevel')
示例7: get_response_content
# 需要导入模块: import RUtil [as 别名]
# 或者: from RUtil import run_plotter [as 别名]
def get_response_content(fs):
# legend labels
label_a = 'N=%d mu=%f' % (fs.nstates_a, fs.mu_a)
label_b = 'N=%d mu=%f' % (fs.nstates_b, fs.mu_b)
arr, headers = make_table(fs)
# compute the max value
ymax = math.log(max(fs.nstates_a, fs.nstates_b))
nfifths = int(math.floor(ymax * 5.0)) + 1
ylim = RUtil.mk_call_str('c', 0, 0.2 * nfifths)
# write the R script body
out = StringIO()
print >> out, RUtil.mk_call_str(
'plot',
'my.table$t',
'my.table$alpha',
type='"n"',
ylim=ylim,
xlab='"time"',
ylab='"information"',
main='"comparison of an information criterion for two processes"',
)
# draw some horizontal lines
for i in range(nfifths+1):
print >> out, RUtil.mk_call_str(
'abline',
h=0.2*i,
col='"lightgray"',
lty='"dotted"')
colors = ('darkblue', 'darkred')
for c, header in zip(colors, headers[1:]):
print >> out, RUtil.mk_call_str(
'lines',
'my.table$t',
'my.table$%s' % header,
col='"%s"' % c,
)
legend_names = (label_a, label_b)
legend_name_str = 'c(' + ', '.join('"%s"' % s for s in legend_names) + ')'
legend_col_str = 'c(' + ', '.join('"%s"' % s for s in colors) + ')'
legend_lty_str = 'c(' + ', '.join('1' for s in colors) + ')'
print >> out, RUtil.mk_call_str(
'legend',
'"%s"' % fs.legend_placement,
legend_name_str,
col=legend_col_str,
lty=legend_lty_str,
)
script_body = out.getvalue()
# create the R plot image
table_string = RUtil.get_table_string(arr, headers)
device_name = Form.g_imageformat_to_r_function[fs.imageformat]
retcode, r_out, r_err, image_data = RUtil.run_plotter(
table_string, script_body, device_name)
if retcode:
raise RUtil.RError(r_err)
return image_data
示例8: get_response_content
# 需要导入模块: import RUtil [as 别名]
# 或者: from RUtil import run_plotter [as 别名]
def get_response_content(fs):
# precompute some transition matrices
P_drift_selection = pgmsinglesite.create_drift_selection_transition_matrix(
fs.npop, fs.selection_ratio)
MatrixUtil.assert_transition_matrix(P_drift_selection)
P_mutation = pgmsinglesite.create_mutation_transition_matrix(
fs.npop, fs.mutation_ab, fs.mutation_ba)
MatrixUtil.assert_transition_matrix(P_mutation)
# define the R table headers
headers = [
'generation',
'number.of.mutants',
'probability',
'log.prob',
]
# compute the transition matrix
P = np.dot(P_drift_selection, P_mutation)
# Compute the endpoint conditional probabilities for various states
# along the unobserved path.
nstates = fs.npop + 1
M = np.zeros((nstates, fs.ngenerations))
M[fs.nmutants_initial, 0] = 1.0
M[fs.nmutants_final, fs.ngenerations-1] = 1.0
for i in range(fs.ngenerations-2):
A_exponent = i + 1
B_exponent = fs.ngenerations - 1 - A_exponent
A = np.linalg.matrix_power(P, A_exponent)
B = np.linalg.matrix_power(P, B_exponent)
weights = np.zeros(nstates)
for k in range(nstates):
weights[k] = A[fs.nmutants_initial, k] * B[k, fs.nmutants_final]
weights /= np.sum(weights)
for k, p in enumerate(weights):
M[k, i+1] = p
arr = []
for g in range(fs.ngenerations):
for k in range(nstates):
p = M[k, g]
if p:
logp = math.log(p)
else:
logp = float('-inf')
row = [g, k, p, logp]
arr.append(row)
# create the R table string and scripts
# get the R table
table_string = RUtil.get_table_string(arr, headers)
# get the R script
script = get_ggplot()
# 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(
table_string, script, device_name)
if retcode:
raise RUtil.RError(r_err)
return image_data
示例9: get_response_content
# 需要导入模块: import RUtil [as 别名]
# 或者: from RUtil import run_plotter [as 别名]
def get_response_content(fs):
f_info = divtime.get_fisher_info_known_distn_fast
requested_triples = []
for triple in g_process_triples:
name, desc, zoo_obj = triple
if getattr(fs, name):
requested_triples.append(triple)
if not requested_triples:
raise ValueError('nothing to plot')
# define the R table headers
r_names = [a.replace('_', '.') for a, b, c in requested_triples]
headers = ['t'] + r_names
# Spend a lot of time doing the optimizations
# to construct the points for the R table.
arr = []
for t in cbreaker.throttled(
progrid.gen_binary(fs.start_time, fs.stop_time),
nseconds=5, ncount=200):
row = [t]
for python_name, desc, zoo_class in requested_triples:
zoo_obj = zoo_class(fs.d)
df = zoo_obj.get_df()
opt_dep = OptDep(zoo_obj, t, f_info)
if df:
X0 = np.random.randn(df)
xopt = scipy.optimize.fmin(
opt_dep, X0, maxiter=10000, maxfun=10000)
# I would like to use scipy.optimize.minimize
# except that this requires a newer version of
# scipy than is packaged for ubuntu right now.
# fmin_bfgs seems to have problems sometimes
# either hanging or maxiter=10K is too big.
"""
xopt = scipy.optimize.fmin_bfgs(opt_dep, X0,
gtol=1e-8, maxiter=10000)
"""
else:
xopt = np.array([])
info_value = -opt_dep(xopt)
row.append(info_value)
arr.append(row)
arr.sort()
npoints = len(arr)
# create the R table string and scripts
# get the R table
table_string = RUtil.get_table_string(arr, headers)
# get the R script
script = get_ggplot()
# 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(
table_string, script, device_name)
if retcode:
raise RUtil.RError(r_err)
return image_data
示例10: get_response_content
# 需要导入模块: import RUtil [as 别名]
# 或者: from RUtil import run_plotter [as 别名]
def get_response_content(fs):
distn_modes = [x for x in g_ordered_modes if x in fs.distribution]
if not distn_modes:
raise ValueError('no distribution mode was specified')
colors = [g_mode_to_color[m] for m in distn_modes]
arr, headers = make_table(fs, distn_modes)
distn_headers = headers[1:]
# Get the largest value in the array,
# skipping the first column.
arrmax = np.max(arr[:,1:])
# write the R script body
out = StringIO()
ylim = RUtil.mk_call_str('c', 0, arrmax + 0.1)
sel_str = {
BALANCED : 'balanced',
HALPERN_BRUNO : 'Halpern-Bruno',
}[fs.selection]
print >> out, RUtil.mk_call_str(
'plot',
'my.table$t',
'my.table$%s' % distn_headers[0],
type='"n"',
ylim=ylim,
xlab='""',
ylab='"relaxation time"',
main='"Effect of selection (%s) on relaxation time for %d states"' % (sel_str, fs.nstates),
)
for c, header in zip(colors, distn_headers):
print >> out, RUtil.mk_call_str(
'lines',
'my.table$t',
'my.table$%s' % header,
col='"%s"' % c,
)
mode_names = [s.replace('_', ' ') for s in distn_modes]
legend_name_str = 'c(' + ', '.join('"%s"' % s for s in mode_names) + ')'
legend_col_str = 'c(' + ', '.join('"%s"' % s for s in colors) + ')'
legend_lty_str = 'c(' + ', '.join(['1']*len(distn_modes)) + ')'
print >> out, RUtil.mk_call_str(
'legend',
'"%s"' % fs.legend_placement,
legend_name_str,
col=legend_col_str,
lty=legend_lty_str,
)
script_body = out.getvalue()
# create the R plot image
table_string = RUtil.get_table_string(arr, headers)
device_name = Form.g_imageformat_to_r_function[fs.imageformat]
retcode, r_out, r_err, image_data = RUtil.run_plotter(
table_string, script_body, device_name)
if retcode:
raise RUtil.RError(r_err)
return image_data
示例11: get_latex_documentbody
# 需要导入模块: import RUtil [as 别名]
# 或者: from RUtil import run_plotter [as 别名]
def get_latex_documentbody(fs):
"""
This is obsolete.
"""
out = StringIO()
table_string, scripts = get_table_string_and_scripts(fs)
for script in scripts:
retcode, r_out, r_err, tikz_code = RUtil.run_plotter(table_string, script, "tikz", width=5, height=5)
if retcode:
raise RUtil.RError(r_err)
print >> out, tikz_code
return out.getvalue()
示例12: main
# 需要导入模块: import RUtil [as 别名]
# 或者: from RUtil import run_plotter [as 别名]
def main(args):
# check args
if gmpy.popcount(args.ntiles) != 1:
raise ValueError('the number of tiles should be a power of two')
# set up the logger
f = logging.getLogger('toplevel.logger')
h = logging.StreamHandler()
h.setFormatter(logging.Formatter('%(message)s %(asctime)s'))
f.addHandler(h)
if args.verbose:
f.setLevel(logging.DEBUG)
else:
f.setLevel(logging.WARNING)
f.info('(local) read the xml contents')
if args.infile is None:
xmldata = sys.stdin.read()
else:
with open(args.infile) as fin:
xmldata = fin.read()
f.info('(local) modify the log filename and chain length xml contents')
xmldata = beast.set_nsamples(xmldata, args.mcmc_id, args.nsamples)
xmldata = beast.set_log_filename(xmldata, args.log_id, args.log_filename)
xmldata = beast.set_log_logevery(xmldata, args.log_id, args.log_logevery)
f.info('(local) define the hierarchically nested intervals')
start_stop_pairs = tuple(
(a+1,b) for a, b in beasttiling.gen_hierarchical_slices(
args.tile_width, args.offset, args.tile_width * args.ntiles))
f.info('(local) run BEAST serially locally and build the R stuff')
table_string, full_table_string, scripts = get_table_strings_and_scripts(
xmldata, args.alignment_id, start_stop_pairs, args.nsamples)
if args.full_table_out:
f.info('(local) create the verbose R table')
with open(args.full_table_out, 'w') as fout:
fout.write(full_table_string)
f.info('(local) create the composite R script')
out = StringIO()
print >> out, 'library(ggplot2)'
print >> out, 'par(mfrow=c(3,1))'
for script in scripts:
print >> out, script
comboscript = out.getvalue()
f.info('(local) run R to create the pdf')
device_name = Form.g_imageformat_to_r_function['pdf']
retcode, r_out, r_err, image_data = RUtil.run_plotter(
table_string, comboscript, device_name, keep_intermediate=True)
if retcode:
raise RUtil.RError(r_err)
f.info('(local) write the .pdf file')
with open(args.outfile, 'wb') as fout:
fout.write(image_data)
f.info('(local) return from toplevel')
示例13: get_response_content
# 需要导入模块: import RUtil [as 别名]
# 或者: from RUtil import run_plotter [as 别名]
def get_response_content(fs):
# get the table string and scripts
table_string, scripts = get_table_string_and_scripts(fs)
# create a comboscript
out = StringIO()
print >> out, "par(mfrow=c(3,1))"
for script in scripts:
print >> out, script
comboscript = out.getvalue()
# 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(table_string, comboscript, device_name)
if retcode:
raise RUtil.RError(r_err)
return image_data
示例14: get_response_content
# 需要导入模块: import RUtil [as 别名]
# 或者: from RUtil import run_plotter [as 别名]
def get_response_content(fs):
f_info = ctmcmi.get_mutual_info_known_distn
requested_triples = []
for triple in g_process_triples:
name, desc, zoo_obj = triple
if getattr(fs, name):
requested_triples.append(triple)
if not requested_triples:
raise ValueError('nothing to plot')
# define the R table headers
headers = ['t']
if fs.log4:
headers.append('log.4')
if fs.log3:
headers.append('log.3')
r_names = [a.replace('_', '.') for a, b, c in requested_triples]
headers.extend(r_names)
# Spend a lot of time doing the optimizations
# to construct the points for the R table.
times = np.linspace(fs.start_time, fs.stop_time, 101)
arr = []
for t in times:
row = [t]
if fs.log4:
row.append(math.log(4))
if fs.log3:
row.append(math.log(3))
for python_name, desc, zoo_obj in requested_triples:
X = np.array([])
info_value = f_info(
zoo_obj.get_rate_matrix(X),
zoo_obj.get_distn(X),
t)
row.append(info_value)
arr.append(row)
# create the R table string and scripts
# get the R table
table_string = RUtil.get_table_string(arr, headers)
# get the R script
script = get_ggplot()
# 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(
table_string, script, device_name)
if retcode:
raise RUtil.RError(r_err)
return image_data
示例15: get_response_content
# 需要导入模块: import RUtil [as 别名]
# 或者: from RUtil import run_plotter [as 别名]
def get_response_content(fs):
Q_mut, Q_sels = get_qmut_qsels(fs)
# compute the statistics
ER_ratios, NSR_ratios, ER_NSR_ratios = get_statistic_ratios(Q_mut, Q_sels)
M = zip(*(ER_ratios, NSR_ratios, ER_NSR_ratios))
column_headers = ('ER.ratio', 'NSR.ratio', 'ER.times.NSR.ratio')
table_string = RUtil.get_table_string(M, column_headers)
nsels = len(Q_sels)
# get the R script
comboscript = get_r_comboscript(nsels, column_headers)
# 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(
table_string, comboscript, device_name)
if retcode:
raise RUtil.RError(r_err)
return image_data