Search in sources :

Example 1 with AssociationUploadRow

use of uk.ac.ebi.spot.goci.model.AssociationUploadRow 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 SECONDARY_EFFECT_ALLELE:
                                associationUploadRow.setEffectAllele(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 2 with AssociationUploadRow

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

the class AssociationFileUploadService method processAndValidateAssociationFile.

/**
 * Process uploaded file and return a list of errors
 *
 * @param file XLSX file supplied by user
 */
public ValidationSummary processAndValidateAssociationFile(File file, String validationLevel) throws FileNotFoundException, SheetProcessingException {
    ValidationSummary validationSummary = new ValidationSummary();
    Collection<RowValidationSummary> rowValidationSummaries = new ArrayList<>();
    Collection<AssociationSummary> associationSummaries = new ArrayList<>();
    Collection<AssociationUploadRow> fileRows = new ArrayList<>();
    if (file.exists()) {
        // Create sheet
        XSSFSheet sheet = null;
        try {
            // Create a sheet for reading
            sheet = sheetCreationService.createSheet(file.getAbsolutePath());
            // Process file, depending on validation level, into a generic row object
            UploadSheetProcessor uploadSheetProcessor = uploadSheetProcessorBuilder.buildProcessor(validationLevel);
            fileRows = uploadSheetProcessor.readSheetRows(sheet);
        } catch (InvalidFormatException | InvalidOperationException | IOException | NullPointerException e) {
            getLog().error("File: " + file.getName() + " cannot be processed", e);
            file.delete();
            throw new SheetProcessingException("File: " + file.getName() + " cannot be processed", e);
        }
    } else {
        getLog().error("File: " + file.getName() + " cannot be found");
        throw new FileNotFoundException("File does not exist");
    }
    String eRelease = ensemblRestTemplateService.getRelease();
    // Error check each row
    if (!fileRows.isEmpty()) {
        // Check for missing values and syntax errors that would prevent code creating an association
        for (AssociationUploadRow row : fileRows) {
            getLog().info("Syntax checking row: " + row.getRowNumber() + " of file, " + file.getAbsolutePath());
            RowValidationSummary rowValidationSummary = createRowValidationSummary(row, eRelease);
            // Only store summary if there is an error
            if (!rowValidationSummary.getErrors().isEmpty()) {
                rowValidationSummaries.add(rowValidationSummary);
            }
        }
        if (rowValidationSummaries.isEmpty()) {
            // Proceed to carry out full checks of values
            fileRows.forEach(row -> {
                associationSummaries.add(createAssociationSummary(row, validationLevel, eRelease));
            });
        }
    }
    validationSummary.setAssociationSummaries(associationSummaries);
    validationSummary.setRowValidationSummaries(rowValidationSummaries);
    return validationSummary;
}
Also used : SheetProcessingException(uk.ac.ebi.spot.goci.exception.SheetProcessingException) RowValidationSummary(uk.ac.ebi.spot.goci.model.RowValidationSummary) RowValidationSummary(uk.ac.ebi.spot.goci.model.RowValidationSummary) ValidationSummary(uk.ac.ebi.spot.goci.model.ValidationSummary) AssociationSummary(uk.ac.ebi.spot.goci.model.AssociationSummary) ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) InvalidFormatException(org.apache.poi.openxml4j.exceptions.InvalidFormatException) XSSFSheet(org.apache.poi.xssf.usermodel.XSSFSheet) InvalidOperationException(org.apache.poi.openxml4j.exceptions.InvalidOperationException) AssociationUploadRow(uk.ac.ebi.spot.goci.model.AssociationUploadRow)

Aggregations

ArrayList (java.util.ArrayList)2 AssociationUploadRow (uk.ac.ebi.spot.goci.model.AssociationUploadRow)2 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 InvalidFormatException (org.apache.poi.openxml4j.exceptions.InvalidFormatException)1 InvalidOperationException (org.apache.poi.openxml4j.exceptions.InvalidOperationException)1 XSSFCell (org.apache.poi.xssf.usermodel.XSSFCell)1 XSSFRow (org.apache.poi.xssf.usermodel.XSSFRow)1 XSSFSheet (org.apache.poi.xssf.usermodel.XSSFSheet)1 CellProcessingException (uk.ac.ebi.spot.goci.exception.CellProcessingException)1 SheetProcessingException (uk.ac.ebi.spot.goci.exception.SheetProcessingException)1 AssociationSummary (uk.ac.ebi.spot.goci.model.AssociationSummary)1 RowValidationSummary (uk.ac.ebi.spot.goci.model.RowValidationSummary)1 ValidationError (uk.ac.ebi.spot.goci.model.ValidationError)1 ValidationSummary (uk.ac.ebi.spot.goci.model.ValidationSummary)1 UploadFileHeader (uk.ac.ebi.spot.goci.utils.UploadFileHeader)1