示例#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
示例#2
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 
示例#3
0
def validate_barcoded_sample_info(sampleName, sampleId, nucleotideType, sampleReference, runType, applicationGroupName, displayedName='Barcoded Sample'):
    errors = []
    if not validation.is_valid_chars(sampleName):
        errors.append(validation.invalid_chars_error(displayedName))

    if not validation.is_valid_leading_chars(sampleName):
        errors.append(validation.invalid_chars_error(displayedName))

    if not validation.is_valid_length(sampleName, MAX_LENGTH_SAMPLE_NAME):
        errors.append(validation.invalid_length_error(displayedName, MAX_LENGTH_SAMPLE_NAME))

    sample_id_errors = validate_sample_id(sampleId)
    if sample_id_errors:
        errors.extend(sample_id_errors)

    nucleotideType_errors, sample_nucleotideType = validate_sample_nucleotideType(nucleotideType, runType, applicationGroupName)
    if (nucleotideType_errors):
        errors.extend(nucleotideType_errors)

    ref_displayedName = "Sample Reference" if nucleotideType != "RNA" else "RNA Sample Reference"
    ref_errors, ref_short_name = validate_reference(sampleReference, runType, applicationGroupName, displayedName=ref_displayedName)
    if (ref_errors):
        errors.extend(ref_errors)

    return errors, ref_short_name, sample_nucleotideType
示例#4
0
def validate_barcoded_sample_info(sampleName, sampleId, nucleotideType, sampleReference, runType, applicationGroupName, displayedName='Barcoded Sample'):
    errors = []
    if not validation.is_valid_chars(sampleName):
        errors.append(validation.invalid_chars_error(displayedName))

    if not validation.is_valid_leading_chars(sampleName):
        errors.append(validation.invalid_chars_error(displayedName))

    if not validation.is_valid_length(sampleName, MAX_LENGTH_SAMPLE_NAME):
        errors.append(validation.invalid_length_error(displayedName, MAX_LENGTH_SAMPLE_NAME))

    sample_id_errors = validate_sample_id(sampleId)
    if sample_id_errors:
        errors.extend(sample_id_errors)

    nucleotideType_errors, sample_nucleotideType = validate_sample_nucleotideType(nucleotideType, runType, applicationGroupName)
    if (nucleotideType_errors):
        errors.extend(nucleotideType_errors)

    ref_displayedName = "Sample Reference" if nucleotideType != "RNA" else "RNA Sample Reference"
    ref_errors, ref_short_name = validate_reference(sampleReference, runType, applicationGroupName, displayedName=ref_displayedName)
    if (ref_errors):
        errors.extend(ref_errors)

    return errors, ref_short_name, sample_nucleotideType
示例#5
0
def validate_barcoded_sample_info(
    sampleName, sampleId, nucleotideType, runTypeName, sampleReference, displayedName="Barcoded Sample"
):
    errors = []
    if not validation.is_valid_chars(sampleName):
        errors.append(validation.invalid_chars_error(displayedName))

    if not validation.is_valid_leading_chars(sampleName):
        errors.append(validation.invalid_chars_error(displayedName))

    if not validation.is_valid_length(sampleName, MAX_LENGTH_SAMPLE_NAME):
        errors.append(validation.invalid_length_error(displayedName, MAX_LENGTH_SAMPLE_NAME))

    sample_id_errors = validate_sample_id(sampleId)
    if sample_id_errors:
        errors.extend(sample_id_errors)

    sample_nucleotideType = ""

    nucleotideType_errors, sample_nucleotideType = validate_sample_nucleotideType(nucleotideType, runTypeName)
    if nucleotideType_errors:
        errors.extend(nucleotideType_errors)

    ref_errors, ref_short_name = validate_reference(sampleReference, displayedName="Sample Reference")
    ##logger.debug("plan_validator.validate_barcoded_sample_info() sampleReference=%s; ref_short_name=%s" %(sampleReference, ref_short_name))

    if ref_errors:
        errors.extend(ref_errors)

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

    return errors, ref_short_name, sample_nucleotideType
