|
32 | 32 | import org.biojava.nbio.core.sequence.compound.AminoAcidCompound; |
33 | 33 | import org.biojava.nbio.structure.Atom; |
34 | 34 | import org.biojava.nbio.structure.Chain; |
| 35 | +import org.biojava.nbio.structure.EntityInfo; |
| 36 | +import org.biojava.nbio.structure.Group; |
35 | 37 | import org.biojava.nbio.structure.Structure; |
36 | 38 | import org.biojava.nbio.structure.StructureException; |
37 | 39 | import org.biojava.nbio.structure.align.StructureAlignment; |
@@ -252,12 +254,49 @@ public boolean mergeIdenticalByEntityId(SubunitCluster other) { |
252 | 254 | if (!isIdenticalByEntityIdTo(other)) |
253 | 255 | return false; |
254 | 256 |
|
| 257 | + Subunit thisSub = this.subunits.get(this.representative); |
| 258 | + Subunit otherSub = other.subunits.get(other.representative); |
255 | 259 | 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()); |
258 | 262 |
|
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); |
261 | 300 |
|
262 | 301 | return true; |
263 | 302 | } |
|
0 commit comments