Search in sources :

Example 6 with MolgenisDataException

use of org.molgenis.data.MolgenisDataException in project molgenis by molgenis.

the class GavinJob method call.

@Override
public Void call(Progress progress) throws Exception {
    progress.setProgressMax(5);
    progress.progress(0, "Preprocessing input file...");
    Multiset<LineType> lineTypes = parser.tryTransform(inputFile, processedInputFile, errorFile);
    progress.status(format("Parsed input file. Found {0} lines ({1} comments, {2} valid VCF, {3} valid CADD, " + "{4} errors, {5} indels without CADD score, {6} skipped)", lineTypes.size(), lineTypes.count(COMMENT), lineTypes.count(VCF), lineTypes.count(CADD), lineTypes.count(ERROR), lineTypes.count(INDEL_NOCADD), lineTypes.count(SKIPPED)));
    gavinJobExecution.setLineTypes(lineTypes);
    if (lineTypes.contains(SKIPPED)) {
        throw new MolgenisDataException(format("Input file contains too many lines. Maximum is {0}.", Parser.MAX_LINES));
    }
    if (lineTypes.containsAll(Arrays.asList(CADD, VCF))) {
        throw new MolgenisDataException("Input file contains mixed line types. Please use one type only, either VCF or CADD.");
    }
    if (!lineTypes.contains(CADD) && !lineTypes.contains(VCF)) {
        throw new MolgenisDataException("Not a single valid variant line found.");
    }
    File exacInputFile = processedInputFile;
    if (!lineTypes.contains(CADD)) {
        progress.progress(1, "Annotating with cadd...");
        annotatorRunner.runAnnotator(cadd, processedInputFile, caddOutputFile, true);
        exacInputFile = caddOutputFile;
    } else {
        progress.progress(1, "File already annotated by cadd, skipping cadd annotation.");
    }
    progress.progress(2, "Annotating with exac...");
    annotatorRunner.runAnnotator(exac, exacInputFile, exacOutputFile, true);
    progress.progress(3, "Annotating with snpEff...");
    annotatorRunner.runAnnotator(snpeff, exacOutputFile, snpeffOutputFile, false);
    progress.progress(4, "Annotating with gavin...");
    annotatorRunner.runAnnotator(gavin, snpeffOutputFile, gavinOutputFile, false);
    progress.progress(5, "Result is ready for download.");
    String path = menuReaderService.getMenu().findMenuItemPath(GAVIN_APP);
    // TODO Filter
    // TODO write to database
    // TODO result -> GeneNetwork
    // TODO VCF pipe aware import
    progress.setResultUrl(format("{0}/result/{1}", path, jobIdentifier));
    return null;
}
Also used : MolgenisDataException(org.molgenis.data.MolgenisDataException) LineType(org.molgenis.gavin.job.input.model.LineType) File(java.io.File)

Example 7 with MolgenisDataException

use of org.molgenis.data.MolgenisDataException in project molgenis by molgenis.

the class ExcelSheetWriter method add.

/**
 * Add a new row to the sheet
 */
@Override
public void add(Entity entity) {
    if (entity == null)
        throw new IllegalArgumentException("Entity cannot be null");
    if (cachedAttributes == null)
        throw new MolgenisDataException("The attribute names are not defined, call writeAttributeNames first");
    int i = 0;
    Row poiRow = sheet.createRow(row++);
    for (Attribute attribute : cachedAttributes) {
        Cell cell = poiRow.createCell(i++, CellType.STRING);
        cell.setCellValue(toValue(entity.get(attribute.getName())));
    }
    entity.getIdValue();
}
Also used : MolgenisDataException(org.molgenis.data.MolgenisDataException) Attribute(org.molgenis.data.meta.model.Attribute) Row(org.apache.poi.ss.usermodel.Row) Cell(org.apache.poi.ss.usermodel.Cell)

Example 8 with MolgenisDataException

use of org.molgenis.data.MolgenisDataException in project molgenis by molgenis.

the class ConnectionRetryConfigTest method testRetryPolicyMolgenisDataException.

@Test
public void testRetryPolicyMolgenisDataException() {
    RetryContext context = retryPolicy.open(null);
    retryPolicy.registerThrowable(context, new MolgenisDataException("Failed to connect"));
    assertTrue(retryPolicy.canRetry(context));
}
Also used : MolgenisDataException(org.molgenis.data.MolgenisDataException) RetryContext(org.springframework.retry.RetryContext) Test(org.testng.annotations.Test)

