Пример #1
0
 def __update_batch_plate_record(self, record):
     record.dg_method = self.form_result['dg_method']
     record.qc_plate = self.form_result['qc_plate'] and True or False
     record.plate_notes = self.form_result['plate_notes']
     record.thermal_cycler_id = self.form_result['thermal_cycler_id']
     Session.add(record)
     Session.commit()
Пример #2
0
    def command(self):
        app = self.load_wsgi_app()
        min_id = 0
        if len(self.args) > 1:
            min_id = self.args[0]
        storage = QLStorageSource(app.config)

        qlbplates = Session.query(QLBPlate).filter(QLBPlate.id > min_id).order_by('id').all()
        for qlbplate in qlbplates:
            try:
                path = storage.qlbplate_path(qlbplate)
            except Exception:
                print "Could not find plate: %s (%s)" % (qlbplate.plate.name if qlbplate.plate else 'Name unknown', qlbplate.id)
                continue
            try:
                qlplate = get_plate(path)
            except Exception:
                print "Could not read plate: %s (%s)" % (qlbplate.plate.name if qlbplate.plate else 'Name Unknown', qlbplate.id)
                continue

            if qlplate.is_fam_vic:
                qlbplate.dyeset = QLBPlate.DYESET_FAM_VIC
            elif qlplate.is_fam_hex:
                qlbplate.dyeset = QLBPlate.DYESET_FAM_HEX
            elif qlplate.is_eva_green:
                qlbplate.dyeset = QLBPlate.DYESET_EVA
            else:
                qlbplate.dyeset = QLBPlate.DYESET_UNKNOWN

            print "Assigned dye %s - %s (%s)" % (qlbplate.dyeset, qlbplate.plate.name if qlbplate.plate else 'Name Unknown', qlbplate.id)
            Session.commit()
Пример #3
0
 def tearDown(self):
     from qtools.model import Session
     Session.delete(self.testUser)
     Session.delete(self.testProject)
     Session.delete(self.readQLP)
     Session.delete(self.unreadQLP)
     Session.commit()
Пример #4
0
    def register_algorithm(self):
        storage = QSAlgorithmSource(config)
        existing_folders = [tup[0] for tup in Session.query(ReprocessConfig.original_folder).all()]

        errors = dict()
        src_dir = self.form_result['src_dir']
        if src_dir in existing_folders:
            errors['src_dir'] = 'This algorithm has already been registered.'

        elif not storage.source_path_exists(src_dir):
            errors['src_dir'] = 'This algorithm is not accessible in the file system.'

        if self.form_result['peak_detection_version'] == (0,0):
            # this is arbitrary
            peak_detection_version = (0, QUANTASOFT_DIR_VERSION_RE.search(src_dir).group(1).split('_')[-1])
        else:
            peak_detection_version = self.form_result['peak_detection_version']

        if self.form_result['peak_quantitation_version'] == (0,0):
            peak_quantitation_version = (0, QUANTASOFT_DIR_VERSION_RE.search(src_dir).group(1).split('_')[-1])
        else:
            peak_quantitation_version = self.form_result['peak_quantitation_version']

        if errors:
            resp = self._algorithms_base()
            defaults = AlgorithmRegisterForm.from_python(self.form_result)
            return h.render_bootstrap_form(resp,
                defaults=defaults,
                errors=errors,
                error_formatters=h.tw_bootstrap_error_formatters)

        try:
            rp = ReprocessConfig(name=src_dir.split(os.path.sep)[0],
                                 code=self.form_result['code'],
                                 peak_detection_major=peak_detection_version[0],
                                 peak_detection_minor=peak_detection_version[1],
                                 peak_quant_major=peak_quantitation_version[0],
                                 peak_quant_minor=peak_quantitation_version[1],
                                 trigger_fixed_width=100,
                                 active=True,
                                 cluster_mode=ReprocessConfig.CLUSTER_MODE_CLUSTER,
                                 original_folder=src_dir)

            storage.add_reprocessor(src_dir, self.form_result['code'])
            Session.add(rp)
            Session.commit()
            session['flash'] = 'New algorithm reprocessor created.'
            session.save()
            return redirect(url(controller='product', action='algorithms'))

        except shutil.Error:
            session['flash'] = 'Could not copy source algorithm to destination.'
            session['flash_class'] = 'error'
            session.save()
            return redirect(url(controller='product', action='algorithms'))
        except IOError:
            session['flash'] = "Could not access the algorithm's file system."
            session['flash_class'] = 'error'
            session.save()
            return redirect(url(controller='product', action='algorithms'))
