示例#1
0
def validate_csv_sample(csvSampleDict, request):
    """ 
    validate csv contents and convert user input to raw data to prepare for sample persistence
    returns: a collection of error messages if errors found and whether to skip the row
    """
    failed = []
    isToSkipRow = False

    logger.debug("ENTER import_sample_processor.validate_csv_sample() csvSampleDict=%s; " %(csvSampleDict))
        
    sampleDisplayedName = csvSampleDict.get(COLUMN_SAMPLE_NAME, '').strip()
    sampleExtId = csvSampleDict.get(COLUMN_SAMPLE_EXT_ID, '').strip()
    sampleGender = csvSampleDict.get(COLUMN_GENDER, '').strip()
    sampleGroupType = csvSampleDict.get(COLUMN_GROUP_TYPE, '').strip()
    sampleGroup = csvSampleDict.get(COLUMN_GROUP, '').strip()
    sampleDescription = csvSampleDict.get(COLUMN_SAMPLE_DESCRIPTION, '').strip()
    barcodeAssignment = csvSampleDict.get(COLUMN_BARCODE, '').strip()
        
    #skip blank line
    hasAtLeastOneValue = bool([v for v in csvSampleDict.values() if v != ''])
    if not hasAtLeastOneValue:
        isToSkipRow = True
        return failed, isToSkipRow
    
    isValid, errorMessage = sample_validator.validate_sampleDisplayedName(sampleDisplayedName)
    if not isValid:
        failed.append((COLUMN_SAMPLE_NAME, errorMessage))    
        
    isValid, errorMessage = sample_validator.validate_sampleExternalId(sampleExtId)
    if not isValid:
        failed.append((COLUMN_SAMPLE_EXT_ID, errorMessage))
        
    isValid, errorMessage = sample_validator.validate_sampleDescription(sampleDescription)
    if not isValid:
        failed.append((COLUMN_SAMPLE_DESCRIPTION, errorMessage))
        
    isValid, errorMessage, gender_CV_value = sample_validator.validate_sampleGender(sampleGender)
    if not isValid:
        failed.append((COLUMN_GENDER, errorMessage))
       
    isValid, errorMessage, role_CV_value = sample_validator.validate_sampleGroupType(sampleGroupType)
    if not isValid:
        failed.append((COLUMN_GROUP_TYPE, errorMessage))
        
    if sampleGroup: 
        isValid, errorMessage = sample_validator.validate_sampleGroup(sampleGroup)
        if not isValid:
            failed.append((COLUMN_GROUP, errorMessage))
            
    if not isValid:
        failed.append((COLUMN_BARCODE, errorMessage))

    #validate user-defined custom attributes
    failed_userDefined = _validate_csv_user_defined_attributes(csvSampleDict, request)
    failed.extend(failed_userDefined)
               
    logger.debug("import_sample_processor.validate_csv_sample() failed=%s" %(failed))
        
    return failed, isToSkipRow
