Search in sources :

Example 1 with ParentAliquot

use of uk.ac.bbsrc.tgac.miso.core.data.impl.view.ParentAliquot in project miso-lims by miso-lims.

the class DefaultPoolService method getMismatchesWithOrders.

private List<ValidationError> getMismatchesWithOrders(Pool pool, List<PoolOrder> poolOrders) throws IOException {
    Set<Long> poolAliquotIds = new HashSet<>();
    List<ValidationError> errors = new LinkedList<>();
    for (PoolElement pe : pool.getPoolContents()) {
        poolAliquotIds.add(pe.getAliquot().getId());
        for (ParentAliquot parent = pe.getAliquot().getParentAliquot(); parent != null; parent = parent.getParentAliquot()) {
            poolAliquotIds.add(parent.getId());
        }
    }
    for (PoolOrder order : poolOrders) {
        for (OrderLibraryAliquot orderAliquot : order.getOrderLibraryAliquots()) {
            if (!poolAliquotIds.contains(orderAliquot.getAliquot().getId())) {
                String errorMessage = String.format("Pool must contain library aliquot '%s', as specified by pool order '%s'", orderAliquot.getAliquot().getAlias(), order.getAlias());
                errors.add(new ValidationError("poolElements", errorMessage));
            }
        }
    }
    return errors;
}
Also used : PoolOrder(uk.ac.bbsrc.tgac.miso.core.data.impl.PoolOrder) OrderLibraryAliquot(uk.ac.bbsrc.tgac.miso.core.data.impl.OrderLibraryAliquot) PoolElement(uk.ac.bbsrc.tgac.miso.core.data.impl.view.PoolElement) ValidationError(uk.ac.bbsrc.tgac.miso.core.service.exception.ValidationError) ParentAliquot(uk.ac.bbsrc.tgac.miso.core.data.impl.view.ParentAliquot) LinkedList(java.util.LinkedList) HashSet(java.util.HashSet)

Example 2 with ParentAliquot

use of uk.ac.bbsrc.tgac.miso.core.data.impl.view.ParentAliquot in project miso-lims by miso-lims.

the class Dtos method asDto.

public static LibraryAliquotDto asDto(@Nonnull ListLibraryAliquotView from) {
    LibraryAliquotDto dto = null;
    if (from.getParentAttributes() != null) {
        // indicates detailed sample
        DetailedLibraryAliquotDto detailedDto = new DetailedLibraryAliquotDto();
        setId(detailedDto::setLibraryDesignCodeId, from.getDesignCode());
        if (from.getSubprojectId() != null) {
            detailedDto.setSubprojectAlias(from.getSubprojectAlias());
            detailedDto.setSubprojectPriority(from.getSubprojectPriority());
        }
        if (from.getIdentityAttributes() != null) {
            ParentIdentityAttributes identity = from.getIdentityAttributes();
            setString(detailedDto::setIdentityConsentLevel, maybeGetProperty(identity.getConsentLevel(), ConsentLevel::getLabel));
            setString(detailedDto::setEffectiveExternalNames, identity.getExternalName());
        }
        if (from.getTissueAttributes() != null) {
            ParentTissueAttributes tissue = from.getTissueAttributes();
            setString(detailedDto::setEffectiveTissueOriginAlias, tissue.getTissueOrigin().getAlias());
            setString(detailedDto::setEffectiveTissueOriginDescription, tissue.getTissueOrigin().getDescription());
            setString(detailedDto::setEffectiveTissueTypeAlias, tissue.getTissueType().getAlias());
            setString(detailedDto::setEffectiveTissueTypeDescription, tissue.getTissueType().getDescription());
        }
        dto = detailedDto;
    } else {
        dto = new LibraryAliquotDto();
    }
    dto.setId(from.getId());
    dto.setName(from.getName());
    setString(dto::setAlias, from.getAlias());
    setString(dto::setCreatorName, maybeGetProperty(from.getCreator(), User::getFullName));
    setString(dto::setConcentration, from.getConcentration());
    dto.setConcentrationUnits(from.getConcentrationUnits());
    dto.setLastModified(formatDateTime(from.getLastModified()));
    dto.setCreationDate(formatDate(from.getCreated()));
    dto.setIdentificationBarcode(from.getAliquotBarcode());
    dto.setLocationLabel(BoxUtils.makeLocationLabel(from));
    dto.setIndexIds(Stream.of(from.getParentLibrary().getIndex1(), from.getParentLibrary().getIndex2()).filter(Objects::nonNull).map(Index::getId).collect(Collectors.toList()));
    dto.setIndexLabels(Stream.of(from.getParentLibrary().getIndex1(), from.getParentLibrary().getIndex2()).filter(Objects::nonNull).map(Index::getLabel).collect(Collectors.toList()));
    dto.setTargetedSequencingId(from.getTargetedSequencingId());
    setInteger(dto::setDnaSize, from.getDnaSize(), true);
    setString(dto::setVolume, from.getAliquotVolume());
    dto.setVolumeUnits(from.getAliquotVolumeUnits());
    setString(dto::setNgUsed, from.getNgUsed());
    setString(dto::setVolumeUsed, from.getVolumeUsed());
    dto.setLibraryId(from.getLibraryId());
    dto.setLibraryName(from.getLibraryName());
    dto.setLibraryAlias(from.getLibraryAlias());
    dto.setLibraryLowQuality(from.isLibraryLowQuality());
    dto.setLibraryPlatformType(from.getPlatformType().getKey());
    dto.setSampleId(from.getSampleId());
    dto.setSampleName(from.getSampleName());
    dto.setSampleAlias(from.getSampleAlias());
    setString(dto::setSequencingControlTypeAlias, maybeGetProperty(from.getSampleSequencingControlType(), SequencingControlType::getAlias));
    setId(dto::setDetailedQcStatusId, from.getDetailedQcStatus());
    setString(dto::setDetailedQcStatusNote, from.getDetailedQcStatusNote());
    setString(dto::setQcUserName, maybeGetProperty(from.getQcUser(), User::getFullName));
    setDateString(dto::setQcDate, from.getQcDate());
    List<Long> parentAliquotIds = new ArrayList<>();
    for (ParentAliquot parent = from.getParentAliquot(); parent != null; parent = parent.getParentAliquot()) {
        parentAliquotIds.add(parent.getId());
    }
    dto.setParentAliquotIds(parentAliquotIds);
    setEffectiveQcFailure(from, dto);
    return dto;
}
Also used : ParentTissueAttributes(uk.ac.bbsrc.tgac.miso.core.data.impl.view.ParentTissueAttributes) ParentIdentityAttributes(uk.ac.bbsrc.tgac.miso.core.data.impl.view.ParentIdentityAttributes) ArrayList(java.util.ArrayList) Index(uk.ac.bbsrc.tgac.miso.core.data.Index) ParentAliquot(uk.ac.bbsrc.tgac.miso.core.data.impl.view.ParentAliquot)