Пример #5
0
    def command(self):
        app = self.load_wsgi_app()
        root = app.config['qlb.dg_root']
        top_folders = app.config['qlb.top_dg_folders']
        source = DGLogSource(root, top_folders)

        min_file_dict = dict(Session.query(DropletGeneratorRun.dirname,
                                      func.max(DropletGeneratorRun.basename).label('last_file')).\
                                group_by(DropletGeneratorRun.dirname).all())
        
        min_file_prefix = '2011-03-21'

        dgs = Session.query(DropletGenerator).all()
        dg_ids = [dg.id for dg in dgs]

        for dirname, basename in source.path_iter(min_file_name=min_file_prefix, min_file_dict=min_file_dict):
            print dirname, basename
            dg_run = read_dg_log(source.full_path(dirname, basename))
            if not dg_run:
                continue
            dg_run.dirname = dirname
            dg_run.basename = basename
            if dg_run.droplet_generator_id in dg_ids:
                Session.add(dg_run)
                Session.commit()
Пример #6
0
    def batch_plate_template_download(self, id=None):
        plate = self.__load_batch_plate(id)
        box2 = Session.query(Box2).get(self.form_result['box2_id'])
        if not plate or not box2:
            abort(404)
            
        code = plate.batch.plate_type.code

        if self.form_result['qc_plate']:
            plate.qc_plate = self.form_result['qc_plate']
            Session.commit()

        # TODO FIXFIX or incorporate into model
        if plate.qc_plate:
            serial = 'QC'
        else:
            serial = box2.name.split(' ')[-1]
        # only mfgco supported right now
        if code == 'mfgco':
            qlt_file = "%s/carryover.qlt" % config['qlb.setup_template_store']
        elif code == 'fvtitr':
            qlt_file = "%s/fvbatch_QC.qlt" % config['qlb.setup_template_store']
        else:
            abort(404)
        
        response.headers['Content-Type'] = 'application/quantalife-template'
        h.set_download_response_header(request, response, "%s_%s.qlt" % (serial, plate.name))
        response.headers['Pragma'] = 'no-cache'
        response.headers['Cache-Control'] = 'no-cache'
        return forward(FileApp(qlt_file, response.headerlist))
Пример #7
0
    def batch_plate_do_upload(self, id=None):
        batch_plate = self.__load_batch_plate(id)
        if not batch_plate:
            abort(404)
        box2 = self.form_result['box2']
        plate = self.form_result['plate']
        plate_type = batch_plate.batch.plate_type
        if plate_type.code == 'fvtitr' and len(plate.analyzed_wells) == 4:
            # if four wells, it's really a MFGCC (FVTITR FAM+/VIC+ should have 2)
            plate_type = Session.query(PlateType).filter_by(code='mfgcc').one()

        plateobj = save_plate_from_upload_request(request.POST['plate'], plate, box2, plate_type_obj=plate_type)

        # I want to put this in the form validator, but it's field dependent, so not right now
        if plate_type.code in ('mfgcc', 'bcc'):
            ok, message = validate_colorcomp_plate(plate)
            if not ok:
                response = self._batch_plate_upload_base(id)
                Session.rollback()
                return h.render_bootstrap_form(response, errors={'plate': message})
        
        Session.add(plateobj)
        if batch_plate.batch.plate_type.code == plate_type.code:
            batch_plate.plate = plateobj
        else:
            batch_plate.secondary_plate = plateobj

        batch_plate.qc_plate = self.form_result['qc_plate']
        batch_plate.plate_notes = self.form_result['plate_notes']
        Session.commit()

        session['flash'] = 'Plate linked.'
        session.save()
        return redirect(url(controller='metrics', action='per_plate', id=plateobj.id))
Пример #8
0
 def batch_csfv_unhook(self):
     plate = self.__load_batch_plate(self.form_result['batch_plate_id'])
     plate.plate_id = None
     Session.commit()
     session['flash'] = 'CSFV QC plate discarded.'
     session.save()
     return redirect(url(controller='product', action='batch_plates', id=plate.mfg_batch_id))
