Esempio n. 1
0
def main(argv=sys.argv[1:]):
    assert len(argv) == 1

    su.mkdirp(OUTPUTDIR)

    for target, spec in readinput(argv[0]):
        output = outpath(target)
        write_signature(output, rows, marker_labels, lims=None)
Esempio n. 2
0
def main(argv=sys.argv[1:]):
    assert len(argv) == 1

    su.mkdirp(OUTPUTDIR)

    for target, spec in readinput(argv[0]):
        output = outpath(target)
        write_signature(output, rows, marker_labels, lims=None)
Esempio n. 3
0
def main(argv):
    _parseargs(argv)

    def want_h5(b, d, i):
        return b == 'Data.h5'

    subdir = '.DATA'
    extent, path, antibody = [getattr(PARAM, a) for a in
                              'extent path antibody'
                              .split()]

#     if extent == 'plate':
#         ncrmode = bool(int(argv[3])) if nargs > 3 else False
#     else:
#         ncrmode = _scrape_ncrmode(path, antibody)

    param = PARAM
    if extent == 'plate':
        def mode(path, wells, antibody):
            modes = map(partial(_scrape_ncrmode, antibody=antibody),
                        [op.join(path, w) for w in wells])

            if all(modes):
                return True
            else:
                assert all(map(notop, modes))
                return False

        q = [(sum([list(find(op.join(path, w), want_h5))
                   for w in c], []),
              _dimspec(mode(path, z, antibody), **param.__dict__),
              op.join(path, subdir, antibody, ','.join(c)))
             for c, z in getcontrols(path)]
    else:
        ncrmode = _scrape_ncrmode(path, antibody)
        assert extent == 'well'
        q = [(find(path, want_h5),
              _dimspec(ncrmode, **param.__dict__),
              op.join(path, subdir, antibody))]

    for paths, param, basedir in q:
        data, warnings = extractdata(paths, param)
        processed, rawheaders = process(data, param)
        preamble = makepreamble(rawheaders, warnings)
        dir_ = op.join(basedir, param.readout)
        mkdirp(dir_)
        dump(dir_, transpose_map(dict(data=processed, preamble=preamble)))
        
    return 0
Esempio n. 4
0
def main(argv=sys.argv[1:]):
    assert len(argv) == 1

    su.mkdirp(OUTPUTDIR)

    rows = readinput(argv[0])
    specs, data, lims = process(rows)

    spd = sp.ScatterplotData

    for pair in it.product(data, data):
        ax, vs = zip(*pair)
        if ax[0] == ax[1]: continue
        output = outpath(ax)
        spd = tuple(spd(*(k + (x, y))) for k, x, y in zip(specs, *vs))
        axis_labels = tuple(', '.join(l) for l in ax)
        write_scatterplot(output, spd, axis_labels, lims)
Esempio n. 5
0
def main(argv=sys.argv[1:]):
    assert len(argv) == 1

    su.mkdirp(OUTPUTDIR)

    rows = readinput(argv[0])
    specs, data, lims = process(rows)

    spd = sp.ScatterplotData

    for pair in it.product(data, data):
        ax, vs = zip(*pair)
        if ax[0] == ax[1]: continue
        output = outpath(ax)
        spd = tuple(spd(*(k + (x, y))) for k, x, y in zip(specs, *vs))
        axis_labels = tuple(', '.join(l) for l in ax)
        write_scatterplot(output, spd, axis_labels, lims)
Esempio n. 6
0
def main(argv=sys.argv[1:]):
    assert len(argv) == 1

    su.mkdirp(OUTPUTDIR)

    rows = readinput(argv[0])
    cl_metadata, responses = parse(rows)

    _to_do = co.namedtuple('_to_do', 'args imgid')
    _args = co.namedtuple('_args', 'xy_data xy_metadata output')
    to_do = []
    for xr, yr in it.product(responses, responses):
        (xmd, ymd), (xs, ys) = zip(xr, yr)
        if xmd >= ymd or xmd.time != ymd.time: continue
        base_id = _base_id((xmd, ymd))
        output = outpath(base_id)
        if not CLOBBEROK and op.exists(output):
            raise Exception("won't clobber %s" % output)

        img_id = IDPREFIX + base_id
        to_do.append(_to_do(_args((xs, ys), (xmd, ymd), output), img_id))

    pixel_maps = do_scatterplots(cl_metadata, responses, to_do, WITHLIMITS)
    print_pixel_annotations(pixel_maps)