Example 3 with ParentAliquot

use of uk.ac.bbsrc.tgac.miso.core.data.impl.view.ParentAliquot in project miso-lims by miso-lims.

the class DefaultPoolOrderService method collectValidationErrors.

@Override
protected void collectValidationErrors(PoolOrder object, PoolOrder beforeChange, List<ValidationError> errors) throws IOException {
    if (object.getPool() != null || object.getSequencingOrder() != null) {
        // order should be fulfilled
        if (object.isDraft()) {
            errors.add(new ValidationError("draft", "Fulfilled order cannot be a draft"));
        }
        if (object.getPool() == null) {
            errors.add(new ValidationError("poolId", "Pool must be provided if a sequencing order is linked"));
        } else {
            for (OrderLibraryAliquot orderAli : object.getOrderLibraryAliquots()) {
                if (object.getPool().getPoolContents().stream().map(PoolElement::getAliquot).noneMatch(poolElement -> {
                    if (poolElement.getId() == orderAli.getAliquot().getId()) {
                        return true;
                    }
                    for (ParentAliquot parent = poolElement.getParentAliquot(); parent != null; parent = parent.getParentAliquot()) {
                        if (parent.getId() == orderAli.getAliquot().getId()) {
                            return true;
                        }
                    }
                    return false;
                })) {
                    errors.add(new ValidationError("Pool does not contain all of the required aliquots"));
                    break;
                }
            }
            if (object.getSequencingOrder() != null) {
                SequencingOrder seqOrder = object.getSequencingOrder();
                if (seqOrder.getPurpose().getId() != object.getPurpose().getId() || seqOrder.getSequencingParameter().getId() != object.getParameters().getId() || !seqOrder.getPartitions().equals(object.getPartitions()) || seqOrder.getPool().getId() != object.getPool().getId() || (object.getContainerModel() != null && (seqOrder.getContainerModel() == null || seqOrder.getContainerModel().getId() != object.getContainerModel().getId()))) {
                    errors.add(new ValidationError("Sequencing order does not match the pool order"));
                }
            }
        }
        preventFulfilledChange("partitions", PoolOrder::getPartitions, object, beforeChange, errors);
        preventFulfilledChange("parametersId", PoolOrder::getParameters, object, beforeChange, errors);
        preventFulfilledChange("containerModelId", PoolOrder::getContainerModel, object, beforeChange, errors);
        preventFulfilledChange("description", PoolOrder::getDescription, object, beforeChange, errors);
        preventFulfilledChange("alias", PoolOrder::getAlias, object, beforeChange, errors);
        preventFulfilledChange("purposeId", PoolOrder::getPurpose, object, beforeChange, errors);
        if (!allMatch(object.getOrderLibraryAliquots(), beforeChange.getOrderLibraryAliquots())) {
            errors.add(new ValidationError("Aliquots cannot be changed after the order is fulfilled"));
        }
    }
    // if any sequencing requirements are specified, all are required
    if (object.getContainerModel() != null || object.getParameters() != null || object.getPartitions() != null) {
        // exception: container model not required for legacy orders (from before container model was added to orders)
        if ((beforeChange == null || beforeChange.getContainerModel() != null) && object.getContainerModel() == null) {
            errors.add(ValidationUtils.makeNoNullError("containerModelId"));
        }
        if (object.getParameters() == null) {
            errors.add(ValidationUtils.makeNoNullError("parametersId"));
        }
        if (object.getPartitions() == null) {
            errors.add(ValidationUtils.makeNoNullError("partitions"));
        }
    }
    // Container model and seq params must be linked to same instrument model
    if (object.getContainerModel() != null && object.getParameters().getInstrumentModel().getContainerModels().stream().noneMatch(model -> model.getId() == object.getContainerModel().getId())) {
        errors.add(new ValidationError("containerModelId", "Not compatible with the selected sequencing parameters"));
    }
    PlatformType orderPlatform = object.getParameters() == null ? null : object.getParameters().getInstrumentModel().getPlatformType();
    for (OrderLibraryAliquot orderAli : object.getOrderLibraryAliquots()) {
        PlatformType libPlatform = orderAli.getAliquot().getLibrary().getPlatformType();
        if (orderPlatform == null) {
            orderPlatform = libPlatform;
        } else if (!libPlatform.equals(orderPlatform)) {
            errors.add(new ValidationError("Platform for all aliquots and sequencing parameters (if specified) must match"));
            break;
        }
    }
    if (!object.isDraft() && object.getOrderLibraryAliquots().isEmpty()) {
        errors.add(new ValidationError("Non-draft order must include at least one library aliquot"));
    }
    if (strictPools) {
        validateNoNewDuplicateIndices(object, beforeChange, errors);
    }
}
Also used : PoolOrder(uk.ac.bbsrc.tgac.miso.core.data.impl.PoolOrder) RunPurposeService(uk.ac.bbsrc.tgac.miso.core.service.RunPurposeService) AuthorizationManager(uk.ac.bbsrc.tgac.miso.core.security.AuthorizationManager) SequencingOrderService(uk.ac.bbsrc.tgac.miso.core.service.SequencingOrderService) PaginationFilter(uk.ac.bbsrc.tgac.miso.core.util.PaginationFilter) SequencingOrder(uk.ac.bbsrc.tgac.miso.core.data.SequencingOrder) Autowired(org.springframework.beans.factory.annotation.Autowired) Function(java.util.function.Function) SequencingContainerModelService(uk.ac.bbsrc.tgac.miso.core.service.SequencingContainerModelService) LibraryAliquotService(uk.ac.bbsrc.tgac.miso.core.service.LibraryAliquotService) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Value(org.springframework.beans.factory.annotation.Value) Service(org.springframework.stereotype.Service) PoolOrder(uk.ac.bbsrc.tgac.miso.core.data.impl.PoolOrder) ParentAliquot(uk.ac.bbsrc.tgac.miso.core.data.impl.view.ParentAliquot) PoolElement(uk.ac.bbsrc.tgac.miso.core.data.impl.view.PoolElement) ValidationError(uk.ac.bbsrc.tgac.miso.core.service.exception.ValidationError) ValidationResult(uk.ac.bbsrc.tgac.miso.core.service.exception.ValidationResult) OrderLibraryAliquot(uk.ac.bbsrc.tgac.miso.core.data.impl.OrderLibraryAliquot) Predicate(java.util.function.Predicate) Collection(java.util.Collection) Set(java.util.Set) DeletionStore(uk.ac.bbsrc.tgac.miso.core.store.DeletionStore) PoolOrderDao(uk.ac.bbsrc.tgac.miso.persistence.PoolOrderDao) IOException(java.io.IOException) IndexChecker(uk.ac.bbsrc.tgac.miso.core.util.IndexChecker) Consumer(java.util.function.Consumer) List(java.util.List) SequencingParametersService(uk.ac.bbsrc.tgac.miso.core.service.SequencingParametersService) PoolOrderService(uk.ac.bbsrc.tgac.miso.service.PoolOrderService) PoolService(uk.ac.bbsrc.tgac.miso.core.service.PoolService) ChangeLogService(uk.ac.bbsrc.tgac.miso.core.service.ChangeLogService) PlatformType(uk.ac.bbsrc.tgac.miso.core.data.type.PlatformType) AbstractSaveService(uk.ac.bbsrc.tgac.miso.service.AbstractSaveService) SaveDao(uk.ac.bbsrc.tgac.miso.persistence.SaveDao) Transactional(org.springframework.transaction.annotation.Transactional) OrderLibraryAliquot(uk.ac.bbsrc.tgac.miso.core.data.impl.OrderLibraryAliquot) SequencingOrder(uk.ac.bbsrc.tgac.miso.core.data.SequencingOrder) ValidationError(uk.ac.bbsrc.tgac.miso.core.service.exception.ValidationError) PlatformType(uk.ac.bbsrc.tgac.miso.core.data.type.PlatformType) ParentAliquot(uk.ac.bbsrc.tgac.miso.core.data.impl.view.ParentAliquot)