Пример #9
0
    def save(self, id=None):
        """
        """
        if id is None:
            abort(404)
        assay_q = Session.query(Assay)
        assay = assay_q.filter_by(id=id).first()
        if assay is None:
            abort(404)

        reload_sequences = False
        for k, v in self.form_result.items():
            if k in ("primer_fwd", "primer_rev", "chromosome", "probe_pos", "amplicon_width", "snp_rsid"):
                if getattr(assay, k) != v:
                    reload_sequences = True
            if k not in ("id"):
                setattr(assay, k, v)

        # blow away previous sequences; on view, this will update.
        if reload_sequences:
            cached_sequences = assay.cached_sequences
            for i in range(len(cached_sequences)):
                cs = cached_sequences[-1]
                snps = cs.snps
                for j in range(len(snps)):
                    snp = snps.pop()
                    Session.delete(snp)
                cached_sequences.pop()
                Session.delete(cs)

        self.__update_tms(assay)

        Session.commit()
        session.save()
        redirect(url(controller="assay", action="view", id=assay.id))
Пример #10
0
 def batch_delete(self, id=None):
     batch = self.__load_batch(id)
     if not batch:
         abort(404)
     
     # check for bound plates
     bound_plates = [p for p in batch.plates if p.plate_id is not None]
     if bound_plates:
         session['flash'] = "Cannot delete this batch; there are run plates bound to it."
         session['flash_class'] = 'error'
         session.save()
         return redirect(url(controller='product', action='batch_edit', id=id))
     else:
         try:
             for plate in batch.plates:
                 Session.delete(plate)
             batch.plates = []
             Session.delete(batch)
             Session.commit()
             session['flash'] = "Batch deleted."
             session.save()
         except Exception, e:
             logging.exception("Error from batch deletion:")
             session['flash'] = "Could not delete the batch from the database."
             session['flash_class'] = 'error'
             session.save()
             return redirect(url(controller='product', action='batch_edit', id=id))
         
         # redirect = Exception!  good to know-- don't put in try block...
         return redirect(url(controller='product', action='batch_list'))
Пример #11
0
 def sensitivity(self):
     enz = Session.query(Enzyme).get(self.form_result['enzyme'])
     if not self.form_result['sensitivity']:
         enz.methylation_sensitivity = None
     else:
         enz.methylation_sensitivity = self.form_result['sensitivity']
     Session.commit()
     return "OK"
Пример #12
0
 def instock(self):
     enz = Session.query(VendorEnzyme).get(self.form_result['vendor_enzyme_id'])
     if self.form_result['in_stock']:
         enz.stock_units = 1
     else:
         enz.stock_units = 0
     
     Session.commit()
     return 'OK'
Пример #13
0
    def enzyme_conc_create(self):
        conc = EnzymeConcentration()

        for k, v in self.form_result.items():
            setattr(conc, k, v)

        Session.add(conc)
        Session.commit()

        redirect(url(controller="assay", action="view", id=self.form_result["assay_id"]))
Пример #14
0
    def update_reader(self):
        log_entry = self.__make_box2_log_entry(self.form_result)
        Session.add(log_entry)
        Session.commit()

        box2 = Session.query(Box2).get(self.form_result['box2_id'])
        session['flash'] = 'Configuration for %s updated.' % box2.name
        session.save()

        redirect(url(controller='admin', action='reader_history', id=box2.code))
Пример #15
0
 def save_reagents(self, id=None):
     self.__load_context()
     setup, struct = self.__load_setup(id)
     if not setup:
         abort(404)
     
     for k, v in self.form_result.items():
         setattr(setup, k, v)
     Session.commit()
     redirect(url(controller='setup', action='dg', id=id, beta=c.beta))