示例#6
0
def validate_barcoded_sample_info(sampleName,
                                  sampleId,
                                  nucleotideType,
                                  sampleReference,
                                  sampleRnaReference,
                                  runType,
                                  applicationGroupName,
                                  displayedName='Barcoded Sample'):
    errors = []
    if not validation.is_valid_chars(sampleName):
        errors.append(validation.invalid_chars_error(displayedName))

    if not validation.is_valid_leading_chars(sampleName):
        errors.append(validation.invalid_chars_error(displayedName))

    if not validation.is_valid_length(sampleName, MAX_LENGTH_SAMPLE_NAME):
        errors.append(
            validation.invalid_length_error(displayedName,
                                            MAX_LENGTH_SAMPLE_NAME))

    sample_id_errors = validate_sample_id(sampleId)
    if sample_id_errors:
        errors.extend(sample_id_errors)

    sample_nucleotideType = ""

    nucleotideType_errors, sample_nucleotideType = validate_sample_nucleotideType(
        nucleotideType, runType, applicationGroupName)

    if (nucleotideType_errors):
        errors.extend(nucleotideType_errors)

    if runType == "AMPS_DNA_RNA" and sample_nucleotideType.upper() == "RNA":
        rna_ref_errors, rna_ref_short_name = validate_reference(
            sampleRnaReference,
            runType,
            applicationGroupName,
            displayedName="RNA Sample Reference")
        logger.debug(
            "plan_validator.validate_barcoded_sample_info() sampleRnaReference=%s; rna_ref_short_name=%s"
            % (sampleRnaReference, rna_ref_short_name))

        if (rna_ref_errors):
            errors.extend(rna_ref_errors)

    else:
        rna_ref_errors = []
        rna_ref_short_name = ""

    ref_errors, ref_short_name = validate_reference(
        sampleReference,
        runType,
        applicationGroupName,
        displayedName="Sample Reference")
    ##logger.debug("plan_validator.validate_barcoded_sample_info() sampleReference=%s; ref_short_name=%s" %(sampleReference, ref_short_name))

    if (ref_errors):
        errors.extend(ref_errors)

    return errors, ref_short_name, rna_ref_short_name, sample_nucleotideType
示例#7
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   
示例#8
0
def validate_projects(value, displayedName='Project Name', delim=','):
    """
    validate projects case-insensitively with leading/trailing blanks in the input ignored
    """

    errors = []
    trimmed_projects = ""
    if value:
        for project in value.split(delim):
            trimmed_project = project.strip()
            if trimmed_project:
                trimmed_projects = trimmed_projects + trimmed_project + delim

                if not validation.is_valid_chars(trimmed_project):
                    errors.append(
                        validation.invalid_chars_error(displayedName))
                if not validation.is_valid_length(trimmed_project,
                                                  PROJECT_NAME_LENGTH):
                    errors.append(
                        validation.invalid_length_error(
                            displayedName, PROJECT_NAME_LENGTH))
                if errors:
                    break

    return errors, trimmed_projects
示例#9
0
def validate_sample_name(value,
                         displayedName='Sample Name',
                         isTemplate=None,
                         barcodeId=None):
    errors = []
    if not value:
        if not isTemplate:
            errors.append(validation.required_error(displayedName))
    else:
        if isTemplate:
            errors.append(
                "Invalid input. Sample information cannot be saved in the template"
            )
        if barcodeId:
            errors.append(
                "Invalid input. Barcode kit should not be provided (%s) for non barcoded plan"
                % barcodeId)
        if not validation.is_valid_chars(value):
            errors.append(validation.invalid_chars_error(displayedName))
        if not validation.is_valid_leading_chars(value):
            errors.append(validation.invalid_chars_error(displayedName))
        if not validation.is_valid_length(value, MAX_LENGTH_SAMPLE_NAME):
            errors.append(
                validation.invalid_length_error(displayedName,
                                                MAX_LENGTH_SAMPLE_NAME))

    return errors