Example 4 with ParentAliquot

use of uk.ac.bbsrc.tgac.miso.core.data.impl.view.ParentAliquot in project miso-lims by miso-lims.

the class Dtos method setEffectiveQcFailure.

private static void setEffectiveQcFailure(ListLibraryAliquotView from, UpstreamQcFailableDto to) {
    for (ParentAliquot parent = from.getParentAliquot(); parent != null; parent = parent.getParentAliquot()) {
        if (parent.getDetailedQcStatus() != null && Boolean.FALSE.equals(parent.getDetailedQcStatus().getStatus())) {
            to.setEffectiveQcFailureId(parent.getDetailedQcStatus().getId());
            to.setEffectiveQcFailureLevel(EntityType.LIBRARY_ALIQUOT.getLabel());
            return;
        }
    }
    ParentLibrary lib = from.getParentLibrary();
    if (lib != null) {
        if (lib.getDetailedQcStatus() != null && Boolean.FALSE.equals(lib.getDetailedQcStatus().getStatus())) {
            to.setEffectiveQcFailureId(lib.getDetailedQcStatus().getId());
            to.setEffectiveQcFailureLevel(EntityType.LIBRARY.getLabel());
            return;
        }
        ParentSample sam = lib.getParentSample();
        if (sam != null) {
            if (sam.getDetailedQcStatus() != null && Boolean.FALSE.equals(sam.getDetailedQcStatus().getStatus())) {
                to.setEffectiveQcFailureId(sam.getDetailedQcStatus().getId());
                to.setEffectiveQcFailureLevel(sam.getParentSampleClass() == null ? EntityType.SAMPLE.getLabel() : sam.getParentSampleClass().getSampleCategory());
                return;
            }
            for (GrandparentSample parent = sam.getParentSample(); parent != null; parent = parent.getParentSample()) {
                if (sam.getDetailedQcStatus() != null && Boolean.FALSE.equals(sam.getDetailedQcStatus().getStatus())) {
                    to.setEffectiveQcFailureId(parent.getDetailedQcStatus().getId());
                    to.setEffectiveQcFailureLevel(parent.getParentSampleClass() == null ? EntityType.SAMPLE.getLabel() : parent.getParentSampleClass().getSampleCategory());
                    return;
                }
            }
        }
    }
}
Also used : ParentLibrary(uk.ac.bbsrc.tgac.miso.core.data.impl.view.ParentLibrary) ParentSample(uk.ac.bbsrc.tgac.miso.core.data.impl.view.ParentSample) GrandparentSample(uk.ac.bbsrc.tgac.miso.core.data.impl.view.GrandparentSample) ParentAliquot(uk.ac.bbsrc.tgac.miso.core.data.impl.view.ParentAliquot)

Aggregations

ParentAliquot (uk.ac.bbsrc.tgac.miso.core.data.impl.view.ParentAliquot)4 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 OrderLibraryAliquot (uk.ac.bbsrc.tgac.miso.core.data.impl.OrderLibraryAliquot)2 PoolOrder (uk.ac.bbsrc.tgac.miso.core.data.impl.PoolOrder)2 PoolElement (uk.ac.bbsrc.tgac.miso.core.data.impl.view.PoolElement)2 ValidationError (uk.ac.bbsrc.tgac.miso.core.service.exception.ValidationError)2 IOException (java.io.IOException)1 Collection (java.util.Collection)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Set (java.util.Set)1 Consumer (java.util.function.Consumer)1 Function (java.util.function.Function)1 Predicate (java.util.function.Predicate)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1 Value (org.springframework.beans.factory.annotation.Value)1 Service (org.springframework.stereotype.Service)1 Transactional (org.springframework.transaction.annotation.Transactional)1 Index (uk.ac.bbsrc.tgac.miso.core.data.Index)1