Search in sources :

Example 1 with RunPartition

use of uk.ac.bbsrc.tgac.miso.core.data.Experiment.RunPartition 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 2 with RunPartition

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

the class EditExperimentController method setupForm.

@GetMapping(value = "/{experimentId}")
public ModelAndView setupForm(@PathVariable Long experimentId, ModelMap model) throws IOException {
    Experiment experiment = experimentService.get(experimentId);
    if (experiment == null)
        throw new NotFoundException("No experiment found for ID " + experimentId.toString());
    ObjectMapper mapper = new ObjectMapper();
    ObjectNode consumableConfig = mapper.createObjectNode();
    consumableConfig.put("experimentId", experiment.getId());
    Stream.<// 
    KitDescriptor>concat(// 
    Stream.of(experiment.getLibrary().getKitDescriptor()), // 
    experiment.getRunPartitions().stream().map(// 
    RunPartition::getPartition).flatMap(partition -> Stream.of(partition.getSequencerPartitionContainer().getClusteringKit(), // 
    partition.getSequencerPartitionContainer().getMultiplexingKit()))).filter(// 
    Objects::nonNull).distinct().map(// 
    Dtos::asDto).forEach(consumableConfig.putArray("allowedDescriptors")::addPOJO);
    model.put("experiment", experiment);
    model.put("experimentDto", mapper.writeValueAsString(Dtos.asDto(experiment)));
    model.put("consumables", experiment.getKits().stream().map(Dtos::asDto).collect(Collectors.toList()));
    model.put("consumableConfig", mapper.writeValueAsString(consumableConfig));
    model.put("runPartitions", experiment.getRunPartitions().stream().map(entry -> new ExperimentDto.RunPartitionDto(Dtos.asDto(entry.getRun()), Dtos.asDto(entry.getPartition(), indexChecker))).collect(Collectors.toList()));
    model.put("title", "Edit Experiment");
    return new ModelAndView("/WEB-INF/pages/editExperiment.jsp", model);
}
Also used : KitDescriptor(uk.ac.bbsrc.tgac.miso.core.data.impl.kit.KitDescriptor) PathVariable(org.springframework.web.bind.annotation.PathVariable) RunPartition(uk.ac.bbsrc.tgac.miso.core.data.Experiment.RunPartition) NotFoundException(org.springframework.security.acls.model.NotFoundException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Autowired(org.springframework.beans.factory.annotation.Autowired) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) IOException(java.io.IOException) Experiment(uk.ac.bbsrc.tgac.miso.core.data.Experiment) ExperimentDto(uk.ac.bbsrc.tgac.miso.dto.ExperimentDto) Controller(org.springframework.stereotype.Controller) Dtos(uk.ac.bbsrc.tgac.miso.dto.Dtos) Collectors(java.util.stream.Collectors) IndexChecker(uk.ac.bbsrc.tgac.miso.core.util.IndexChecker) ModelMap(org.springframework.ui.ModelMap) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Objects(java.util.Objects) ModelAndView(org.springframework.web.servlet.ModelAndView) ExperimentService(uk.ac.bbsrc.tgac.miso.core.service.ExperimentService) Stream(java.util.stream.Stream) GetMapping(org.springframework.web.bind.annotation.GetMapping) KitDescriptor(uk.ac.bbsrc.tgac.miso.core.data.impl.kit.KitDescriptor) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Dtos(uk.ac.bbsrc.tgac.miso.dto.Dtos) ExperimentDto(uk.ac.bbsrc.tgac.miso.dto.ExperimentDto) Experiment(uk.ac.bbsrc.tgac.miso.core.data.Experiment) ModelAndView(org.springframework.web.servlet.ModelAndView) NotFoundException(org.springframework.security.acls.model.NotFoundException) RunPartition(uk.ac.bbsrc.tgac.miso.core.data.Experiment.RunPartition) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 3 with RunPartition

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

the class ExperimentRestController method addPartition.

