Search in sources :

Example 16 with ValidationError

use of uk.ac.ebi.spot.goci.model.ValidationError in project goci by EBISPOT.

the class SheetProcessorImpl method readSheetRows.

// Read and parse uploaded spreadsheet
@Override
public Collection<AssociationUploadRow> readSheetRows(XSSFSheet sheet) {
    XSSFRow headerRow = sheet.getRow(0);
    Map<Integer, UploadFileHeader> headerRowMap = createHeaderMap(headerRow);
    // Create collection to store all newly created rows
    Collection<AssociationUploadRow> associationUploadRows = new ArrayList<>();
    Integer lastRow = sheet.getLastRowNum();
    Integer rowNum = 1;
    while (rowNum <= lastRow) {
        AssociationUploadRow associationUploadRow = new AssociationUploadRow();
        // Set row number so its consistent with numbering curator will see via Excel
        associationUploadRow.setRowNumber(rowNum + 1);
        XSSFRow row = sheet.getRow(rowNum);
        // If the row contains defined cell values
        if (row.getPhysicalNumberOfCells() > 0) {
            for (Map.Entry<Integer, UploadFileHeader> heading : headerRowMap.entrySet()) {
                Integer colNum = heading.getKey();
                UploadFileHeader headerName = heading.getValue();
                XSSFCell cell = row.getCell(colNum, Row.RETURN_BLANK_AS_NULL);
                if (cell != null) {
                    try {
                        switch(headerName) {
                            case GENES:
                                associationUploadRow.setAuthorReportedGene(SheetCellProcessingService.processMandatoryStringValue(cell));
                                break;
                            case SNP:
                                associationUploadRow.setSnp(SheetCellProcessingService.processMandatoryStringValue(cell));
                                break;
                            case EFFECT_ALLELE:
                                associationUploadRow.setStrongestAllele(SheetCellProcessingService.processMandatoryStringValue(cell));
                                break;
                            case OTHER_ALLELES:
                                associationUploadRow.setOtherAllele(SheetCellProcessingService.processMandatoryStringValue(cell));
                                break;
                            case PROXY_SNP:
                                associationUploadRow.setProxy(SheetCellProcessingService.processMandatoryStringValue(cell));
                                break;
                            case EFFECT_ELEMENT_FREQUENCY_IN_CONTROLS:
                                associationUploadRow.setAssociationRiskFrequency(SheetCellProcessingService.processStringValue(cell));
                                break;
                            case INDEPENDENT_SNP_EFFECT_ALLELE_FREQUENCY_IN_CONTROLS:
                                associationUploadRow.setRiskFrequency(SheetCellProcessingService.processStringValue(cell));
                                break;
                            case PVALUE_MANTISSA:
                                associationUploadRow.setPvalueMantissa(SheetCellProcessingService.processIntValues(cell));
                                break;
                            case PVALUE_EXPONENT:
                                associationUploadRow.setPvalueExponent(SheetCellProcessingService.processIntValues(cell));
                                break;
                            case PVALUE_DESCRIPTION:
                                associationUploadRow.setPvalueDescription(SheetCellProcessingService.processMandatoryStringValue(cell));
                                break;
                            case OR:
                                associationUploadRow.setOrPerCopyNum(SheetCellProcessingService.processFloatValues(cell));
                                break;
                            case OR_RECIPROCAL:
                                associationUploadRow.setOrPerCopyRecip(SheetCellProcessingService.processFloatValues(cell));
                                break;
                            case BETA:
                                associationUploadRow.setBetaNum(SheetCellProcessingService.processFloatValues(cell));
                                break;
                            case BETA_UNIT:
                                associationUploadRow.setBetaUnit(SheetCellProcessingService.processMandatoryStringValue(cell));
                                break;
                            case BETA_DIRECTION:
                                associationUploadRow.setBetaDirection(SheetCellProcessingService.processMandatoryStringValue(cell));
                                break;
                            case RANGE:
                                associationUploadRow.setRange(SheetCellProcessingService.processMandatoryStringValue(cell));
                                break;
                            case OR_RECIPROCAL_RANGE:
                                associationUploadRow.setOrPerCopyRecipRange(SheetCellProcessingService.processMandatoryStringValue(cell));
                                break;
                            case STANDARD_ERROR:
                                associationUploadRow.setStandardError(SheetCellProcessingService.processFloatValues(cell));
                                break;
                            case DESCRIPTION:
                                associationUploadRow.setDescription(SheetCellProcessingService.processMandatoryStringValue(cell));
                                break;
                            case MULTI_SNP_HAPLOTYPE:
                                associationUploadRow.setMultiSnpHaplotype(SheetCellProcessingService.processMandatoryStringValue(cell));
                                break;
                            case SNP_INTERACTION:
                                associationUploadRow.setSnpInteraction(SheetCellProcessingService.processMandatoryStringValue(cell));
                                break;
                            case SNP_STATUS:
                                associationUploadRow.setSnpStatus(SheetCellProcessingService.processMandatoryStringValue(cell));
                                break;
                            case SNP_TYPE:
                                associationUploadRow.setSnpType(SheetCellProcessingService.processMandatoryStringValue(cell));
                                break;
                            case EFO_TRAITS:
                                associationUploadRow.setEfoTrait(SheetCellProcessingService.processMandatoryStringValue(cell));
                                break;
                            default:
                                getLog().warn("Column with unknown heading found in file.");
                                break;
                        }
                    } catch (CellProcessingException cpe) {
                        // Add an excel error to the list of the errors.
                        ValidationError cpeValidationError = new ValidationError(headerName.toString(), cpe.getMessage(), false, "excel");
                        associationUploadRow.addCellErrorType(cpeValidationError);
                    }
                }
            }
            associationUploadRows.add(associationUploadRow);
        }
        rowNum++;
    }
    return associationUploadRows;
}
Also used : UploadFileHeader(uk.ac.ebi.spot.goci.utils.UploadFileHeader) XSSFRow(org.apache.poi.xssf.usermodel.XSSFRow) CellProcessingException(uk.ac.ebi.spot.goci.exception.CellProcessingException) ArrayList(java.util.ArrayList) XSSFCell(org.apache.poi.xssf.usermodel.XSSFCell) AssociationUploadRow(uk.ac.ebi.spot.goci.model.AssociationUploadRow) ValidationError(uk.ac.ebi.spot.goci.model.ValidationError) HashMap(java.util.HashMap) Map(java.util.Map)

