Search in sources :

Example 6 with SampleClass

use of uk.ac.bbsrc.tgac.miso.core.data.SampleClass in project miso-lims by miso-lims.

the class DefaultSampleClassService method loadChildEntities.

@Override
protected void loadChildEntities(SampleClass object) throws IOException {
    Set<SampleValidRelationship> parents = new HashSet<>();
    for (SampleValidRelationship svr : object.getParentRelationships()) {
        SampleValidRelationship loaded = null;
        if (svr.isSaved()) {
            loaded = sampleValidRelationshipService.get(svr.getId());
            if (loaded == null) {
                throw new ValidationException(new ValidationError("No parent relationship found with ID: " + svr.getId()));
            }
            loaded.setArchived(svr.isArchived());
        } else {
            loaded = svr;
            loaded.setChild(object);
            SampleClass parent = loaded.getParent() == null ? null : get(loaded.getParent().getId());
            if (parent == null) {
                throw new ValidationException(String.format("Parent sample class not found%s%s", loaded.getParent() == null ? "" : " with ID: ", loaded.getParent() == null ? "" : loaded.getParent().getId()));
            }
            loaded.setParent(parent);
        }
        parents.add(loaded);
    }
    object.getParentRelationships().clear();
    object.getParentRelationships().addAll(parents);
    if (object.getDefaultSampleType() != null) {
        object.setDefaultSampleType(sampleTypeService.getByName(object.getDefaultSampleType().getName()));
    }
}
Also used : SampleValidRelationship(uk.ac.bbsrc.tgac.miso.core.data.SampleValidRelationship) ValidationException(uk.ac.bbsrc.tgac.miso.core.service.exception.ValidationException) SampleClass(uk.ac.bbsrc.tgac.miso.core.data.SampleClass) ValidationError(uk.ac.bbsrc.tgac.miso.core.service.exception.ValidationError) HashSet(java.util.HashSet)

Example 7 with SampleClass

use of uk.ac.bbsrc.tgac.miso.core.data.SampleClass in project miso-lims by miso-lims.

the class DefaultSampleService method isValidRelationship.

public boolean isValidRelationship(Sample parent, Sample child) throws IOException {
    if (parent == null && !isDetailedSample(child)) {
        // Simple sample has no relationships.
        return true;
    }
    if (!isDetailedSample(child) || !isDetailedSample(parent)) {
        return false;
    }
    SampleClass parentClass = ((DetailedSample) parent).getSampleClass();
    SampleClass childClass = ((DetailedSample) child).getSampleClass();
    return sampleValidRelationshipService.getByClasses(parentClass, childClass) != null;
}
Also used : SampleClass(uk.ac.bbsrc.tgac.miso.core.data.SampleClass) DetailedSample(uk.ac.bbsrc.tgac.miso.core.data.DetailedSample)

Example 8 with SampleClass

use of uk.ac.bbsrc.tgac.miso.core.data.SampleClass in project miso-lims by miso-lims.

the class DefaultSampleService method createParentIdentity.

private SampleIdentity createParentIdentity(DetailedSample sample, SampleIdentity identity) throws IOException, MisoNamingException, SQLException {
    log.debug("Creating a new Identity to use as a parent.");
    List<SampleClass> identityClasses = sampleClassService.listByCategory(SampleIdentity.CATEGORY_NAME);
    if (identityClasses.size() != 1) {
        throw new IllegalStateException("Found more or less than one SampleClass of category " + SampleIdentity.CATEGORY_NAME + ". Cannot choose which to use as root sample class.");
    }
    SampleClass rootSampleClass = identityClasses.get(0);
    confirmExternalNameUniqueForProjectIfRequired(identity.getExternalName(), sample);
    Sample identitySample = new IdentityBuilder().project(sample.getProject()).sampleType(sample.getSampleType()).scientificName(sample.getScientificName()).name(generateTemporaryName()).rootSampleClass(rootSampleClass).volume(BigDecimal.ZERO).externalName(identity.getExternalName()).donorSex(identity.getDonorSex()).consentLevel(identity.getConsentLevel()).build();
    identitySample.setAlias(getNamingScheme(sample).generateSampleAlias(identitySample));
    identitySample.setChangeDetails(authorizationManager.getCurrentUser());
    return (SampleIdentity) save(identitySample, true);
}
Also used : SampleClass(uk.ac.bbsrc.tgac.miso.core.data.SampleClass) IdentityBuilder(uk.ac.bbsrc.tgac.miso.core.data.impl.SampleIdentityImpl.IdentityBuilder) SampleIdentity(uk.ac.bbsrc.tgac.miso.core.data.SampleIdentity) DetailedSample(uk.ac.bbsrc.tgac.miso.core.data.DetailedSample) Sample(uk.ac.bbsrc.tgac.miso.core.data.Sample) TransferSample(uk.ac.bbsrc.tgac.miso.core.data.impl.transfer.TransferSample)

