Exemplo n.º 1
0
def validate_sampleSet_values(sampleSetName, sampleSetDesc, isNew = False):
    """ 
    validate the sampleSet input. 
    returns a boolean isValid and a text string for error message, None if input passes validation
    Note: Input length willl not be validated since maxLength has been specified in the form.
    """
    
    isValid = False
    if not validation.has_value(sampleSetName):
        return isValid, validation.required_error("Error, Sample set name")
    else:        
        if not validation.is_valid_chars(sampleSetName):
            return isValid, validation.invalid_chars_error("Error, Sample set name")
        
        if not validation.is_valid_length(sampleSetName, MAX_LENGTH_SAMPLE_SET_DISPLAYED_NAME):
            errorMessage = validation.invalid_length_error("Error, Sample set name", MAX_LENGTH_SAMPLE_SET_DISPLAYED_NAME) + ". It is currently %s characters long." % str(len(sampleSetName.strip()))
            return isValid, errorMessage

        if isNew:
            #error if new sample set already exists
            existingSampleSets = SampleSet.objects.filter(displayedName = sampleSetName)
            if existingSampleSets:
                errorMessage = "Error, Sample set %s already exists." % (sampleSetName)           
                return isValid, errorMessage
    
    if validation.has_value(sampleSetDesc):
        if not validation.is_valid_chars(sampleSetDesc):
            return isValid, validation.invalid_chars_error("Error, Sample set description")
        
        if not validation.is_valid_length(sampleSetDesc, MAX_LENGTH_SAMPLE_SET_DESCRIPTION):
            errorMessage = validation.invalid_length_error("Error, Sample set description", MAX_LENGTH_SAMPLE_SET_DESCRIPTION) + ". It is currently %s characters long." % str(len(sampleSetDesc.strip()))
            return isValid, errorMessage

    isValid = True
    return isValid, None
Exemplo n.º 2
0
    def validateField(self, field_name, new_field_value):
        '''
        Flows qc value must be a positive integer
        Chip type is required
        '''
        if field_name == KitsFieldNames.FLOWS:
            errors = validate_flows(new_field_value)
            if errors:
                self.validationErrors[field_name] = ' '.join(errors)
            else:
                self.validationErrors.pop(field_name, None)

        if field_name == KitsFieldNames.CHIP_TYPE and self.prepopulatedFields.get(
                'is_chipType_required', True):
            if validation.has_value(new_field_value):
                self.validationErrors.pop(field_name, None)
            else:
                self.validationErrors[field_name] = validation.required_error(
                    "Chip Type")

        if field_name == KitsFieldNames.TEMPLATE_KIT_NAME:
            if validation.has_value(new_field_value):
                self.validationErrors.pop(field_name, None)
            else:
                self.validationErrors[field_name] = validation.required_error(
                    "Template Kit")
Exemplo n.º 3
0
    def validateField(self, field_name, new_field_value):
        """
        Flows qc value must be a positive integer
        Chip type is required
        """

        if field_name == KitsFieldNames.FLOWS:
            errors = validate_flows(
                new_field_value,
                field_label=_("workflow.step.kits.fields.flows.label"))
            if errors:
                self.validationErrors[field_name] = " ".join(errors)
            else:
                self.validationErrors.pop(field_name, None)

        if field_name == KitsFieldNames.CHIP_TYPE and self.prepopulatedFields.get(
                "is_chipType_required", True):
            if validation.has_value(new_field_value):
                self.validationErrors.pop(field_name, None)
            else:
                self.validationErrors[field_name] = validation.required_error(
                    _("workflow.step.kits.fields.chipType.label")
                )  # "Chip Type"

        if field_name == KitsFieldNames.TEMPLATE_KIT_NAME:
            if validation.has_value(new_field_value):
                self.validationErrors.pop(field_name, None)
            else:
                self.validationErrors[field_name] = validation.required_error(
                    _("workflow.step.kits.fields.templatekitname.label")
                )  # "Template Kit"

        if field_name == KitsFieldNames.LIBRARY_READ_LENGTH:
            errors = validate_libraryReadLength(
                new_field_value,
                field_label=_(
                    "workflow.step.kits.fields.libraryReadLength.label"),
            )
            if errors:
                self.validationErrors[field_name] = " ".join(errors)
            else:
                self.validationErrors.pop(field_name, None)

        if field_name == KitsFieldNames.READ_LENGTH:
            if new_field_value:
                errors = validate_libraryReadLength(
                    new_field_value,
                    field_label=_(
                        "workflow.step.kits.fields.readLength.label"),
                )
                if errors:
                    self.validationErrors[field_name] = " ".join(errors)
                else:
                    self.validationErrors.pop(field_name, None)
                    self.savedFields[
                        KitsFieldNames.LIBRARY_READ_LENGTH] = new_field_value
