def create_genotypic_companions(slides): GENO_CYCLES = 11 logging.info("Generating genotypic metadata files") filePaths = [] for slide in slides: for i in range(GENO_CYCLES): images = [] index = i + 1 logging.debug("Processing %s" % slide) # Genotypic metadata generation for position in sorted(slides[slide]): logging.debug(" Creating image for %s" % position) image = Image(position, 2048, 879, 1, 5, 1, order="XYZCT", type="uint16") image.add_channel("Cy5", -16776961) image.add_channel("Cy3", 16711935) image.add_channel("TxR", 65535) image.add_channel("Fam", -65281) image.add_channel("Phase", -1) image.add_tiff(get_genotypic_filename(position, "1_cy5_fluor", index), c=0, z=0, t=0) image.add_tiff(get_genotypic_filename(position, "2_cy3_fluor", index), c=1, z=0, t=0) image.add_tiff(get_genotypic_filename(position, "3_TxR_fluor", index), c=2, z=0, t=0) image.add_tiff(get_genotypic_filename(position, "4_fam_flour", index), c=3, z=0, t=0) image.add_tiff(get_genotypic_filename(position, "phase", index), c=4, z=0, t=0) images.append(image) position_dir = join(EXPERIMENTB_DIRECTORY, 'companions', slide, 'geno', position) if not os.path.lexists(position_dir): os.symlink(join(DATA_DIRECTORY, slide, "geno", position), position_dir) companion_file = join( EXPERIMENTB_DIRECTORY, 'companions', slide, "geno", '%s_round-%02g.companion.ome' % (slide, index)) write_companion(images, companion_file) filePaths.append( "Project:name:idr0065-camsund-crispri/experimentB/" "Dataset:name:%s_round-%02g\t" "%s\t%s\n" % (slide, index, companion_file, slide)) tsv = join(EXPERIMENTB_DIRECTORY, 'idr0065-experimentB-filePaths.tsv') with open(tsv, 'w') as f: for p in filePaths: f.write(p)
size_z, 2, 1, order="XYZCT", type="uint16") image.data['Pixels']['PhysicalSizeX'] = '20' image.data['Pixels']['PhysicalSizeXUnit'] = 'nm' image.data['Pixels']['PhysicalSizeY'] = '20' image.data['Pixels']['PhysicalSizeYUnit'] = 'nm' (n1, c1, n2, c2) = CHANNEL_MAPPING[os.path.basename(folder)] image.add_channel(n1, c1) image.add_channel(n2, c2) for i in range(len(rawtiffs)): image.add_tiff("%s/%s" % (os.path.basename(cell), rawtiffs[i]), c=i, z=0, t=0, ifd=0, planeCount=size_z) create_companion(images=[image], out=cell + '.companion.ome') # Generate indented XML for readability proc = subprocess.Popen([ 'xmllint', '--format', '-o', cell + '.companion.ome', cell + '.companion.ome' ], stdin=subprocess.PIPE, stdout=subprocess.PIPE) (output, error_output) = proc.communicate()
def create_phenotypic_companions(): """Phenotypic metadata files""" logging.info("Generating phenotypic metadata files") time_indexes = read_phenotypic_time_indexes() timestamps = read_phenotypic_timestamps() slides = parse_phenotypic_filenames(timestamps) filePaths = [] for slide in slides: images = [] logging.debug("Processing phenotypic %s" % slide) # Genotypic metadata generation for position in sorted(slides[slide]): logging.debug(" Creating image for %s" % position) image = Image(position, 2048, 879, 1, 2, 481, order="XYZCT", type="uint16") image.add_channel("Phase", -1) image.add_channel("Fluorescence", 16711935) # Phase images for t in range(481): relative_path = get_phenotypic_filename(position, "phase", t) full_path = get_phenotypic_filename(position, "phase", t, slide=slide) image.add_tiff(relative_path, c=0, z=0, t=t, planeCount=1) plane_options = { "DeltaT": timestamps[full_path], "DeltaTUnit": "s", "ExposureTime": "20", "ExposureTimeUnit": "ms", } image.add_plane(c=0, z=0, t=t, options=plane_options) # Fluorescence images for i in range(241): relative_path = get_phenotypic_filename(position, "fluor", i) full_path = get_phenotypic_filename(position, "fluor", i, slide=slide) t = time_indexes[full_path] plane_options = { "DeltaT": timestamps[full_path], "DeltaTUnit": "s", "ExposureTime": "300", "ExposureTimeUnit": "ms", } if t == 2 * i: image.add_tiff(relative_path, c=1, z=0, t=t, planeCount=1) if i != 240: image.add_tiff(None, c=1, z=0, t=(2 * i) + 1) elif t == (2 * i) + 1: image.add_tiff(None, c=1, z=0, t=2 * i) if t != 481: image.add_tiff(relative_path, c=1, z=0, t=t, planeCount=1) else: raise Exception("Invalid mapping") image.add_plane(c=1, z=0, t=t, options=plane_options) images.append(image) position_dir = join(EXPERIMENTA_DIRECTORY, 'companions', slide, "pheno", position) if not os.path.lexists(position_dir): os.symlink(join(DATA_DIRECTORY, slide, "pheno", position), position_dir) companion_file = join(EXPERIMENTA_DIRECTORY, 'companions', slide, "pheno", slide + '.companion.ome') write_companion(images, companion_file) filePaths.append("Project:name:idr0065-camsund-crispri/experimentA/" "Dataset:name:%s\t" "%s\t%s\n" % (slide, companion_file, slide)) tsv = join(EXPERIMENTA_DIRECTORY, 'idr0065-experimentA-filePaths.tsv') with open(tsv, 'w') as f: for p in filePaths: f.write(p) return slides
test = "{}_{}{}_0h.tiff".format(plate_name, row, column) if test in filenames: basename = "{}{}".format(row, column) image = Image(basename, 2080, 1552, 25, 3, len(timepoints), order="XYZTC", type="uint8") image.add_channel(samplesPerPixel=3) for i, timepoint in enumerate(timepoints): filename = "{}_{}{}_{}.tiff".format(plate_name, row, column, timepoint) image.add_tiff(filename, c=0, z=0, t=i, planeCount=25) options = { 'DeltaT': timepoint[:-1], 'DeltaTUnit': 'h', } for z in range(25): image.add_plane(c=0, z=z, t=i, options=options) well.add_wellsample(well_index, image) well_index += 1 companion_file = "../companions/{}.companion.ome".format(plate_name) create_companion(plates=[plate], out=companion_file) # Indent XML for readability proc = subprocess.Popen( ['xmllint', '--format', '-o', companion_file, companion_file], stdin=subprocess.PIPE,