示例#2
0
def validate_csv_sample(csvSampleDict, request):
    """
    validate csv contents and convert user input to raw data to prepare for sample persistence
    returns: a collection of error messages if errors found and whether to skip the row
    """
    failed = []
    isToSkipRow = False
    isToAbort = False

    logger.debug("ENTER import_sample_processor.validate_csv_sample() csvSampleDict=%s; " % (csvSampleDict))

    try:
        sampleDisplayedName = csvSampleDict.get(COLUMN_SAMPLE_NAME, '').strip()
        sampleExtId = csvSampleDict.get(COLUMN_SAMPLE_EXT_ID, '').strip()
        sampleControlType = csvSampleDict.get(COLUMN_CONTROLTYPE, '').strip()
        sampleGender = csvSampleDict.get(COLUMN_GENDER, '').strip()
        sampleGroupType = csvSampleDict.get(COLUMN_GROUP_TYPE, '').strip()
        sampleGroup = csvSampleDict.get(COLUMN_GROUP, '').strip()
        sampleDescription = csvSampleDict.get(COLUMN_SAMPLE_DESCRIPTION, '').strip()
        barcodeKit = csvSampleDict.get(COLUMN_BARCODE_KIT, '')
        barcodeAssignment = csvSampleDict.get(COLUMN_BARCODE, '')

        nucleotideType = csvSampleDict.get(COLUMN_NUCLEOTIDE_TYPE, "").strip()

        cancerType = csvSampleDict.get(COLUMN_CANCER_TYPE, "").strip()
        cellularityPct = csvSampleDict.get(COLUMN_CELLULARITY_PCT, None).strip()
        pcrPlateRow = csvSampleDict.get(COLUMN_PCR_PLATE_POSITION, "").strip()

        biopsyDays = csvSampleDict.get(COLUMN_BIOPSY_DAYS, "0").strip()
        cellNum = csvSampleDict.get(COLUMN_CELL_NUM, "").strip()
        coupleId = csvSampleDict.get(COLUMN_COUPLE_ID, "").strip()
        embryoId = csvSampleDict.get(COLUMN_EMBRYO_ID, "").strip()

        # Trim off barcode and barcode kit leading and trailing spaces and update the log file if exists
        if ((len(barcodeKit) - len(barcodeKit.lstrip())) or
                (len(barcodeKit) - len(barcodeKit.rstrip()))):
            logger.warning("The BarcodeKitName(%s) contains Leading/Trailing spaces and got trimmed." % barcodeKit)

        if ((len(barcodeAssignment) - len(barcodeAssignment.lstrip())) or
                (len(barcodeAssignment) - len(barcodeAssignment.rstrip()))):
            logger.warning("The BarcodeName (%s) of BarcodeKitName(%s) contains Leading/Trailing spaces and got trimmed." % (barcodeAssignment, barcodeKit))

        barcodeKit = barcodeKit.strip()
        barcodeAssignment = barcodeAssignment.strip()

        # skip blank line
        hasAtLeastOneValue = bool([v for v in csvSampleDict.values() if v != ''])
        if not hasAtLeastOneValue:
            isToSkipRow = True
            return failed, isToSkipRow, isToAbort

        isValid, errorMessage = sample_validator.validate_sampleDisplayedName(sampleDisplayedName)
        if not isValid:
            failed.append((COLUMN_SAMPLE_NAME, errorMessage))

        isValid, errorMessage = sample_validator.validate_sampleExternalId(sampleExtId)
        if not isValid:
            failed.append((COLUMN_SAMPLE_EXT_ID, errorMessage))

        isValid, errorMessage = sample_validator.validate_sampleDescription(sampleDescription)
        if not isValid:
            failed.append((COLUMN_SAMPLE_DESCRIPTION, errorMessage))

        isValid, errorMessage, gender_CV_value = sample_validator.validate_sampleGender(sampleGender)
        if not isValid:
            failed.append((COLUMN_GENDER, errorMessage))

        isValid, errorMessage, role_CV_value = sample_validator.validate_sampleGroupType(sampleGroupType)
        if not isValid:
            failed.append((COLUMN_GROUP_TYPE, errorMessage))

        if sampleGroup:
            isValid, errorMessage = sample_validator.validate_sampleGroup(sampleGroup)
            if not isValid:
                failed.append((COLUMN_GROUP, errorMessage))

        if cancerType:
            isValid, errorMessage, cancerType_CV_value = sample_validator.validate_cancerType(cancerType)
            if not isValid:
                failed.append((COLUMN_CANCER_TYPE, errorMessage))

        if cellularityPct:
            isValid, errorMessage, value = sample_validator.validate_cellularityPct(cellularityPct)
            if not isValid:
                failed.append((COLUMN_CELLULARITY_PCT, errorMessage))

        if nucleotideType:
            isValid, errorMessage, nucleotideType_internal_value = sample_validator.validate_nucleotideType(nucleotideType)
            if not isValid:
                failed.append((COLUMN_NUCLEOTIDE_TYPE, errorMessage))

        if pcrPlateRow:
            isValid, errorMessage, pcrPlateRow_internal_value = sample_validator.validate_pcrPlateRow(pcrPlateRow)
            if not isValid:
                failed.append((COLUMN_PCR_PLATE_POSITION, errorMessage))

        if biopsyDays:
            isValid, errorMessage = sample_validator.validate_sampleBiopsyDays(biopsyDays)
            if not isValid:
                failed.append((COLUMN_BIOPSY_DAYS, errorMessage))

        if cellNum:
            isValid, errorMessage = sample_validator.validate_sampleCellNum(cellNum)
            if not isValid:
                failed.append((COLUMN_CELL_NUM, errorMessage))

        if coupleId:
            isValid, errorMessage = sample_validator.validate_sampleCoupleId(coupleId)
            if not isValid:
                failed.append((COLUMN_COUPLE_ID, errorMessage))

        if embryoId:
            isValid, errorMessage = sample_validator.validate_sampleEmbryoId(embryoId)
            if not isValid:
                failed.append((COLUMN_EMBRYO_ID, errorMessage))

        if sampleControlType:
            isValid, errorMessage, controlType_CV_value = sample_validator.validate_controlType(sampleControlType)
            if not isValid:
                failed.append((COLUMN_CONTROLTYPE, errorMessage))

        # NEW VALIDATION FOR BARCODEKIT AND BARCODE_ID_STR
        isValid, errorMessage, item = sample_validator.validate_barcodekit_and_id_str(barcodeKit, barcodeAssignment)
        if not isValid:
            if item == 'barcodeKit':
                failed.append((COLUMN_BARCODE_KIT, errorMessage))
            else:
                failed.append((COLUMN_BARCODE, errorMessage))
        # if not isValid:
        #     failed.append((COLUMN_BARCODE, errorMessage))

        # validate user-defined custom attributes
        failed_userDefined = _validate_csv_user_defined_attributes(csvSampleDict, request)
        failed.extend(failed_userDefined)

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

        return failed, isToSkipRow, isToAbort

    except:
        logger.exception(format_exc())

        failed.append(("File Contents", " the CSV file does not seem to have all the columns. Click the Sample File Format button for an example. "))
        isToAbort = True
        logger.debug("import_sample_processor.validate_csv_sample() failed=%s" % (failed))
        return failed, isToSkipRow, isToAbort