Exemplo n.º 4
0
def validate_targetRegionBedFile_for_runType(value, runType, reference, nucleotideType=None, applicationGroupName=None, displayedName="Target Regions BED File", isPrimaryTargetRegion = True):
    """
    validate targetRegionBedFile based on the selected reference and the plan's runType
    """
    errors = []
    value = value.strip() if value else ""
    if value:
        missing_file = check_uploaded_files(bedfilePaths=[value])
        if missing_file:
            errors.append("%s : %s not found" % (displayedName, value))
            logger.debug("plan_validator.validate_targetRegionBedFile_for_run() SKIPS validation due to no targetRegion file exists in db. value=%s" % (value))
        return errors

    logger.debug("plan_validator.validate_targetRegionBedFile_for_runType() value=%s; runType=%s; reference=%s; nucleotideType=%s; applicationGroupName=%s" % (value, runType, reference, nucleotideType, applicationGroupName))

    if not isPrimaryTargetRegion:
        logger.debug("plan_validator.validate_targetRegionBedFile_for_run() SKIPS validation due to no validation rules for non-primary targetRegion. value=%s" %(value))
        return errors

    if reference:
        if runType:
            runType = runType.strip()
            applProducts = ApplProduct.objects.filter(isActive=True, applType__runType=runType, applicationGroup__name=applicationGroupName) \
                or ApplProduct.objects.filter(isActive=True, applType__runType=runType)
            if applProducts:
                applProduct = applProducts[0]
                if applProduct:
                    if validation.has_value(value) and not applProduct.isTargetRegionBEDFileSupported:
                        errors.append(displayedName+" selection is not supported for this Application")
                    else:
                        isRequired = applProduct.isTargetRegionBEDFileSelectionRequiredForRefSelection
                        if isRequired and not validation.has_value(value):
                            # skip for now
                            if runType in ["AMPS_DNA_RNA","AMPS_HD_DNA_RNA"] and nucleotideType and nucleotideType.upper() == "RNA":
                                logger.debug("plan_validator.validate_targetRegionBedFile_for_runType() ALLOW MISSING targetRegionBed for runType=%s; nucleotideType=%s" % (runType, nucleotideType))
                            elif runType in ["AMPS_RNA","AMPS_HD_RNA"]:
                                logger.debug("plan_validator.validate_targetRegionBedFile_for_runType() ALLOW MISSING targetRegionBed for runType=%s; applicationGroupName=%s" % (runType, applicationGroupName))
                            else:
                                errors.append("%s is required for this application" % (displayedName))
                        elif value:
                            if not os.path.isfile(value):
                                errors.append("Missing or Invalid %s - %s" % (displayedName, value))
            else:
                errors.append("%s Application %s not found" % (displayedName, runType))
        else:
            errors.append("%s Run type is missing" % (displayedName))

    # logger.debug("EXIT plan_validator.validate_targetRegionBedFile_for_runType() errors=%s" %(errors))

    return errors
Exemplo n.º 5
0
    def validateField(self, field_name, new_field_value):
        '''
        Flows qc value must be a positive integer
        Chip type is required
        '''
        if field_name == KitsFieldNames.FLOWS:
            errors = validate_flows(new_field_value)
            if errors:
                self.validationErrors[field_name] = ' '.join(errors)
            else:
                self.validationErrors.pop(field_name, None)

        if field_name == KitsFieldNames.CHIP_TYPE and self.prepopulatedFields.get(
                'is_chipType_required', True):
            if validation.has_value(new_field_value):
                self.validationErrors.pop(field_name, None)
            else:
                self.validationErrors[field_name] = validation.required_error(
                    "Chip Type")

        if field_name == KitsFieldNames.TEMPLATE_KIT_NAME:
            if validation.has_value(new_field_value):
                self.validationErrors.pop(field_name, None)
            else:
                self.validationErrors[field_name] = validation.required_error(
                    "Template Kit")

        if field_name == KitsFieldNames.LIBRARY_READ_LENGTH:
            errors = validate_libraryReadLength(new_field_value)
            if errors:
                self.validationErrors[field_name] = ' '.join(errors)
            else:
                self.validationErrors.pop(field_name, None)

        if field_name == KitsFieldNames.READ_LENGTH:
            if new_field_value:
                errors = validate_libraryReadLength(new_field_value)
                if errors:
                    self.validationErrors[field_name] = ' '.join(errors)
                else:
                    self.validationErrors.pop(field_name, None)
                    self.savedFields[
                        KitsFieldNames.LIBRARY_READ_LENGTH] = new_field_value

        if field_name == KitsFieldNames.TEMPLATING_SIZE:
            errors = validate_templatingSize(new_field_value)
            if errors:
                self.validationErrors[field_name] = ' '.join(errors)
            else:
                self.validationErrors.pop(field_name, None)
Exemplo n.º 6
0
    def validateField_in_section(self, field_name, new_field_value):
        """
        field validation for a step that acts as a section to another step
        """
        #logger.debug("at validateField_in_section field_name=%s; new_field_value=%s" %(field_name, new_field_value))

        if field_name == ReferenceFieldNames.REFERENCE:
            if new_field_value in [
                    ref.short_name for ref in self.prepopulatedFields[
                        ReferenceFieldNames.REFERENCES]
            ]:
                self.prepopulatedFields[
                    ReferenceFieldNames.REFERENCE_MISSING] = False

        #if the plan has been sequenced, do not enforce the target bed file to be selected

        if self.prepopulatedFields[ReferenceFieldNames.PLAN_STATUS] != "run":
            if field_name == ReferenceFieldNames.TARGET_BED_FILE:
                reference = self.savedFields[ReferenceFieldNames.REFERENCE]

                #logger.debug("at validateField_in_section reference=%s; REQUIRE_TARGET_BED_FILE=%s; targetBed=%s" %(reference, str(self.prepopulatedFields[ReferenceFieldNames.REQUIRE_TARGET_BED_FILE]), new_field_value))
                if self.prepopulatedFields[
                        ReferenceFieldNames.REQUIRE_TARGET_BED_FILE]:
                    if reference:
                        if validation.has_value(new_field_value):
                            self.validationErrors.pop(field_name, None)
                        else:
                            self.validationErrors[
                                field_name] = validation.required_error(
                                    "Target Regions BED File")
                    else:
                        self.validationErrors.pop(field_name, None)
