Search in sources :

Example 1 with Experiment

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

the class EnaSubmissionPreparation method toBytes.

public byte[] toBytes() {
    try (ByteArrayOutputStream outputBytes = new ByteArrayOutputStream()) {
        ZipOutputStream output = new ZipOutputStream(outputBytes);
        submission.setSubmissionDate(new Date());
        Document submissionDocument = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
        Element s = submissionDocument.createElementNS(null, "SUBMISSION");
        s.setAttribute("alias", submission.getAlias());
        s.setAttribute("submission_date", DF_TIMESTAMP.format(submission.getSubmissionDate()));
        s.setAttribute("submission_comment", submission.getDescription());
        s.setAttribute("center_name", centreName);
        Element title = submissionDocument.createElementNS(null, "TITLE");
        title.setTextContent(submission.getTitle());
        s.appendChild(title);
        Element contacts = submissionDocument.createElementNS(null, "CONTACTS");
        Stream.concat(Stream.of(user), submission.getExperiments().stream().map(experiment -> experiment.getCreator()).filter(Objects::nonNull)).map(User::getFullName).distinct().map(contactName -> {
            Element contact = submissionDocument.createElementNS(null, "CONTACT");
            contact.setAttribute("name", contactName);
            return contact;
        }).forEach(contacts::appendChild);
        s.appendChild(contacts);
        Element actions = submissionDocument.createElementNS(null, "ACTIONS");
        for (ChildSubmissionFile subFile : FILES) {
            subFile.generateDocument(output);
            if (!subFile.isEmpty()) {
                if (submissionAction == SubmissionActionType.ADD || submissionAction == SubmissionActionType.VALIDATE) {
                    Element action = submissionDocument.createElementNS(null, "ACTION");
                    Element validate = submissionDocument.createElementNS(null, submissionAction.name());
                    validate.setAttribute("schema", subFile.name());
                    validate.setAttribute("source", subFile.fileName());
                    action.appendChild(validate);
                    actions.appendChild(action);
                }
            }
        }
        s.appendChild(actions);
        if (submissionDocument.getElementsByTagName("SUBMISSION_SET").item(0) != null) {
            submissionDocument.getElementsByTagName("SUBMISSION_SET").item(0).appendChild(s);
        } else {
            Element submissionSet = submissionDocument.createElementNS(null, "SUBMISSION_SET");
            submissionDocument.appendChild(submissionSet);
            submissionSet.appendChild(s);
        }
        ZipEntry mainFile = new ZipEntry("SUBMISSON.xml");
        output.putNextEntry(mainFile);
        Transformer transformer = TransformerFactory.newInstance().newTransformer();
        transformer.setOutputProperty(OutputKeys.INDENT, "yes");
        StreamResult result = new StreamResult(output);
        DOMSource source = new DOMSource(submissionDocument);
        transformer.transform(source, result);
        output.closeEntry();
        output.close();
        return outputBytes.toByteArray();
    } catch (ParserConfigurationException | TransformerException | IOException e) {
        throw new RuntimeException("Cannot generate data.");
    }
}
Also used : ZipOutputStream(java.util.zip.ZipOutputStream) Transformer(javax.xml.transform.Transformer) DOMSource(javax.xml.transform.dom.DOMSource) User(com.eaglegenomics.simlims.core.User) ByteArrayOutputStream(java.io.ByteArrayOutputStream) TransformerException(javax.xml.transform.TransformerException) RunPartition(uk.ac.bbsrc.tgac.miso.core.data.Experiment.RunPartition) Date(java.util.Date) StreamResult(javax.xml.transform.stream.StreamResult) ParentLibrary(uk.ac.bbsrc.tgac.miso.core.data.impl.view.ParentLibrary) SimpleDateFormat(java.text.SimpleDateFormat) HealthType(uk.ac.bbsrc.tgac.miso.core.data.type.HealthType) Experiment(uk.ac.bbsrc.tgac.miso.core.data.Experiment) Submission(uk.ac.bbsrc.tgac.miso.core.data.Submission) Run(uk.ac.bbsrc.tgac.miso.core.data.Run) Sample(uk.ac.bbsrc.tgac.miso.core.data.Sample) Document(org.w3c.dom.Document) Library(uk.ac.bbsrc.tgac.miso.core.data.Library) TransformerFactoryConfigurationError(javax.xml.transform.TransformerFactoryConfigurationError) PoolElement(uk.ac.bbsrc.tgac.miso.core.data.impl.view.PoolElement) ZipEntry(java.util.zip.ZipEntry) DateFormat(java.text.DateFormat) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) ListLibraryAliquotView(uk.ac.bbsrc.tgac.miso.core.data.impl.view.ListLibraryAliquotView) SubmissionActionType(uk.ac.bbsrc.tgac.miso.core.data.type.SubmissionActionType) Set(java.util.Set) IOException(java.io.IOException) OutputKeys(javax.xml.transform.OutputKeys) Partition(uk.ac.bbsrc.tgac.miso.core.data.Partition) Study(uk.ac.bbsrc.tgac.miso.core.data.Study) Objects(java.util.Objects) Stream(java.util.stream.Stream) Element(org.w3c.dom.Element) LimsUtils.isStringEmptyOrNull(uk.ac.bbsrc.tgac.miso.core.util.LimsUtils.isStringEmptyOrNull) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) Pair(uk.ac.bbsrc.tgac.miso.core.data.Pair) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) TransformerFactory(javax.xml.transform.TransformerFactory) Pool(uk.ac.bbsrc.tgac.miso.core.data.Pool) DOMSource(javax.xml.transform.dom.DOMSource) Transformer(javax.xml.transform.Transformer) StreamResult(javax.xml.transform.stream.StreamResult) PoolElement(uk.ac.bbsrc.tgac.miso.core.data.impl.view.PoolElement) Element(org.w3c.dom.Element) ZipEntry(java.util.zip.ZipEntry) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) Document(org.w3c.dom.Document) Date(java.util.Date) ZipOutputStream(java.util.zip.ZipOutputStream) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) TransformerException(javax.xml.transform.TransformerException)

