示例#1
0
def write_screen(data_dir, plate, outf, rev_well_tag=False):
    writer = ScreenWriter(plate, ROWS, COLUMNS, FIELDS)
    for idx in xrange(ROWS * COLUMNS):
        r, c = writer.coordinates(idx)
        well_tag = "%d%s" % (c, r) if rev_well_tag else "%s%d" % (r, c)
        fn = first_existing(data_dir, [well_tag.lower(), well_tag])
        if fn is None:
            sys.stderr.write("missing: %s\n" % os.path.join(data_dir, well_tag.lower()))
            field_values = None
        else:
            field_values = [fn]
        writer.add_well(field_values)
    writer.write(outf)
def write_screen(data_dir, plate, outf, screen=None):
    kwargs = {"screen_name": screen} if screen else {}
    channel_map = get_channel_map(data_dir)
    try:
        channel_tags = channel_map[plate]
    except KeyError:
        raise ValueError("Plate %r not found" % (plate,))
    file_maps = {}
    n_fields = []
    for c in channel_tags:
        subd = os.path.join(data_dir, "%s-%s" % (plate, c))
        file_maps[c], nf = get_file_map(subd)
        n_fields.append(nf)
    n_fields = max(n_fields)
    base_path = os.path.join(data_dir, "%s-" % plate)
    writer = ScreenWriter(plate, ROWS, COLUMNS, n_fields, **kwargs)
    for idx in xrange(ROWS * COLUMNS):
        well_tag = "%s%02d" % writer.coordinates(idx)
        if not any(well_tag in file_maps[_] for _ in channel_tags):
            sys.stderr.write(
                "WARNING: plate %s: missing well: %s\n" % (plate, well_tag)
            )
            writer.add_well([])
            continue
        field_values = []
        for i in xrange(n_fields):
            try:
                fnames = [file_maps[_][well_tag][i] for _ in channel_tags]
            except IndexError:
                sys.stderr.write(
                    "WARNING: plate %s: missing field for well %s: %d\n" %
                    (plate, well_tag, i)
                )
            else:
                split_fnames = [os.path.splitext(_) for _ in fnames]
                assert len(set(_[1] for _ in split_fnames)) == 1
                ext = split_fnames[0][1]
                elems = [os.path.join(c, t[0])
                         for (c, t) in zip(channel_tags, split_fnames)]
                field_values.append(
                    "%s<%s>%s" % (base_path, ",".join(elems), ext)
                )
        if len(field_values) == n_fields:
            extra_kv = EXTRA_KV.copy()
            extra_kv['ChannelNames'] = ",".join(channel_tags)
            writer.add_well(field_values, extra_kv=extra_kv)
        else:
            # treat wells with less than n_fields as missing
            writer.add_well([])
    writer.write(outf)
示例#3
0
def write_screen(data_dir, plate, outf):
    writer = ScreenWriter(plate, ROWS, COLUMNS, FIELDS)
    for idx in xrange(ROWS * COLUMNS):
        r, c = writer.coordinates(idx)
        well_tag = "Well %s%03d" % (r, c)
        subdir = os.path.join(data_dir, well_tag)
        field_values = []
        if not os.path.isdir(subdir):
            sys.stderr.write("missing: %s\n" % subdir)
        else:
            pattern = "<FITC,Hoechst,Tritc>_Flo - n000000.tif"
            field_values.append(os.path.join(subdir, pattern))
        writer.add_well(field_values, extra_kv=EXTRA_KV)
    writer.write(outf)
示例#4
0
def write_screen(data_dir, plate, outf, rev_well_tag=False):
    writer = ScreenWriter(plate, ROWS, COLUMNS, FIELDS)
    for idx in range(ROWS * COLUMNS):
        r, c = writer.coordinates(idx)
        well_tag = "%d%s" % (c, r) if rev_well_tag else "%s%d" % (r, c)
        fn = first_existing(data_dir, [well_tag.lower(), well_tag])
        if fn is None:
            sys.stderr.write("missing: %s\n" %
                             os.path.join(data_dir, well_tag.lower()))
            field_values = None
        else:
            field_values = [fn]
        writer.add_well(field_values)
    writer.write(outf)
示例#5
0
def write_screen(data_dir, plate, outf):
    writer = ScreenWriter(plate, ROWS, COLUMNS, FIELDS)
    for idx in range(ROWS * COLUMNS):
        r, c = writer.coordinates(idx)
        well_tag = "Well %s%03d" % (r, c)
        subdir = os.path.join(data_dir, well_tag)
        field_values = []
        if not os.path.isdir(subdir):
            sys.stderr.write("missing: %s\n" % subdir)
        elif not has_images(subdir):
            sys.stderr.write("no images: %s\n" % subdir)
        else:
            field_values.append(os.path.join(subdir, PATTERN))
        writer.add_well(field_values, extra_kv=EXTRA_KV)
    writer.write(outf)
