示例#1
0
def _one_scatterplot(cl_metadata, xy_data, xy_metadata,
                     output=None,
                     lims=None, specs=None,

                     _spd=sp.ScatterplotData,
                     _anno=co.namedtuple('_annotation',
                                         CellLineMetadata._fields +
                                         ('x', 'y')),
                     _annopxl=co.namedtuple('_annotated_pixel',
                                            'coords annotation')):
    if specs is None:
        specs = get_specs(cl_metadata)

    readouts = zip(*xy_data)
    if lims is None and WITHLIMITS:
        lims = limits(readouts)

    points = tuple(_spd(*(k + (x, y))) for k, x, y in zip(specs, *xy_data))

    fig = sp.scatterplot(points, xy_metadata, lims=lims, outpath=output)
    pixels = sp.pixels(points, fig)

    annotations = tuple(_anno(*(m + r))
                        for m, r in zip(cl_metadata, readouts))

    return tuple(sorted([_annopxl(p, a) for p, a in zip(pixels, annotations)],
                        key=lambda r: (r.coords.y, r.coords.x,
                                       r.annotation.cell_line_name)))
示例#2
0
def _one_scatterplot(
    cl_metadata,
    xy_data,
    xy_metadata,
    output=None,
    lims=None,
    specs=None,
    _spd=sp.ScatterplotData,
    _anno=co.namedtuple('_annotation', CellLineMetadata._fields + ('x', 'y')),
    _annopxl=co.namedtuple('_annotated_pixel', 'coords annotation')):
    if specs is None:
        specs = get_specs(cl_metadata)

    readouts = zip(*xy_data)
    if lims is None and WITHLIMITS:
        lims = limits(readouts)

    points = tuple(_spd(*(k + (x, y))) for k, x, y in zip(specs, *xy_data))

    fig = sp.scatterplot(points, xy_metadata, lims=lims, outpath=output)
    pixels = sp.pixels(points, fig)

    annotations = tuple(_anno(*(m + r)) for m, r in zip(cl_metadata, readouts))

    return tuple(
        sorted([_annopxl(p, a) for p, a in zip(pixels, annotations)],
               key=lambda r:
               (r.coords.y, r.coords.x, r.annotation.cell_line_name)))
示例#3
0
文件: _1j.py 项目: elcovi/hmslincs
def _1j():
    rows = readinput(INPUTPATH)

    headers = rows[0]

    f = mplf.Figure(figsize=(FIGSIZEPX/DPI, FIGSIZEPX/DPI), dpi=DPI)

    ax = f.gca()

    datarec = co.namedtuple('_datarec',
                            'cell_line_name cell_line_classification '
                            'cluster x y')

    data = tuple(datarec(*(r[:-2] + map(lambda z: 10**float(z), r[-2:])))
                 for r in rows[1:])

    blue = '#1228B4'
    blue = '#4A8CF5'
    yellow = '#F9D712'
    green = '#5E9563'
    black = '#000000'
    gray0 = '#666666'
    gray0 = '#999999'
    gray1 = '#B3B3B3'
    gray2 = '#CBCBCB'
    red = 'r'

    color_lookup = {'1': blue, '2': green, '3': yellow,
                    '4': gray0, '5': black, '6': black, '7': black}
    circle = 'o'
    triangle = '^'
    square = 's'
    marker_lookup = {'TNBC': circle, 'HER2amp': triangle, 'HR+': square}

    fixedkwargs = dict(s=200, linewidth=0.5)
    for row in sorted(data, key=lambda r: r.cluster):
        color = color_lookup[row.cluster]
        marker = marker_lookup[row.cell_line_classification]
        # see http://matplotlib.org/api/axes_api.html#matplotlib.axes.Axes.scatter
        ax.scatter(row.x, row.y, c=color, marker=marker, **fixedkwargs)

    ax.set_xscale('log')
    ax.set_yscale('log')

    xlim = tuple(10**v for v in (-5, -1))
    ylim = tuple(10**v for v in (-4.5, 0))

    ax.set_xlim(xlim)
    ax.set_ylim(ylim)

    # this aspect will result in a square plot
    ax.set_aspect((ma.log10(xlim[1]/xlim[0])/ma.log10(ylim[1]/ylim[0])))

    xlabel = 'Erb3 (pg/cell)'
    ylabel = 'EGFR (pg/cell)'

    ax.set_xlabel(xlabel)
    ax.set_ylabel(ylabel)

    fmtr = lambda v, _: ('%g' % v) if v < 1e-4 else ('%.4f' % v).rstrip('.0')

    xaxis = ax.xaxis
    xaxis.set_major_locator(mplpp.FixedLocator([10**i for i in range(-5, 0)]))
    xaxis.set_major_formatter(mplpp.FuncFormatter(fmtr))
    xaxis.set_ticks((), minor=True)

    yaxis = ax.yaxis
    yaxis.set_major_locator(mplpp.FixedLocator([10**i for i in range(-4, 1)]))
    yaxis.set_major_formatter(mplpp.FuncFormatter(fmtr))
    yaxis.set_ticks((), minor=True)

    f.subplots_adjust(left=0.22, bottom=0.2, right=0.97, top=0.95,
                      wspace=0, hspace=0)
    mplpp.setp(f, 'facecolor', 'none')

    canvas = mplbb.FigureCanvasAgg(f)
    f.set_canvas(canvas)

    canvas.print_png(OUTPUTPATH)

    htmlrows = [dict(coords=pixel._asdict(), row=make_row(data))
                for pixel, data in zip(sp.pixels(data, f), data)]

    print '        %s: %s,' % (json.dumps(IMGID), json.dumps(htmlrows))

    return f