Example 9 with SampleClass

use of uk.ac.bbsrc.tgac.miso.core.data.SampleClass in project miso-lims by miso-lims.

the class DefaultLibraryService method loadChildEntities.

/**
 * Loads persisted objects into library fields. Should be called before saving libraries. Loads all member objects <b>except</b>
 * <ul>
 * <li>creator/lastModifier User objects</li>
 * </ul>
 *
 * @param library the Library to load entities into. Must contain at least the IDs of objects to load (e.g. to load the persisted Sample
 *          into library.sample, library.sample.id must be set)
 * @throws IOException
 */
private void loadChildEntities(Library library) throws IOException {
    if (library.getSample() != null) {
        library.setSample(sampleService.get(library.getSample().getId()));
    }
    if (library.getLibraryType() != null) {
        library.setLibraryType(libraryTypeService.get(library.getLibraryType().getId()));
    }
    if (library.getLibrarySelectionType() != null) {
        library.setLibrarySelectionType(librarySelectionService.get(library.getLibrarySelectionType().getId()));
    }
    if (library.getLibraryStrategyType() != null) {
        library.setLibraryStrategyType(libraryStrategyService.get(library.getLibraryStrategyType().getId()));
    }
    loadChildEntity(library::setIndex1, library.getIndex1(), indexService, "index1Id");
    loadChildEntity(library::setIndex2, library.getIndex2(), indexService, "index2Id");
    if (library.getKitDescriptor() != null) {
        library.setKitDescriptor(kitService.get(library.getKitDescriptor().getId()));
    }
    if (library.getSpikeIn() != null) {
        library.setSpikeIn(librarySpikeInService.get(library.getSpikeIn().getId()));
    }
    if (library.getWorkstation() != null) {
        library.setWorkstation(workstationService.get(library.getWorkstation().getId()));
    }
    if (library.getThermalCycler() != null) {
        library.setThermalCycler(instrumentService.get(library.getThermalCycler().getId()));
    }
    loadChildEntity(library::setSop, library.getSop(), sopService, "sopId");
    loadChildEntity(library::setDetailedQcStatus, library.getDetailedQcStatus(), detailedQcStatusService, "detailedQcStatusId");
    if (isDetailedLibrary(library)) {
        DetailedLibrary lai = (DetailedLibrary) library;
        if (lai.getLibraryDesignCode() != null) {
            lai.setLibraryDesignCode(libraryDesignCodeService.get(lai.getLibraryDesignCode().getId()));
        }
        if (lai.getLibraryDesign() != null) {
            LibraryDesign design = libraryDesignService.get(lai.getLibraryDesign().getId());
            lai.setLibraryDesign(design);
            lai.setLibrarySelectionType(design.getLibrarySelectionType());
            lai.setLibraryStrategyType(design.getLibraryStrategyType());
            lai.setLibraryDesignCode(design.getLibraryDesignCode());
            SampleClass sampleClass = ((DetailedSample) library.getSample()).getSampleClass();
            if (sampleClass.getId() != design.getSampleClass().getId()) {
                throw new IllegalArgumentException("Cannot use design " + design.getName() + " for a library from a sample of type " + sampleClass.getAlias());
            }
        }
    }
}
Also used : LibraryDesign(uk.ac.bbsrc.tgac.miso.core.data.LibraryDesign) SampleClass(uk.ac.bbsrc.tgac.miso.core.data.SampleClass) DetailedSample(uk.ac.bbsrc.tgac.miso.core.data.DetailedSample) DetailedLibrary(uk.ac.bbsrc.tgac.miso.core.data.DetailedLibrary)

Example 10 with SampleClass

use of uk.ac.bbsrc.tgac.miso.core.data.SampleClass in project miso-lims by miso-lims.

the class Dtos method toDetailedSample.