Exemplo n.º 7
0
def validate_plan_templating_kit_name(value, field_label, isNewPlan=None):
    errors = []
    warnings = []

    if not validation.has_value(value):
        errors.append(validation.required_error(field_label))
    else:
        value = value.strip()
        query_kwargs = {"kitType__in": ["TemplatingKit", "IonChefPrepKit"]}

        query_args = (Q(name=value) | Q(description=value), )
        kit = KitInfo.objects.filter(*query_args, **query_kwargs)

        if not kit:
            errors.append(
                validation.invalid_not_found_error(field_label, value))
        elif kit and not kit[0].isActive:
            if isNewPlan:
                errors.append(validation.invalid_not_active(
                    field_label, value))
            else:
                warnings.append(
                    validation.invalid_not_active(field_label, value))

    return errors, warnings
Exemplo n.º 8
0
    def validateField_crossField_dependency(self, field_name, new_field_value,
                                            dependent_field_name,
                                            dependent_field_value):
        isBarcodeKitRequired = False

        if field_name == KitsFieldNames.LIBRARY_KIT_NAME:
            if new_field_value:
                libKit_objs = KitInfo.objects.filter(
                    kitType='LibraryKit',
                    name=new_field_value).order_by("-isActive")
                if libKit_objs and len(libKit_objs) > 0:
                    libKit_obj = libKit_objs[0]
                    if libKit_obj.categories and (
                            "bcrequired" in libKit_obj.categories.lower()):
                        isBarcodeKitRequired = True

        if dependent_field_name == KitsFieldNames.BARCODE_KIT_NAME:
            if self.prepopulatedFields[
                    KitsFieldNames.
                    IS_BARCODE_KIT_SELECTION_REQUIRED] or isBarcodeKitRequired:

                if validation.has_value(dependent_field_value):
                    self.validationErrors.pop(dependent_field_name, None)
                else:
                    self.validationErrors[
                        dependent_field_name] = validation.required_error(
                            "Barcode Set")
            else:
                self.validationErrors.pop(dependent_field_name, None)
Exemplo n.º 9
0
def validate_plan_templating_kit_name(value,
                                      displayedName="Template Kit",
                                      isNewPlan=None):
    errors = []
    warnings = []

    if not validation.has_value(value):
        errors.append(validation.required_error(displayedName))
    else:
        value = value.strip()
        query_kwargs = {"kitType__in": ["TemplatingKit", "IonChefPrepKit"]}

        query_args = (Q(name=value) | Q(description=value), )
        kit = KitInfo.objects.filter(*query_args, **query_kwargs)

        if not kit:
            errors.append("%s %s not found" % (displayedName, value))
        elif kit and not kit[0].isActive:
            if isNewPlan:
                errors.append("%s %s not active" % (displayedName, value))
            else:
                warnings.append("Found inactive %s %s" %
                                (displayedName, value))

    return errors, warnings
Exemplo n.º 10
0
def validate_sampleAttribute_definition(attributeName, attributeDescription):
    """
    validate the sample attribute definition
    return a boolean isValid and a text string for error message, None if input passes validation
    Note: Input length will not be validated since maxLength has been specified in the form.
    """    
        
    isValid = False
    
    if not validation.has_value(attributeName):
        return isValid, validation.required_error("Error, Attribute name")
    if not validation.is_valid_chars(attributeName.strip()):
        return isValid, validation.invalid_chars_error("Error, Attribute name")
            
    if not validation.is_valid_length(attributeName.strip(), MAX_LENGTH_SAMPLE_ATTRIBUTE_DISPLAYED_NAME):
        errorMessage = validation.invalid_length_error("Error, User-defined sample attribute", MAX_LENGTH_SAMPLE_ATTRIBUTE_DISPLAYED_NAME) + ". It is currently %s characters long." % str(len((attributeName.strip())))
        return isValid, errorMessage
    
    if not validation.is_valid_chars(attributeDescription):
        return isValid, validation.invalid_chars_error("Error, Attribute description")

    if not validation.is_valid_length(attributeDescription.strip(), MAX_LENGTH_SAMPLE_ATTRIBUTE_DESCRIPTION):
        errorMessage = validation.invalid_length_error("Error, User-defined sample attribute description", MAX_LENGTH_SAMPLE_ATTRIBUTE_DESCRIPTION) + ". It is currently %s characters long." % str(len(attributeDescription.strip()))
        return isValid, errorMessage
    
    isValid = True
    return isValid, None 
Exemplo n.º 11
0
def validate_sampleAttribute(attribute, value):
    """
    validate the sample attribute value for the attribute of interest
    return a boolean isValid and a text string for error message, None if input passes validation
    Note: Input length will not be validated since maxLength has been specified in the form.
    """    
        
    isValid = False
    if not attribute:
        return isValid, "Error, No sample attribute to validate."
    
    if not validation.has_value(value):
        if attribute.isMandatory:
            return isValid, "Error, "+ validation.required_error(attribute.displayedName)
    else:
        aValue = value.strip()
        if attribute.dataType.dataType == "Text" and not validation.is_valid_chars(aValue):
            return isValid, "Error, "+ validation.invalid_chars_error(attribute.displayedName)
        if attribute.dataType.dataType == "Integer" and not aValue.isdigit():
            return isValid, "Error, "+ attribute.displayedName + ERROR_MSG_INVALID_DATATYPE
        if not validation.is_valid_chars(aValue):
            return isValid, "Error, "+ validation.invalid_chars_error(attribute.displayedName)

        if not validation.is_valid_length(aValue, MAX_LENGTH_SAMPLE_ATTRIBUTE_VALUE):
            errorMessage = validation.invalid_length_error("Error, User-defined sample attribute value", MAX_LENGTH_SAMPLE_ATTRIBUTE_VALUE) + ". It is currently %s characters long." % str(len(aValue.strip()))
            return isValid, errorMessage
        
    isValid = True
    return isValid, None   