示例#10
0
def validate_sampleName(sampleName):
    displayedTerm = "Sample name"

    isValid, errorMessage = _validate_textValue_mandatory(
        sampleName, displayedTerm)

    if not isValid:
        return isValid, errorMessage

    isValid, errorMessage = _validate_textValue(sampleName, displayedTerm)
    if not isValid:
        return isValid, errorMessage

    isValid, errorMessage = _validate_textValue_leadingChars(
        sampleName, displayedTerm)
    if not isValid:
        return isValid, errorMessage

    if not validation.is_valid_length(sampleName.strip(),
                                      MAX_LENGTH_SAMPLE_NAME):
        errorMessage = validation.invalid_length_error(
            "Error, Sample name", MAX_LENGTH_SAMPLE_NAME
        ) + ". It is currently %s characters long." % str(
            len(sampleName.strip()))
        return isValid, errorMessage

    return True, None
示例#11
0
def validate_notes(value, displayedName='Notes'):
    errors = []
    if not validation.is_valid_chars(value):
        errors.append(validation.invalid_chars_error(displayedName))
    
    if not validation.is_valid_length(value, MAX_LENGTH_NOTES):
        errors.append(validation.invalid_length_error(displayedName, MAX_LENGTH_NOTES))
        
    return errors
示例#12
0
def validate_sample_id(value, displayedName='Sample Id'):
    errors = []    
    if not validation.is_valid_chars(value):
        errors.append(validation.invalid_chars_error(displayedName))
    
    if not validation.is_valid_length(value, MAX_LENGTH_SAMPLE_ID):
        errors.append(validation.invalid_length_error(displayedName, MAX_LENGTH_SAMPLE_ID))

    return errors
示例#13
0
def validate_sample_id(value, displayedName="Sample Id"):
    errors = []
    if not validation.is_valid_chars(value):
        errors.append(validation.invalid_chars_error(displayedName))

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

    return errors
示例#14
0
def validate_notes(value, displayedName="Notes"):
    errors = []
    if not validation.is_valid_chars(value):
        errors.append(validation.invalid_chars_error(displayedName))

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

    return errors
示例#15
0
def _validate_optional_text(value, maxLength, displayedTerm):
    isValid, errorMessage = _validate_textValue(value.strip(), displayedTerm)
    if not isValid:
        return isValid, errorMessage

    if not validation.is_valid_length(value.strip(), maxLength):
        errorMessage = validation.invalid_length_error("Error, " + displayedTerm, maxLength) + ". It is currently %s characters long." % str(len(value.strip()))
        return isValid, errorMessage

    return True, None
示例#16
0
def validate_sample_tube_label(value, displayedName='Sample Tube Label'):    
    errors = []
    
    if value:
        if not validation.is_valid_chars(value):
            errors.append(validation.invalid_chars_error(displayedName))
            
        if not validation.is_valid_length(value, MAX_LENGTH_SAMPLE_TUBE_LABEL):
            errors.append(validation.invalid_length_error(displayedName, MAX_LENGTH_SAMPLE_TUBE_LABEL))

    return errors
示例#17
0
def validate_sample_tube_label(value, displayedName="Sample Tube Label"):
    errors = []

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

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

    return errors
示例#18
0
def validate_sample_id(value, field_label):
    errors = []
    if not validation.is_valid_chars(value):
        errors.append(validation.invalid_chars_error(field_label))

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

    return errors
示例#19
0
def _validate_optional_text(value, maxLength, displayedTerm):
    isValid, errorMessage = _validate_textValue(value.strip(), displayedTerm)
    if not isValid:
        return isValid, errorMessage

    if not validation.is_valid_length(value.strip(), maxLength):
        errorMessage = validation.invalid_length_error(
            "Error, " + displayedTerm, maxLength
        ) + ". It is currently %s characters long." % str(len(value.strip()))
        return isValid, errorMessage

    return True, None
示例#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
示例#21
0
def validate_notes(value, field_label=_Experiment.notes.verbose_name):
    errors = []
    if value:
        if not validation.is_valid_chars(value):
            errors.append(validation.invalid_chars_error(field_label))

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

    return errors
示例#22
0
def validate_sample_name(value, displayedName='Sample Name'):
    errors = []    
    if not validation.is_valid_chars(value):
        errors.append(validation.invalid_chars_error(displayedName))
        
    if not validation.is_valid_leading_chars(value):
        errors.append(validation.invalid_chars_error(displayedName))
    
    if not validation.is_valid_length(value, MAX_LENGTH_SAMPLE_NAME):
        errors.append(validation.invalid_length_error(displayedName, MAX_LENGTH_SAMPLE_NAME))

    return errors