Example 2 with Experiment

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

the class PoolRestController method assignPool.

@PostMapping(value = "/{poolId}/assign", produces = "application/json")
@ResponseStatus(code = HttpStatus.NO_CONTENT)
public void assignPool(@PathVariable Long poolId, @RequestBody AssignPoolDto request) throws IOException {
    Pool pool = poolId == 0 ? null : poolService.get(poolId);
    // Determine if this pool transition is allowed for this experiment. If removing a pool, it strictly isn't. If the new pool contains the
    // same library as the experiment, it's fine.
    Predicate<Experiment> isTransitionValid = pool == null ? experiment -> false : experiment -> pool.getPoolContents().stream().map(pd -> pd.getAliquot().getLibraryId()).anyMatch(id -> id == experiment.getLibrary().getId());
    // 
    request.getPartitionIds().stream().map(// 
    WhineyFunction.rethrow(containerService::getPartition)).peek(WhineyConsumer.rethrow(partition -> {
        for (RunPosition runPos : partition.getSequencerPartitionContainer().getRunPositions()) {
            Run run = runPos.getRun();
            // Check that we aren't going to hose any existing experiments through this reassignment
            boolean relatedExperimentsOkay = // 
            experimentService.listAllByRunId(run.getId()).stream().flatMap(// 
            experiment -> experiment.getRunPartitions().stream()).filter(// 
            rp -> rp.getRun().getId() == run.getId() && rp.getPartition().getId() == partition.getId()).map(// 
            RunPartition::getExperiment).allMatch(isTransitionValid);
            if (!relatedExperimentsOkay) {
                throw new RestException(String.format("%s %d is used in an experiment.", partition.getSequencerPartitionContainer().getModel().getPlatformType().getPartitionName(), partition.getPartitionNumber()), Status.BAD_REQUEST);
            }
        }
        if (pool != null && partition.getSequencerPartitionContainer().getModel().getPlatformType() != pool.getPlatformType()) {
            throw new RestException(String.format("%s %d in %s is not compatible with pool %s.", partition.getSequencerPartitionContainer().getModel().getPlatformType().getPartitionName(), partition.getPartitionNumber(), partition.getSequencerPartitionContainer().getIdentificationBarcode(), pool.getName()), Status.BAD_REQUEST);
        }
        partition.setPool(pool);
        if (request.getConcentration() != null) {
            partition.setLoadingConcentration(new BigDecimal(request.getConcentration()));
            partition.setLoadingConcentrationUnits(request.getUnits());
        } else {
            partition.setLoadingConcentration(null);
            partition.setLoadingConcentrationUnits(null);
        }
    })).forEach(WhineyConsumer.rethrow(containerService::update));
    if (pool != null) {
        poolService.update(pool);
    }
}
Also used : PathVariable(org.springframework.web.bind.annotation.PathVariable) UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder) RequestParam(org.springframework.web.bind.annotation.RequestParam) LibraryAliquotSpreadSheets(uk.ac.bbsrc.tgac.miso.core.data.spreadsheet.LibraryAliquotSpreadSheets) SampleTissueProcessing(uk.ac.bbsrc.tgac.miso.core.data.SampleTissueProcessing) PoolSpreadSheets(uk.ac.bbsrc.tgac.miso.core.data.spreadsheet.PoolSpreadSheets) PaginationFilter(uk.ac.bbsrc.tgac.miso.core.util.PaginationFilter) RunPartition(uk.ac.bbsrc.tgac.miso.core.data.Experiment.RunPartition) DataTablesResponseDto(uk.ac.bbsrc.tgac.miso.dto.DataTablesResponseDto) Autowired(org.springframework.beans.factory.annotation.Autowired) Experiment(uk.ac.bbsrc.tgac.miso.core.data.Experiment) SequencingOrderSummaryViewService(uk.ac.bbsrc.tgac.miso.core.service.SequencingOrderSummaryViewService) Dtos(uk.ac.bbsrc.tgac.miso.dto.Dtos) BigDecimal(java.math.BigDecimal) PutMapping(org.springframework.web.bind.annotation.PutMapping) Sample(uk.ac.bbsrc.tgac.miso.core.data.Sample) Map(java.util.Map) ListPoolView(uk.ac.bbsrc.tgac.miso.core.data.impl.view.ListPoolView) PostMapping(org.springframework.web.bind.annotation.PostMapping) ListLibraryAliquotViewService(uk.ac.bbsrc.tgac.miso.core.service.ListLibraryAliquotViewService) SampleService(uk.ac.bbsrc.tgac.miso.core.service.SampleService) SequencingOrderCompletionDto(uk.ac.bbsrc.tgac.miso.dto.SequencingOrderCompletionDto) PoolDto(uk.ac.bbsrc.tgac.miso.dto.PoolDto) AdvancedSearchParser(uk.ac.bbsrc.tgac.miso.webapp.controller.component.AdvancedSearchParser) PoolPickerEntry(uk.ac.bbsrc.tgac.miso.webapp.util.PoolPickerResponse.PoolPickerEntry) Predicate(java.util.function.Predicate) ListLibraryAliquotView(uk.ac.bbsrc.tgac.miso.core.data.impl.view.ListLibraryAliquotView) Collection(java.util.Collection) ListPoolViewService(uk.ac.bbsrc.tgac.miso.core.service.ListPoolViewService) Collectors(java.util.stream.Collectors) IndexChecker(uk.ac.bbsrc.tgac.miso.core.util.IndexChecker) StandardCharsets(java.nio.charset.StandardCharsets) LibraryDto(uk.ac.bbsrc.tgac.miso.dto.LibraryDto) List(java.util.List) HttpEntity(org.springframework.http.HttpEntity) MisoWebUtils(uk.ac.bbsrc.tgac.miso.webapp.util.MisoWebUtils) Stream(java.util.stream.Stream) SequencingParametersService(uk.ac.bbsrc.tgac.miso.core.service.SequencingParametersService) SampleStock(uk.ac.bbsrc.tgac.miso.core.data.SampleStock) PoolService(uk.ac.bbsrc.tgac.miso.core.service.PoolService) RunService(uk.ac.bbsrc.tgac.miso.core.service.RunService) Entry(java.util.Map.Entry) LibraryAliquotDto(uk.ac.bbsrc.tgac.miso.dto.LibraryAliquotDto) SampleIdentity(uk.ac.bbsrc.tgac.miso.core.data.SampleIdentity) PoolPickerResponse(uk.ac.bbsrc.tgac.miso.webapp.util.PoolPickerResponse) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) Controller(org.springframework.stereotype.Controller) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) LibraryAliquotService(uk.ac.bbsrc.tgac.miso.core.service.LibraryAliquotService) ArrayList(java.util.ArrayList) RunDto(uk.ac.bbsrc.tgac.miso.dto.run.RunDto) Value(org.springframework.beans.factory.annotation.Value) RequestBody(org.springframework.web.bind.annotation.RequestBody) LibraryAliquot(uk.ac.bbsrc.tgac.miso.core.data.impl.LibraryAliquot) HttpServletRequest(javax.servlet.http.HttpServletRequest) SampleDto(uk.ac.bbsrc.tgac.miso.dto.SampleDto) Run(uk.ac.bbsrc.tgac.miso.core.data.Run) Library(uk.ac.bbsrc.tgac.miso.core.data.Library) ContainerService(uk.ac.bbsrc.tgac.miso.core.service.ContainerService) GetMapping(org.springframework.web.bind.annotation.GetMapping) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) PoolElement(uk.ac.bbsrc.tgac.miso.core.data.impl.view.PoolElement) Status(javax.ws.rs.core.Response.Status) SampleAliquot(uk.ac.bbsrc.tgac.miso.core.data.SampleAliquot) SampleTissue(uk.ac.bbsrc.tgac.miso.core.data.SampleTissue) ConcentrationUnit(uk.ac.bbsrc.tgac.miso.core.data.ConcentrationUnit) LibraryService(uk.ac.bbsrc.tgac.miso.core.service.LibraryService) WhineyFunction(uk.ac.bbsrc.tgac.miso.core.util.WhineyFunction) HttpServletResponse(javax.servlet.http.HttpServletResponse) SpreadsheetRequest(uk.ac.bbsrc.tgac.miso.dto.SpreadsheetRequest) IOException(java.io.IOException) SequencingParameters(uk.ac.bbsrc.tgac.miso.core.data.SequencingParameters) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) WhineyConsumer(uk.ac.bbsrc.tgac.miso.core.util.WhineyConsumer) Consumer(java.util.function.Consumer) HttpStatus(org.springframework.http.HttpStatus) RunPosition(uk.ac.bbsrc.tgac.miso.core.data.impl.RunPosition) ExperimentService(uk.ac.bbsrc.tgac.miso.core.service.ExperimentService) PlatformType(uk.ac.bbsrc.tgac.miso.core.data.type.PlatformType) PaginatedDataSource(uk.ac.bbsrc.tgac.miso.core.util.PaginatedDataSource) IlluminaExperiment(uk.ac.bbsrc.tgac.miso.core.util.IlluminaExperiment) AsyncOperationManager(uk.ac.bbsrc.tgac.miso.webapp.controller.component.AsyncOperationManager) Pool(uk.ac.bbsrc.tgac.miso.core.data.Pool) RunPosition(uk.ac.bbsrc.tgac.miso.core.data.impl.RunPosition) Experiment(uk.ac.bbsrc.tgac.miso.core.data.Experiment) IlluminaExperiment(uk.ac.bbsrc.tgac.miso.core.util.IlluminaExperiment) Pool(uk.ac.bbsrc.tgac.miso.core.data.Pool) Run(uk.ac.bbsrc.tgac.miso.core.data.Run) BigDecimal(java.math.BigDecimal) PostMapping(org.springframework.web.bind.annotation.PostMapping) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus)

