public static InstrumentDto asDto(@Nonnull Instrument from) { InstrumentDto dto = new InstrumentDto(); dto.setId(from.getId()); dto.setDateCommissioned(formatDate(from.getDateCommissioned())); dto.setDateDecommissioned(formatDate(from.getDateDecommissioned())); dto.setName(from.getName()); dto.setInstrumentModel(asDto(from.getInstrumentModel())); dto.setSerialNumber(from.getSerialNumber()); if (from.getDateDecommissioned() == null) { if (from.isOutOfService()) { dto.setStatus("Out of Service"); } else { dto.setStatus("Production"); } } else if (from.getUpgradedInstrument() != null) { dto.setStatus("Upgraded"); } else { dto.setStatus("Retired"); } return dto; }
private void applyChanges(Instrument target, Instrument source) { target.setInstrumentModel(source.getInstrumentModel()); target.setName(source.getName()); target.setSerialNumber(source.getSerialNumber()); target.setDateCommissioned(source.getDateCommissioned()); target.setDateDecommissioned(source.getDateDecommissioned()); target.setUpgradedInstrument(source.getUpgradedInstrument()); }
private void loadChildEntities(Instrument instrument) throws IOException { if (instrument.getUpgradedInstrument() != null) { instrument.setUpgradedInstrument(get(instrument.getUpgradedInstrument().getId())); } else { instrument.setUpgradedInstrument(null); } }
public static Instrument to(@Nonnull InstrumentDto dto) { Instrument to = new InstrumentImpl(); to.setId(dto.getId()); to.setDateCommissioned(parseDate(dto.getDateCommissioned())); to.setDateDecommissioned(parseDate(dto.getDateDecommissioned())); to.setName(dto.getName()); to.setInstrumentModel(to(dto.getInstrumentModel())); to.setSerialNumber(dto.getSerialNumber()); return to; }
private InstrumentPosition findPosition(long id, Instrument instrument) { return instrument.getInstrumentModel().getPositions().stream() .filter(p -> p.getId() == id) .findFirst().orElse(null); }
@Override public String toString() { return "AbstractInstrument [id=" + id + ", name=" + name + ", instrumentModel=" + instrumentModel.getId() + ", serialNumber=" + serialNumber + ", dateCommissioned=" + dateCommissioned + ", dateDecommissioned=" + dateDecommissioned + ", upgradedInstrument=" + (upgradedInstrument == null ? null : upgradedInstrument.getId()) + "]"; }
public static ContainerDto asDto(@Nonnull SequencerPartitionContainer from, boolean includePartitions, boolean includePoolContents) { ContainerDto dto = new ContainerDto(); dto.setId(from.getId()); dto.setIdentificationBarcode(from.getIdentificationBarcode()); dto.setModel(asDto(from.getModel())); Run lastRun = from.getLastRun(); if (lastRun != null) { dto.setLastRunAlias(lastRun.getAlias()); dto.setLastRunId(lastRun.getId()); dto.setLastSequencerId(lastRun.getSequencer().getId()); dto.setLastSequencerName(lastRun.getSequencer().getName()); } if (from.getLastModified() != null) { dto.setLastModified(formatDateTime(from.getLastModified())); } if (from.getClusteringKit() != null) { dto.setClusteringKit(asDto(from.getClusteringKit())); } if (from.getMultiplexingKit() != null) { dto.setMultiplexingKit(asDto(from.getMultiplexingKit())); } if (includePartitions) { dto.setPartitions(asPartitionDtos(from.getPartitions(), includePoolContents)); } return dto; }
private List<InstrumentStatus> map(List<InstrumentPositionStatus> positions) { Map<Long, InstrumentStatus> statusByInstrumentId = new HashMap<>(); for (InstrumentPositionStatus position : positions) { if (!statusByInstrumentId.containsKey(position.getInstrument().getId())) { InstrumentStatus status = new InstrumentStatus(); status.setInstrument(position.getInstrument()); statusByInstrumentId.put(position.getInstrument().getId(), status); } InstrumentStatus existing = statusByInstrumentId.get(position.getInstrument().getId()); if (position.getPosition() == null) { InstrumentPosition nullPosition = new InstrumentPosition(); nullPosition.setAlias("n/a"); nullPosition.setInstrumentModel(position.getInstrument().getInstrumentModel()); position.setPosition(nullPosition); } if (existing.getPositions().containsKey(position.getPosition())) { // there are likely multiple runs with the same start date Run moreRecent = getMoreRecentRun(existing.getPositions().get(position.getPosition()), position.getRun()); existing.getPositions().put(position.getPosition(), moreRecent); } else { existing.getPositions().put(position.getPosition(), position.getRun()); } } return new ArrayList<>(statusByInstrumentId.values()); }
@Override public long save(ServiceRecord ssr) throws IOException { long id; if (ssr.getId() == ServiceRecord.UNSAVED_ID) { if (ssr.getInstrument().getDateDecommissioned() != null) throw new IOException("Cannot add service records to a retired instrument!"); id = (long) currentSession().save(ssr); } else { currentSession().update(ssr); id = ssr.getId(); } return id; }
@Override public String getDeleteDescription() { return getInstrument().getName() + " " + (getReferenceNumber() == null ? "" : "RE " + getReferenceNumber() + ": ") + getTitle(); }
public boolean isFull() { return getRunPositions().size() >= sequencer.getInstrumentModel().getNumContainers(); }
public static ArrayRunDto asDto(@Nonnull ArrayRun from) { ArrayRunDto dto = new ArrayRunDto(); dto.setId(from.getId()); dto.setAlias(from.getAlias()); dto.setDescription(from.getDescription()); dto.setFilePath(from.getFilePath()); if (from.getInstrument() != null) { dto.setInstrumentId(from.getInstrument().getId()); dto.setInstrumentName(from.getInstrument().getName()); } if (from.getArray() != null) { dto.setArray(asDto(from.getArray())); } dto.setStatus(from.getHealth().getKey()); if (from.getStartDate() != null) { dto.setStartDate(formatDate(from.getStartDate())); } if (from.getCompletionDate() != null) { dto.setCompletionDate(formatDate(from.getCompletionDate())); } if (from.getLastModified() != null) { dto.setLastModified(formatDate(from.getLastModified())); } return dto; }
@Override protected void makeColumns(Run run, Partition partition, PoolableElementView dilution, String userName, String[] output) { output[0] = dilution.getLibraryName(); output[1] = dilution.getLibraryAlias(); final Optional<Index> firstIndex = dilution.getIndices().stream().filter(i -> i.getPosition() == 1).findFirst(); output[2] = firstIndex.map(Index::getName).orElse(""); output[3] = firstIndex.map(Index::getSequence).orElse(""); final Optional<Index> secondIndex = dilution.getIndices().stream().filter(i -> i.getPosition() == 2).findFirst(); output[4] = secondIndex.map(Index::getName).orElse(""); output[5] = secondIndex.map(Index::getSequence) .map(run.getSequencer().getInstrumentModel().getDataManglingPolicy() == InstrumentDataManglingPolicy.I5_RC ? SampleSheet::reverseComplement : Function.identity()) .orElse(""); }
@Override public long create(ServiceRecord record) throws IOException { record.setInstrument(instrumentService.get(record.getInstrument().getId())); return serviceRecordDao.save(record); }
private boolean updateSequencingParameters(final Run target, User user, Predicate<SequencingParameters> filterParameters, final Instrument sequencer) throws IOException { // If the sequencing parameters haven't been updated by a human, see if we can find exactly one that matches. if (!target.didSomeoneElseChangeColumn("parameters", user)) { List<SequencingParameters> possibleParameters = sequencingParametersService.getForInstrumentModel(sequencer.getInstrumentModel().getId()).stream() .filter(parameters -> !parameters.getName().startsWith("Custom")).filter(filterParameters).collect(Collectors.toList()); if (possibleParameters.size() == 1) { if (target.getSequencingParameters() == null || possibleParameters.get(0).getId() != target.getSequencingParameters().getId()) { target.setSequencingParameters(possibleParameters.get(0)); return true; } } } return false; }
@Override public void update(Instrument instrument) throws IOException { authorizationManager.throwIfNonAdmin(); Instrument managed = get(instrument.getId()); applyChanges(managed, instrument); loadChildEntities(managed); save(managed); }
@Override protected void makeColumns(Run run, Partition p, PoolableElementView dilution, String userName, String[] output) { output[0] = p.getSequencerPartitionContainer().getIdentificationBarcode(); output[1] = p.getPartitionNumber().toString(); output[2] = String.format("%d_%s_%s", p.getSequencerPartitionContainer().getId(), dilution.getLibraryName(), dilution.getDilutionName()); output[3] = dilution.getSampleAlias().replaceAll("\\s", ""); output[4] = dilution.getIndices().stream()// .sorted(Comparator.comparingInt(Index::getPosition))// .map(i -> { if (run.getSequencer().getInstrumentModel().getDataManglingPolicy() == InstrumentDataManglingPolicy.I5_RC && i.getPosition() == 2) { return reverseComplement(i.getSequence()); } return i.getSequence(); })// .collect(Collectors.joining("-")); output[5] = dilution.getLibraryDescription(); output[6] = "N"; output[7] = "NA"; output[8] = userName; }
@Override public void update(ServiceRecord record) throws IOException { ServiceRecord managed = get(record.getId()); record.setInstrument(instrumentService.get(managed.getInstrument().getId())); validateChange(record, managed); applyRecordChanges(managed, record); serviceRecordDao.save(managed); }
InstrumentPosition position = null; if (!isStringEmptyOrNull(positionName)) { position = target.getSequencer().getInstrumentModel().getPositions().stream() .filter(pos -> positionName.equals(pos.getAlias())) .findFirst().orElseThrow(() -> new IllegalArgumentException(String.format("Unknown position '%s' for platform '%s'", positionName, target.getSequencer().getInstrumentModel().getAlias())));