def _load_data(self, channel): dtable = HmmDataTable() # XXX read region names from hdf not from settings mask = "%s__%s" % (channel, self.ecopts.regionnames[channel]) c = 2 if self.ecopts.write_gallery: c += 1 thread = QThread.currentThread() with Ch5File(self.ch5file, mode="r") as ch5: layout = ch5.layout(self.plate) mappings = PlateMapping(layout) thread.statusUpdate(min=0, max=ch5.numberSites(self.plate) + c) for site in ch5.iterSites(): ws = "%s_%02d" % (site.well, int(site.site)) thread.statusUpdate(text="loading plate: %s, file: %s" % (site.plate, ws)) thread.increment.emit() thread.interruption_point() QtCore.QCoreApplication.processEvents() if not ch5.hasClassifier(mask): continue # make dtable aware of all positions, sometime they contain # no tracks and I don't want to ignore them dtable.add_position(ws, mappings[ws]) if not ch5.hasEvents(site): continue objidx = ch5.events(site, self.ecopts.ignore_tracking_branches) tracks = np.asarray(ch5.predictions(site, mask))[objidx] try: probs = ch5.probabilities(site, mask)[objidx, :] except KeyError as e: probs = None site.mask = mask dtable.add_tracks(tracks, ws, mappings[ws], objidx, site, probs) if dtable.is_empty(): raise RuntimeError( "No data found for plate '%s' and channel '%s' " % (self.plate, channel)) return dtable, self._load_classdef(mask)
def __call__(self): self._makedirs() mappings = PlateMapping([splitext(basename(f))[0] for f in self.files]) if self.ecopts.position_labels: mpfile = join(self.ecopts.mapping_dir, "%s.txt" %self.plate) mappings.read(mpfile) for channel in self.ecopts.regionnames.keys(): dtable, cld = self._load_data(mappings, channel) msg = 'performing error correction on channel %s' %channel self.interruption_point(msg) # error correction if self.ecopts.hmm_algorithm == self.ecopts.HMM_BAUMWELCH: hmm = HmmSklearn(dtable, channel, cld, self.ecopts) else: hmm = HmmTde(dtable, channel, cld, self.ecopts) data = hmm() # plots and export report = HmmReport(data, self.ecopts, cld, self._hmm_dir) prefix = "%s_%s" %(channel.title(), self.ecopts.regionnames[channel]) sby = self.ecopts.sortby.replace(" ", "_") self.interruption_point("plotting overview") report.overview(join(self._hmm_dir, '%s-%s.pdf' %(prefix, sby))) report.close_figures() self.interruption_point("plotting bar- and boxplots") report.bars_and_boxes(join(self._hmm_dir, '%s-%s_boxbars.pdf' %(prefix, sby))) report.close_figures() self.interruption_point("plotting hmm model") report.hmm_model(join(self._hmm_dir, "%s-%s_model.pdf") %(prefix, sby)) if self.ecopts.write_gallery: self.interruption_point("plotting image gallery") try: # replace image_gallery_png with image_gallery_pdf fn = join(self._gallery_dir, '%s-%s_gallery.png' %(prefix, sby)) with cellh5.ch5open(self.ch5file, 'r') as ch5: report.image_gallery_png(ch5, fn, self.ecopts.n_galleries, self.ecopts.resampling_factor, self.ecopts.size_gallery_image) report.close_figures() except Exception as e: # don't stop error corection with open(join(self._gallery_dir, '%s-%s_error_readme.txt' %(prefix, sby)), 'w') as fp: traceback.print_exc(file=fp) fp.write("Check if gallery images exist!") report.export_hmm(join(self._hmm_dir, "%s-%s_hmm.csv" %(prefix, sby)), self.ecopts.sortby)
def __call__(self): self._makedirs() mappings = PlateMapping([splitext(basename(f))[0] for f in self.files]) if self.ecopts.position_labels: mpfile = join(self.ecopts.mapping_dir, "%s.txt" % self.plate) mappings.read(mpfile) for channel in self.ecopts.regionnames.keys(): dtable, cld = self._load_data(mappings, channel) msg = 'performing error correction on channel %s' % channel self.interruption_point(msg) # error correction if self.ecopts.hmm_algorithm == self.ecopts.HMM_BAUMWELCH: hmm = HmmSklearn(dtable, channel, cld, self.ecopts) else: hmm = HmmTde(dtable, channel, cld, self.ecopts) data = hmm() # plots and export report = HmmReport(data, self.ecopts, cld, self._hmm_dir) prefix = "%s_%s" % (channel.title(), self.ecopts.regionnames[channel]) sby = self.ecopts.sortby.replace(" ", "_") self.interruption_point("plotting overview") report.overview(join(self._hmm_dir, '%s-%s.pdf' % (prefix, sby))) report.close_figures() self.interruption_point("plotting bar- and boxplots") report.bars_and_boxes( join(self._hmm_dir, '%s-%s_boxbars.pdf' % (prefix, sby))) report.close_figures() self.interruption_point("plotting hmm model") report.hmm_model( join(self._hmm_dir, "%s-%s_model.pdf") % (prefix, sby)) if self.ecopts.write_gallery: self.interruption_point("plotting image gallery") try: # replace image_gallery_png with image_gallery_pdf fn = join(self._gallery_dir, '%s-%s_gallery.png' % (prefix, sby)) with cellh5.ch5open(self.ch5file, 'r') as ch5: report.image_gallery_png( ch5, fn, self.ecopts.n_galleries, self.ecopts.resampling_factor, self.ecopts.size_gallery_image) report.close_figures() except Exception as e: # don't stop error corection with open( join(self._gallery_dir, '%s-%s_error_readme.txt' % (prefix, sby)), 'w') as fp: traceback.print_exc(file=fp) fp.write("Check if gallery images exist!") report.export_hmm( join(self._hmm_dir, "%s-%s_hmm.csv" % (prefix, sby)), self.ecopts.sortby)
# replace image_gallery_png with image_gallery_pdf fn = join(self._gallery_dir, '%s-%s_gallery.png' %(prefix, sby)) with cellh5.ch5open(self.ch5file, 'r') as ch5: report.image_gallery_png(ch5, fn, self.ecopts.n_galleries, self.ecopts.resampling_factor, self.ecopts.size_gallery_image) report.close_figures() except Exception as e: # don't stop error corection with open(join(self._gallery_dir, '%s-%s_error_readme.txt' %(prefix, sby)), 'w') as fp: traceback.print_exc(file=fp) fp.write("Check if gallery images exist!") report.export_hmm(join(self._hmm_dir, "%s-%s_hmm.csv" %(prefix, sby)), self.ecopts.sortby) if __name__ == "__main__": path_in = '/Users/hoefler/demo_data/ibb/mappings/input.txt' path_out = '/Users/hoefler/demo_data/ibb/mappings/output.txt' positons = ["018", "028", "051", "067"] pm = PlateMapping(positons) pm.read(path_in) pm['018']['OligoID'] = "just made up" pm.save(path_out)
with cellh5.ch5open(self.ch5file, 'r') as ch5: report.image_gallery_png( ch5, fn, self.ecopts.n_galleries, self.ecopts.resampling_factor, self.ecopts.size_gallery_image) report.close_figures() except Exception as e: # don't stop error corection with open( join(self._gallery_dir, '%s-%s_error_readme.txt' % (prefix, sby)), 'w') as fp: traceback.print_exc(file=fp) fp.write("Check if gallery images exist!") report.export_hmm( join(self._hmm_dir, "%s-%s_hmm.csv" % (prefix, sby)), self.ecopts.sortby) if __name__ == "__main__": path_in = '/Users/hoefler/demo_data/ibb/mappings/input.txt' path_out = '/Users/hoefler/demo_data/ibb/mappings/output.txt' positons = ["018", "028", "051", "067"] pm = PlateMapping(positons) pm.read(path_in) pm['018']['OligoID'] = "just made up" pm.save(path_out)