use of de.bioforscher.jstructure.model.Pair in project jstructure by JonStargaryen.
the class AbstractAlignmentAlgorithm method comparableGroupContainerPair.
/**
* Creates a comparable entity of 2 {@link AtomContainer} objects. They fulfill certain criteria:
* <ul>
* <li>{@link Atom}s are cloned
* <li>for each {@link Group} only shared atoms are retained</li>
* <li>{@link Atom}s are in identical ordering</li>
* <li>{@link Atom}s are wrapped in {@link Group} objects if they were initially</li>
* </ul>
* @param container1 a collection of reference atoms
* @param container2 a collection of candidate atoms
* @param minimalSetOfAtomNames the lower bound of required atom names present (e.g. by setting CA, every time an
* amino acid missing the alpha carbon will result in an exception thrown)
* @param maximalSetOfAtomNames the upper bound of required atom names present (e.g. by setting CA, everything else
* will be dropped, even when both amino acids would share more atoms)
* @return a pair of both collections which can now be aligned
*/
static Pair<GroupContainer, GroupContainer> comparableGroupContainerPair(AtomContainer container1, AtomContainer container2, Set<String> minimalSetOfAtomNames, Set<String> maximalSetOfAtomNames) {
//TODO what happens for alternative positions?
GroupContainer groupContainer1 = cloneIntoGroupContainer(container1);
GroupContainer groupContainer2 = cloneIntoGroupContainer(container2);
int limitingSize = Math.min(groupContainer1.getGroups().size(), groupContainer2.getGroups().size());
List<Group> groups1 = new ArrayList<>();
List<Group> groups2 = new ArrayList<>();
for (int groupIndex = 0; groupIndex < limitingSize; groupIndex++) {
Group group1 = groupContainer1.getGroups().get(groupIndex);
Group group2 = groupContainer2.getGroups().get(groupIndex);
Pair<List<Atom>, List<Atom>> sharedAtoms = selectSharedAtoms(group1, group2, minimalSetOfAtomNames, maximalSetOfAtomNames);
// remove additional/not-shared atoms
group1.getAtoms().clear();
group1.getAtoms().addAll(sharedAtoms.getLeft());
group2.getAtoms().clear();
group2.getAtoms().addAll(sharedAtoms.getRight());
logger.trace("shared atoms between {} and {}: {}", group1, group2, sharedAtoms);
groups1.add(group1);
groups2.add(group2);
}
return new Pair<>(groups1.stream().collect(StructureCollectors.toGroupContainer()), groups2.stream().collect(StructureCollectors.toGroupContainer()));
}
Aggregations