Example 17 with ValidationError

use of uk.ac.ebi.spot.goci.model.ValidationError in project goci by EBISPOT.

the class ValidationChecksBuilder method runLociAttributeChecks.

/**
     * Run loci attributes checks on association
     *
     * @param association association to be checked
     */
public Collection<ValidationError> runLociAttributeChecks(Association association, String eRelease) {
    Collection<ValidationError> validationErrors = new ArrayList<>();
    if (association.getLoci() != null) {
        Set<String> associationGenes = new HashSet<>();
        Collection<ValidationError> geneErrors = new ArrayList<>();
        // Create a unique set of all locus genes
        for (Locus locus : association.getLoci()) {
            Set<String> locusGenes = new HashSet<>();
            if (!locus.getAuthorReportedGenes().isEmpty()) {
                locusGenes = locus.getAuthorReportedGenes().stream().map(Gene::getGeneName).collect(Collectors.toSet());
            }
            associationGenes.addAll(locusGenes);
        }
        // Check genes
        associationGenes.forEach(geneName -> {
            getLog().info("Checking gene: ".concat(geneName));
            ValidationError geneError = errorCreationService.checkGene(geneName, eRelease);
            if (geneError.getError() != null) {
                geneErrors.add(geneError);
            }
        });
        if (!geneErrors.isEmpty()) {
            validationErrors.addAll(geneErrors);
        }
        for (Locus locus : association.getLoci()) {
            Collection<RiskAllele> riskAlleles = locus.getStrongestRiskAlleles();
            // Check risk allele attributes
            riskAlleles.forEach(riskAllele -> {
                ValidationError riskAlleleError = errorCreationService.checkRiskAllele(riskAllele.getRiskAlleleName());
                validationErrors.add(riskAlleleError);
                if (geneErrors.isEmpty()) {
                    Set<String> locusGenes = locus.getAuthorReportedGenes().stream().map(Gene::getGeneName).collect(Collectors.toSet());
                    locusGenes.forEach(geneName -> {
                        getLog().info("Checking snp/gene location: ".concat(geneName).concat(" ").concat(riskAllele.getSnp().getRsId()));
                        ValidationError snpGeneLocationError = errorCreationService.checkSnpGeneLocation(riskAllele.getSnp().getRsId(), geneName, eRelease);
                        validationErrors.add(snpGeneLocationError);
                    });
                } else {
                    ValidationError snpError = errorCreationService.checkSnp(riskAllele.getSnp().getRsId(), eRelease);
                    validationErrors.add(snpError);
                }
            });
        }
    }
    return ErrorProcessingService.checkForValidErrors(validationErrors);
}
Also used : Gene(uk.ac.ebi.spot.goci.model.Gene) RiskAllele(uk.ac.ebi.spot.goci.model.RiskAllele) ArrayList(java.util.ArrayList) ValidationError(uk.ac.ebi.spot.goci.model.ValidationError) Locus(uk.ac.ebi.spot.goci.model.Locus) HashSet(java.util.HashSet)