Example 9 with MolgenisDataException

use of org.molgenis.data.MolgenisDataException in project molgenis by molgenis.

the class CsvIterator method get.

private Entity get() {
    if (getNext) {
        try {
            String[] values = csvReader.readNext();
            if (values != null && values.length == colNamesMap.size()) {
                List<String> valueList = Arrays.asList(values);
                for (int i = 0; i < values.length; ++i) {
                    // subsequent separators indicate
                    // null
                    // values instead of empty strings
                    String value = values[i].isEmpty() ? null : values[i];
                    values[i] = processCell(value, false);
                }
                next = new DynamicEntity(entityType);
                for (String name : colNamesMap.keySet()) {
                    next.set(name, valueList.get(colNamesMap.get(name)));
                }
            } else if (values != null && (values.length > 1 || (values.length == 1 && values[0].length() > 0)) && values.length < colNamesMap.size()) {
                throw new MolgenisDataException(format("Number of values (%d) doesn't match the number of headers (%d): [%s]", values.length, colNamesMap.size(), stream(values).collect(joining(","))));
            } else {
                next = null;
            }
            getNext = false;
        } catch (IOException e) {
            throw new MolgenisDataException(format("Exception reading line of csv file [%s]", repositoryName), e);
        }
    }
    return next;
}
Also used : MolgenisDataException(org.molgenis.data.MolgenisDataException) DynamicEntity(org.molgenis.data.support.DynamicEntity)

Example 10 with MolgenisDataException

use of org.molgenis.data.MolgenisDataException in project molgenis by molgenis.

the class CsvRepositoryCollection method loadEntityNames.

private void loadEntityNames() {
    String extension = StringUtils.getFilenameExtension(file.getName());
    entityTypeIds = Lists.newArrayList();
    entityTypeIdsLowerCase = Lists.newArrayList();
    if (extension.equalsIgnoreCase("zip")) {
        ZipFile zipFile = null;
        try {
            zipFile = new ZipFile(file);
            for (Enumeration<? extends ZipEntry> e = zipFile.entries(); e.hasMoreElements(); ) {
                ZipEntry entry = e.nextElement();
                if (!entry.getName().contains(MAC_ZIP) && !entry.isDirectory()) {
                    String name = getRepositoryName(entry.getName());
                    entityTypeIds.add(name);
                    entityTypeIdsLowerCase.add(name.toLowerCase());
                }
            }
        } catch (Exception e) {
            throw new MolgenisDataException(e);
        } finally {
            IOUtils.closeQuietly(zipFile);
        }
    } else {
        String name = getRepositoryName(file.getName());
        entityTypeIds.add(name);
        entityTypeIdsLowerCase.add(name.toLowerCase());
    }
}
Also used : MolgenisDataException(org.molgenis.data.MolgenisDataException) ZipFile(java.util.zip.ZipFile) ZipEntry(java.util.zip.ZipEntry) IOException(java.io.IOException) MolgenisInvalidFormatException(org.molgenis.data.MolgenisInvalidFormatException) MolgenisDataException(org.molgenis.data.MolgenisDataException)

Aggregations

MolgenisDataException (org.molgenis.data.MolgenisDataException)51 Entity (org.molgenis.data.Entity)16 Attribute (org.molgenis.data.meta.model.Attribute)11 EntityType (org.molgenis.data.meta.model.EntityType)11 Test (org.testng.annotations.Test)7 IOException (java.io.IOException)6 List (java.util.List)6 DynamicEntity (org.molgenis.data.support.DynamicEntity)6 File (java.io.File)5 AttributeType (org.molgenis.data.meta.AttributeType)5 UnexpectedEnumException (org.molgenis.util.UnexpectedEnumException)5 Instant (java.time.Instant)4 LocalDate (java.time.LocalDate)4 Collectors.toList (java.util.stream.Collectors.toList)4 DataService (org.molgenis.data.DataService)4 RepositoryCollection (org.molgenis.data.RepositoryCollection)4 String.format (java.lang.String.format)3 DateTimeParseException (java.time.format.DateTimeParseException)3 Map (java.util.Map)3 Stream (java.util.stream.Stream)3