def validate_csv_sample(csvSampleDict, request):
    """ 
    validate csv contents and convert user input to raw data to prepare for sample persistence
    returns: a collection of error messages if errors found and whether to skip the row
    """
    failed = []
    isToSkipRow = False
    isToAbort = False

    logger.debug("ENTER import_sample_processor.validate_csv_sample() csvSampleDict=%s; " %(csvSampleDict))
    
    try:
        sampleDisplayedName = csvSampleDict.get(COLUMN_SAMPLE_NAME, '').strip()
        sampleExtId = csvSampleDict.get(COLUMN_SAMPLE_EXT_ID, '').strip()
        sampleGender = csvSampleDict.get(COLUMN_GENDER, '').strip()
        sampleGroupType = csvSampleDict.get(COLUMN_GROUP_TYPE, '').strip()
        sampleGroup = csvSampleDict.get(COLUMN_GROUP, '').strip()
        sampleDescription = csvSampleDict.get(COLUMN_SAMPLE_DESCRIPTION, '').strip()
        barcodeKit = csvSampleDict.get(COLUMNS_BARCODE_KIT, '').strip()
        barcodeAssignment = csvSampleDict.get(COLUMN_BARCODE, '').strip()
        
        nucleotideType = csvSampleDict.get(COLUMN_NUCLEOTIDE_TYPE, "").strip()
     
        cancerType = csvSampleDict.get(COLUMN_CANCER_TYPE, "").strip()
        cellularityPct = csvSampleDict.get(COLUMN_CELLULARITY_PCT, None).strip()
        pcrPlateRow = csvSampleDict.get(COLUMN_PCR_PLATE_POSITION, "").strip()
        
        #skip blank line
        hasAtLeastOneValue = bool([v for v in csvSampleDict.values() if v != ''])
        if not hasAtLeastOneValue:
            isToSkipRow = True
            return failed, isToSkipRow, isToAbort
        
        isValid, errorMessage = sample_validator.validate_sampleDisplayedName(sampleDisplayedName)
        if not isValid:
            failed.append((COLUMN_SAMPLE_NAME, errorMessage))    
            
        isValid, errorMessage = sample_validator.validate_sampleExternalId(sampleExtId)
        if not isValid:
            failed.append((COLUMN_SAMPLE_EXT_ID, errorMessage))
            
        isValid, errorMessage = sample_validator.validate_sampleDescription(sampleDescription)
        if not isValid:
            failed.append((COLUMN_SAMPLE_DESCRIPTION, errorMessage))
            
        isValid, errorMessage, gender_CV_value = sample_validator.validate_sampleGender(sampleGender)
        if not isValid:
            failed.append((COLUMN_GENDER, errorMessage))
           
        isValid, errorMessage, role_CV_value = sample_validator.validate_sampleGroupType(sampleGroupType)
        if not isValid:
            failed.append((COLUMN_GROUP_TYPE, errorMessage))
            
        if sampleGroup: 
            isValid, errorMessage = sample_validator.validate_sampleGroup(sampleGroup)
            if not isValid:
                failed.append((COLUMN_GROUP, errorMessage))
    
        if cancerType:
            isValid, errorMessage, cancerType_CV_value = sample_validator.validate_cancerType(cancerType) 
            if not isValid:
                failed.append((COLUMN_CANCER_TYPE, errorMessage))
        
        if cellularityPct:
            isValid, errorMessage, value = sample_validator.validate_cellularityPct(cellularityPct)
            if not isValid:
                failed.append((COLUMN_CELLULARITY_PCT, errorMessage))     

        if nucleotideType:
            isValid, errorMessage, nucleotideType_internal_value = sample_validator.validate_nucleotideType(nucleotideType)
            if not isValid:
                failed.append((COLUMN_NUCLEOTIDE_TYPE, errorMessage))     
        
        if pcrPlateRow:
            isValid, errorMessage, pcrPlateRow_internal_value = sample_validator.validate_pcrPlateRow(pcrPlateRow)
            if not isValid:
                failed.append((COLUMN_PCR_PLATE_POSITION, errorMessage))     

        ##NEW VALIDATION FOR BARCODEKIT AND BARCODE_ID_STR
        isValid, errorMessage, item = sample_validator.validate_barcodekit_and_id_str(barcodeKit, barcodeAssignment)
        if not isValid:
            if item == 'barcodeKit':
                failed.append((COLUMNS_BARCODE_KIT, errorMessage))
            else:
                failed.append((COLUMN_BARCODE, errorMessage))
        # if not isValid:
        #     failed.append((COLUMN_BARCODE, errorMessage))
    
        #validate user-defined custom attributes
        failed_userDefined = _validate_csv_user_defined_attributes(csvSampleDict, request)
        failed.extend(failed_userDefined)
                   
        logger.debug("import_sample_processor.validate_csv_sample() failed=%s" %(failed))
            
        return failed, isToSkipRow, isToAbort
    
    except:
        logger.exception(format_exc())
        
        failed.append(("File Contents", " the CSV file does not seem to have all the columns. Click the Sample File Format button for an example. "))
        isToAbort = True               
        logger.debug("import_sample_processor.validate_csv_sample() failed=%s" %(failed))        
        return failed, isToSkipRow, isToAbort