Exemplo n.º 12
0
    def validateField_in_section(self, field_name, new_field_value):
        """
        field validation for a step that acts as a section to another step
        """
        #logger.debug("at validateField_in_section field_name=%s; new_field_value=%s" %(field_name, new_field_value))
        
        if field_name == ReferenceFieldNames.REFERENCE:
            if new_field_value in [ref.short_name for ref in self.prepopulatedFields[ReferenceFieldNames.REFERENCES]]:
                self.prepopulatedFields[ReferenceFieldNames.REFERENCE_MISSING] = False

        #if the plan has been sequenced, do not enforce the target bed file to be selected
        
        if self.prepopulatedFields[ReferenceFieldNames.PLAN_STATUS] != "run":
            if field_name == ReferenceFieldNames.TARGET_BED_FILE:
                reference = self.savedFields[ReferenceFieldNames.REFERENCE]
    
                #logger.debug("at validateField_in_section reference=%s; REQUIRE_TARGET_BED_FILE=%s; targetBed=%s" %(reference, str(self.prepopulatedFields[ReferenceFieldNames.REQUIRE_TARGET_BED_FILE]), new_field_value))               
                if self.prepopulatedFields[ReferenceFieldNames.REQUIRE_TARGET_BED_FILE]:
                    if reference:
                        if validation.has_value(new_field_value):
                            self.validationErrors.pop(field_name, None)
                        else:
                            self.validationErrors[field_name] = validation.required_error("Target Regions BED File")
                    else:
                        self.validationErrors.pop(field_name, None)
Exemplo n.º 13
0
def validate_targetRegionBedFile_for_runType(value, runType, reference, nucleotideType = None, displayedName="Target Regions BED File"):
    """
    validate targetRegionBedFile based on the selected reference and the plan's runType
    """            
    errors = []
    
    logger.debug("plan_validator.validate_targetRegionBedFile_for_runType() value=%s; runType=%s; reference=%s; nucleotideType=%s" %(value, runType, reference, nucleotideType))
    
    if reference:
        if runType:
            runType = runType.strip()
            applProducts = ApplProduct.objects.filter(applType__runType = runType)
            if applProducts:
                applProduct = applProducts[0]
                if applProduct:
                    isRequired = applProduct.isTargetRegionBEDFileSelectionRequiredForRefSelection
                                 
                    if isRequired and not validation.has_value(value):
                        #skip for now
                        if runType == "AMPS_DNA_RNA" and nucleotideType and nucleotideType.upper() == "RNA":                        
                            logger.debug("plan_validator.validate_targetRegionBedFile_for_runType() ALLOW MISSING targetRegionBed for runType=%s; nucleotideType=%s" %(runType, nucleotideType))
                        else:    
                            errors.append("%s is required for this application" %(displayedName))
            else:
                errors.append("%s Application %s not found" %(displayedName, runType))
        else:
            errors.append("%s Run type is missing" %(displayedName))  
    
    ##logger.debug("EXIT plan_validator.validate_targetRegionBedFile_for_runType() errors=%s" %(errors))
                      
    return errors
Exemplo n.º 14
0
    def validateField(self, field_name, new_field_value):
        '''
        Flows qc value must be a positive integer
        Chip type is required
        '''
        if field_name == KitsFieldNames.FLOWS:
            errors = validate_flows(new_field_value)
            if errors:
                self.validationErrors[field_name] = ' '.join(errors)
            else:
                self.validationErrors.pop(field_name, None)

        if field_name == KitsFieldNames.CHIP_TYPE and self.prepopulatedFields.get('is_chipType_required',True):
            if validation.has_value(new_field_value):
                self.validationErrors.pop(field_name, None)
            else:
                self.validationErrors[field_name] = validation.required_error("Chip Type")
        
        if field_name == KitsFieldNames.TEMPLATE_KIT_NAME:
            if validation.has_value(new_field_value):
                self.validationErrors.pop(field_name, None)
            else:
                self.validationErrors[field_name] = validation.required_error("Template Kit")

        if field_name == KitsFieldNames.LIBRARY_READ_LENGTH:
            errors = validate_libraryReadLength(new_field_value)
            if errors:
                self.validationErrors[field_name] = ' '.join(errors)
            else:
                self.validationErrors.pop(field_name, None)

        if field_name == KitsFieldNames.READ_LENGTH:
            if new_field_value:
                errors = validate_libraryReadLength(new_field_value)
                if errors:
                    self.validationErrors[field_name] = ' '.join(errors)
                else:
                    self.validationErrors.pop(field_name, None)
                    self.savedFields[KitsFieldNames.LIBRARY_READ_LENGTH] = new_field_value 

        if field_name == KitsFieldNames.TEMPLATING_SIZE:
            errors = validate_templatingSize(new_field_value)
            if errors:
                self.validationErrors[field_name] = ' '.join(errors)
            else:
                self.validationErrors.pop(field_name, None)
Exemplo n.º 15
0
def validate_reference_short_name(value, displayedName='Reference'):
    errors = []
    if validation.has_value(value):
        value = value.strip()
        reference = ReferenceGenome.objects.filter(short_name=value, enabled=True)
        if not reference.exists():
            errors.append(validation.invalid_not_found_error(displayedName, value))

    return errors
