In [11]:
%matplotlib inline
import pylab
from collections import defaultdict

In [21]:
colors = {
    'WCT-S': 'r',
    'WCT-F': 'g',
    'BuPred': 'k',
    'BuLong': 'm',
    'BuTrout': 'y',
}

In [41]:
def read_table(f):
    headers = f.readline().rstrip().split(' ')
    for l in f:
        toks = l.rstrip().split(' ')
        yield dict(zip(headers, toks))

In [49]:
def get_sampling(nsnps, ninds):
    f = open('../output/table-ci-%d-%d.txt' % (nsnps, ninds))
    nones = defaultdict(dict)
    logquads = defaultdict(dict)
    for rec in read_table(f):
        if rec['Corr'] == 'None':
            dict_ = nones
        elif rec['Corr'] == 'LogQuad':
            dict_ = logquads
        else:
            continue
        dict_[rec['Model']][int(rec['Nb'])] = float(rec['median'])
    return nones, logquads


def plot_sampling(nsnps, ninds, nones, logquads):
    fig = pylab.figure(figsize=(20, 10)) 
    sp = fig.add_subplot(111)
    sp.set_title("SNPs: %d / Inds: %d" % (nsnps, ninds))
    for name, char, dict_ in [('N', '.', nones), ('LQ', 'o', logquads)]:
        for model, vals in dict_.items():
            xs = []
            ys = []
            for x, y in vals.items():
                if x < 10:
                    continue
                xs.append(x)
                ys.append(abs(y - x) / x)
            sp.plot(xs, ys, colors[model] + char, label='%s-%s' % (name, model))
    xmin, xmax = sp.get_xlim()
    sp.set_xlim(xmin, xmax + 0.2 * xmax)
    sp.legend()

In [51]:
nones, logquads = get_sampling(100, 25)
plot_sampling(100, 25, nones, logquads)

nones, logquads = get_sampling(100, 50)
plot_sampling(100, 50, nones, logquads)

nones, logquads = get_sampling(200, 50)
plot_sampling(200, 50, nones, logquads)



In [ ]: