Skip to content

Commit cb06fe4

Browse files
committed
added option to add symmetric interactions in plip parser
Signed-off-by: Christoph Leberecht <[email protected]>
1 parent bd3d4a6 commit cb06fe4

File tree

7 files changed

+81
-55
lines changed

7 files changed

+81
-55
lines changed

.idea/compiler.xml

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

singa-chemistry/src/main/java/bio/singa/chemistry/model/elements/Element.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ public Element asIon(int charge) {
227227
* @return An cation of this element.
228228
*/
229229
public Element asCation(int numberOfElectronsLost) {
230-
return asIon(-numberOfElectronsLost);
230+
return asIon(numberOfElectronsLost);
231231
}
232232

233233
/**
@@ -237,7 +237,7 @@ public Element asCation(int numberOfElectronsLost) {
237237
* @return An anion of this element.
238238
*/
239239
public Element asAnion(int numberOfElectronsGained) {
240-
return asIon(numberOfElectronsGained);
240+
return asIon(-numberOfElectronsGained);
241241
}
242242

243243
/**

singa-structure/pom.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,18 @@
33
xmlns="http://maven.apache.org/POM/4.0.0"
44
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
55
<modelVersion>4.0.0</modelVersion>
6+
<build>
7+
<plugins>
8+
<plugin>
9+
<groupId>org.apache.maven.plugins</groupId>
10+
<artifactId>maven-compiler-plugin</artifactId>
11+
<configuration>
12+
<source>8</source>
13+
<target>8</target>
14+
</configuration>
15+
</plugin>
16+
</plugins>
17+
</build>
618

719
<parent>
820
<artifactId>singa-all</artifactId>

singa-structure/src/main/java/bio/singa/structure/parser/plip/InteractionContainer.java

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ public class InteractionContainer {
2424

2525
private static final Logger logger = LoggerFactory.getLogger(InteractionContainer.class);
2626

27+
public static boolean checkAddedInteractions = true;
28+
2729
/**
2830
* The interactions
2931
*/
@@ -59,24 +61,6 @@ private static boolean interactionPairEquals(LeafIdentifier firstSource, LeafIde
5961
return firstSource.equals(secondTarget) && firstTarget.equals(secondSource);
6062
}
6163

62-
/**
63-
* Tests if two sets of integers (atom identifiers in this context) overlap.
64-
*
65-
* @param firstList The first list of integers.
66-
* @param secondList The second lst of integers.
67-
* @return True, if at least one integer is contained in both sets.
68-
*/
69-
private static boolean atomsOverlap(List<Integer> firstList, List<Integer> secondList) {
70-
for (int first : firstList) {
71-
for (int second : secondList) {
72-
if (first == second) {
73-
return true;
74-
}
75-
}
76-
}
77-
return false;
78-
}
79-
8064
public Map<Ligand, List<Interaction>> getLigandInteractionMap() {
8165
return ligandInteractionMap;
8266
}
@@ -167,7 +151,7 @@ public void addInteraction(Interaction interaction) {
167151
logger.debug("Handling interaction between: {} and {}", interaction.getSource(), interaction.getTarget());
168152
// get interactions that are already present between the leaves
169153
List<Interaction> presentInteractions = getInteractionsBetween(interaction.getSource(), interaction.getTarget());
170-
if (presentInteractions.size() > 0) {
154+
if (presentInteractions.size() > 0 && InteractionContainer.checkAddedInteractions) {
171155
// there are already interactions between those leaves
172156
logger.trace("There are already interactions annotated between those leaves.");
173157
boolean allAreDifferent = true;

singa-structure/src/main/java/bio/singa/structure/parser/plip/PlipContentHandler.java

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package bio.singa.structure.parser.plip;
22

3-
import bio.singa.structure.model.families.AminoAcidFamily;
43
import bio.singa.features.identifiers.LeafIdentifier;
54
import org.slf4j.Logger;
65
import org.slf4j.LoggerFactory;
@@ -85,35 +84,35 @@ public void startElement(String uri, String localName, String qName, Attributes
8584
currentTag = qName;
8685
switch (qName) {
8786
case "halogen_bond":
88-
currentInteraction = new HalogenBond(Integer.valueOf(atts.getValue("id")));
87+
currentInteraction = new HalogenBond(Integer.parseInt(atts.getValue("id")));
8988
interactionType = InteractionType.HALOGEN_BOND;
9089
break;
9190
case "hydrophobic_interaction":
92-
currentInteraction = new HydrophobicInteraction(Integer.valueOf(atts.getValue("id")));
91+
currentInteraction = new HydrophobicInteraction(Integer.parseInt(atts.getValue("id")));
9392
interactionType = InteractionType.HYDROPHOBIC_INTERACTION;
9493
break;
9594
case "hydrogen_bond":
96-
currentInteraction = new HydrogenBond(Integer.valueOf(atts.getValue("id")));
95+
currentInteraction = new HydrogenBond(Integer.parseInt(atts.getValue("id")));
9796
interactionType = InteractionType.HYDROGEN_BOND;
9897
break;
9998
case "water_bridge":
100-
currentInteraction = new WaterBridge(Integer.valueOf(atts.getValue("id")));
99+
currentInteraction = new WaterBridge(Integer.parseInt(atts.getValue("id")));
101100
interactionType = InteractionType.WATER_BRIDGE;
102101
break;
103102
case "salt_bridge":
104-
currentInteraction = new SaltBridge(Integer.valueOf(atts.getValue("id")));
103+
currentInteraction = new SaltBridge(Integer.parseInt(atts.getValue("id")));
105104
interactionType = InteractionType.SALT_BRIDGE;
106105
break;
107106
case "pi_stack":
108-
currentInteraction = new PiStacking(Integer.valueOf(atts.getValue("id")));
107+
currentInteraction = new PiStacking(Integer.parseInt(atts.getValue("id")));
109108
interactionType = InteractionType.PI_STACKING;
110109
break;
111110
case "pi_cation_interaction":
112-
currentInteraction = new PiCation(Integer.valueOf(atts.getValue("id")));
111+
currentInteraction = new PiCation(Integer.parseInt(atts.getValue("id")));
113112
interactionType = InteractionType.PI_CATION_INTERACTION;
114113
break;
115114
case "metal_complex":
116-
currentInteraction = new MetalComplex(Integer.valueOf(atts.getValue("id")));
115+
currentInteraction = new MetalComplex(Integer.parseInt(atts.getValue("id")));
117116
interactionType = InteractionType.METAL_COMPLEX;
118117
break;
119118
case "ligcoo":
@@ -148,6 +147,11 @@ public void endElement(String uri, String localName, String qName) {
148147

149148
@Override
150149
public void characters(char[] ch, int start, int length) {
150+
// String testString = new String(ch, start, length);
151+
// if (currentTag.isEmpty() || testString.isBlank()) {
152+
// return;
153+
// }
154+
// System.out.println(currentTag + ": ("+length+") " + testString);
151155
switch (currentTag) {
152156
case "resnr":
153157
firstLeafSerial = new String(ch, start, length);
@@ -233,12 +237,8 @@ public void characters(char[] ch, int start, int length) {
233237
as(WaterBridge.class).setAcceptor(asInteger(ch, start, length));
234238
break;
235239
case "sidechain":
236-
switch (interactionType) {
237-
case HYDROGEN_BOND:
238-
as(HydrogenBond.class).setSidechain(asBoolean(ch, start, length));
239-
break;
240-
default:
241-
break;
240+
if (interactionType == InteractionType.HYDROGEN_BOND) {
241+
as(HydrogenBond.class).setSidechain(asBoolean(ch, start, length));
242242
}
243243
break;
244244
case "protisdon":
@@ -341,11 +341,6 @@ public void characters(char[] ch, int start, int length) {
341341
case "ligcarbonidx":
342342
as(HydrophobicInteraction.class).setAtom2(asInteger(ch, start, length));
343343
break;
344-
case "restype_lig":
345-
String restype = new String(ch, start, length);
346-
if (!AminoAcidFamily.getAminoAcidTypeByThreeLetterCode(restype).isPresent()) {
347-
// this.noResidueInteraction = true;
348-
}
349344
}
350345

351346
}
@@ -371,7 +366,7 @@ private <InteractionClass extends Interaction> InteractionClass as(Class<Interac
371366

372367
private void addInteraction() {
373368
// skip all interactions that are not between standard amino acids
374-
// TODO This may be going down for amino acid ligands or modified amino acids
369+
// TODO This may be failing for amino acid ligands or modified amino acids
375370
if (noResidueInteraction) {
376371
noResidueInteraction = false;
377372
return;
@@ -386,8 +381,8 @@ private void addInteraction() {
386381
return;
387382
}
388383
// generate identifiers
389-
final LeafIdentifier source = new LeafIdentifier(currentPdbIdentifier, 1, firstLeafChain, Integer.valueOf(firstLeafSerial));
390-
final LeafIdentifier target = new LeafIdentifier(currentPdbIdentifier, 1, secondLeafChain, Integer.valueOf(secondLeafSerial));
384+
final LeafIdentifier source = new LeafIdentifier(currentPdbIdentifier, 1, firstLeafChain, Integer.parseInt(firstLeafSerial));
385+
final LeafIdentifier target = new LeafIdentifier(currentPdbIdentifier, 1, secondLeafChain, Integer.parseInt(secondLeafSerial));
391386
// FIXME for metal complexes this seems to be not valid to take the first occurring entry as source: at atom level source is always the ion
392387
currentInteraction.setSource(source);
393388
currentInteraction.setTarget(target);
@@ -399,15 +394,15 @@ private void addInteraction() {
399394
}
400395

401396
private double asDouble(char[] ch, int start, int length) {
402-
return Double.valueOf(new String(ch, start, length));
397+
return Double.parseDouble(new String(ch, start, length));
403398
}
404399

405400
private int asInteger(char[] ch, int start, int length) {
406-
return Integer.valueOf(new String(ch, start, length));
401+
return Integer.parseInt(new String(ch, start, length));
407402
}
408403

409404
private boolean asBoolean(char[] ch, int start, int length) {
410-
return Boolean.valueOf(new String(ch, start, length));
405+
return Boolean.parseBoolean(new String(ch, start, length));
411406
}
412407

413408

singa-structure/src/main/java/bio/singa/structure/parser/plip/PlipParser.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ public static InteractionContainer parse(String pdbIdentifier, InputStream input
4545
PlipParser parser = new PlipParser(pdbIdentifier, inputStream);
4646
try {
4747
InputSource input = new InputSource(parser.getFetchResult());
48-
input.setEncoding("UTF-8");
4948
parser.getXmlReader().parse(input);
5049
return ((PlipContentHandler) parser.getXmlReader().getContentHandler()).getInteractionContainer();
5150
} catch (IOException e) {

singa-structure/src/test/java/bio/singa/structure/parser/plip/PlipParserTest.java

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,15 @@
66
import org.slf4j.Logger;
77
import org.slf4j.LoggerFactory;
88

9+
import java.io.FileInputStream;
10+
import java.io.FileNotFoundException;
911
import java.io.InputStream;
12+
import java.nio.file.Paths;
1013
import java.util.List;
14+
import java.util.Optional;
1115

1216
import static bio.singa.core.utility.Resources.getResourceAsStream;
13-
import static org.junit.jupiter.api.Assertions.assertEquals;
17+
import static org.junit.jupiter.api.Assertions.*;
1418

1519
/**
1620
* @author cl
@@ -40,6 +44,38 @@ void shouldParseLigandInteractions() {
4044
assertEquals(93, interactionContainer.getInteractions().size());
4145
}
4246

47+
@Test
48+
void shouldFixSymmetricInteractions() {
49+
InputStream inputStream = null;
50+
try {
51+
inputStream = new FileInputStream(Paths.get("/home/leberech/Downloads/PYW_4bge-1-A-1270.xml").toFile());
52+
} catch (FileNotFoundException e) {
53+
fail("");
54+
}
55+
InteractionContainer.checkAddedInteractions = false;
56+
InteractionContainer interactionContainer = PlipParser.parse("4bge", inputStream);
57+
Optional<Interaction> secondHBond = interactionContainer.getAllInteractions()
58+
.stream()
59+
.filter(interaction -> interaction instanceof HydrogenBond)
60+
.filter(interaction -> interaction.getPlipIdentifier() == 2)
61+
.findAny();
62+
assertTrue(secondHBond.isPresent());
63+
64+
inputStream = null;
65+
try {
66+
inputStream = new FileInputStream(Paths.get("/home/leberech/Downloads/PYW_4bge-1-A-1270.xml").toFile());
67+
} catch (FileNotFoundException e) {
68+
fail("");
69+
}
70+
InteractionContainer.checkAddedInteractions = true;
71+
interactionContainer = PlipParser.parse("4bge", inputStream);
72+
secondHBond = interactionContainer.getAllInteractions()
73+
.stream()
74+
.filter(interaction -> interaction instanceof HydrogenBond)
75+
.filter(interaction -> interaction.getPlipIdentifier() == 2)
76+
.findAny();
77+
assertFalse(secondHBond.isPresent());
78+
}
4379

4480
@Test
4581
void shouldParseInteractionsWithInsertionCodes() {

0 commit comments

Comments
 (0)