示例#4
0
def _1j():
    rows = readinput(INPUTPATH)

    headers = rows[0]

    f = mplf.Figure(figsize=(FIGSIZEPX / DPI, FIGSIZEPX / DPI), dpi=DPI)

    ax = f.gca()

    datarec = co.namedtuple(
        '_datarec', 'cell_line_name cell_line_classification '
        'cluster x y')

    data = tuple(
        datarec(*(r[:-2] + map(lambda z: 10**float(z), r[-2:])))
        for r in rows[1:])

    blue = '#1228B4'
    blue = '#4A8CF5'
    yellow = '#F9D712'
    green = '#5E9563'
    black = '#000000'
    gray0 = '#666666'
    gray0 = '#999999'
    gray1 = '#B3B3B3'
    gray2 = '#CBCBCB'
    red = 'r'

    color_lookup = {
        '1': blue,
        '2': green,
        '3': yellow,
        '4': gray0,
        '5': black,
        '6': black,
        '7': black
    }
    circle = 'o'
    triangle = '^'
    square = 's'
    marker_lookup = {'TNBC': circle, 'HER2amp': triangle, 'HR+': square}

    fixedkwargs = dict(s=200, linewidth=0.5)
    for row in sorted(data, key=lambda r: r.cluster):
        color = color_lookup[row.cluster]
        marker = marker_lookup[row.cell_line_classification]
        # see http://matplotlib.org/api/axes_api.html#matplotlib.axes.Axes.scatter
        ax.scatter(row.x, row.y, c=color, marker=marker, **fixedkwargs)

    ax.set_xscale('log')
    ax.set_yscale('log')

    xlim = tuple(10**v for v in (-5, -1))
    ylim = tuple(10**v for v in (-4.5, 0))

    ax.set_xlim(xlim)
    ax.set_ylim(ylim)

    # this aspect will result in a square plot
    ax.set_aspect((ma.log10(xlim[1] / xlim[0]) / ma.log10(ylim[1] / ylim[0])))

    xlabel = 'Erb3 (pg/cell)'
    ylabel = 'EGFR (pg/cell)'

    ax.set_xlabel(xlabel)
    ax.set_ylabel(ylabel)

    fmtr = lambda v, _: ('%g' % v) if v < 1e-4 else ('%.4f' % v).rstrip('.0')

    xaxis = ax.xaxis
    xaxis.set_major_locator(mplpp.FixedLocator([10**i for i in range(-5, 0)]))
    xaxis.set_major_formatter(mplpp.FuncFormatter(fmtr))
    xaxis.set_ticks((), minor=True)

    yaxis = ax.yaxis
    yaxis.set_major_locator(mplpp.FixedLocator([10**i for i in range(-4, 1)]))
    yaxis.set_major_formatter(mplpp.FuncFormatter(fmtr))
    yaxis.set_ticks((), minor=True)

    f.subplots_adjust(left=0.22,
                      bottom=0.2,
                      right=0.97,
                      top=0.95,
                      wspace=0,
                      hspace=0)
    mplpp.setp(f, 'facecolor', 'none')

    canvas = mplbb.FigureCanvasAgg(f)
    f.set_canvas(canvas)

    canvas.print_png(OUTPUTPATH)

    htmlrows = [
        dict(coords=pixel._asdict(), row=make_row(data))
        for pixel, data in zip(sp.pixels(data, f), data)
    ]

    print '        %s: %s,' % (json.dumps(IMGID), json.dumps(htmlrows))

    return f
