def command(self): app = self.load_wsgi_app() print "Clearing NEB buffer tables..." # make this reversible... neb = Session.query(Vendor).filter_by(name='NEB').first() if neb: enzymes = neb.enzymes for enz in enzymes: Session.delete(enz) neb.enzymes = [] Session.commit() # now go with the vendors (question: is it vendor enzyme or enzyme # in general subject to methylation) source = NEBEnzymeSource() if not neb: neb = Vendor(name="NEB", website="http://www.neb.com") Session.add(neb) Session.commit() try: for name, page_uri in source.iter_restriction_enzymes(): print "Processing %s..." % name enz = Session.query(Enzyme).filter_by(name=name).first() if not enz: enz = Enzyme(name=name) Session.add(enz) details = source.enzyme_details(name, page_uri) if details: enz.cutseq = details['sequence'] enz.methylation = details['methylation_sensitivity'] buf = Session.query(Buffer).filter_by(name=details['buffer']).first() if not buf: buf = Buffer(name=details['buffer']) Session.add(buf) ve = VendorEnzyme(enzyme=enz, vendor=neb, buffer=buf) ve.unit_cost_1 = details.get('unit_cost_1', None) ve.unit_cost_2 = details.get('unit_cost_2', None) ve.unit_serial_1 = details.get('unit_serial_1', None) ve.unit_serial_2 = details.get('unit_serial_2', None) ve.vendor_serial = details.get('vendor_serial', None) if ve.unit_cost_1 is not None: Session.add(ve) # save per enzyme, interruption should be logged Session.commit() except IOError, e: Session.rollback() print "Could not communicate with NEB server"
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): 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()