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);
}
}
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);
}
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);
}
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;
}
Aggregations