示例#5
0
def _4e():
    rows = readinput(INPUTPATH)

    headers = rows[0]

    f = mplf.Figure(figsize=(FIGSIZEPX/DPI, FIGSIZEPX/DPI), dpi=DPI)

    ax = f.gca()

    datarec = co.namedtuple('_datarec',
                            'cell_line_name cell_line_classification '
                            'erlotinib_gi50 x y')

    data = tuple(datarec(*(r[:-3] + [float(r[-3])] +
                           map(lambda z: 10**float(z), r[-2:])))
                 for r in rows[1:])

    circle = 'o'
    triangle = '^'
    square = 's'
    marker_lookup = {'TNBC': circle, 'HER2amp': triangle, 'HR+': square}

    pointspec = co.namedtuple('_pointspec', 'x y level marker')
    points = tuple(pointspec(rec.x, rec.y, rec.erlotinib_gi50,
                             marker_lookup[rec.cell_line_classification])
                   for rec in data)

    # eyeballed from PDF
    min_gi50 = -5.9 # min log_10 gi50
    max_gi50 = -3.7 # max log_10 gi50

    fixedkwargs = dict(s=200, linewidth=0.5, vmin=min_gi50, vmax=max_gi50,
                       cmap=CMAP_BWR)
    for marker in (circle, triangle, square):
        xs, ys, cs = zip(*((p.x, p.y, p.level)
                           for p in points if p.marker == marker))
        ax.scatter(xs, ys, c=cs, marker=marker, **fixedkwargs)

    ax.set_xscale('log')
    ax.set_yscale('log')

    # eyeballed from the PDF
    xlim = (0.8, 25)
    ylim = (0.9, 1.9)

    ax.set_xlim(xlim)
    ax.set_ylim(ylim)

    # this aspect will result in a square plot
    # ax.set_aspect((xlim[1] - xlim[0])/(ylim[1] - ylim[0]))
    ax.set_aspect((ma.log10(xlim[1]/xlim[0])/ma.log10(ylim[1]/ylim[0])))

    ax.set_title('Erlotinib')

    xlabel = 'pErk[FGF-2$_1$] max (fold change)'
    ylabel = 'pAkt[EPR$_1$] max (fold change)'

    ax.set_xlabel(xlabel)
    ax.set_ylabel(ylabel)

    xaxis = ax.xaxis
    xaxis.set_major_formatter(mplpp.FormatStrFormatter('%d'))
    xaxis.set_major_locator(mplpp.FixedLocator([1, 2, 5, 10, 20]))
    xaxis.set_ticks((), minor=True)

    fmtr = lambda v, _: ('%.1f' % v).rstrip('.0')
    yaxis = ax.yaxis
    yaxis.set_major_formatter(mplpp.FuncFormatter(fmtr))
    yaxis.set_major_locator(mplpp.FixedLocator([1, 1.8]))
    yaxis.set_ticks((), minor=True)


    f.subplots_adjust(left=0.2, bottom=0.15, right=0.95, top=0.9, wspace=0, hspace=0)
    mplpp.setp(f, 'facecolor', 'none')

    canvas = mplbb.FigureCanvasAgg(f)
    f.set_canvas(canvas)

    canvas.print_png(OUTPUTPATH)

    htmlrows = [dict(coords=p._asdict(), row=make_row(d))
                for p, d in zip(sp.pixels(data, f), data)]

    print '        %s: %s,' % (json.dumps(IMGID), json.dumps(htmlrows))

    return f