示例#4
0
def validate_csv_sample(csvSampleDict, request):
    """
    validate csv contents and convert user input to raw data to prepare for sample persistence
    returns: a collection of error messages if errors found and whether to skip the row
    """
    failed = []
    isToSkipRow = False
    isToAbort = False

    logger.debug(
        "ENTER import_sample_processor.validate_csv_sample() csvSampleDict=%s; "
        % (csvSampleDict))
    try:

        sampleDisplayedName = csvSampleDict.get(COLUMN_SAMPLE_NAME, "").strip()
        sampleExtId = csvSampleDict.get(COLUMN_SAMPLE_EXT_ID, "").strip()
        sampleControlType = csvSampleDict.get(COLUMN_CONTROLTYPE, "").strip()
        sampleGender = csvSampleDict.get(COLUMN_GENDER, "").strip()
        sampleGroupType = csvSampleDict.get(COLUMN_GROUP_TYPE, "").strip()
        sampleGroup = csvSampleDict.get(COLUMN_GROUP, "").strip()
        if not sampleGroup:
            sampleGroup = None
        sampleDescription = csvSampleDict.get(COLUMN_SAMPLE_DESCRIPTION,
                                              "").strip()
        barcodeKit = csvSampleDict.get(COLUMN_BARCODE_KIT, "")
        barcodeAssignment = csvSampleDict.get(COLUMN_BARCODE, "")

        nucleotideType = csvSampleDict.get(COLUMN_NUCLEOTIDE_TYPE, "").strip()

        cancerType = csvSampleDict.get(COLUMN_CANCER_TYPE, "").strip()
        cellularityPct = csvSampleDict.get(COLUMN_CELLULARITY_PCT,
                                           None).strip()
        if not cellularityPct:
            cellularityPct = None
        pcrPlateRow = csvSampleDict.get(COLUMN_PCR_PLATE_POSITION, "").strip()

        biopsyDays = csvSampleDict.get(COLUMN_BIOPSY_DAYS, "0").strip()
        cellNum = csvSampleDict.get(COLUMN_CELL_NUM, "").strip()
        coupleId = csvSampleDict.get(COLUMN_COUPLE_ID, "").strip()
        embryoId = csvSampleDict.get(COLUMN_EMBRYO_ID, "").strip()
        sampleSource = csvSampleDict.get(COLUMN_SAMPLE_SOURCE, "").strip()
        panelPoolType = csvSampleDict.get(COLUMN_PANEL_POOL_TYPE, "").strip()
        sampleCollectionDate = csvSampleDict.get(COLUMN_SAMPLE_COLLECTION_DATE,
                                                 "").strip()
        sampleReceiptDate = csvSampleDict.get(COLUMN_SAMPLE_RECEIPT_DATE,
                                              "").strip()
        population = csvSampleDict.get(COLUMN_SAMPLE_POPULATION, "").strip()
        mouseStrains = csvSampleDict.get(COLUMN_SAMPLE_MOUSE_STRAINS,
                                         "").strip()

        # Trim off barcode and barcode kit leading and trailing spaces and update the log file if exists
        if (len(barcodeKit) - len(barcodeKit.lstrip())) or (
                len(barcodeKit) - len(barcodeKit.rstrip())):
            logger.warning(
                "The BarcodeKitName(%s) contains Leading/Trailing spaces and got trimmed."
                % barcodeKit)

        if (len(barcodeAssignment) - len(barcodeAssignment.lstrip())) or (
                len(barcodeAssignment) - len(barcodeAssignment.rstrip())):
            logger.warning(
                "The BarcodeName (%s) of BarcodeKitName(%s) contains Leading/Trailing spaces and got trimmed."
                % (barcodeAssignment, barcodeKit))

        barcodeKit = barcodeKit.strip()
        barcodeAssignment = barcodeAssignment.strip()

        # skip blank line
        hasAtLeastOneValue = bool(
            [v for v in list(csvSampleDict.values()) if v != ""])
        if not hasAtLeastOneValue:
            isToSkipRow = True
            return failed, isToSkipRow, isToAbort

        isValid, errorMessage = sample_validator.validate_sampleDisplayedName(
            sampleDisplayedName, field_label=COLUMN_SAMPLE_NAME)
        if not isValid:
            failed.append((COLUMN_SAMPLE_NAME, errorMessage))

        isValid, errorMessage = sample_validator.validate_sampleExternalId(
            sampleExtId, field_label=COLUMN_SAMPLE_EXT_ID)
        if not isValid:
            failed.append((COLUMN_SAMPLE_EXT_ID, errorMessage))

        isValid, errorMessage = sample_validator.validate_sampleDescription(
            sampleDescription, field_label=COLUMN_SAMPLE_DESCRIPTION)
        if not isValid:
            failed.append((COLUMN_SAMPLE_DESCRIPTION, errorMessage))

        isValid, errorMessage, gender_CV_value = sample_validator.validate_sampleGender(
            sampleGender, field_label=COLUMN_GENDER)
        if not isValid:
            failed.append((COLUMN_GENDER, errorMessage))

        isValid, errorMessage, role_CV_value = sample_validator.validate_sampleGroupType(
            sampleGroupType, field_label=COLUMN_GROUP_TYPE)
        if not isValid:
            failed.append((COLUMN_GROUP_TYPE, errorMessage))

        if sampleGroup:
            isValid, errorMessage = sample_validator.validate_sampleGroup(
                sampleGroup, field_label=COLUMN_GROUP)
            if not isValid:
                failed.append((COLUMN_GROUP, errorMessage))

        if cancerType:
            isValid, errorMessage, cancerType_CV_value = sample_validator.validate_cancerType(
                cancerType, field_label=COLUMN_CANCER_TYPE)
            if not isValid:
                failed.append((COLUMN_CANCER_TYPE, errorMessage))

        if cellularityPct:
            isValid, errorMessage = sample_validator.validate_cellularityPct(
                cellularityPct, field_label=COLUMN_CELLULARITY_PCT)
            if not isValid:
                failed.append((COLUMN_CELLULARITY_PCT, errorMessage))

        if pcrPlateRow:
            isValid, errorMessage, pcrPlateRow_internal_value = sample_validator.validate_pcrPlateRow(
                pcrPlateRow, field_label=COLUMN_PCR_PLATE_POSITION)
            if not isValid:
                failed.append((COLUMN_PCR_PLATE_POSITION, errorMessage))

        if nucleotideType:
            isValid, errorMessage, nucleotideType_internal_value = sample_validator.validate_nucleotideType(
                nucleotideType, field_label=COLUMN_NUCLEOTIDE_TYPE)
            if not isValid:
                failed.append((COLUMN_NUCLEOTIDE_TYPE, errorMessage))

        if biopsyDays:
            isValid, errorMessage = sample_validator.validate_sampleBiopsyDays(
                biopsyDays, field_label=COLUMN_BIOPSY_DAYS)
            if not isValid:
                failed.append((COLUMN_BIOPSY_DAYS, errorMessage))

        if cellNum:
            isValid, errorMessage = sample_validator.validate_sampleCellNum(
                cellNum, field_label=COLUMN_CELL_NUM)
            if not isValid:
                failed.append((COLUMN_CELL_NUM, errorMessage))

        if coupleId:
            isValid, errorMessage = sample_validator.validate_sampleCoupleId(
                coupleId, field_label=COLUMN_COUPLE_ID)
            if not isValid:
                failed.append((COLUMN_COUPLE_ID, errorMessage))

        if embryoId:
            isValid, errorMessage = sample_validator.validate_sampleEmbryoId(
                embryoId, field_label=COLUMN_EMBRYO_ID)
            if not isValid:
                failed.append((COLUMN_EMBRYO_ID, errorMessage))

        if sampleControlType:
            isValid, errorMessage, controlType_CV_value = sample_validator.validate_controlType(
                sampleControlType, field_label=COLUMN_CONTROLTYPE)
            if not isValid:
                failed.append((COLUMN_CONTROLTYPE, errorMessage))
        if population:
            isValid, errorMessage, _ = sample_validator.validate_population(
                population)
            if not isValid:
                failed.append((COLUMN_SAMPLE_POPULATION, errorMessage))
        if mouseStrains:
            isValid, errorMessage, _ = sample_validator.validate_mouseStrains(
                mouseStrains)
            if not isValid:
                failed.append((COLUMN_SAMPLE_MOUSE_STRAINS, errorMessage))
        if sampleSource:
            isValid, errorMessage, _ = sample_validator.validate_sampleSource(
                sampleSource)
            if not isValid:
                failed.append((COLUMN_SAMPLE_SOURCE, errorMessage))
        if panelPoolType:
            isValid, errorMessage, _ = sample_validator.validate_panelPoolType(
                panelPoolType)
            if not isValid:
                failed.append((COLUMN_PANEL_POOL_TYPE, errorMessage))
        if sampleCollectionDate:
            isValid, errorMessage = sample_validator.validate_sampleCollectionDate(
                sampleCollectionDate)
            if not isValid:
                failed.append((COLUMN_SAMPLE_COLLECTION_DATE, errorMessage))
        if sampleReceiptDate:
            isValid, errorMessage = sample_validator.validate_sampleReceiptDate(
                sampleReceiptDate, sampleCollectionDate)
            if not isValid:
                failed.append((COLUMN_SAMPLE_RECEIPT_DATE, errorMessage))

        # NEW VALIDATION FOR BARCODEKIT AND BARCODE_ID_STR
        isValid, errorMessage, item = sample_validator.validate_barcodekit_and_id_str(
            barcodeKit,
            barcodeAssignment,
            barcodeKit_label=COLUMN_BARCODE_KIT,
            barcode_id_str_label=COLUMN_BARCODE,
        )  # TODO: i18n
        if not isValid:
            if item == "barcodeKit":
                failed.append((COLUMN_BARCODE_KIT, errorMessage))
            else:
                failed.append((COLUMN_BARCODE, errorMessage))
        # if not isValid:
        #     failed.append((COLUMN_BARCODE, errorMessage))

        # validate user-defined custom attributes
        failed_userDefined = _validate_csv_user_defined_attributes(
            csvSampleDict, request)
        failed.extend(failed_userDefined)

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

        return failed, isToSkipRow, isToAbort

    except Exception:
        logger.exception(format_exc())
        failed.append((
            "File Contents",
            " the CSV file does not seem to have all the columns. Click the Sample File Format button for an example. ",
        ))  # TODO: i18n
        logger.debug(
            "import_sample_processor.validate_csv_sample() failed=%s" %
            (failed))
        return failed, isToSkipRow, True