Exemplo n.º 16
0
def validate_barcode_kit_name(value, displayedName="Barcode Kit"):
    errors = []

    if validation.has_value(value):
        value = value.strip()
        kits = dnaBarcode.objects.filter(name=value)
        if not kits:
            errors.append("%s %s not found" % (displayedName, value))

    return errors
Exemplo n.º 17
0
def validate_barcode_kit_name(value, displayedName="Barcode Kit"):
    errors = []

    if validation.has_value(value):
        value = value.strip()
        kits = dnaBarcode.objects.filter(name=value)
        if not kits:
            errors.append("%s %s not found" % (displayedName, value))

    return errors
Exemplo n.º 18
0
def validate_reference_short_name(value, displayedName='Reference'):
    errors = []
    if validation.has_value(value):
        value = value.strip()
        reference = ReferenceGenome.objects.filter(short_name=value, enabled=True)
        if not reference.exists():
            generic_not_found_error = validation.invalid_not_found_error(displayedName, value)
            error_fixing_message = ". To import it, visit Settings > References > Import Preloaded Ion References"
            reference_error_message = generic_not_found_error.strip() + error_fixing_message
            errors.append(reference_error_message)
    return errors
Exemplo n.º 19
0
def validate_reference_short_name(value, displayedName='Reference'):
    errors = []
    if validation.has_value(value):
        value = value.strip()
        reference = ReferenceGenome.objects.filter(short_name=value, enabled=True)
        if not reference.exists():
            generic_not_found_error = validation.invalid_not_found_error(displayedName, value)
            error_fixing_message = ". To import it, visit Settings > References > Import Preloaded Ion References"
            reference_error_message = generic_not_found_error.strip() + error_fixing_message
            errors.append(reference_error_message)
    return errors
Exemplo n.º 20
0
def validate_plan_name(value, displayedName='Plan Name'):
    errors = []
    if not validation.has_value(value):
        errors.append(validation.required_error(displayedName))
        
    if not validation.is_valid_chars(value):
        errors.append(validation.invalid_chars_error(displayedName))
    
    if not validation.is_valid_length(value, MAX_LENGTH_PLAN_NAME):
        errors.append(validation.invalid_length_error(displayedName, MAX_LENGTH_PLAN_NAME))
    
    return errors
Exemplo n.º 21
0
def validate_plan_name(value, displayedName="Plan Name"):
    errors = []
    if not validation.has_value(value):
        errors.append(validation.required_error(displayedName))

    if not validation.is_valid_chars(value):
        errors.append(validation.invalid_chars_error(displayedName))

    if not validation.is_valid_length(value, MAX_LENGTH_PLAN_NAME):
        errors.append(validation.invalid_length_error(displayedName, MAX_LENGTH_PLAN_NAME))

    return errors
Exemplo n.º 22
0
def validate_targetRegionBedFile_for_runType(value, runType, reference, nucleotideType=None, applicationGroupName=None, displayedName="Target Regions BED File"):
    """
    validate targetRegionBedFile based on the selected reference and the plan's runType
    """
    errors = []
    value = value.strip() if value else ""

    logger.debug("plan_validator.validate_targetRegionBedFile_for_runType() value=%s; runType=%s; reference=%s; nucleotideType=%s; applicationGroupName=%s" % (value, runType, reference, nucleotideType, applicationGroupName))

    if reference:
        if runType:
            runType = runType.strip()
            applProducts = ApplProduct.objects.filter(isActive=True, applType__runType=runType, applicationGroup__name=applicationGroupName) \
                or ApplProduct.objects.filter(isActive=True, applType__runType=runType)
            if applProducts:
                applProduct = applProducts[0]
                if applProduct:
                    if validation.has_value(value) and not applProduct.isTargetRegionBEDFileSupported:
                        errors.append(displayedName+" selection is not supported for this Application")
                    else:
                        isRequired = applProduct.isTargetRegionBEDFileSelectionRequiredForRefSelection
                        if isRequired and not validation.has_value(value):
                            # skip for now
                            if runType == "AMPS_DNA_RNA" and nucleotideType and nucleotideType.upper() == "RNA":
                                logger.debug("plan_validator.validate_targetRegionBedFile_for_runType() ALLOW MISSING targetRegionBed for runType=%s; nucleotideType=%s" % (runType, nucleotideType))
                            elif runType == "AMPS_RNA" and applicationGroupName and applicationGroupName in ["DNA + RNA", "DNA and Fusions"]:
                                logger.debug("plan_validator.validate_targetRegionBedFile_for_runType() ALLOW MISSING targetRegionBed for runType=%s; applicationGroupName=%s" % (runType, applicationGroupName))
                            else:
                                errors.append("%s is required for this application" % (displayedName))
                        elif value:
                            if not os.path.isfile(value):
                                errors.append("Missing or Invalid %s - %s" % (displayedName, value))
            else:
                errors.append("%s Application %s not found" % (displayedName, runType))
        else:
            errors.append("%s Run type is missing" % (displayedName))

    # logger.debug("EXIT plan_validator.validate_targetRegionBedFile_for_runType() errors=%s" %(errors))

    return errors
Exemplo n.º 23
0
def validate_barcode_kit_name(value, field_label):
    errors = []

    if validation.has_value(value):
        value = value.strip()
        kits = dnaBarcode.objects.filter(name=value)
        if not kits:
            errors.append(
                validation.invalid_not_found_error(
                    field_label,
                    value))  # "%s %s not found" % (displayedName, value)

    return errors