示例#6
0
def write_screen(data_dir, plate, outf):
    writer = ScreenWriter(plate, ROWS, COLUMNS, FIELDS)
    for idx in xrange(ROWS * COLUMNS):
        r, c = writer.coordinates(idx)
        well_tag = "Well %s%03d" % (r, c)
        subdir = os.path.join(data_dir, well_tag)
        field_values = []
        if not os.path.isdir(subdir):
            sys.stderr.write("missing: %s\n" % subdir)
        elif not has_images(subdir):
            sys.stderr.write("no images: %s\n" % subdir)
        else:
            field_values.append(os.path.join(subdir, PATTERN))
        writer.add_well(field_values, extra_kv=EXTRA_KV)
    writer.write(outf)
示例#7
0
def write_screen(data_dir, plate, outf):
    writer = ScreenWriter(plate, ROWS, COLUMNS, FIELDS)
    for idx in xrange(ROWS * COLUMNS):
        r, c = writer.coordinates(idx)
        well_tag = "%s%s%03d" % (os.path.basename(data_dir), r, c)
        subdir = os.path.join(data_dir, well_tag)
        field_values = []
        if not os.path.isdir(subdir):
            sys.stderr.write("missing: %s\n" % subdir)
        else:
            for run in xrange(FIELDS):
                pattern = "%s_<A,H,T>%d.tif" % (well_tag, run + 1)
                field_values.append(os.path.join(subdir, pattern))
        writer.add_well(field_values, extra_kv=EXTRA_KV)
    writer.write(outf)
示例#8
0
def write_screen(data_dir, plate, outf, screen=None):
    kwargs = {"screen_name": screen} if screen else {}
    patterns = get_patterns(data_dir)
    writer = ScreenWriter(plate, ROWS, COLUMNS, FIELDS, **kwargs)
    for idx in xrange(ROWS * COLUMNS):
        well_tag = "%s%02d" % writer.coordinates(idx)
        try:
            field_map = patterns[well_tag]
        except KeyError:
            writer.add_well([])
            continue
        field_values = []
        for i in xrange(1, FIELDS + 1):
            field_values.append(os.path.join(data_dir, field_map[i]))
        writer.add_well(field_values, extra_kv=EXTRA_KV)
    writer.write(outf)
示例#9
0
def write_screen(data_dir, plate, outf, screen=None):
    kwargs = {"screen_name": screen} if screen else {}
    patterns = get_patterns(data_dir)
    writer = ScreenWriter(plate, ROWS, COLUMNS, FIELDS, **kwargs)
    for idx in range(ROWS * COLUMNS):
        well_tag = "%s%02d" % writer.coordinates(idx)
        try:
            field_map = patterns[well_tag]
        except KeyError:
            writer.add_well([])
            continue
        field_values = []
        for i in range(1, FIELDS + 1):
            field_values.append(os.path.join(data_dir, field_map[i]))
        writer.add_well(field_values, extra_kv=EXTRA_KV)
    writer.write(outf)
示例#10
0
def write_screen(data_dir, plate, outf):
    writer = ScreenWriter(plate, ROWS, COLUMNS, FIELDS)
    for idx in xrange(ROWS * COLUMNS):
        r, c = writer.coordinates(idx)
        well_tag = "%s%s%03d" % (os.path.basename(data_dir), r, c)
        subdir = os.path.join(data_dir, well_tag)
        field_values = []
        if not os.path.isdir(subdir):
            sys.stderr.write("missing: %s\n" % subdir)
        else:
            patterns = get_patterns(subdir)
            if not patterns:
                sys.stderr.write("missing images: %s\n" % subdir)
            for p in patterns:
                field_values.append(os.path.join(subdir, p))
        writer.add_well(field_values, extra_kv=EXTRA_KV)
    writer.write(outf)
示例#11
0
def write_screen(data_dir, plate, outf):
    writer = ScreenWriter(plate, ROWS, COLUMNS, FIELDS)
    for idx in xrange(ROWS * COLUMNS):
        r, c = writer.coordinates(idx)
        well_tag = "%s%s%03d" % (os.path.basename(data_dir), r, c)
        subdir = os.path.join(data_dir, well_tag)
        field_values = []
        if not os.path.isdir(subdir):
            sys.stderr.write("missing: %s\n" % subdir)
        else:
            patterns = get_patterns(subdir)
            if not patterns:
                sys.stderr.write("missing images: %s\n" % subdir)
            for p in patterns:
                field_values.append(os.path.join(subdir, p))
        writer.add_well(field_values, extra_kv=EXTRA_KV)
    writer.write(outf)