private static DetailedSample toDetailedSample(@Nonnull DetailedSampleDto from) {
    DetailedSample to = null;
    if (from.getClass() == SampleIdentityDto.class) {
        to = toIdentitySample((SampleIdentityDto) from);
    } else if (from.getClass() == SampleTissueDto.class) {
        to = toTissueSample((SampleTissueDto) from);
    } else if (from instanceof SampleTissueProcessingDto) {
        to = toTissueProcessingSample((SampleTissueProcessingDto) from);
    } else if (from instanceof SampleAliquotDto) {
        to = toAliquotSample((SampleAliquotDto) from);
    } else if (from instanceof SampleStockDto) {
        to = toStockSample((SampleStockDto) from);
    } else {
        to = new DetailedSampleImpl();
    }
    if (from.getSubprojectId() != null) {
        Subproject subproject = new SubprojectImpl();
        subproject.setId(from.getSubprojectId());
        to.setSubproject(subproject);
    }
    if (from.getSampleClassId() != null) {
        SampleClass sampleClass = new SampleClassImpl();
        sampleClass.setId(from.getSampleClassId());
        to.setSampleClass(sampleClass);
    }
    to.setGroupId(nullifyStringIfBlank(from.getGroupId()));
    to.setGroupDescription(nullifyStringIfBlank(from.getGroupDescription()));
    to.setSynthetic(from.getSynthetic());
    to.setCreationDate(LimsUtils.isStringEmptyOrNull(from.getCreationDate()) ? null : parseDate(from.getCreationDate()));
    if (from.getIdentityId() != null) {
        to.setIdentityId(from.getIdentityId());
    }
    to.setNonStandardAlias(from.getNonStandardAlias());
    to.setParent(getParent(from));
    setBigDecimal(to::setVolumeUsed, from.getVolumeUsed());
    setBigDecimal(to::setNgUsed, from.getNgUsed());
    return to;
}
Also used : Subproject(uk.ac.bbsrc.tgac.miso.core.data.Subproject) SampleClass(uk.ac.bbsrc.tgac.miso.core.data.SampleClass) SampleClassImpl(uk.ac.bbsrc.tgac.miso.core.data.impl.SampleClassImpl) DetailedSample(uk.ac.bbsrc.tgac.miso.core.data.DetailedSample) SubprojectImpl(uk.ac.bbsrc.tgac.miso.core.data.impl.SubprojectImpl) DetailedSampleImpl(uk.ac.bbsrc.tgac.miso.core.data.impl.DetailedSampleImpl) IonTorrentRunDto(uk.ac.bbsrc.tgac.miso.dto.run.IonTorrentRunDto) QcHierarchyNodeDto(uk.ac.bbsrc.tgac.miso.dto.dashi.QcHierarchyNodeDto) RunPositionDto(uk.ac.bbsrc.tgac.miso.dto.run.RunPositionDto) PacBioRunDto(uk.ac.bbsrc.tgac.miso.dto.run.PacBioRunDto) Ls454RunDto(uk.ac.bbsrc.tgac.miso.dto.run.Ls454RunDto) IlluminaNotificationDto(ca.on.oicr.gsi.runscanner.dto.IlluminaNotificationDto) OxfordNanoporeRunDto(uk.ac.bbsrc.tgac.miso.dto.run.OxfordNanoporeRunDto) IlluminaRunDto(uk.ac.bbsrc.tgac.miso.dto.run.IlluminaRunDto) NotificationDto(ca.on.oicr.gsi.runscanner.dto.NotificationDto) OxfordNanoporeNotificationDto(ca.on.oicr.gsi.runscanner.dto.OxfordNanoporeNotificationDto) RunDto(uk.ac.bbsrc.tgac.miso.dto.run.RunDto) SolidRunDto(uk.ac.bbsrc.tgac.miso.dto.run.SolidRunDto) OrderAliquotDto(uk.ac.bbsrc.tgac.miso.dto.PoolOrderDto.OrderAliquotDto)

Aggregations

SampleClass (uk.ac.bbsrc.tgac.miso.core.data.SampleClass)41 SampleClassImpl (uk.ac.bbsrc.tgac.miso.core.data.impl.SampleClassImpl)27 SampleStock (uk.ac.bbsrc.tgac.miso.core.data.SampleStock)10 SampleTissue (uk.ac.bbsrc.tgac.miso.core.data.SampleTissue)10 Test (org.junit.Test)8 AbstractDAOTest (uk.ac.bbsrc.tgac.miso.AbstractDAOTest)8 DetailedSample (uk.ac.bbsrc.tgac.miso.core.data.DetailedSample)8 SampleStockImpl (uk.ac.bbsrc.tgac.miso.core.data.impl.SampleStockImpl)8 SampleAliquot (uk.ac.bbsrc.tgac.miso.core.data.SampleAliquot)6 SampleIdentity (uk.ac.bbsrc.tgac.miso.core.data.SampleIdentity)5 SampleValidRelationship (uk.ac.bbsrc.tgac.miso.core.data.SampleValidRelationship)5 SampleTissueImpl (uk.ac.bbsrc.tgac.miso.core.data.impl.SampleTissueImpl)4 User (com.eaglegenomics.simlims.core.User)3 HashSet (java.util.HashSet)3 Project (uk.ac.bbsrc.tgac.miso.core.data.Project)3 SampleTissuePiece (uk.ac.bbsrc.tgac.miso.core.data.SampleTissuePiece)3 SampleAliquotImpl (uk.ac.bbsrc.tgac.miso.core.data.impl.SampleAliquotImpl)3 IlluminaNotificationDto (ca.on.oicr.gsi.runscanner.dto.IlluminaNotificationDto)2 NotificationDto (ca.on.oicr.gsi.runscanner.dto.NotificationDto)2 OxfordNanoporeNotificationDto (ca.on.oicr.gsi.runscanner.dto.OxfordNanoporeNotificationDto)2