Exemplo n.º 24
0
def validate_sequencing_kit_name(value, displayedName="Sequencing Kit"):
    errors = []
    
    if validation.has_value(value):
        value = value.strip()
        kit = KitInfo.objects.filter(kitType__in = ["SequencingKit"], name = value)
        if not kit:
            kit = KitInfo.objects.filter(kitType__in = ["SequencingKit"], description = value)
        
        if not kit:
            errors.append("%s %s not found" %(displayedName, value))
            
    return errors
Exemplo n.º 25
0
def validate_sampleDescription(sampleDescription):
    isValid = False
        
    if validation.has_value(sampleDescription):
        isValid, errorMessage = _validate_textValue(sampleDescription, "Sample description ")
        if not isValid:
            return isValid, errorMessage
    
        if not validation.is_valid_length(sampleDescription.strip(), MAX_LENGTH_SAMPLE_DESCRIPTION):
            errorMessage = validation.invalid_length_error("Error, Sample description", MAX_LENGTH_SAMPLE_DESCRIPTION) + ". It is currently %s characters long." % str(len(sampleDescription.strip()))
            return isValid, errorMessage
    
    return True, None
Exemplo n.º 26
0
def validate_sequencing_kit_name(value, displayedName="Sequencing Kit"):
    errors = []

    if validation.has_value(value):
        value = value.strip()
        kit = KitInfo.objects.filter(kitType__in=["SequencingKit"], name=value)
        if not kit:
            kit = KitInfo.objects.filter(kitType__in=["SequencingKit"], description=value)

        if not kit:
            errors.append("%s %s not found" % (displayedName, value))

    return errors
Exemplo n.º 27
0
    def validateField(self, field_name, new_field_value):
        '''
        Flows qc value must be a positive integer
        Chip type is required
        '''
        if field_name == KitsFieldNames.FLOWS:
            errors = validate_flows(new_field_value)
            if errors:
                self.validationErrors[field_name] = ' '.join(errors)
            else:
                self.validationErrors.pop(field_name, None)

        if field_name == KitsFieldNames.CHIP_TYPE and self.prepopulatedFields.get('is_chipType_required',True):
            if validation.has_value(new_field_value):
                self.validationErrors.pop(field_name, None)
            else:
                self.validationErrors[field_name] = validation.required_error("Chip Type")
        
        if field_name == KitsFieldNames.TEMPLATE_KIT_NAME:
            if validation.has_value(new_field_value):
                self.validationErrors.pop(field_name, None)
            else:
                self.validationErrors[field_name] = validation.required_error("Template Kit")
Exemplo n.º 28
0
def validate_plan_name(value, field_label):
    errors = []
    if not validation.has_value(value):
        errors.append(validation.required_error(field_label))

    if not validation.is_valid_chars(value):
        errors.append(validation.invalid_chars_error(field_label))

    if not validation.is_valid_length(value, MAX_LENGTH_PLAN_NAME):
        errors.append(
            validation.invalid_length_error(field_label, MAX_LENGTH_PLAN_NAME,
                                            value))

    return errors
Exemplo n.º 29
0
def validate_plan_templating_kit_name(value, displayedName="Template Kit"):
    errors = []
    
    if not validation.has_value(value):
        errors.append(validation.required_error(displayedName))
    else:
        value = value.strip()
        kit = KitInfo.objects.filter(kitType__in = ["TemplatingKit", "IonChefPrepKit"], name = value)
        if not kit:
            kit = KitInfo.objects.filter(kitType__in = ["TemplatingKit", "IonChefPrepKit"], description = value)
        
        if not kit:
            errors.append("%s %s not found" %(displayedName, value))
            
    return errors
Exemplo n.º 30
0
def validate_plan_templating_kit_name(value, displayedName="Template Kit"):
    errors = []

    if not validation.has_value(value):
        errors.append(validation.required_error(displayedName))
    else:
        value = value.strip()
        kit = KitInfo.objects.filter(kitType__in=["TemplatingKit", "IonChefPrepKit"], name=value)
        if not kit:
            kit = KitInfo.objects.filter(kitType__in=["TemplatingKit", "IonChefPrepKit"], description=value)

        if not kit:
            errors.append("%s %s not found" % (displayedName, value))

    return errors
Exemplo n.º 31
0
def check_uploaded_files(referenceNames=[], bedfilePaths=[]):
    ''' checks if reference or BED files are missing '''
    missing_files = {}
    for reference in referenceNames:
        ref_err = validate_reference_short_name(reference)
        if ref_err:
            missing_files.setdefault('references',[]).append(reference)
    
    content = Content.objects.filter(publisher__name="BED")
    for bedfile in bedfilePaths:
        bedfile_err = validation.has_value(bedfile) and (content.filter(path=bedfile).count() == 0
                                                         and content.filter(file=bedfile).count() == 0)
        if bedfile_err:
            missing_files.setdefault('bedfiles',[]).append(bedfile)

    return missing_files
Exemplo n.º 32
0
def check_uploaded_files(referenceNames=[], bedfilePaths=[]):
    ''' checks if reference or BED files are missing '''
    missing_files = {}
    for reference in referenceNames:
        ref_err = validate_reference_short_name(reference)
        if ref_err:
            missing_files.setdefault('references', []).append(reference)

    content = Content.objects.filter(publisher__name="BED")
    for bedfile in bedfilePaths:
        bedfile_err = validation.has_value(bedfile) and content.filter(
            path=bedfile).count() == 0
        if bedfile_err:
            missing_files.setdefault('bedfiles', []).append(bedfile)

    return missing_files