Example 3 with Experiment

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

the class ExperimentRestController method addKit.

@PostMapping(value = "/{experimentId}/addkit", produces = "application/json")
@ResponseBody
public KitConsumableDto addKit(@PathVariable Long experimentId, @RequestBody KitConsumableDto dto) throws IOException {
    Experiment experiment = experimentService.get(experimentId);
    if (experiment == null) {
        throw new RestException("No such experiment.", Status.NOT_FOUND);
    }
    Kit kit = kitService.getKitByLotNumber(dto.getLotNumber());
    if (kit == null) {
        kit = Dtos.to(dto);
        kitService.saveKit(kit);
    } else {
        if (kit.getKitDescriptor().getId() != (dto.getDescriptor().getId())) {
            throw new RestException("Kit exists, but kit type does not match.", Status.BAD_REQUEST);
        }
    }
    long savedKitId = kit.getId();
    if (experiment.getKits().stream().noneMatch(k -> k.getId() == savedKitId)) {
        experiment.addKit(kit);
    }
    experimentService.update(experiment);
    return Dtos.asDto(kit);
}
Also used : Experiment(uk.ac.bbsrc.tgac.miso.core.data.Experiment) Kit(uk.ac.bbsrc.tgac.miso.core.data.Kit) PostMapping(org.springframework.web.bind.annotation.PostMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 4 with Experiment

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

the class HibernateExperimentDao method listAll.

@Override
public List<Experiment> listAll() {
    Criteria criteria = currentSession().createCriteria(Experiment.class);
    @SuppressWarnings("unchecked") List<Experiment> results = criteria.list();
    return results;
}
Also used : Experiment(uk.ac.bbsrc.tgac.miso.core.data.Experiment) Criteria(org.hibernate.Criteria)

Example 5 with Experiment

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

the class HibernateExperimentDao method listByLibrary.

@Override
public Collection<Experiment> listByLibrary(long id) throws IOException {
    Criteria criteria = currentSession().createCriteria(Experiment.class);
    criteria.createAlias("library", "library");
    criteria.add(Restrictions.eq("library.id", id));
    @SuppressWarnings("unchecked") List<Experiment> results = criteria.list();
    return results;
}
Also used : Experiment(uk.ac.bbsrc.tgac.miso.core.data.Experiment) Criteria(org.hibernate.Criteria)

Aggregations

Experiment (uk.ac.bbsrc.tgac.miso.core.data.Experiment)17 IOException (java.io.IOException)5 Criteria (org.hibernate.Criteria)5 RunPartition (uk.ac.bbsrc.tgac.miso.core.data.Experiment.RunPartition)5 Collectors (java.util.stream.Collectors)3 Stream (java.util.stream.Stream)3 Test (org.junit.Test)3 Autowired (org.springframework.beans.factory.annotation.Autowired)3 Controller (org.springframework.stereotype.Controller)3 GetMapping (org.springframework.web.bind.annotation.GetMapping)3 PathVariable (org.springframework.web.bind.annotation.PathVariable)3 PostMapping (org.springframework.web.bind.annotation.PostMapping)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)3 AbstractDAOTest (uk.ac.bbsrc.tgac.miso.AbstractDAOTest)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 User (com.eaglegenomics.simlims.core.User)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2