Пример #16
0
    def upload_file(self, id=None):
        self.__setup_box2_code_context(id)
        source = QLStorageSource(config)
        basename = upload_basename(self.form_result['file'].filename)
        errors = {}

        existing_path = self.__file_name_query(c.box2.id, basename)
        if existing_path and not self.form_result['file_id'] == existing_path.id:
            # todo, if existing update path
            errors = dict(file='File with this name already exists for this reader.  Use the Update page.')

        path = "%s_%s" % (int(round(time.time())), basename)
        thefile = self.form_result['file'].file

        filerec = self.__file_id_query(c.box2.id, self.form_result['file_id'])
        new_record = False
        if not filerec:
            filerec = Box2File(box2_id=c.box2.id)
            new_record = True

        filerec.name = basename
        filerec.deleted = False
        filerec.path = path
        filerec.updated = datetime.datetime.now()
        filerec.description = self.form_result['description']
        filerec.mime_type = guess_type(basename)[0] or 'text/plain'


        if errors:
            response = self._upload_base(id)
            return h.render_bootstrap_form(response, errors=errors, error_formatters=h.tw_bootstrap_error_formatters)

        try:
            attachment_dir = self.__upload_file_dir(c.box2)
            if not os.path.exists(attachment_dir):
                os.mkdir(attachment_dir)

            permanent_path = self.__upload_file_path(c.box2, path)
            permanent_file = open(permanent_path, 'wb')
            shutil.copyfileobj(thefile, permanent_file)
            thefile.close()
            permanent_file.close()

            filerec.size = os.stat(permanent_path).st_size
            if new_record:
                Session.add(filerec)
            else:
                Session.merge(filerec)
            Session.commit()
            session['flash'] = 'File uploaded.'
            write_success = True
        except Exception, e:
            session['flash'] = 'Could not upload file: %s' % str(e)
            session['flash_class'] = 'error'
            write_success = False
Пример #17
0
 def donotrun(self, id=None):
     c.beta = True
     setup, struct = self.__load_setup(id)
     if not setup:
         abort(404)
     
     setup.donotrun = True
     Session.commit()
     session['flash'] = "Marked %s as skipped." % setup.name
     session.save()
     redirect(url(controller='setup', action='list', beta=c.beta))
Пример #18
0
 def __save_setup(self, setup, key, block):
     setup_obj = json.loads(setup.setup or '{}')
     # Hack.
     if type(block) == type(dict()) and block.get('notes', None) is not None:
         notes = block.pop('notes')
         setup.notes = notes
     setup_obj[key] = block
     setup.setup = json.dumps(setup_obj)
     if key == 'progress':
         setup.completed = (self.__check_progress(setup_obj) == 'Done')
     Session.commit()
Пример #19
0
    def create(self):
        self.__load_context()
        plate_setup = PlateSetup()
        plate_setup.project_id = self.form_result['project_id']
        plate_setup.author_id = self.form_result['author_id']
        plate_setup.name = self.form_result['name']
        plate_setup.prefix = make_setup_name(plate_setup)

        Session.add(plate_setup)
        Session.commit()
        redirect(url(controller='setup', action='consumable', id=plate_setup.id, beta=c.beta))
Пример #20
0
    def delete_file(self, id=None):
        self.__setup_box2_code_context(id)
        thefile = self.__file_id_query(c.box2.id, self.form_result['file_id'])
        if not thefile:
            abort(404)

        Session.delete(thefile)
        Session.commit()
        session['flash'] = 'File deleted.'
        session.save()
        return redirect(url(controller='metrics', action='certification', id=c.box2.code))
Пример #21
0
 def update(self, id=None):
     batch = self.__batch(id)
     batch.manufacturer = self.form_result["manufacturer"]
     batch.insert = self.form_result["insert"]
     batch.consumable_molding_style_id = self.form_result["molding_style"]
     batch.consumable_bonding_style_id = self.form_result["bonding_style"]
     batch.manufacturing_date = self.form_result["manufacture_date"]
     batch.bside = self.form_result["bside"]
     Session.commit()
     session.flash = "Updated batch %s" % batch.lot_num
     return redirect(url(controller="consumable", action="details", id=batch.id))
Пример #22
0
 def save_name(self, id=None):
     self.__load_context()
     setup, struct = self.__load_setup(id)
     if not setup:
         abort(404)
     
     for k, v in self.form_result.items():
         setattr(setup, k, v)
     setup.prefix = make_setup_name(setup)
     
     Session.commit()
     redirect(url(controller='setup', action='consumable', id=id, beta=c.beta))
Пример #23
0
 def command(self):
     self.load_wsgi_app()
     
     unknown_plates = Session.query(QLBPlate).filter(QLBPlate.plate == None)
     for qlbplate in unknown_plates:
         try:
             plate = plate_from_qlp(qlbplate)
             Session.add(plate)
             qlbplate.plate = plate
             Session.commit()
         except Exception:
             Session.rollback()