@PostMapping(value = "/{experimentId}/add", produces = "application/json")
@ResponseBody
public ExperimentDto addPartition(@PathVariable Long experimentId, @RequestParam("runId") Long runId, @RequestParam("partitionId") Long partitionId) throws IOException {
    Experiment experiment = experimentService.get(experimentId);
    if (experiment == null) {
        throw new RestException("No such experiment.", Status.NOT_FOUND);
    }
    Run run = runService.get(runId);
    if (run == null) {
        throw new RestException("No such run.", Status.NOT_FOUND);
    }
    Partition partition = containerService.getPartition(partitionId);
    if (partition == null) {
        throw new RestException("No such partition.", Status.NOT_FOUND);
    }
    if (run.getSequencerPartitionContainers().stream().flatMap(container -> container.getPartitions().stream()).noneMatch(p -> p.getId() == partitionId)) {
        throw new RestException("Partition not in run.", Status.BAD_REQUEST);
    }
    if (experiment.getRunPartitions().stream().noneMatch(rp -> rp.getPartition().getId() == partition.getId() && rp.getRun().getId() == run.getId())) {
        RunPartition rp = new RunPartition();
        rp.setExperiment(experiment);
        rp.setPartition(partition);
        rp.setRun(run);
        experiment.getRunPartitions().add(rp);
        experimentService.update(experiment);
    }
    return get(experimentId);
}
Also used : PathVariable(org.springframework.web.bind.annotation.PathVariable) RequestParam(org.springframework.web.bind.annotation.RequestParam) RunPartition(uk.ac.bbsrc.tgac.miso.core.data.Experiment.RunPartition) Autowired(org.springframework.beans.factory.annotation.Autowired) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) Experiment(uk.ac.bbsrc.tgac.miso.core.data.Experiment) Controller(org.springframework.stereotype.Controller) Dtos(uk.ac.bbsrc.tgac.miso.dto.Dtos) KitConsumableDto(uk.ac.bbsrc.tgac.miso.dto.KitConsumableDto) RequestBody(org.springframework.web.bind.annotation.RequestBody) PutMapping(org.springframework.web.bind.annotation.PutMapping) Run(uk.ac.bbsrc.tgac.miso.core.data.Run) ContainerService(uk.ac.bbsrc.tgac.miso.core.service.ContainerService) GetMapping(org.springframework.web.bind.annotation.GetMapping) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) KitService(uk.ac.bbsrc.tgac.miso.core.service.KitService) Status(javax.ws.rs.core.Response.Status) PostMapping(org.springframework.web.bind.annotation.PostMapping) Collection(java.util.Collection) IOException(java.io.IOException) ExperimentDto(uk.ac.bbsrc.tgac.miso.dto.ExperimentDto) Kit(uk.ac.bbsrc.tgac.miso.core.data.Kit) Partition(uk.ac.bbsrc.tgac.miso.core.data.Partition) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) Collectors(java.util.stream.Collectors) HttpStatus(org.springframework.http.HttpStatus) ExperimentService(uk.ac.bbsrc.tgac.miso.core.service.ExperimentService) List(java.util.List) RunService(uk.ac.bbsrc.tgac.miso.core.service.RunService) RunPartition(uk.ac.bbsrc.tgac.miso.core.data.Experiment.RunPartition) Partition(uk.ac.bbsrc.tgac.miso.core.data.Partition) Experiment(uk.ac.bbsrc.tgac.miso.core.data.Experiment) RunPartition(uk.ac.bbsrc.tgac.miso.core.data.Experiment.RunPartition) Run(uk.ac.bbsrc.tgac.miso.core.data.Run) PostMapping(org.springframework.web.bind.annotation.PostMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 4 with RunPartition

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

the class Dtos method to.

public static Experiment to(@Nonnull ExperimentDto dto) {
    Experiment to = new Experiment();
    setLong(to::setId, dto.getId(), false);
    setString(to::setAccession, dto.getAccession());
    to.setAlias(dto.getAlias());
    to.setDescription(dto.getDescription());
    setString(to::setName, dto.getName());
    to.setLibrary(to(dto.getLibrary()));
    to.setInstrumentModel(to(dto.getInstrumentModel()));
    to.setRunPartitions(dto.getPartitions().stream().map(rpDto -> {
        RunPartition rpTo = new RunPartition();
        rpTo.setExperiment(to);
        rpTo.setPartition(to(rpDto.getPartition()));
        rpTo.setRun(PlatformType.get(rpDto.getRun().getPlatformType()).createRun());
        rpTo.getRun().setId(rpDto.getRun().getId());
        return rpTo;
    }).collect(Collectors.toList()));
    to.setStudy(to(dto.getStudy()));
    to.setTitle(dto.getTitle());
    return to;
}
Also used : Experiment(uk.ac.bbsrc.tgac.miso.core.data.Experiment) RunPartition(uk.ac.bbsrc.tgac.miso.core.data.Experiment.RunPartition) 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

Experiment (uk.ac.bbsrc.tgac.miso.core.data.Experiment)4 RunPartition (uk.ac.bbsrc.tgac.miso.core.data.Experiment.RunPartition)4 IOException (java.io.IOException)3 Collectors (java.util.stream.Collectors)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 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 ExperimentService (uk.ac.bbsrc.tgac.miso.core.service.ExperimentService)3 Dtos (uk.ac.bbsrc.tgac.miso.dto.Dtos)3 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 Collection (java.util.Collection)2 List (java.util.List)2 Stream (java.util.stream.Stream)2 Status (javax.ws.rs.core.Response.Status)2 HttpStatus (org.springframework.http.HttpStatus)2 PostMapping (org.springframework.web.bind.annotation.PostMapping)2 PutMapping (org.springframework.web.bind.annotation.PutMapping)2 RequestBody (org.springframework.web.bind.annotation.RequestBody)2