示例#12
0
def write_screen(data_dir, plate, outf):
    d = group_files(data_dir)
    consistency_check(d)
    writer = ScreenWriter(plate, ROWS, COLUMNS, FIELDS)
    for idx in xrange(ROWS * COLUMNS):
        r, c = writer.coordinates(idx)
        well = "%s%02d" % (r.lower(), c)
        field_values = []
        by_field = d[well]
        for i in xrange(FIELDS):
            field = "%d" % (i + 1)
            seq = by_field[field]
            assert len(set(_[1] for _ in seq)) == 1
            head = seq[0][1]
            c_block = "<%s>" % ",".join(_[0] for _ in sorted(seq))
            pattern = "%s_%s_s%s_w%s.tif" % (head, well, field, c_block)
            field_values.append(os.path.join(data_dir, pattern))
        writer.add_well(field_values, extra_kv=EXTRA_KV)
    writer.write(outf)
示例#13
0
def write_screen(data_dir, plate, outf):

    # For the second screen, remove "-(\d\d)", "-repeated", etc.
    well_tag = os.path.basename(data_dir)
    p1 = well_tag.find("(")
    p2 = well_tag.find(")")
    if p1 > 0 and p2 > 0:
        well_tag = well_tag[0:p1 - 1]
        well_tag += well_tag[p2:]
    well_tag = well_tag.replace("-repeated", "")
    well_tag = well_tag.replace("-used pics", "")
    # Special case these!
    well_tag = well_tag.replace("Plate1-Blue-A", "P1-Bl-A")
    well_tag = well_tag.replace("Plate2-Red-B", "P2-Red-B")
    well_tag = well_tag.replace("Plate2-Blue-A", "Plate2-Red-B")

    count = 0
    writer = ScreenWriter(plate, ROWS, COLUMNS, FIELDS)
    for idx in range(ROWS * COLUMNS):
        r, c = writer.coordinates(idx)
        field_values = []
        pattern = "*[_-]%s%s[_-]*.[cz][zv]i" % (r, c)
        glob_str = os.path.join(data_dir, pattern)
        found = sorted(glob.glob(glob_str))
        assert str(found), len(found) >= 1 and len(found) <= FIELDS
        for idx in range(FIELDS):
            if found:
                field_values.append(os.path.join(data_dir, found.pop(0)))
            else:
                field_values.append("")

        if not any(field_values):
            print("missing well: %s (%s%s)" % (well_tag, r, c),
                  file=sys.stderr)
            field_values = []
        else:
            count += 1
        writer.add_well(field_values)

    if not count:
        raise Exception("no wells: %s" % plate)
    writer.write(outf)
示例#14
0
def write_screen(data_dir, plate, outf):

    # For the second screen, remove "-(\d\d)", "-repeated", etc.
    well_tag = os.path.basename(data_dir)
    p1 = well_tag.find("(")
    p2 = well_tag.find(")")
    if p1 > 0 and p2 > 0:
        well_tag = well_tag[0:p1-1]
        well_tag += well_tag[p2:]
    well_tag = well_tag.replace("-repeated", "")
    well_tag = well_tag.replace("-used pics", "")
    # Special case these!
    well_tag = well_tag.replace("Plate1-Blue-A", "P1-Bl-A")
    well_tag = well_tag.replace("Plate2-Red-B", "P2-Red-B")
    well_tag = well_tag.replace("Plate2-Blue-A", "Plate2-Red-B")

    count = 0
    writer = ScreenWriter(plate, ROWS, COLUMNS, FIELDS)
    for idx in xrange(ROWS * COLUMNS):
        r, c = writer.coordinates(idx)
        field_values = []
        pattern = "*[_-]%s%s[_-]*.[cz][zv]i" % (r, c)
        glob_str = os.path.join(data_dir, pattern)
        found = sorted(glob.glob(glob_str))
        assert str(found), len(found) >= 1 and len(found) <= FIELDS
        for idx in range(FIELDS):
            if found:
                field_values.append(os.path.join(data_dir, found.pop(0)))
            else:
                field_values.append("")

        if not any(field_values):
            print >>sys.stderr, "missing well: %s (%s%s)" % (well_tag, r, c)
            field_values = []
        else:
            count += 1
        writer.add_well(field_values)

    if not count:
        raise Exception("no wells: %s" % plate)
    writer.write(outf)