Пример #24
0
 def tearDown(self):
     Session.rollback() # catches pending changes
     Session.delete(self.plateTemplate)
     Session.delete(self.shortTemplate)
     Session.delete(self.qlbPlate)
     Session.delete(self.plateVariant)
     Session.delete(self.unknownPlate)
     Session.delete(self.nameVariant)
     Session.delete(self.unknownName)
     Session.commit()
     
     super(TestNamePlate, self).tearDown()
Пример #25
0
    def update_size(self, id=None):
        batch = self.__batch(id)
        if not batch:
            abort(404)

        batch_test = self.__batch_test(id)
        if not batch_test:
            batch_test = ConsumableBatchTest(consumable_batch_id=batch.id)
            Session.add(batch_test)

        batch_test.pixel_calibration = self.form_result["pixel_calibration"]

        garbage = []
        # check for cleared entities first
        for chan in batch_test.size_channels:
            thechip = [chip for chip in self.form_result["chips"] if chip["chip_num"] == chan.chip_num]
            if not thechip:
                garbage.append(chan)
                continue

            thechan = [c for c in thechip[0]["channels"] if c["channel_num"] == chan.channel_num]
            if not thechan:
                garbage.append(chan)
                continue

            if thechan[0]["droplet_count"] is None and thechan[0]["mean"] is None and thechan[0]["stdev"] is None:
                garbage.append(chan)

        for g in garbage:
            batch_test.size_channels.remove(g)
            Session.delete(g)

        # This is the case for a GAE-like Entity or a Mongo object or storing
        # JSON in a text column or whatever
        for chip in self.form_result["chips"]:
            for channel in chip["channels"]:
                if channel["droplet_count"] is not None or channel["mean"] is not None or channel["stdev"] is not None:
                    dbchan = batch_test.size_channel(chip["chip_num"], channel["channel_num"])
                    if not dbchan:
                        dbchan = ConsumableBatchSizeChannel(
                            chip_num=chip["chip_num"], channel_num=channel["channel_num"]
                        )
                        batch_test.size_channels.append(dbchan)

                    dbchan.size_mean = channel["mean"]
                    dbchan.size_stdev = channel["stdev"]
                    dbchan.droplet_count = channel["droplet_count"]

        Session.commit()
        session["flash"] = "Sizes updated."
        session.save()

        return redirect(url(controller="consumable", action="size", id=batch.id))
Пример #26
0
 def command(self):
     self.load_wsgi_app()
     
     qlbplates = Session.query(QLBPlate).\
                      filter(and_(QLBPlate.file_id != None, QLBPlate.plate_id != None)).\
                      order_by(desc(QLBPlate.id)).\
                      options(joinedload_all(QLBPlate.plate, innerjoin=True))
     
     for qlbplate in qlbplates:
         qlbplate.plate.score = Plate.compute_score(qlbplate.plate)
         print "%s: %s points" % (qlbplate.plate.id, qlbplate.plate.score)
         Session.commit()
Пример #27
0
    def enzyme_conc_delete(self, id=None):
        if id is None:
            abort(404)

        conc = Session.query(EnzymeConcentration).get(id)
        if not conc:
            abort(404)

        assay_id = conc.assay_id
        Session.delete(conc)
        Session.commit()

        redirect(url(controller="assay", action="view", id=assay_id))
Пример #28
0
    def unreject(self, id=None):
        if id is None:
            abort(404)

        assay = Session.query(Assay).get(id)
        if not assay:
            abort(404)

        assay.rejected = False
        Session.commit()
        session["flash"] = "Assay marked as valid."
        session.save()
        redirect(url(controller="assay", action="view", id=id))
Пример #29
0
 def save_cycler(self, id=None):
     self.__load_context()
     setup, struct = self.__load_setup(id)
     if not setup:
         abort(404)
     
     for k, v in self.form_result.items():
         setattr(setup, k, v)
     Session.commit()
     if c.beta:
         redirect(url(controller='setup', action='plan', id=id, beta=c.beta))
     else:
         redirect(url(controller='setup', action='reader', id=id, beta=c.beta))
Пример #30
0
 def delete(self, id=None):
     """
     """
     if id is None:
         abort(404)
     assay_q = Session.query(Assay)
     assay = assay_q.filter_by(id=id).first()
     if assay:
         Session.delete(assay)
     Session.commit()
     session["flash"] = "Assay deleted."
     session.save()
     redirect(url(controller="assay", action="list"))