Search in sources :

Example 1 with OxfordNanoporeNotificationDto

use of ca.on.oicr.gsi.runscanner.dto.OxfordNanoporeNotificationDto in project miso-lims by miso-lims.

the class RunScannerClient method processResults.

private void processResults(List<NotificationDto> results) {
    try {
        User user = userService.getByLoginName("notification");
        SecurityContextHolder.getContext().setAuthentication(new SuperuserAuthentication(user));
        try (AutoCloseable timer = acquireTime.start()) {
            lock.acquire();
        } catch (Exception e) {
            log.error("Failed to acquire lock", e);
            return;
        }
        for (NotificationDto dto : results) {
            try (AutoCloseable timer = saveTime.start()) {
                // Determine whether the SequencingParameters are of the correct type
                Predicate<SequencingParameters> isMatchingSequencingParameters;
                switch(dto.getPlatformType()) {
                    case ILLUMINA:
                        isMatchingSequencingParameters = params -> {
                            IlluminaNotificationDto illuminaDto = (IlluminaNotificationDto) dto;
                            if (params.getInstrumentModel().getPlatformType() != PlatformType.ILLUMINA) {
                                return false;
                            }
                            if (params.getChemistry() != Dtos.getMisoIlluminaChemistryFromRunscanner(illuminaDto.getChemistry())) {
                                return false;
                            }
                            // If we are talking to an old Run Scanner that doens't provide read lengths, use the old logic
                            if (illuminaDto.getReadLengths() == null) {
                                // The read length must match the first read length
                                if (Math.abs(params.getReadLength() - illuminaDto.getReadLength()) < 2) {
                                    // if there is no second read length, then this must be single ended
                                    if (params.getReadLength2() == 0) {
                                        return !illuminaDto.isPairedEndRun();
                                    } else {
                                        // If there is, it must be paired and symmetric
                                        return illuminaDto.isPairedEndRun() && params.getReadLength() == params.getReadLength2();
                                    }
                                } else {
                                    return false;
                                }
                            }
                            // If we have real read lengths, check they match what we see from Run Scanner
                            if (illuminaDto.getReadLengths().size() == 0) {
                                return false;
                            }
                            if (Math.abs(params.getReadLength() - illuminaDto.getReadLengths().get(0)) > 1) {
                                return false;
                            }
                            // If no second read is provided, make sure none is required
                            if (illuminaDto.getReadLengths().size() == 1) {
                                return params.getReadLength2() == 0;
                            }
                            // Otherwise, check the second read matches the right length
                            return Math.abs(params.getReadLength2() - illuminaDto.getReadLengths().get(1)) < 2;
                        };
                        break;
                    case OXFORDNANOPORE:
                        isMatchingSequencingParameters = params -> params.getInstrumentModel().getPlatformType() == PlatformType.OXFORDNANOPORE && params.getRunType().equals(((OxfordNanoporeNotificationDto) dto).getRunType());
                        break;
                    default:
                        isMatchingSequencingParameters = params -> params.getInstrumentModel().getPlatformType() == Dtos.getMisoPlatformTypeFromRunscanner(dto.getPlatformType());
                        break;
                }
                GetLaneContents laneContents = new GetLaneContents() {

                    /**
                     * Get getLaneContents implementation from DTO.
                     * Illumina DTOs have a unique implementation of getLaneContents.
                     */
                    @Override
                    public Optional<String> getLaneContents(int lane) {
                        return dto.getLaneContents(lane);
                    }
                };
                Run notificationRun = Dtos.to(dto);
                boolean isNew = runService.processNotification(notificationRun, dto.getLaneCount(), dto.getContainerModel(), dto.getContainerSerialNumber(), dto.getSequencerName(), isMatchingSequencingParameters, laneContents, dto.getSequencerPosition());
                (isNew ? saveNew : saveUpdate).inc();
                saveCount.inc();
                badRuns.remove(dto.getRunAlias());
                Run saved = runService.getRunByAlias(notificationRun.getAlias());
                if (hasFallbackContainerModel(saved)) {
                    if (isNew && dto.getContainerModel() != null) {
                        fallbackContainerModelRuns.add(saved.getAlias());
                    }
                } else {
                    fallbackContainerModelRuns.remove(saved.getAlias());
                }
                if (dto.getSequencingKit() != null && saved.getSequencingKit() == null) {
                    if (isNew) {
                        unknownSequencingKitRuns.add(saved.getAlias());
                    }
                } else {
                    unknownSequencingKitRuns.remove(saved.getAlias());
                }
            } catch (ValidationException e) {
                String errors = e.getErrors().stream().map(error -> error.getProperty() + ": " + error.getMessage()).collect(Collectors.joining("; "));
                log.error("Failed to save run due to validation errors: " + errors, e);
                saveFailures.inc();
                badRuns.add(dto.getRunAlias());
            } catch (Exception e) {
                log.error("Failed to save run: " + dto.getRunAlias(), e);
                saveFailures.inc();
                badRuns.add(dto.getRunAlias());
            }
            badRunCount.set(badRuns.size());
            fallbackContainerModelCount.set(fallbackContainerModelRuns.size());
            unknownSequencingKitCount.set(unknownSequencingKitRuns.size());
        }
        lock.release();
    } catch (IOException e) {
        log.error("Failed to save runs", e);
    }
}
Also used : User(com.eaglegenomics.simlims.core.User) OxfordNanoporeNotificationDto(ca.on.oicr.gsi.runscanner.dto.OxfordNanoporeNotificationDto) IlluminaNotificationDto(ca.on.oicr.gsi.runscanner.dto.IlluminaNotificationDto) NotificationDto(ca.on.oicr.gsi.runscanner.dto.NotificationDto) ValidationException(uk.ac.bbsrc.tgac.miso.core.service.exception.ValidationException) GetLaneContents(uk.ac.bbsrc.tgac.miso.core.data.GetLaneContents) Run(uk.ac.bbsrc.tgac.miso.core.data.Run) IOException(java.io.IOException) ValidationException(uk.ac.bbsrc.tgac.miso.core.service.exception.ValidationException) IOException(java.io.IOException) IlluminaNotificationDto(ca.on.oicr.gsi.runscanner.dto.IlluminaNotificationDto) SequencingParameters(uk.ac.bbsrc.tgac.miso.core.data.SequencingParameters) SuperuserAuthentication(uk.ac.bbsrc.tgac.miso.core.security.SuperuserAuthentication)

Aggregations

IlluminaNotificationDto (ca.on.oicr.gsi.runscanner.dto.IlluminaNotificationDto)1 NotificationDto (ca.on.oicr.gsi.runscanner.dto.NotificationDto)1 OxfordNanoporeNotificationDto (ca.on.oicr.gsi.runscanner.dto.OxfordNanoporeNotificationDto)1 User (com.eaglegenomics.simlims.core.User)1 IOException (java.io.IOException)1 GetLaneContents (uk.ac.bbsrc.tgac.miso.core.data.GetLaneContents)1 Run (uk.ac.bbsrc.tgac.miso.core.data.Run)1 SequencingParameters (uk.ac.bbsrc.tgac.miso.core.data.SequencingParameters)1 SuperuserAuthentication (uk.ac.bbsrc.tgac.miso.core.security.SuperuserAuthentication)1 ValidationException (uk.ac.bbsrc.tgac.miso.core.service.exception.ValidationException)1