Exemplo n.º 1
0
def write_screen(data_dir, plate, outf):
    d, ch_names = group_files(data_dir)
    extra_kv = {"AxisTypes": "CT", "ChannelNames": ",".join(ch_names)}
    n_fields = len(d)
    writer = ScreenWriter(plate, ROWS, COLUMNS, n_fields)
    assert ROWS == COLUMNS == 1
    field_values = []
    for field_idx in sorted(d):
        field_values.append(os.path.join(data_dir, d[field_idx]))
    writer.add_well(field_values, extra_kv=extra_kv)
    writer.write(outf)
Exemplo n.º 2
0
def consistency_check(d):
    if len(d) != ROWS * COLUMNS:
        writer = ScreenWriter("foo", ROWS, COLUMNS, FIELDS)
        missing = []
        for idx in xrange(ROWS * COLUMNS):
            k = writer.index2d(idx)
            if k not in d:
                missing.append(k)
        print "ERROR: missing well(s):", missing
    for v in d.itervalues():
        assert set(v) == set(EXPECTED_FIELDS)
Exemplo n.º 3
0
def consistency_check(d):
    if len(d) != ROWS * COLUMNS:
        writer = ScreenWriter("foo", ROWS, COLUMNS, FIELDS)
        missing = []
        for idx in range(ROWS * COLUMNS):
            k = writer.index2d(idx)
            if k not in d:
                missing.append(k)
        print("ERROR: missing well(s):", missing)
    for v in d.itervalues():
        assert set(v) == set(EXPECTED_FIELDS)
Exemplo n.º 4
0
 def setUp(self, screen_name=None):
     super(TestScreenWriter, self).setUp(screen_name=screen_name)
     fout = StringIO()
     self.all_field_values = []
     self.extra_kv = {"Dimensions": "ZCT"}
     kwargs = {"screen_name": screen_name} if screen_name else {}
     writer = ScreenWriter(
         self.name, self.rows, self.columns, self.fields, **kwargs
     )
     for i in xrange(self.size):
         writer.add_well(self._field_values(i), extra_kv=self.extra_kv)
     writer.write(fout)
     fout.seek(0)
     self.cp = ConfigParser.ConfigParser()
     self.cp.readfp(fout)
Exemplo n.º 5
0
def write_screen(data_dir, plate, outf, screen=None):
    kwargs = {"screen_name": screen} if screen else {}
    writer = ScreenWriter(plate, ROWS, COLUMNS, FIELDS, **kwargs)
    for i in xrange(ROWS):
        for j in xrange(COLUMNS):
            x, y = j, i
            subdir = os.path.join(data_dir, "field--X%02d--Y%02d" % (x, y))
            field_values = []
            if not os.path.isdir(subdir):
                sys.stderr.write("WARNING: no subdir for X=%d, Y=%d (%s)\n" % (x, y, subdir))
            else:
                pattern = find_pattern(subdir)
                if pattern is not None:
                    field_values.append(os.path.join(subdir, pattern))
                else:
                    sys.stderr.write("WARNING: no images in subdir for X=%d, Y=%d (%s)\n" % (x, y, subdir))
            writer.add_well(field_values)
    writer.write(outf)
Exemplo n.º 6
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)
Exemplo n.º 7
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)
Exemplo n.º 8
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)
Exemplo n.º 9
0
def write_screen(data_dir, plate, outf):
    d, ch_names = group_files(data_dir)
    extra_kv = {"AxisTypes": "CT", "ChannelNames": ",".join(ch_names)}
    n_fields = len(d)
    writer = ScreenWriter(plate, ROWS, COLUMNS, n_fields)
    assert ROWS == COLUMNS == 1
    field_values = []
    for field_idx in sorted(d):
        field_values.append(os.path.join(data_dir, d[field_idx]))
    writer.add_well(field_values, extra_kv=extra_kv)
    writer.write(outf)
Exemplo n.º 10
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)
Exemplo n.º 11
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)
Exemplo n.º 12
0
def write_screen(data_dir, plate, outf):
    d = group_files(data_dir)
    consistency_check(d)
    writer = ScreenWriter(plate, ROWS, COLUMNS, FIELDS,
                          exclude_readers=EXCLUDE_READERS)
    for idx in range(ROWS * COLUMNS):
        well_coords = writer.index2d(idx)
        field_values = []
        try:
            by_field = d[well_coords]
        except KeyError:
            sys.stderr.write("missing well: %r\n" % (well_coords,))
        else:
            for i, field_coords in enumerate(EXPECTED_FIELDS):
                field_values.append(build_pattern(by_field[field_coords]))
        writer.add_well(field_values)
    writer.write(outf)
Exemplo n.º 13
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)
Exemplo n.º 14
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)
Exemplo n.º 15
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)
Exemplo n.º 16
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)
Exemplo n.º 17
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)
Exemplo n.º 18
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)
Exemplo n.º 19
0
def write_screen(data_dir, plate, outf):
    d = group_files(data_dir)
    consistency_check(d)
    writer = ScreenWriter(plate, ROWS, COLUMNS, FIELDS,
                          exclude_readers=EXCLUDE_READERS)
    for idx in xrange(ROWS * COLUMNS):
        well_coords = writer.index2d(idx)
        field_values = []
        try:
            by_field = d[well_coords]
        except KeyError:
            sys.stderr.write("missing well: %r\n" % (well_coords,))
        else:
            for i, field_coords in enumerate(EXPECTED_FIELDS):
                field_values.append(build_pattern(by_field[field_coords]))
        writer.add_well(field_values)
    writer.write(outf)
Exemplo n.º 20
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)
Exemplo n.º 21
0
 def setUp(self, screen_name=None):
     super(TestScreenWriter, self).setUp(screen_name=screen_name)
     fout = StringIO()
     self.all_field_values = []
     self.exclude_readers = ["z.x.FooReader", "z.x.BarReader"]
     self.extra_kv = {"Dimensions": "ZCT"}
     kwargs = {"exclude_readers": self.exclude_readers}
     if screen_name:
         kwargs["screen_name"] = screen_name
     writer = ScreenWriter(
         self.name, self.rows, self.columns, self.fields, **kwargs
     )
     for i in xrange(self.size):
         writer.add_well(self._field_values(i), extra_kv=self.extra_kv)
     writer.write(fout)
     fout.seek(0)
     self.cp = ConfigParser.ConfigParser()
     self.cp.readfp(fout)
Exemplo n.º 22
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)
Exemplo n.º 23
0
def write_screen(data_dir, plate, outf, screen=None):
    kwargs = {"screen_name": screen} if screen else {}
    writer = ScreenWriter(plate, ROWS, COLUMNS, FIELDS, **kwargs)
    for i in range(ROWS):
        for j in range(COLUMNS):
            x, y = j, i
            subdir = os.path.join(data_dir, "field--X%02d--Y%02d" % (x, y))
            field_values = []
            if not os.path.isdir(subdir):
                sys.stderr.write("WARNING: no subdir for X=%d, Y=%d (%s)\n" %
                                 (x, y, subdir))
            else:
                pattern = find_pattern(subdir)
                if pattern is not None:
                    field_values.append(os.path.join(subdir, pattern))
                else:
                    sys.stderr.write(
                        "WARNING: no images in subdir for X=%d, Y=%d (%s)\n" %
                        (x, y, subdir))
            writer.add_well(field_values)
    writer.write(outf)
Exemplo n.º 24
0
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)