Skip to content

Commit fc543af

Browse files
committed
Fixing the cluster by entity id alignment issue. Now tests pass
1 parent 44cdda1 commit fc543af

1 file changed

Lines changed: 43 additions & 4 deletions

File tree

biojava-structure/src/main/java/org/biojava/nbio/structure/cluster/SubunitCluster.java

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
import org.biojava.nbio.core.sequence.compound.AminoAcidCompound;
3333
import org.biojava.nbio.structure.Atom;
3434
import org.biojava.nbio.structure.Chain;
35+
import org.biojava.nbio.structure.EntityInfo;
36+
import org.biojava.nbio.structure.Group;
3537
import org.biojava.nbio.structure.Structure;
3638
import org.biojava.nbio.structure.StructureException;
3739
import org.biojava.nbio.structure.align.StructureAlignment;
@@ -252,12 +254,49 @@ public boolean mergeIdenticalByEntityId(SubunitCluster other) {
252254
if (!isIdenticalByEntityIdTo(other))
253255
return false;
254256

257+
Subunit thisSub = this.subunits.get(this.representative);
258+
Subunit otherSub = other.subunits.get(other.representative);
255259
logger.info("SubunitClusters {}-{} belong to same entity. Assuming they are identical",
256-
this.subunits.get(this.representative).getName(),
257-
other.subunits.get(other.representative).getName());
260+
thisSub.getName(),
261+
otherSub.getName());
258262

259-
this.subunits.addAll(other.subunits);
260-
this.subunitEQR.addAll(other.subunitEQR);
263+
List<Integer> thisAligned = new ArrayList<>();
264+
List<Integer> otherAligned = new ArrayList<>();
265+
266+
// we've merged by entity id, we can assume structure, chain and entity are available
267+
Structure thisStruct = thisSub.getStructure();
268+
Structure otherStruct = otherSub.getStructure();
269+
String thisName = thisSub.getName();
270+
String otherName = otherSub.getName();
271+
Chain thisChain = thisStruct.getChain(thisName);
272+
Chain otherChain = otherStruct.getChain(otherName);
273+
EntityInfo entityInfo = thisChain.getEntityInfo();
274+
275+
// Extract the aligned residues of both Subunits
276+
for (int thisIndex=0; thisIndex < thisSub.size(); thisIndex++) {
277+
278+
Group g = thisSub.getRepresentativeAtoms()[thisIndex].getGroup();
279+
280+
int seqresIndex = entityInfo.getAlignedResIndex(g, thisChain);
281+
282+
Group otherG = otherChain.getSeqResGroups().get(seqresIndex - 1);
283+
284+
if (!otherChain.getAtomGroups().contains(otherG)) {
285+
// skip residues that are unobserved in other sequence ("gaps" in the entity alignment)
286+
continue;
287+
}
288+
289+
int otherIndex = otherChain.getAtomGroups().indexOf(otherG);
290+
291+
// Only consider residues that are part of the SubunitCluster
292+
if (this.subunitEQR.get(this.representative).contains(thisIndex)
293+
&& other.subunitEQR.get(other.representative).contains(otherIndex)) {
294+
thisAligned.add(thisIndex);
295+
otherAligned.add(otherIndex);
296+
}
297+
}
298+
299+
updateEquivResidues(other, thisAligned, otherAligned);
261300

262301
return true;
263302
}

0 commit comments

Comments
 (0)