Esempio n. 7
0
def main(argv=sys.argv[1:]):
    assert len(argv) == 1

    su.mkdirp(OUTPUTDIR)

    rows = readinput(argv[0])
    cl_metadata, responses = parse(rows)

    _to_do = co.namedtuple('_to_do', 'args imgid')
    _args = co.namedtuple('_args', 'xy_data xy_metadata output')
    to_do = []
    for xr, yr in it.product(responses, responses):
        (xmd, ymd), (xs, ys) = zip(xr, yr)
        if xmd >= ymd or xmd.time != ymd.time: continue
        base_id = _base_id((xmd, ymd))
        output = outpath(base_id)
        if not CLOBBEROK and op.exists(output):
            raise Exception("won't clobber %s" % output)

        img_id = IDPREFIX + base_id
        to_do.append(_to_do(_args((xs, ys), (xmd, ymd), output), img_id))

    pixel_maps = do_scatterplots(cl_metadata, responses, to_do, WITHLIMITS)
    print_pixel_annotations(pixel_maps)
def main(argv):

    argparser = argparse.ArgumentParser(
        description='Build sampattavanich_2014 app resources.')
    argparser.add_argument('-n', '--no-media', action='store_true',
                           default=False,
                           help="Don't copy media files)")
    args = argparser.parse_args()

    cur_dir = op.abspath(op.dirname(__file__))
    html_dir = op.abspath(op.join(
        cur_dir, '..', 'temp', 'docroot', 'explore', 'sampattavanich-2014'))
    html_filename = op.join(html_dir, 'index.html')
    cell_img_out_dir = op.join(html_dir, 'img', 'cell')
    popup_img_out_dir = op.join(html_dir, 'img', 'popup')

    platemap = build_platemap(PLATEMAP_FILENAME)
    ligand_concs = [c for c in sorted(platemap.ligand_conc.unique()) if c > 0]

    table = []
    for row, ligand_conc in enumerate(ligand_concs):
        intensity = (CONCENTRATION_COLOR_BEGIN +
                     (CONCENTRATION_COLOR_END - CONCENTRATION_COLOR_BEGIN) /
                     len(ligand_concs) * row)
        color = '#' + ('%02x' % intensity * 3)
        table_row = {'ligand_conc': ligand_conc,
                     'color': color,
                     'cells': []}
        for col, ligand in enumerate(LIGAND_ORDER):
            location = ((platemap.ligand_conc == ligand_conc) &
                        (platemap.ligand == ligand) &
                        (platemap.inhibitor == ''))
            table_row['cells'].append(platemap[location].iloc[0])
        table.append(table_row)
    # FIXME We should really just build a pivoted dataframe in the right way so
    # that we can just iterate over it cleanly. This duplication is not good.
    table_inhibitors = []
    for row, inhibitor in enumerate(INHIBITOR_ORDER):
        color = '#' + ('%02x' % CONCENTRATION_COLOR_END * 3)
        table_row = {'ligand_conc': ligand_concs[-1],
                     'color': color,
                     'inhibitors': inhibitor.split(' + '),
                     'cells': []}
        for col, ligand in enumerate(LIGAND_ORDER):
            location = ((platemap.inhibitor == inhibitor) &
                        (platemap.ligand == ligand))
            table_row['cells'].append(platemap[location].iloc[0])
        table_inhibitors.append(table_row)
            
    data = {'ligands': LIGAND_ORDER,
            'table': table,
            'table_inhibitors': table_inhibitors,
            'num_ligand_concs': len(ligand_concs),
            'num_inhibitors': len(INHIBITOR_ORDER),
            'STATIC_URL': django.conf.settings.STATIC_URL,
            }
    content = render_to_string('sampattavanich_2014/index.html', data)
    with codecs.open(html_filename, 'w', 'utf-8') as out_file:
        out_file.write(content)

    if not args.no_media:
        su.mkdirp(cell_img_out_dir)
        for src_filename in os.listdir(CELL_IMAGE_PATH):
            if not src_filename.endswith('.png'):
                continue
            src_path = op.join(CELL_IMAGE_PATH, src_filename)
            dest_filename = src_filename.partition(CELL_IMAGE_PREFIX)[2]
            dest_path = op.join(cell_img_out_dir, dest_filename)
            shutil.copy(src_path, dest_path)
            os.chmod(dest_path, 0644)
        su.mkdirp(popup_img_out_dir)
        for src_filename in os.listdir(POPUP_IMAGE_PATH):
            if not src_filename.endswith('.png'):
                continue
            src_path = op.join(POPUP_IMAGE_PATH, src_filename)
            dest_filename = src_filename
            dest_path = op.join(popup_img_out_dir, dest_filename)
            shutil.copy(src_path, dest_path)
            os.chmod(dest_path, 0644)

    return 0
