def validate(self): err = [] ## barcodedSamples from eas / barcodeSampleInfo from plan if self.barcodedSamples is None: return True for sample in self.barcodedSamples: err.extend(plan_validator.validate_sample_name(sample)) if err: raise ValidationError(err) return True
def _validate_sample(input, selectedTemplate, planObj): """ validate sample name with leading/trailing blanks in the input ignored """ errorMsg = None sampleDisplayedName = "" if not input: errorMsg = "Required column is empty" else: errors = validate_sample_name(input) if errors: errorMsg = ' '.join(errors) else: sampleDisplayedName = input.strip() return errorMsg, sampleDisplayedName
def validateStep(self): any_samples = False self.validationErrors[SavePlanFieldNames.BAD_SAMPLE_NAME] = [] self.validationErrors[SavePlanFieldNames.BAD_SAMPLE_EXTERNAL_ID] = [] self.validationErrors[SavePlanFieldNames.BAD_SAMPLE_DESCRIPTION] = [] self.validationErrors[SavePlanFieldNames.BAD_TUBE_LABEL] = [] self.validationErrors[SavePlanFieldNames.BAD_CHIP_BARCODE] = [] self.validationErrors[SavePlanFieldNames.BAD_IR_SET_ID] = [] self.validationErrors.pop(SavePlanFieldNames.NO_BARCODE, None) self.validationErrors.pop(SavePlanFieldNames.BAD_BARCODES, None) barcodeSet = self.savedFields[SavePlanFieldNames.BARCODE_SET] selectedBarcodes = [] endBarcodeSet = self.savedFields[SavePlanFieldNames.END_BARCODE_SET] selectedEndBarcodes = [] samplesTable = json.loads(self.savedFields[SavePlanFieldNames.SAMPLES_TABLE]) # logger.debug("save_plan_step_data - anySamples? samplesTable=%s" %(samplesTable)) for row in samplesTable: sample_name = row.get(SavePlanFieldNames.SAMPLE_NAME, '').strip() # logger.debug("save_plan_step_data - anySamples? sampleName=%s" %(sample_name)) if sample_name: any_samples = True if validate_sample_name(sample_name): self.validationErrors[SavePlanFieldNames.BAD_SAMPLE_NAME].append(sample_name) external_id = row.get(SavePlanFieldNames.SAMPLE_EXTERNAL_ID, '') if external_id: self.validate_field(external_id, self.validationErrors[SavePlanFieldNames.BAD_SAMPLE_EXTERNAL_ID]) description = row.get(SavePlanFieldNames.SAMPLE_DESCRIPTION, '') if description: self.validate_field(description, self.validationErrors[SavePlanFieldNames.BAD_SAMPLE_DESCRIPTION], False, MAX_LENGTH_SAMPLE_DESCRIPTION) ir_set_id = row.get('irSetId', '') if ir_set_id and not (str(ir_set_id).isdigit()): self.validationErrors[SavePlanFieldNames.BAD_IR_SET_ID].append(ir_set_id) tube_label = row.get('tubeLabel', '') if validate_sample_tube_label(tube_label): self.validationErrors[SavePlanFieldNames.BAD_TUBE_LABEL].append(tube_label) chip_barcode = row.get('chipBarcode', '') if validate_chipBarcode(chip_barcode): self.validationErrors[SavePlanFieldNames.BAD_CHIP_BARCODE].append(chip_barcode) if barcodeSet: selectedBarcodes.append(row.get(SavePlanFieldNames.BARCODE_SAMPLE_BARCODE_ID_UI_KEY)) if endBarcodeSet: endBarcode_id_value = row.get(SavePlanFieldNames.BARCODE_SAMPLE_END_BARCODE_ID_UI_KEY) if endBarcode_id_value: selectedEndBarcodes.append(endBarcode_id_value) if any_samples: self.validationErrors.pop(SavePlanFieldNames.NO_SAMPLES, None) else: self.validationErrors[SavePlanFieldNames.NO_SAMPLES] = "You must enter at least one sample" if not self.validationErrors[SavePlanFieldNames.BAD_SAMPLE_NAME]: self.validationErrors.pop(SavePlanFieldNames.BAD_SAMPLE_NAME, None) if not self.validationErrors[SavePlanFieldNames.BAD_TUBE_LABEL]: self.validationErrors.pop(SavePlanFieldNames.BAD_TUBE_LABEL, None) if not self.validationErrors[SavePlanFieldNames.BAD_CHIP_BARCODE]: self.validationErrors.pop(SavePlanFieldNames.BAD_CHIP_BARCODE, None) if not self.validationErrors[SavePlanFieldNames.BAD_SAMPLE_EXTERNAL_ID]: self.validationErrors.pop(SavePlanFieldNames.BAD_SAMPLE_EXTERNAL_ID, None) if not self.validationErrors[SavePlanFieldNames.BAD_SAMPLE_DESCRIPTION]: self.validationErrors.pop(SavePlanFieldNames.BAD_SAMPLE_DESCRIPTION, None) if not self.validationErrors[SavePlanFieldNames.BAD_IR_SET_ID]: self.validationErrors.pop(SavePlanFieldNames.BAD_IR_SET_ID, None) #20170928-TODO-WIP if barcodeSet: errors = validate_barcode_sample_association(selectedBarcodes, barcodeSet) myErrors = convert(errors) if myErrors.get("MISSING_BARCODE", ""): self.validationErrors[SavePlanFieldNames.NO_BARCODE] = myErrors.get("MISSING_BARCODE", "") if myErrors.get("DUPLICATE_BARCODE", ""): self.validationErrors[SavePlanFieldNames.BAD_BARCODES] = myErrors.get("DUPLICATE_BARCODE", "") if selectedEndBarcodes: applProduct = self.savedObjects[SavePlanFieldNames.APPL_PRODUCT] if applProduct and applProduct.dualBarcodingRule == "no_reuse": errors = validate_barcode_sample_association(selectedEndBarcodes, endBarcodeSet, isEndBarcodeExists = True) myErrors = convert(errors) if myErrors.get("DUPLICATE_BARCODE", ""): self.validationErrors[SavePlanFieldNames.BAD_BARCODES] = myErrors.get("DUPLICATE_BARCODE", "")
def validateStep(self): any_samples = False self.validationErrors[SavePlanFieldNames.BAD_SAMPLE_NAME] = [] self.validationErrors[SavePlanFieldNames.BAD_SAMPLE_EXTERNAL_ID] = [] self.validationErrors[SavePlanFieldNames.BAD_SAMPLE_DESCRIPTION] = [] self.validationErrors[SavePlanFieldNames.BAD_TUBE_LABEL] = [] self.validationErrors[SavePlanFieldNames.BAD_IR_SET_ID] = [] self.validationErrors.pop(SavePlanFieldNames.NO_BARCODE, None) self.validationErrors.pop(SavePlanFieldNames.BAD_BARCODES, None) barcodeSet = self.savedFields[SavePlanFieldNames.BARCODE_SET] selectedBarcodes = [] samplesTable = json.loads(self.savedFields[SavePlanFieldNames.SAMPLES_TABLE]) # logger.debug("save_plan_step_data - anySamples? samplesTable=%s" %(samplesTable)) for row in samplesTable: sample_name = row.get(SavePlanFieldNames.SAMPLE_NAME, "").strip() # logger.debug("save_plan_step_data - anySamples? sampleName=%s" %(sample_name)) if sample_name: any_samples = True if validate_sample_name(sample_name): self.validationErrors[SavePlanFieldNames.BAD_SAMPLE_NAME].append(sample_name) external_id = row.get(SavePlanFieldNames.SAMPLE_EXTERNAL_ID, "") if external_id: self.validate_field(external_id, self.validationErrors[SavePlanFieldNames.BAD_SAMPLE_EXTERNAL_ID]) description = row.get(SavePlanFieldNames.SAMPLE_DESCRIPTION, "") if description: self.validate_field( description, self.validationErrors[SavePlanFieldNames.BAD_SAMPLE_DESCRIPTION], False, MAX_LENGTH_SAMPLE_DESCRIPTION, ) ir_set_id = row.get("irSetId", "") if ir_set_id and not (str(ir_set_id).isdigit()): self.validationErrors[SavePlanFieldNames.BAD_IR_SET_ID].append(ir_set_id) tube_label = row.get("tubeLabel", "") if validate_sample_tube_label(tube_label): self.validationErrors[SavePlanFieldNames.BAD_TUBE_LABEL].append(tube_label) if barcodeSet: selectedBarcodes.append(row.get("barcodeId")) if any_samples: self.validationErrors.pop(SavePlanFieldNames.NO_SAMPLES, None) else: self.validationErrors[SavePlanFieldNames.NO_SAMPLES] = "You must enter at least one sample" if not self.validationErrors[SavePlanFieldNames.BAD_SAMPLE_NAME]: self.validationErrors.pop(SavePlanFieldNames.BAD_SAMPLE_NAME, None) if not self.validationErrors[SavePlanFieldNames.BAD_TUBE_LABEL]: self.validationErrors.pop(SavePlanFieldNames.BAD_TUBE_LABEL, None) if not self.validationErrors[SavePlanFieldNames.BAD_SAMPLE_EXTERNAL_ID]: self.validationErrors.pop(SavePlanFieldNames.BAD_SAMPLE_EXTERNAL_ID, None) if not self.validationErrors[SavePlanFieldNames.BAD_SAMPLE_DESCRIPTION]: self.validationErrors.pop(SavePlanFieldNames.BAD_SAMPLE_DESCRIPTION, None) if not self.validationErrors[SavePlanFieldNames.BAD_IR_SET_ID]: self.validationErrors.pop(SavePlanFieldNames.BAD_IR_SET_ID, None) if barcodeSet: errors = validate_barcode_sample_association(selectedBarcodes, barcodeSet) myErrors = convert(errors) if myErrors.get("MISSING_BARCODE", ""): self.validationErrors[SavePlanFieldNames.NO_BARCODE] = myErrors.get("MISSING_BARCODE", "") if myErrors.get("DUPLICATE_BARCODE", ""): self.validationErrors[SavePlanFieldNames.BAD_BARCODES] = myErrors.get("DUPLICATE_BARCODE", "")
def validateStep(self): any_samples = False self.validationErrors[SavePlanFieldNames.BAD_SAMPLE_NAME] = [] self.validationErrors[SavePlanFieldNames.BAD_SAMPLE_EXTERNAL_ID] = [] self.validationErrors[SavePlanFieldNames.BAD_SAMPLE_DESCRIPTION] = [] self.validationErrors[SavePlanFieldNames.BAD_TUBE_LABEL] = [] self.validationErrors[SavePlanFieldNames.BAD_IR_SET_ID] = [] self.validationErrors.pop(SavePlanFieldNames.NO_BARCODE, None) self.validationErrors.pop(SavePlanFieldNames.BAD_BARCODES, None) barcodeSet = self.savedFields[SavePlanFieldNames.BARCODE_SET] selectedBarcodes = [] samplesTable = json.loads( self.savedFields[SavePlanFieldNames.SAMPLES_TABLE]) #logger.debug("save_plan_step_data - anySamples? samplesTable=%s" %(samplesTable)) for row in samplesTable: sample_name = row.get(SavePlanFieldNames.SAMPLE_NAME, '').strip() #logger.debug("save_plan_step_data - anySamples? sampleName=%s" %(sample_name)) if sample_name: any_samples = True if validate_sample_name(sample_name): self.validationErrors[ SavePlanFieldNames.BAD_SAMPLE_NAME].append(sample_name) external_id = row.get(SavePlanFieldNames.SAMPLE_EXTERNAL_ID, '') if external_id: self.validate_field( external_id, self.validationErrors[ SavePlanFieldNames.BAD_SAMPLE_EXTERNAL_ID]) description = row.get(SavePlanFieldNames.SAMPLE_DESCRIPTION, '') if description: self.validate_field( description, self.validationErrors[ SavePlanFieldNames.BAD_SAMPLE_DESCRIPTION], False, MAX_LENGTH_SAMPLE_DESCRIPTION) ir_set_id = row.get('irSetId', '') if ir_set_id and not (str(ir_set_id).isdigit()): self.validationErrors[ SavePlanFieldNames.BAD_IR_SET_ID].append(ir_set_id) tube_label = row.get('tubeLabel', '') if validate_sample_tube_label(tube_label): self.validationErrors[ SavePlanFieldNames.BAD_TUBE_LABEL].append(tube_label) if barcodeSet: selectedBarcodes.append(row.get('barcodeId')) if any_samples: self.validationErrors.pop(SavePlanFieldNames.NO_SAMPLES, None) else: self.validationErrors[ SavePlanFieldNames. NO_SAMPLES] = "You must enter at least one sample" if not self.validationErrors[SavePlanFieldNames.BAD_SAMPLE_NAME]: self.validationErrors.pop(SavePlanFieldNames.BAD_SAMPLE_NAME, None) if not self.validationErrors[SavePlanFieldNames.BAD_TUBE_LABEL]: self.validationErrors.pop(SavePlanFieldNames.BAD_TUBE_LABEL, None) if not self.validationErrors[ SavePlanFieldNames.BAD_SAMPLE_EXTERNAL_ID]: self.validationErrors.pop( SavePlanFieldNames.BAD_SAMPLE_EXTERNAL_ID, None) if not self.validationErrors[ SavePlanFieldNames.BAD_SAMPLE_DESCRIPTION]: self.validationErrors.pop( SavePlanFieldNames.BAD_SAMPLE_DESCRIPTION, None) if not self.validationErrors[SavePlanFieldNames.BAD_IR_SET_ID]: self.validationErrors.pop(SavePlanFieldNames.BAD_IR_SET_ID, None) if barcodeSet: errors = validate_barcode_sample_association( selectedBarcodes, barcodeSet) myErrors = convert(errors) if myErrors.get("MISSING_BARCODE", ""): self.validationErrors[ SavePlanFieldNames.NO_BARCODE] = myErrors.get( "MISSING_BARCODE", "") if myErrors.get("DUPLICATE_BARCODE", ""): self.validationErrors[ SavePlanFieldNames.BAD_BARCODES] = myErrors.get( "DUPLICATE_BARCODE", "")