Example 18 with ValidationError

use of uk.ac.ebi.spot.goci.model.ValidationError in project goci by EBISPOT.

the class AssociationFileUploadService method createAssociationSummary.

/**
     * Process uploaded file, create an association and return a list of its errors
     *
     * @param row             Row to validate and convert into an association
     * @param validationLevel level of validation to run
     */
private AssociationSummary createAssociationSummary(AssociationUploadRow row, String validationLevel, String eRelease) {
    getLog().info("Creating association summary for row " + row.getRowNumber());
    Association association = associationRowProcessor.createAssociationFromUploadRow(row);
    Collection<ValidationError> errors = validationService.runAssociationValidation(association, validationLevel, eRelease);
    AssociationSummary associationSummary = new AssociationSummary();
    associationSummary.setRowNumber(row.getRowNumber());
    associationSummary.setAssociation(association);
    associationSummary.setErrors(errors);
    return associationSummary;
}
Also used : Association(uk.ac.ebi.spot.goci.model.Association) AssociationSummary(uk.ac.ebi.spot.goci.model.AssociationSummary) ValidationError(uk.ac.ebi.spot.goci.model.ValidationError)

Example 19 with ValidationError

use of uk.ac.ebi.spot.goci.model.ValidationError in project goci by EBISPOT.

the class AssociationUploadService method upload.

public List<AssociationUploadErrorView> upload(MultipartFile file, Study study, SecureUser user) throws IOException, EnsemblMappingException {
    // File errors will contain any validation errors and be returned to controller if any are found
    List<AssociationUploadErrorView> fileErrors = new ArrayList<>();
    String originalFilename = file.getOriginalFilename();
    getLog().info("Uploading file: ".concat(originalFilename));
    // Upload file
    try {
        uploadFile(file, study.getId());
        // Send file, including path, to SNP batch loader process
        File uploadedFile = studyFileService.getFileFromFileName(study.getId(), originalFilename);
        ValidationSummary validationSummary = associationFileUploadService.processAndValidateAssociationFile(uploadedFile, "full");
        if (validationSummary != null) {
            // Check if we have any row errors
            long rowErrorCount = validationSummary.getRowValidationSummaries().parallelStream().filter(rowValidationSummary -> !rowValidationSummary.getErrors().isEmpty()).count();
            // Errors found
            if (rowErrorCount > 0) {
                studyFileService.deleteFile(study.getId(), originalFilename);
                getLog().error("Row errors found in file: " + originalFilename);
                validationSummary.getRowValidationSummaries().forEach(rowValidationSummary -> fileErrors.addAll(processRowError(rowValidationSummary)));
            } else {
                // Determine if we have any errors rather than warnings
                // Errors prevent saving association
                List<ValidationError> allAssociationsErrors = new ArrayList<>();
                validationSummary.getAssociationSummaries().forEach(associationSummary -> allAssociationsErrors.addAll(associationSummary.getErrors()));
                long associationErrorCount = allAssociationsErrors.parallelStream().filter(validationError -> !validationError.getWarning()).count();
                if (associationErrorCount > 0) {
                    studyFileService.deleteFile(study.getId(), originalFilename);
                    getLog().error("Association errors found in file: " + originalFilename);
                    validationSummary.getAssociationSummaries().forEach(associationSummary -> fileErrors.addAll(processAssociationError(associationSummary)));
                } else {
                    Integer numberOfAssociations = validationSummary.getAssociationSummaries().size();
                    String description = numberOfAssociations.toString().concat(" associations created from upload of '").concat(originalFilename).concat("'");
                    createBatchUploadEvent(study, description, user);
                    saveAssociations(validationSummary.getAssociationSummaries(), study, user);
                }
            }
        }
        return fileErrors;
    } catch (IOException e) {
        throw new IOException(e);
    }
}
Also used : RowValidationSummary(uk.ac.ebi.spot.goci.model.RowValidationSummary) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) Collection(java.util.Collection) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) ValidationSummary(uk.ac.ebi.spot.goci.model.ValidationSummary) EnsemblMappingException(uk.ac.ebi.spot.goci.exception.EnsemblMappingException) ValidationError(uk.ac.ebi.spot.goci.model.ValidationError) IOException(java.io.IOException) AssociationUploadErrorView(uk.ac.ebi.spot.goci.curation.model.AssociationUploadErrorView) File(java.io.File) TrackingOperationService(uk.ac.ebi.spot.goci.service.TrackingOperationService) ArrayList(java.util.ArrayList) List(java.util.List) Service(org.springframework.stereotype.Service) Association(uk.ac.ebi.spot.goci.model.Association) Qualifier(org.springframework.beans.factory.annotation.Qualifier) MultipartFile(org.springframework.web.multipart.MultipartFile) Study(uk.ac.ebi.spot.goci.model.Study) StudyRepository(uk.ac.ebi.spot.goci.repository.StudyRepository) AssociationFileUploadService(uk.ac.ebi.spot.goci.service.AssociationFileUploadService) AssociationSummary(uk.ac.ebi.spot.goci.model.AssociationSummary) SecureUser(uk.ac.ebi.spot.goci.model.SecureUser) AssociationUploadErrorView(uk.ac.ebi.spot.goci.curation.model.AssociationUploadErrorView) RowValidationSummary(uk.ac.ebi.spot.goci.model.RowValidationSummary) ValidationSummary(uk.ac.ebi.spot.goci.model.ValidationSummary) ArrayList(java.util.ArrayList) ValidationError(uk.ac.ebi.spot.goci.model.ValidationError) IOException(java.io.IOException) File(java.io.File) MultipartFile(org.springframework.web.multipart.MultipartFile)