示例#23
0
def validate_sample_name(value, displayedName="Sample Name"):
    errors = []
    if not validation.is_valid_chars(value):
        errors.append(validation.invalid_chars_error(displayedName))

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

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

    return errors
示例#24
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
示例#25
0
def validate_sampleExternalId(sampleExternalId):
    isValid = False
    isValid, errorMessage = _validate_textValue(sampleExternalId, "Sample ID ")
    
    if not isValid:
        return isValid, errorMessage

    if not validation.is_valid_length(sampleExternalId.strip(), MAX_LENGTH_SAMPLE_EXTERNAL_ID):
        errorMessage = validation.invalid_length_error("Error, Sample id", MAX_LENGTH_SAMPLE_EXTERNAL_ID) + ". It is currently %s characters long." % str(len(sampleExternalId.strip()))
        return isValid, errorMessage

    return True, None
示例#26
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
示例#27
0
def validate_sample_tube_label(value, field_label):
    errors = []

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

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

    return errors
示例#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
示例#29
0
    def validate_field(self, value, bad_samples, validate_leading_chars=True, max_length=MAX_LENGTH_SAMPLE_NAME):
        exists = False
        if value:
            exists = True
            if not validation.is_valid_chars(value):
                bad_samples.append(value)

            if validate_leading_chars and value not in bad_samples and not validation.is_valid_leading_chars(value):
                bad_samples.append(value)

            if value not in bad_samples and not validation.is_valid_length(value, max_length):
                bad_samples.append(value)

        return exists
示例#30
0
def validate_barcoded_sample_info(
    sampleName,
    sampleName_label,
    sampleExternalId,
    sampleExternalId_label,
    nucleotideType,
    nucleotideType_label,
    sampleReference,
    sampleReference_label,
    runType,
    applicationGroupName,
):
    errors = []
    if not validation.is_valid_chars(sampleName):
        errors.append(validation.invalid_chars_error(sampleName_label))

    if not validation.is_valid_leading_chars(sampleName):
        errors.append(validation.invalid_leading_chars(sampleName_label))

    if not validation.is_valid_length(sampleName, MAX_LENGTH_SAMPLE_NAME):
        errors.append(
            validation.invalid_length_error(sampleName_label,
                                            MAX_LENGTH_SAMPLE_NAME,
                                            sampleName))

    sample_id_errors = validate_sample_id(sampleExternalId,
                                          field_label=sampleExternalId_label)
    if sample_id_errors:
        errors.extend(sample_id_errors)

    nucleotideType_errors, sample_nucleotideType = validate_sample_nucleotideType(
        nucleotideType,
        runType,
        applicationGroupName,
        field_label=nucleotideType_label)
    if nucleotideType_errors:
        errors.extend(nucleotideType_errors)

    ref_errors, ref_short_name = validate_reference(
        sampleReference,
        field_label=sampleReference_label,
        runType=runType,
        applicationGroupName=applicationGroupName,
        application_label=ScientificApplication.verbose_name,
    )
    if ref_errors:
        errors.extend(ref_errors)

    return errors, ref_short_name, sample_nucleotideType
示例#31
0
def validate_sample_name(value, displayedName='Sample Name', isTemplate=None, barcodeId=None):
    errors = []
    if not value:
        if not isTemplate:
            errors.append(validation.required_error(displayedName))
    else:
        if isTemplate:
            errors.append("Invalid input. Sample information cannot be saved in the template")
        if barcodeId:
            errors.append("Invalid input. Barcode kit should not be provided (%s) for non barcoded plan" % barcodeId)
        if not validation.is_valid_chars(value):
            errors.append(validation.invalid_chars_error(displayedName))
        if not validation.is_valid_leading_chars(value):
            errors.append(validation.invalid_chars_error(displayedName))
        if not validation.is_valid_length(value, MAX_LENGTH_SAMPLE_NAME):
            errors.append(validation.invalid_length_error(displayedName, MAX_LENGTH_SAMPLE_NAME))

    return errors