示例#5
0
def validate_csv_sample(csvSampleDict, request):
    """ 
    validate csv contents and convert user input to raw data to prepare for sample persistence
    returns: a collection of error messages if errors found and whether to skip the row
    """
    failed = []
    isToSkipRow = False
    isToAbort = False

    logger.debug(
        "ENTER import_sample_processor.validate_csv_sample() csvSampleDict=%s; "
        % (csvSampleDict))

    try:
        sampleDisplayedName = csvSampleDict.get(COLUMN_SAMPLE_NAME, '').strip()
        sampleExtId = csvSampleDict.get(COLUMN_SAMPLE_EXT_ID, '').strip()
        sampleGender = csvSampleDict.get(COLUMN_GENDER, '').strip()
        sampleGroupType = csvSampleDict.get(COLUMN_GROUP_TYPE, '').strip()
        sampleGroup = csvSampleDict.get(COLUMN_GROUP, '').strip()
        sampleDescription = csvSampleDict.get(COLUMN_SAMPLE_DESCRIPTION,
                                              '').strip()
        barcodeKit = csvSampleDict.get(COLUMN_BARCODE_KIT, '').strip()
        barcodeAssignment = csvSampleDict.get(COLUMN_BARCODE, '').strip()

        nucleotideType = csvSampleDict.get(COLUMN_NUCLEOTIDE_TYPE, "").strip()

        cancerType = csvSampleDict.get(COLUMN_CANCER_TYPE, "").strip()
        cellularityPct = csvSampleDict.get(COLUMN_CELLULARITY_PCT,
                                           None).strip()
        pcrPlateRow = csvSampleDict.get(COLUMN_PCR_PLATE_POSITION, "").strip()

        biopsyDays = csvSampleDict.get(COLUMN_BIOPSY_DAYS, "0").strip()
        coupleId = csvSampleDict.get(COLUMN_COUPLE_ID, "").strip()
        embryoId = csvSampleDict.get(COLUMN_EMBRYO_ID, "").strip()

        #skip blank line
        hasAtLeastOneValue = bool(
            [v for v in csvSampleDict.values() if v != ''])
        if not hasAtLeastOneValue:
            isToSkipRow = True
            return failed, isToSkipRow, isToAbort

        isValid, errorMessage = sample_validator.validate_sampleDisplayedName(
            sampleDisplayedName)
        if not isValid:
            failed.append((COLUMN_SAMPLE_NAME, errorMessage))

        isValid, errorMessage = sample_validator.validate_sampleExternalId(
            sampleExtId)
        if not isValid:
            failed.append((COLUMN_SAMPLE_EXT_ID, errorMessage))

        isValid, errorMessage = sample_validator.validate_sampleDescription(
            sampleDescription)
        if not isValid:
            failed.append((COLUMN_SAMPLE_DESCRIPTION, errorMessage))

        isValid, errorMessage, gender_CV_value = sample_validator.validate_sampleGender(
            sampleGender)
        if not isValid:
            failed.append((COLUMN_GENDER, errorMessage))

        isValid, errorMessage, role_CV_value = sample_validator.validate_sampleGroupType(
            sampleGroupType)
        if not isValid:
            failed.append((COLUMN_GROUP_TYPE, errorMessage))

        if sampleGroup:
            isValid, errorMessage = sample_validator.validate_sampleGroup(
                sampleGroup)
            if not isValid:
                failed.append((COLUMN_GROUP, errorMessage))

        if cancerType:
            isValid, errorMessage, cancerType_CV_value = sample_validator.validate_cancerType(
                cancerType)
            if not isValid:
                failed.append((COLUMN_CANCER_TYPE, errorMessage))

        if cellularityPct:
            isValid, errorMessage, value = sample_validator.validate_cellularityPct(
                cellularityPct)
            if not isValid:
                failed.append((COLUMN_CELLULARITY_PCT, errorMessage))

        if nucleotideType:
            isValid, errorMessage, nucleotideType_internal_value = sample_validator.validate_nucleotideType(
                nucleotideType)
            if not isValid:
                failed.append((COLUMN_NUCLEOTIDE_TYPE, errorMessage))

        if pcrPlateRow:
            isValid, errorMessage, pcrPlateRow_internal_value = sample_validator.validate_pcrPlateRow(
                pcrPlateRow)
            if not isValid:
                failed.append((COLUMN_PCR_PLATE_POSITION, errorMessage))

        if biopsyDays:
            isValid, errorMessage = sample_validator.validate_sampleBiopsyDays(
                biopsyDays)
            if not isValid:
                failed.append((COLUMN_BIOPSY_DAYS, errorMessage))

        if coupleId:
            isValid, errorMessage = sample_validator.validate_sampleCoupleId(
                coupleId)
            if not isValid:
                failed.append((COLUMN_COUPLE_ID, errorMessage))

        if embryoId:
            isValid, errorMessage = sample_validator.validate_sampleEmbryoId(
                embryoId)
            if not isValid:
                failed.append((COLUMN_EMBRYO_ID, errorMessage))

        ##NEW VALIDATION FOR BARCODEKIT AND BARCODE_ID_STR
        isValid, errorMessage, item = sample_validator.validate_barcodekit_and_id_str(
            barcodeKit, barcodeAssignment)
        if not isValid:
            if item == 'barcodeKit':
                failed.append((COLUMN_BARCODE_KIT, errorMessage))
            else:
                failed.append((COLUMN_BARCODE, errorMessage))
        # if not isValid:
        #     failed.append((COLUMN_BARCODE, errorMessage))

        #validate user-defined custom attributes
        failed_userDefined = _validate_csv_user_defined_attributes(
            csvSampleDict, request)
        failed.extend(failed_userDefined)

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

        return failed, isToSkipRow, isToAbort

    except:
        logger.exception(format_exc())

        failed.append((
            "File Contents",
            " the CSV file does not seem to have all the columns. Click the Sample File Format button for an example. "
        ))
        isToAbort = True
        logger.debug(
            "import_sample_processor.validate_csv_sample() failed=%s" %
            (failed))
        return failed, isToSkipRow, isToAbort