Exemplo n.º 33
0
def validate_reference_short_name(value, field_label):
    errors = []
    if validation.has_value(value):
        value = value.strip()
        reference = ReferenceGenome.objects.filter(short_name=value,
                                                   enabled=True)
        if not reference.exists():
            generic_not_found_error = validation.invalid_not_found_error(
                field_label, value)
            error_fixing_message = ugettext_lazy(
                "references_genome_download.messages.help.import"
            )  # "To import it, visit Settings > References > Import Preloaded Ion References"
            reference_error_message = (generic_not_found_error.strip() +
                                       error_fixing_message.strip()
                                       )  # avoid lazy
            errors.append(reference_error_message)
    return errors
Exemplo n.º 34
0
def validate_optional_kit_name(value, kitType, field_label, isNewPlan=None):
    errors = []
    warnings = []
    if validation.has_value(value):
        kit = get_kitInfo_by_name_or_description(value, kitType)

        if not kit:
            errors.append(
                validation.invalid_not_found_error(field_label, value))
        elif kit and not kit.isActive:
            if isNewPlan:
                errors.append(validation.invalid_not_active(
                    field_label, value))
            else:
                warnings.append(
                    validation.invalid_not_active(field_label, value))

    return errors, warnings
Exemplo n.º 35
0
 def validateField_crossField_dependency(self, field_name, new_field_value, dependent_field_name, dependent_field_value):                         
     isBarcodeKitRequired = False
     
     if field_name == KitsFieldNames.LIBRARY_KIT_NAME:
         if new_field_value:
             libKit_objs = KitInfo.objects.filter(kitType='LibraryKit', name = new_field_value).order_by("-isActive")
             if libKit_objs and len(libKit_objs) > 0:
                 libKit_obj = libKit_objs[0]
                 if libKit_obj.categories and ("bcrequired" in libKit_obj.categories.lower()):
                     isBarcodeKitRequired = True         
                     
     if dependent_field_name == KitsFieldNames.BARCODE_KIT_NAME:            
         if self.prepopulatedFields[KitsFieldNames.IS_BARCODE_KIT_SELECTION_REQUIRED] or isBarcodeKitRequired:
             
             if validation.has_value(dependent_field_value):
                 self.validationErrors.pop(dependent_field_name, None)
             else:
                 self.validationErrors[dependent_field_name] = validation.required_error("Barcode Set")    
         else:
             self.validationErrors.pop(dependent_field_name, None)    
Exemplo n.º 36
0
def validate_optional_kit_name(value, kitType, displayedName=None, isNewPlan=None):
    errors = []
    warnings = []
    if validation.has_value(value):
        value = value.strip()
        query_kwargs = {"kitType__in": kitType}

        query_args = (Q(name__iexact=value) | Q(description__iexact=value),)

        kit = KitInfo.objects.filter(*query_args, **query_kwargs)

        if not kit:
            errors.append("%s %s not found" % (displayedName, value))
        elif kit and not kit[0].isActive:
            if isNewPlan:
                errors.append("%s %s not active" % (displayedName, value))
            else:
                warnings.append("Found inactive %s %s" % (displayedName, value))

    return errors, warnings
Exemplo n.º 37
0
def validate_plan_templating_kit_name(value, displayedName="Template Kit", isNewPlan=None):
    errors = []
    warnings = []

    if not validation.has_value(value):
        errors.append(validation.required_error(displayedName))
    else:
        value = value.strip()
        query_kwargs = {"kitType__in": ["TemplatingKit", "IonChefPrepKit"]}

        query_args = (Q(name=value) | Q(description=value), )
        kit = KitInfo.objects.filter(*query_args, **query_kwargs)

        if not kit:
            errors.append("%s %s not found" % (displayedName, value))
        elif kit and not kit[0].isActive:
            if isNewPlan:
                errors.append("%s %s not active" % (displayedName, value))
            else:
                warnings.append("Found inactive %s %s" % (displayedName, value))

    return errors, warnings
Exemplo n.º 38
0
def check_uploaded_files(referenceNames=[],
                         bedfilePaths=[],
                         referenceNames_label="Reference"):
    """ checks if reference or BED files are missing
    referenceNames_label='Reference'
    """
    missing_files = {}
    for reference in referenceNames:
        ref_err = validate_reference_short_name(
            reference, field_label=referenceNames_label)
        if ref_err:
            missing_files.setdefault("references", []).append(reference)

    content = Content.objects.filter(publisher__name="BED")
    for bedfile in bedfilePaths:
        bedfile_err = validation.has_value(bedfile) and (
            content.filter(path=bedfile).count() == 0
            and content.filter(file=bedfile).count() == 0)
        if bedfile_err:
            missing_files.setdefault("bedfiles", []).append(bedfile)

    return missing_files
Exemplo n.º 39
0
def _validate_textValue_mandatory(value, displayedTerm):
    isValid = False
    if not validation.has_value(value):
        return isValid, "Error, " + validation.required_error(displayedTerm)
            
    return True, None
