def command(self): app = self.load_wsgi_app() storage = QLStorageSource(app.config) if len(self.args) < 2: print self.__class__.usage return for i in range(0,len(self.args)-1): plate_id = int(self.args[i]) plate = dbplate_tree(plate_id) try: plate_path = storage.plate_path(plate) except Exception, e: print "Could not read plate: %s" % plate_id continue qlplate = get_plate(plate_path) if not qlplate: raise ValueError, "Could not read plate: %s" % plate_path else: print "Processing %s" % plate_path try: from qtools.lib.metrics import DEFAULT_CNV_CALC, compute_metric_foreach_qlwell plate_metrics = plate.metrics[0] compute_metric_foreach_qlwell(qlplate, plate_metrics, DEFAULT_CNV_CALC) except Exception, e: import sys, traceback traceback.print_exc(file=sys.stdout) Session.rollback() return
def command(self): app = self.load_wsgi_app() # enforce config.ini if len(self.args) < 2: raise ValueError, self.__class__.usage plate_id = int(self.args[0]) plate = dbplate_tree(plate_id) if not plate: raise ValueError, "Invalid plate id: %s" % plate_id storage = QLStorageSource(app.config) # for now, no reprocessing. plate_path = storage.plate_path(plate) qlplate = get_plate(plate_path) if not qlplate: raise ValueError, "Could not read plate: %s" % plate_path try: plate_metrics = plate.metrics[0] self.process_plate( qlplate, plate_metrics) except Exception, e: import sys, traceback traceback.print_exc(file=sys.stdout) Session.rollback() return
def from_plate(self, id=None): if not id: abort(404) plate = Session.query(Plate).get(id) if not plate: abort(404) # ignore possibility of reprocess config for now storage = QLStorageSource(config) path = storage.plate_path(plate) factory = ExperimentMetadataObjectFactory() qlp = factory.parse_plate(path) c.wells = qlp.analyzed_wells c.original_source = plate.name c.plate_template_id = None c.plate_setup_id = None c.id = id return self.__display(rowcol_order=qlp.acquisition_order)
def process_plates(self, app, analysis_group, reprocess_config): storage = QLStorageSource(app.config) plates = analysis_group.plates for plate in plates: pms = [pm for pm in plate.metrics if pm.reprocess_config_id == reprocess_config.id] if not pms: print "Cannot find analysis group for plate %s" % plate.id else: pm = pms[0] dbplate = dbplate_tree(plate.id) if reprocess_config: data_root = app.config['qlb.reprocess_root'] storage = QLPReprocessedFileSource(data_root, reprocess_config) else: storage = QLStorageSource(app.config) try: if reprocess_config: plate_path = storage.full_path(analysis_group, dbplate) else: plate_path = storage.plate_path(dbplate) except Exception, e: print "Could not read plate: %s" % plate.id continue qlplate = get_plate(plate_path) if not qlplate: raise ValueError, "Could not read plate: %s" % plate_path else: print "Processing %s" % plate_path try: self.backfill_plate(qlplate, pm) Session.commit() except Exception, e: print "Could not process plate %s" % dbplate.id import sys, traceback traceback.print_exc(file=sys.stdout) Session.rollback() continue
def command(self): app = self.load_wsgi_app() storage = QLStorageSource(app.config) # enforce config.ini if len(self.args) > 1: plate_id = int(self.args[0]) else: plate_id = 1 ## default start.... plate_metrics = Session.query(PlateMetric).filter(PlateMetric.plate_id >= plate_id)\ .options(joinedload(PlateMetric.plate, innerjoin=True))\ .options(joinedload(PlateMetric.reprocess_config)) # TODO come up with version that takes care of reprocessed plates as well # (by iterating through analysis groups, most likely) for pm in plate_metrics: if pm.from_reprocessed: continue plate = dbplate_tree(pm.plate_id) try: plate_path = storage.plate_path(plate) except Exception: print "Could not read plate: %s" % pm.plate_id continue try: qlplate = get_plate(plate_path) except Exception: print "Could not read plate: %s" % plate_path continue if not qlplate: print "Could not read plate: %s" % plate_path continue else: print "Processing %s: %s..." % (pm.plate_id, plate_path) self.process_plate(qlplate, pm)
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()