def create_output_path(*elements):
    "Create and canonicalize a path relative to the output directory."
    path = op.join(DOCROOT, *elements)
    su.mkdirp(path)
    return path
Esempio n. 10
0
def stash_put(name, obj):
    "Stash an object by name (to disk) for later retrieval."
    path = _stash_path(name)
    su.mkdirp(op.dirname(path))
    pickle_file = open(path, 'w');
    pickle.dump(obj, pickle_file)
def main(argv):

    argparser = argparse.ArgumentParser(
        description='Build single_cell_dynamics app resources.')
    argparser.add_argument('-d', '--no-data', action='store_true',
                           default=False,
                           help="Don't copy data files")
    argparser.add_argument('-m', '--no-media', action='store_true',
                           default=False,
                           help="Don't copy media files")
    args = argparser.parse_args()

    cur_dir = op.abspath(op.dirname(__file__))
    data_out_dir = op.join(DOCROOT, 'data')
    cell_img_out_dir = op.join(DOCROOT, 'img', 'cell')
    popup_img_out_dir = op.join(DOCROOT, 'img', 'popup')
    movie_out_dir = op.join(DOCROOT, 'movies')

    platemap = build_platemap(PLATEMAP_FILENAME)
    platemap = platemap[platemap.egf_conc == 100]
    inhibitor_concs = [c for c in sorted(platemap.inhibitor_conc.unique())
                       if c > 0]
    inhibitors = platemap.inhibitor.unique()
    batimastat_concs = [c for c in sorted(platemap.batimastat_conc.unique())]

    table = []
    for row, inhibitor_conc in enumerate(inhibitor_concs):
        intensity = (CONCENTRATION_COLOR_BEGIN +
                     (CONCENTRATION_COLOR_END - CONCENTRATION_COLOR_BEGIN) /
                     len(inhibitor_concs) * row)
        color = '#' + ('%02x' % intensity * 3)
        table_row = {'inhibitor_conc': inhibitor_conc,
                     'color': color,
                     'cells': []}
        for batimastat_conc in batimastat_concs:
            for inhibitor in inhibitors:
                location = ((platemap.inhibitor == inhibitor) &
                            (platemap.inhibitor_conc == inhibitor_conc) &
                            (platemap.batimastat_conc == batimastat_conc))
                table_row['cells'].append(platemap[location].iloc[0])
        table.append(table_row)
            
    data = {'inhibitors': inhibitors,
            'table': table,
            'num_inhibitor_concs': len(inhibitor_concs),
            'num_inhibitors': len(inhibitors),
            'batimastat_concs': batimastat_concs,
            'STATIC_URL': django.conf.settings.STATIC_URL,
            'BASE_URL': BASE_URL,
            }
    su.mkdirp(DOCROOT)
    render_template('single_cell_dynamics/index.html', data,
                    DOCROOT, 'index.html')

    if not args.no_data:
        su.mkdirp(data_out_dir)
        for src_filename in os.listdir(DATA_PATH):
            match = re.match(r'H5OUT_(r\d+)_(c\d+)\.h5', src_filename)
            if not match:
                continue
            src_path = op.join(DATA_PATH, src_filename)
            dest_filename = 'ekar_single_cell_data_%s%s.csv' % match.groups()
            dest_path = op.join(data_out_dir, dest_filename)
            data = extract_well_data(src_path)
            with open(dest_path, 'w') as f:
                data.to_csv(f, index=False)

    if not args.no_media:
        su.mkdirp(cell_img_out_dir)
        for src_filename in os.listdir(VIDEO_PATH):
            if not (src_filename.startswith(CELL_IMAGE_PREFIX) and
                    src_filename.endswith('.png')):
                continue
            src_path = op.join(VIDEO_PATH, src_filename)
            dest_filename = src_filename[len(CELL_IMAGE_PREFIX):]
            dest_path = op.join(cell_img_out_dir, dest_filename)
            shutil.copy(src_path, dest_path)
            os.chmod(dest_path, 0644)
        su.mkdirp(popup_img_out_dir)
        for src_filename in os.listdir(VIDEO_PATH):
            if not re.match(r'r\d+c\d+\.png', src_filename):
                continue
            src_path = op.join(VIDEO_PATH, src_filename)
            dest_filename = src_filename
            dest_path = op.join(popup_img_out_dir, dest_filename)
            shutil.copy(src_path, dest_path)
            os.chmod(dest_path, 0644)
        su.mkdirp(movie_out_dir)
        for src_filename in os.listdir(VIDEO_PATH):
            if not src_filename.endswith('.mp4'):
                continue
            src_path = op.join(VIDEO_PATH, src_filename)
            dest_filename = re.sub(r'myMov_(\w+)f1ratio', r'\1', src_filename)
            dest_path = op.join(movie_out_dir, dest_filename)
            shutil.copy(src_path, dest_path)
            os.chmod(dest_path, 0644)

    return 0