示例#32
0
def _validate_csv_user_defined_attributes(csvSampleDict, request):
    failed = []

    customAttributes = SampleAttribute.objects.filter(isActive=True)

    for attribute in customAttributes:
        newValue = None

        if attribute.displayedName not in list(csvSampleDict.keys()):
            # add mandatory custom attributes for an imported sample if user has not added it
            if attribute.isMandatory:
                failed.append((
                    attribute.displayedName,
                    validation.required_error(attribute.displayedName,
                                              include_error_prefix=True),
                ))
        else:
            newValue = csvSampleDict.get(attribute.displayedName, "").strip()

        if not newValue:
            continue

        if attribute.dataType and attribute.dataType.dataType == "Integer":
            isValid, errorMessage = sample_validator._validate_intValue(
                newValue, attribute.displayedName)
            if not isValid:
                failed.append((attribute.displayedName, errorMessage))
        if attribute.dataType and attribute.dataType.dataType == "Text":
            if not validation.is_valid_length(
                    newValue,
                    sample_validator.MAX_LENGTH_SAMPLE_ATTRIBUTE_VALUE):
                errorMessage = validation.invalid_length_error(
                    attribute.displayedName,
                    sample_validator.MAX_LENGTH_SAMPLE_ATTRIBUTE_VALUE,
                    newValue,
                    include_error_prefix=True,
                )
                failed.append((attribute.displayedName, errorMessage))

    logger.debug(
        "import_sample_processor._validate_csv_user_defined_attributes() failed=%s"
        % (failed))

    return failed
示例#33
0
def validate_sample_name(
    value,
    field_label,
    isTemplate=None,
    isTemplate_label=PlanTemplate.verbose_name,
    barcodeId=None,
    barcodeId_label=ugettext_lazy("workflow.step.kits.fields.barcodeId.label"),
):  # TODO: i18n
    errors = []
    if not value:
        if not isTemplate:
            errors.append(validation.required_error(field_label))
    else:
        if isTemplate:
            errors.append(
                validation.format(
                    ugettext_lazy(
                        "template.messages.validation.invalidsamples"),
                    {"name": isTemplate_label},
                )
            )  # "Invalid input. Sample information cannot be saved in the %(name)s"
        if barcodeId:
            errors.append(
                validation.format(
                    ugettext_lazy(
                        "plannedexperiment.messages.validation.nonbarcoded.barcodesetnotrequired"
                    ),
                    {
                        "barcodeSetName": barcodeId_label,
                        "barcodeSetValue": barcodeId
                    },
                )
            )  # "Invalid input. %(barcodeSetName)s (%(barcodeSetValue)s) should not be provided for non barcoded plan"
        if not validation.is_valid_chars(value):
            errors.append(validation.invalid_chars_error(field_label))
        if not validation.is_valid_leading_chars(value):
            errors.append(validation.invalid_leading_chars(field_label))
        if not validation.is_valid_length(value, MAX_LENGTH_SAMPLE_NAME):
            errors.append(
                validation.invalid_length_error(field_label,
                                                MAX_LENGTH_SAMPLE_NAME, value))

    return errors
