Exemple #1
0
def random_samples_like(transcriptional_programs):
    'Sample sets of targets and factors randomly that are the same size as those in the programs.'
    from rpy import r
    target_samples = []
    factor_samples = []
    for tp in transcriptional_programs:
        if tp.targets_go_analysis:
            target_samples.append(r.sample(tp.genes, len(tp.tp_targets)))
        if tp.factors_go_analysis:
            factor_samples.append(r.sample(tp.factors, len(tp.tp_factors)))
    return target_samples, factor_samples
Exemple #2
0
def random_samples_like(transcriptional_programs):
    'Sample sets of targets and factors randomly that are the same size as those in the programs.'
    from rpy import r
    target_samples = []
    factor_samples = []
    for tp in transcriptional_programs:
        if tp.targets_go_analysis:
            target_samples.append(r.sample(tp.genes, len(tp.tp_targets)))
        if tp.factors_go_analysis:
            factor_samples.append(r.sample(tp.factors, len(tp.tp_factors)))
    return target_samples, factor_samples
Exemple #3
0
def generate_best_p_values(sample_sizes, num_samples_at_each_size, universe, go_data):
    from rpy import r
    for size in sample_sizes:
        yield size, [
          log10(calculate_best_p_value(go_data, r.sample(universe, size)))
          for i in xrange(num_samples_at_each_size)
        ]
Exemple #4
0
def generate_best_p_values(sample_sizes, num_samples_at_each_size, universe,
                           go_data):
    from rpy import r
    for size in sample_sizes:
        yield size, [
            log10(calculate_best_p_value(go_data, r.sample(universe, size)))
            for i in xrange(num_samples_at_each_size)
        ]
Exemple #5
0
def qqplot_density(samples, density_x, density_y):
    from rpy import r
    # LAME: should do better quantile calculation.  r.quantile() returns a
    # hard-to-use dictionary unfortunately.  r.approx() as per ?quantile, maybe.
    percs = list(np.arange(1,100, .1))
    data_perc=np.percentile(samples, percs)
    real_perc=np.percentile(r.sample(density_x, len(samples)*10, prob=density_y, replace=True), percs)
    r.plot(real_perc, data_perc,  xlab='',ylab='',main='');
    r.abline(a=0,b=1,col='blue')
Exemple #6
0
def qqplot_density(samples, density_x, density_y):
    from rpy import r
    # LAME: should do better quantile calculation.  r.quantile() returns a
    # hard-to-use dictionary unfortunately.  r.approx() as per ?quantile, maybe.
    percs = list(np.arange(1, 100, .1))
    data_perc = np.percentile(samples, percs)
    real_perc = np.percentile(
        r.sample(density_x, len(samples) * 10, prob=density_y, replace=True),
        percs)
    r.plot(real_perc, data_perc, xlab='', ylab='', main='')
    r.abline(a=0, b=1, col='blue')
Exemple #7
0
#r.par(mfrow=[2,2])
# Exhaustive computation to compare to slice sampler

log_concs = np.arange(-50,20,.1)
lls = np.array([ loglik(log_conc) for log_conc in log_concs ])
mle = log_concs[lls.argmax()]
print "MLE", np.exp(mle)
lps = np.array([ logpost(log_conc) for log_conc in log_concs ])
map = log_concs[lps.argmax()]
print "MAP", np.exp(map)
#r.plot(log_concs, lls, xlab='x',ylab='ll')
#plot(log_concs, lls, main='loglik')
#plot(log_concs, lps, main='unnorm logpost')


# For comparisons

real_s = r.sample(log_concs,len(histories)*2,prob=np.exp(lps),replace=True)


# Slice sampler

h = mcmc.slice_sample(logpost, 0.0, 1.0, niter=1000)
h = np.array(h)

# Replications of single slice-sample
#for i in range(500):
#  init = histories[i][-1]
#  h = mcmc.slice_sample(logpost, init, 1.0, niter=200)
#  histories[i] += h