public static IndexDto asDto(@Nonnull Index from, boolean includeFamily) { IndexDto dto = new IndexDto(); dto.setId(from.getId()); dto.setLabel(from.getLabel()); dto.setName(from.getName()); dto.setPosition(from.getPosition()); dto.setSequence(from.getSequence()); if (includeFamily) { dto.setFamily(asDto(from.getFamily(), false)); } return dto; }
public String getLabel() { if (getSequence() == null || getFamily().hasFakeSequence()) return getName(); return getName() + " (" + getSequence() + ")"; }
/** * Turns indices into strings for easier comparison and changelog message concatentation. * * @param indices * @return */ private Set<String> stringifyIndices(List<Index> indices) { Set<String> original = new HashSet<>(); for (Index index : indices) { if (index != null && index.getId() != Index.UNSAVED_ID) { original.add(index.getFamily().getName() + " - " + index.getLabel()); } } return original; }
dto.setIndexFamilyName(from.getIndices().get(0).getFamily().getName()); for (Index index : from.getIndices()) { switch (index.getPosition()) { case 1: dto.setIndex1Id(index.getId()); dto.setIndex1Label(index.getLabel()); break; case 2: dto.setIndex2Id(index.getId()); dto.setIndex2Label(index.getLabel()); break; default: throw new IllegalArgumentException("Index at position " + index.getPosition());
@Override public void setIndices(List<Index> originalIndices) { List<Index> indices = new ArrayList<>(); for (Index index : originalIndices) { if (index != null) { indices.add(index); } } Index.sort(indices); IndexFamily current = null; for (Index index : indices) { if (index == null) continue; if (current == null) { current = index.getFamily(); } else { if (current.getId() != index.getFamily().getId()) { throw new IllegalArgumentException(String.format( "Indices not all from the same family. (%d:%s vs %d:%s)", current.getId(), current.getName(), index.getFamily().getId(), index.getFamily().getName())); } } } this.indices = indices; }
public int getMaximumNumber() { int max = 0; for (Index index : indices) { if (index.getPosition() > max) { max = index.getPosition(); } } return max; }
@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; }
StringBuilder vsb = new StringBuilder(); for (Index index : dilution.getIndices()) { tsb.append(index.getSequence()); vsb.append(index.getName());
@Override public IndexFamily getCurrentFamily() { if (indices == null) { return IndexFamily.NULL; } for (Index index : indices) { if (index != null) { return index.getFamily(); } } return IndexFamily.NULL; }
public static LibraryTemplateDto asDto(@Nonnull LibraryTemplate from) { LibraryTemplateDto dto = null; if (from instanceof DetailedLibraryTemplate) { dto = asDetailedLibraryTemplateDto((DetailedLibraryTemplate) from); } else { dto = new LibraryTemplateDto(); } dto.setId(from.getId()); dto.setAlias(from.getAlias()); dto.setProjectIds(from.getProjects().stream().map(Project::getId).collect(Collectors.toList())); dto.setDefaultVolume(from.getDefaultVolume()); dto.setPlatformType(from.getPlatformType() != null ? from.getPlatformType().name() : null); dto.setLibraryTypeId(from.getLibraryType() != null ? from.getLibraryType().getId() : null); dto.setSelectionTypeId(from.getLibrarySelectionType() != null ? from.getLibrarySelectionType().getId() : null); dto.setStrategyTypeId(from.getLibraryStrategyType() != null ? from.getLibraryStrategyType().getId() : null); dto.setKitDescriptorId(from.getKitDescriptor() != null ? from.getKitDescriptor().getId() : null); dto.setIndexFamilyId(from.getIndexFamily() != null ? from.getIndexFamily().getId() : null); if (from.getIndexFamily() != null) { if (from.getIndexOnes() != null) { dto.setIndexOneIds(from.getIndexOnes().entrySet().stream() .collect(Collectors.toMap(Entry::getKey, entry -> entry.getValue().getId()))); } if (from.getIndexTwos() != null) { dto.setIndexTwoIds(from.getIndexTwos().entrySet().stream() .collect(Collectors.toMap(Entry::getKey, entry -> entry.getValue().getId()))); } } return dto; }
@Override public String getLongestIndex() { Map<Integer, Integer> lengths = poolDilutions.stream() .flatMap(element -> element.getPoolableElementView().getIndices().stream()) .collect(Collectors.toMap(Index::getPosition, index -> index.getSequence().length(), Integer::max)); if (lengths.isEmpty()) { return "0"; } return lengths.entrySet().stream() .sorted((a, b) -> a.getKey().compareTo(b.getKey())) .map(Entry<Integer, Integer>::getValue) .map(length -> length.toString()) .collect(Collectors.joining(",")); }
private Set<String> getIndexSequencesWithMinimumEditDistance(int minimumDistance) { Set<String> sequences = new HashSet<>(); List<PoolableElementView> views = getPoolDilutions().stream().map(PoolDilution::getPoolableElementView).collect(Collectors.toList()); if (minimumDistance > 1 && views.stream().allMatch(PoolImpl::hasFakeSequence)) return Collections.emptySet(); for (int i = 0; i < views.size(); i++) { String sequence1 = getCombinedIndexSequences(views.get(i)); if (sequence1.length() == 0) { continue; } for (int j = i + 1; j < views.size(); j++) { String sequence2 = getCombinedIndexSequences(views.get(j)); if (sequence2.length() == 0 || !isCheckNecessary(views.get(i), views.get(j), minimumDistance)) { continue; } if (Index.checkEditDistance(sequence1, sequence2) < minimumDistance) { sequences.add(sequence1); sequences.add(sequence2); } } } return sequences; }
public static void sort(final List<Index> indices) { Collections.sort(indices, (o1, o2) -> o1.getPosition() - o2.getPosition()); }
public Iterable<Index> getIndicesForPosition(int position) { List<Index> selected = new ArrayList<>(); for (Index index : indices) { if (index.getPosition() == position) { selected.add(index); } } return selected; }
private static String getCombinedIndexSequences(PoolableElementView view) { return view.getIndices().stream() .sorted((i1, i2) -> Integer.compare(i1.getPosition(), i2.getPosition())) .map(Index::getSequence) .collect(Collectors.joining()); }
@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(""); }