示例#6
0
def validate_csv_sample(csvSampleDict, request):
    """ 
    validate csv contents and convert user input to raw data to prepare for sample persistence
    returns: a collection of error messages if errors found and whether to skip the row
    """
    failed = []
    isToSkipRow = False

    logger.debug(
        "ENTER import_sample_processor.validate_csv_sample() csvSampleDict=%s; "
        % (csvSampleDict))

    sampleDisplayedName = csvSampleDict.get(COLUMN_SAMPLE_NAME, '').strip()
    sampleExtId = csvSampleDict.get(COLUMN_SAMPLE_EXT_ID, '').strip()
    sampleGender = csvSampleDict.get(COLUMN_GENDER, '').strip()
    sampleGroupType = csvSampleDict.get(COLUMN_GROUP_TYPE, '').strip()
    sampleGroup = csvSampleDict.get(COLUMN_GROUP, '').strip()
    sampleDescription = csvSampleDict.get(COLUMN_SAMPLE_DESCRIPTION,
                                          '').strip()
    barcodeAssignment = csvSampleDict.get(COLUMN_BARCODE, '').strip()

    #skip blank line
    hasAtLeastOneValue = bool([v for v in csvSampleDict.values() if v != ''])
    if not hasAtLeastOneValue:
        isToSkipRow = True
        return failed, isToSkipRow

    isValid, errorMessage = sample_validator.validate_sampleDisplayedName(
        sampleDisplayedName)
    if not isValid:
        failed.append((COLUMN_SAMPLE_NAME, errorMessage))

    isValid, errorMessage = sample_validator.validate_sampleExternalId(
        sampleExtId)
    if not isValid:
        failed.append((COLUMN_SAMPLE_EXT_ID, errorMessage))

    isValid, errorMessage = sample_validator.validate_sampleDescription(
        sampleDescription)
    if not isValid:
        failed.append((COLUMN_SAMPLE_DESCRIPTION, errorMessage))

    isValid, errorMessage, gender_CV_value = sample_validator.validate_sampleGender(
        sampleGender)
    if not isValid:
        failed.append((COLUMN_GENDER, errorMessage))

    isValid, errorMessage, role_CV_value = sample_validator.validate_sampleGroupType(
        sampleGroupType)
    if not isValid:
        failed.append((COLUMN_GROUP_TYPE, errorMessage))

    if sampleGroup:
        isValid, errorMessage = sample_validator.validate_sampleGroup(
            sampleGroup)
        if not isValid:
            failed.append((COLUMN_GROUP, errorMessage))

    if not isValid:
        failed.append((COLUMN_BARCODE, errorMessage))

    #validate user-defined custom attributes
    failed_userDefined = _validate_csv_user_defined_attributes(
        csvSampleDict, request)
    failed.extend(failed_userDefined)

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

    return failed, isToSkipRow