示例#34
0
def validate_barcoded_sample_info(applicationGroupName, runType, sampleName, sampleId, nucleotideType, runTypeName, sampleReference, sampleRnaReference, displayedName='Barcoded Sample'):
    errors = []
    if not validation.is_valid_chars(sampleName):
        errors.append(validation.invalid_chars_error(displayedName))
        
    if not validation.is_valid_leading_chars(sampleName):
        errors.append(validation.invalid_chars_error(displayedName))
    
    if not validation.is_valid_length(sampleName, MAX_LENGTH_SAMPLE_NAME):
        errors.append(validation.invalid_length_error(displayedName, MAX_LENGTH_SAMPLE_NAME))

    sample_id_errors = validate_sample_id(sampleId)
    if sample_id_errors:
        errors.extend(sample_id_errors)

    sample_nucleotideType = ""
    
    nucleotideType_errors, sample_nucleotideType = validate_sample_nucleotideType(nucleotideType, runTypeName, applicationGroupName)

    if (nucleotideType_errors):
        errors.extend(nucleotideType_errors)

    if runType == "AMPS_DNA_RNA" and sample_nucleotideType.upper() == "RNA":
        rna_ref_errors, rna_ref_short_name = validate_reference(sampleRnaReference, displayedName = "RNA Sample Reference")
        logger.debug("plan_validator.validate_barcoded_sample_info() sampleRnaReference=%s; rna_ref_short_name=%s" %(sampleRnaReference, rna_ref_short_name))
        
        if (rna_ref_errors):
            errors.extend(rna_ref_errors)

    else:
        rna_ref_errors = []
        rna_ref_short_name = ""

    ref_errors, ref_short_name = validate_reference(sampleReference, displayedName = "Sample Reference")
    ##logger.debug("plan_validator.validate_barcoded_sample_info() sampleReference=%s; ref_short_name=%s" %(sampleReference, ref_short_name))

    if (ref_errors):
        errors.extend(ref_errors)

    ##logger.debug("plan_validator.validate_barcoded_sample_info() errors=%s" %(errors))
    
    return errors, ref_short_name, rna_ref_short_name, sample_nucleotideType 
示例#35
0
def validate_projects(value, displayedName="Project Name", delim=","):
    """
    validate projects case-insensitively with leading/trailing blanks in the input ignored
    """

    errors = []
    trimmed_projects = ""
    if value:
        for project in value.split(delim):
            trimmed_project = project.strip()
            if trimmed_project:
                trimmed_projects = trimmed_projects + trimmed_project + delim

                if not validation.is_valid_chars(trimmed_project):
                    errors.append(validation.invalid_chars_error(displayedName))
                if not validation.is_valid_length(trimmed_project, PROJECT_NAME_LENGTH):
                    errors.append(validation.invalid_length_error(displayedName, PROJECT_NAME_LENGTH))
                if errors:
                    break

    return errors, trimmed_projects
示例#36
0
def validate_sampleName(sampleName):
    displayedTerm = "Sample name"

    isValid, errorMessage = _validate_textValue_mandatory(sampleName, displayedTerm)

    if not isValid:
        return isValid, errorMessage

    isValid, errorMessage =  _validate_textValue(sampleName, displayedTerm)
    if not isValid:
        return isValid, errorMessage

    isValid, errorMessage = _validate_textValue_leadingChars(sampleName, displayedTerm)
    if not isValid:
        return isValid, errorMessage

    if not validation.is_valid_length(sampleName.strip(), MAX_LENGTH_SAMPLE_NAME):
        errorMessage = validation.invalid_length_error("Error, Sample name", MAX_LENGTH_SAMPLE_NAME) + ". It is currently %s characters long." % str(len(sampleName.strip()))
        return isValid, errorMessage

    return True, None
示例#37
0
def validate_barcoded_sample_info(sampleName,
                                  sampleId,
                                  nucleotideType,
                                  runTypeName,
                                  sampleReference,
                                  displayedName='Barcoded Sample'):
    errors = []
    if not validation.is_valid_chars(sampleName):
        errors.append(validation.invalid_chars_error(displayedName))

    if not validation.is_valid_leading_chars(sampleName):
        errors.append(validation.invalid_chars_error(displayedName))

    if not validation.is_valid_length(sampleName, MAX_LENGTH_SAMPLE_NAME):
        errors.append(
            validation.invalid_length_error(displayedName,
                                            MAX_LENGTH_SAMPLE_NAME))

    sample_id_errors = validate_sample_id(sampleId)
    if sample_id_errors:
        errors.extend(sample_id_errors)

    sample_nucleotideType = ""

    nucleotideType_errors, sample_nucleotideType = validate_sample_nucleotideType(
        nucleotideType, runTypeName)
    if (nucleotideType_errors):
        errors.extend(nucleotideType_errors)

    ref_errors, ref_short_name = validate_reference(
        sampleReference, displayedName="Sample Reference")
    ##logger.debug("plan_validator.validate_barcoded_sample_info() sampleReference=%s; ref_short_name=%s" %(sampleReference, ref_short_name))

    if (ref_errors):
        errors.extend(ref_errors)

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

    return errors, ref_short_name, sample_nucleotideType