Exemplo n.º 40
0
def validate_targetRegionBedFile_for_runType(
    value,
    field_label,
    runType,
    reference,
    nucleotideType=None,
    applicationGroupName=None,
    isPrimaryTargetRegion=True,
    barcodeId="",
    runType_label=ugettext_lazy(
        "workflow.step.application.fields.runType.label"),
):
    """
    validate targetRegionBedFile based on the selected reference and the plan's runType
    """
    errors = []
    value = value.strip() if value else ""
    if value:
        missing_file = check_uploaded_files(bedfilePaths=[value])
        if missing_file:
            errors.append("%s : %s not found" % (field_label, value))
            logger.debug(
                "plan_validator.validate_targetRegionBedFile_for_run() SKIPS validation due to no targetRegion file exists in db. value=%s"
                % (value))
        return errors

    logger.debug(
        "plan_validator.validate_targetRegionBedFile_for_runType() value=%s; runType=%s; reference=%s; nucleotideType=%s; applicationGroupName=%s"
        % (value, runType, reference, nucleotideType, applicationGroupName))

    if not isPrimaryTargetRegion:
        logger.debug(
            "plan_validator.validate_targetRegionBedFile_for_run() SKIPS validation due to no validation rules for non-primary targetRegion. value=%s"
            % (value))
        return errors

    if reference:
        if runType:
            runType = runType.strip()
            applProducts = ApplProduct.objects.filter(
                isActive=True,
                applType__runType=runType,
                applicationGroup__name=applicationGroupName,
            ) or ApplProduct.objects.filter(isActive=True,
                                            applType__runType=runType)
            if applProducts:
                applProduct = applProducts[0]
                if applProduct:
                    if (validation.has_value(value) and
                            not applProduct.isTargetRegionBEDFileSupported):
                        errors.append(
                            validation.invalid_invalid_related(
                                field_label,
                                ScientificApplication.verbose_name))
                    else:
                        isRequired = (
                            applProduct.
                            isTargetRegionBEDFileSelectionRequiredForRefSelection
                        )
                        if (isRequired and not validation.has_value(value)
                                and not barcodeId):
                            # skip for now
                            if (runType in ["AMPS_DNA_RNA", "AMPS_HD_DNA_RNA"]
                                    and nucleotideType
                                    and nucleotideType.upper() == "RNA"):
                                logger.debug(
                                    "plan_validator.validate_targetRegionBedFile_for_runType() ALLOW MISSING targetRegionBed for runType=%s; nucleotideType=%s"
                                    % (runType, nucleotideType))
                            elif runType in ["AMPS_RNA", "AMPS_HD_RNA"]:
                                logger.debug(
                                    "plan_validator.validate_targetRegionBedFile_for_runType() ALLOW MISSING targetRegionBed for runType=%s; applicationGroupName=%s"
                                    % (runType, applicationGroupName))
                            else:
                                errors.append(
                                    validation.invalid_required_related(
                                        field_label,
                                        ScientificApplication.verbose_name))
                        elif value:
                            if not os.path.isfile(value):
                                errors.append(
                                    validation.invalid_invalid_value(
                                        field_label, value))
            else:
                errors.append(
                    validation.invalid_invalid_value_related(
                        runType_label, runType,
                        ScientificApplication.verbose_name))
        else:
            errors.append(
                validation.invalid_required_related(
                    runType_label, ScientificApplication.verbose_name))

    return errors
Exemplo n.º 41
0
def validate_targetRegionBedFile_for_runType(
        value,
        runType,
        reference,
        nucleotideType=None,
        applicationGroupName=None,
        displayedName="Target Regions BED File"):
    """
    validate targetRegionBedFile based on the selected reference and the plan's runType
    """
    errors = []
    value = value.strip() if value else ""

    logger.debug(
        "plan_validator.validate_targetRegionBedFile_for_runType() value=%s; runType=%s; reference=%s; nucleotideType=%s; applicationGroupName=%s"
        % (value, runType, reference, nucleotideType, applicationGroupName))

    if reference:
        if runType:
            runType = runType.strip()
            applProducts = ApplProduct.objects.filter(isActive=True, applType__runType=runType, applicationGroup__name=applicationGroupName) \
                or ApplProduct.objects.filter(isActive=True, applType__runType=runType)
            if applProducts:
                applProduct = applProducts[0]
                if applProduct:
                    if validation.has_value(
                            value
                    ) and not applProduct.isTargetRegionBEDFileSupported:
                        errors.append(
                            displayedName +
                            " selection is not supported for this Application")
                    else:
                        isRequired = applProduct.isTargetRegionBEDFileSelectionRequiredForRefSelection
                        if isRequired and not validation.has_value(value):
                            # skip for now
                            if runType == "AMPS_DNA_RNA" and nucleotideType and nucleotideType.upper(
                            ) == "RNA":
                                logger.debug(
                                    "plan_validator.validate_targetRegionBedFile_for_runType() ALLOW MISSING targetRegionBed for runType=%s; nucleotideType=%s"
                                    % (runType, nucleotideType))
                            elif runType == "AMPS_RNA" and applicationGroupName and applicationGroupName in [
                                    "DNA + RNA", "DNA and Fusions"
                            ]:
                                logger.debug(
                                    "plan_validator.validate_targetRegionBedFile_for_runType() ALLOW MISSING targetRegionBed for runType=%s; applicationGroupName=%s"
                                    % (runType, applicationGroupName))
                            else:
                                errors.append(
                                    "%s is required for this application" %
                                    (displayedName))
                        elif value:
                            if not os.path.isfile(value):
                                errors.append("Missing or Invalid %s - %s" %
                                              (displayedName, value))
            else:
                errors.append("%s Application %s not found" %
                              (displayedName, runType))
        else:
            errors.append("%s Run type is missing" % (displayedName))

    # logger.debug("EXIT plan_validator.validate_targetRegionBedFile_for_runType() errors=%s" %(errors))

    return errors