def update_reprocess_analysis_group_data(analysis_group, reprocess_config, config, logger): """ Given an analysis_gropu and repocessor, relaod each into qtools """ update_status = 0 plates = analysis_group.plates # remove old metrics if present for plate in plates: pm = [pm for pm in plate.metrics if pm.reprocess_config_id == reprocess_config.id] # should only be of length 1, but just to be safe for p in pm: Session.delete(p) # TODO: how to make this whole operation transactional Session.commit() plate_ids = [plate.id for plate in plates] data_root = config['qlb.reprocess_root'] file_source = QLPReprocessedFileSource(data_root, reprocess_config) for id in plate_ids: dbplate = dbplate_tree(id) # TODO: right abstraction? plate_path = file_source.full_path(analysis_group, dbplate) print "Reading/updating metrics for %s" % plate_path qlplate = get_plate(plate_path) if not qlplate: print "Could not read plate: %s" % plate_path continue plate_metrics = get_beta_plate_metrics(dbplate, qlplate, reprocess_config) Session.add(plate_metrics) del qlplate Session.commit() return update_status
def command(self): from qtools.lib.mplot import plot_cluster_2d, cleanup as plt_cleanup app = self.load_wsgi_app() image_root = app.config['qlb.image_store'] image_source = QLBImageSource(image_root) # enforce config.ini if len(self.args) < 2: raise ValueError, self.__class_.usage analysis_group_id = int(self.args[0]) if len(self.args) == 3: reprocess_config = Session.query(ReprocessConfig).filter_by(code=self.args[1]).one() reprocess_config_id = reprocess_config.id else: reprocess_config = None reprocess_config_id = None if reprocess_config: data_root = app.config['qlb.reprocess_root'] storage = QLPReprocessedFileSource(data_root, reprocess_config) else: storage = QLStorageSource(app.config) analysis_group = Session.query(AnalysisGroup).get(analysis_group_id) if not analysis_group: raise ValueError, "No analysis group for id %s" % analysis_group_id plates = analysis_group.plates for plate in plates: # TODO: UGH THIS CODE INVARIANT SUCKS (should merge QLReprocessedFile/QLStorageSources) if reprocess_config: plate_path = storage.full_path(analysis_group, plate) else: plate_path = storage.plate_path(plate) print "Reading %s" % plate_path qlplate = get_plate(plate_path) if not qlplate: print "Could not read plate: %s" % plate.name continue print "Generating thumbnails for %s" % plate.name for name, qlwell in sorted(qlplate.analyzed_wells.items()): # TODO abstract into utility image generation function (thumbnail.py?) threshold_fallback = qlwell.clustering_method == QLWell.CLUSTERING_TYPE_THRESHOLD fig = plot_cluster_2d(qlwell.peaks, width=60, height=60, thresholds=[qlwell.channels[0].statistics.threshold, qlwell.channels[1].statistics.threshold], boundaries=[0,0,12000,24000], show_axes=False, antialiased=True, unclassified_alpha=0.5, use_manual_clusters=not well_channel_automatic_classification(qlwell), highlight_thresholds=threshold_fallback) image_path = image_source.get_path('%s/%s_2d.png' % (plate.qlbplate.id, name)) print image_path fig.savefig(image_path, format='png', dpi=72) plt_cleanup(fig)
def command(self): app = self.load_wsgi_app() # enforce config.ini if len(self.args) < 2: raise ValueError, self.__class__.usage analysis_group_id = int(self.args[0]) if len(self.args) == 3: reprocess_config = Session.query(ReprocessConfig).filter_by(code=self.args[1]).one() reprocess_config_id = reprocess_config.id else: reprocess_config = None reprocess_config_id = None analysis_group = Session.query(AnalysisGroup).get(analysis_group_id) if not analysis_group: raise ValueError, "No analysis group for id %s" % analysis_group_id plates = analysis_group.plates # todo: add in reprocess config id for plate in plates: pm = [pm for pm in plate.metrics if pm.reprocess_config_id == reprocess_config_id] # should only be of length 1, but just to be safe for p in pm: Session.delete(p) # TODO: how to make this whole operation transactional Session.commit() # this is a little tricky in the ORM world. only get the # ids of the analysis_group plates, so that you can load the plate # and all the necessary children plate_ids = [plate.id for plate in plates] if reprocess_config_id is None: storage = QLStorageSource(app.config) for id in plate_ids: dbplate = dbplate_tree(id) plate_path = storage.plate_path(dbplate) print "Reading/updating metrics for %s" % plate_path qlplate = get_plate(plate_path) if not qlplate: print "Could not read plate: %s" % plate_path continue plate_metrics = get_beta_plate_metrics(dbplate, qlplate) Session.add(plate_metrics) del qlplate else: data_root = app.config['qlb.reprocess_root'] file_source = QLPReprocessedFileSource(data_root, reprocess_config) for id in plate_ids: dbplate = dbplate_tree(id) # TODO: right abstraction? plate_path = file_source.full_path(analysis_group, dbplate) print "Reading/updating metrics for %s" % plate_path qlplate = get_plate(plate_path) if not qlplate: print "Could not read plate: %s" % plate_path continue plate_metrics = get_beta_plate_metrics(dbplate, qlplate, reprocess_config) Session.add(plate_metrics) del qlplate Session.commit()