Example 20 with ValidationError

use of uk.ac.ebi.spot.goci.model.ValidationError in project goci by EBISPOT.

the class ValidationChecksBuilder method runNoEffectChecks.

/**
     * Run no effect checks on a row
     *
     * @param association row to be checked
     */
public Collection<ValidationError> runNoEffectChecks(Association association) {
    Collection<ValidationError> validationErrors = new ArrayList<>();
    ValidationError orFound = errorCreationService.checkOrEmpty(association.getOrPerCopyNum());
    validationErrors.add(orFound);
    ValidationError orRecipFound = errorCreationService.checkOrRecipEmpty(association.getOrPerCopyRecip());
    validationErrors.add(orRecipFound);
    ValidationError orRecipRangeFound = errorCreationService.checkOrPerCopyRecipRangeIsEmpty(association.getOrPerCopyRecipRange());
    validationErrors.add(orRecipRangeFound);
    ValidationError betaFound = errorCreationService.checkBetaValuesIsEmpty(association.getBetaNum());
    validationErrors.add(betaFound);
    ValidationError betaUnitFound = errorCreationService.checkBetaUnitIsEmpty(association.getBetaUnit());
    validationErrors.add(betaUnitFound);
    ValidationError betaDirectionFound = errorCreationService.checkBetaDirectionIsEmpty(association.getBetaDirection());
    validationErrors.add(betaDirectionFound);
    ValidationError rangeFound = errorCreationService.checkRangeIsEmpty(association.getRange());
    validationErrors.add(rangeFound);
    ValidationError standardErrorFound = errorCreationService.checkStandardErrorIsEmpty(association.getStandardError());
    validationErrors.add(standardErrorFound);
    ValidationError descriptionFound = errorCreationService.checkDescriptionIsEmpty(association.getDescription());
    validationErrors.add(descriptionFound);
    return ErrorProcessingService.checkForValidErrors(validationErrors);
}
Also used : ArrayList(java.util.ArrayList) ValidationError(uk.ac.ebi.spot.goci.model.ValidationError)

Aggregations

ValidationError (uk.ac.ebi.spot.goci.model.ValidationError)46 Test (org.junit.Test)32 ArrayList (java.util.ArrayList)11 Locus (uk.ac.ebi.spot.goci.model.Locus)3 Association (uk.ac.ebi.spot.goci.model.Association)2 AssociationSummary (uk.ac.ebi.spot.goci.model.AssociationSummary)2 RowValidationSummary (uk.ac.ebi.spot.goci.model.RowValidationSummary)2 File (java.io.File)1 IOException (java.io.IOException)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Map (java.util.Map)1 XSSFCell (org.apache.poi.xssf.usermodel.XSSFCell)1 XSSFRow (org.apache.poi.xssf.usermodel.XSSFRow)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1