Esempio n. 12
0
def stash_put(name, obj):
    "Stash an object by name (to disk) for later retrieval."
    path = _stash_path(name)
    su.mkdirp(op.dirname(path))
    pickle_file = open(path, 'w')
    pickle.dump(obj, pickle_file)
Esempio n. 13
0
def main(argv):

    argparser = argparse.ArgumentParser(
        description='Build sampattavanich_2014 app resources.')
    argparser.add_argument('-n',
                           '--no-media',
                           action='store_true',
                           default=False,
                           help="Don't copy media files)")
    args = argparser.parse_args()

    cur_dir = op.abspath(op.dirname(__file__))
    html_dir = op.abspath(
        op.join(cur_dir, '..', 'temp', 'docroot', 'explore',
                'sampattavanich-2014'))
    html_filename = op.join(html_dir, 'index.html')
    cell_img_out_dir = op.join(html_dir, 'img', 'cell')
    popup_img_out_dir = op.join(html_dir, 'img', 'popup')

    platemap = build_platemap(PLATEMAP_FILENAME)
    ligand_concs = [c for c in sorted(platemap.ligand_conc.unique()) if c > 0]

    table = []
    for row, ligand_conc in enumerate(ligand_concs):
        intensity = (CONCENTRATION_COLOR_BEGIN +
                     (CONCENTRATION_COLOR_END - CONCENTRATION_COLOR_BEGIN) /
                     len(ligand_concs) * row)
        color = '#' + ('%02x' % intensity * 3)
        table_row = {'ligand_conc': ligand_conc, 'color': color, 'cells': []}
        for col, ligand in enumerate(LIGAND_ORDER):
            location = ((platemap.ligand_conc == ligand_conc) &
                        (platemap.ligand == ligand) &
                        (platemap.inhibitor == ''))
            table_row['cells'].append(platemap[location].iloc[0])
        table.append(table_row)
    # FIXME We should really just build a pivoted dataframe in the right way so
    # that we can just iterate over it cleanly. This duplication is not good.
    table_inhibitors = []
    for row, inhibitor in enumerate(INHIBITOR_ORDER):
        color = '#' + ('%02x' % CONCENTRATION_COLOR_END * 3)
        table_row = {
            'ligand_conc': ligand_concs[-1],
            'color': color,
            'inhibitors': inhibitor.split(' + '),
            'cells': []
        }
        for col, ligand in enumerate(LIGAND_ORDER):
            location = ((platemap.inhibitor == inhibitor) &
                        (platemap.ligand == ligand))
            table_row['cells'].append(platemap[location].iloc[0])
        table_inhibitors.append(table_row)

    data = {
        'ligands': LIGAND_ORDER,
        'table': table,
        'table_inhibitors': table_inhibitors,
        'num_ligand_concs': len(ligand_concs),
        'num_inhibitors': len(INHIBITOR_ORDER),
        'STATIC_URL': django.conf.settings.STATIC_URL,
    }
    content = render_to_string('sampattavanich_2014/index.html', data)
    with codecs.open(html_filename, 'w', 'utf-8') as out_file:
        out_file.write(content)

    if not args.no_media:
        su.mkdirp(cell_img_out_dir)
        for src_filename in os.listdir(CELL_IMAGE_PATH):
            if not src_filename.endswith('.png'):
                continue
            src_path = op.join(CELL_IMAGE_PATH, src_filename)
            dest_filename = src_filename.partition(CELL_IMAGE_PREFIX)[2]
            dest_path = op.join(cell_img_out_dir, dest_filename)
            shutil.copy(src_path, dest_path)
            os.chmod(dest_path, 0644)
        su.mkdirp(popup_img_out_dir)
        for src_filename in os.listdir(POPUP_IMAGE_PATH):
            if not src_filename.endswith('.png'):
                continue
            src_path = op.join(POPUP_IMAGE_PATH, src_filename)
            dest_filename = src_filename
            dest_path = op.join(popup_img_out_dir, dest_filename)
            shutil.copy(src_path, dest_path)
            os.chmod(dest_path, 0644)

    return 0