Skip to content

Commit fb4e53d

Browse files
committed
Unimplement StructureAlignment in CeSymm
This change was necessary since the return type is a MultipleAlignment and the features of symmetry analysis (axes, one input, etc) made the implementation not useful. The only down side is that the UserArgumentProcessor cannot be used anymore, so a new one would be needed for the CLI.
1 parent d6eeb30 commit fb4e53d

File tree

8 files changed

+113
-406
lines changed

8 files changed

+113
-406
lines changed

biojava-structure-gui/src/main/java/demo/DemoCeSymm.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
package demo;
22

33
import java.io.IOException;
4-
import java.util.ArrayList;
5-
import java.util.List;
6-
74
import org.biojava.nbio.structure.Atom;
85
import org.biojava.nbio.structure.Structure;
96
import org.biojava.nbio.structure.StructureException;
@@ -55,13 +52,11 @@ public static void main(String[] args)
5552

5653
//Set the name of the protein structure to analyze
5754
String name = "1vym";
58-
List<Atom[]> atoms = new ArrayList<Atom[]>();
5955

6056
//Download the atoms
6157
AtomCache cache = new AtomCache();
6258
Structure s = cache.getStructure(name);
63-
Atom[] array = StructureTools.getRepresentativeAtomArray(s);
64-
atoms.add(array);
59+
Atom[] atoms = StructureTools.getRepresentativeAtomArray(s);
6560

6661
CeSymm ceSymm = new CeSymm();
6762

@@ -73,7 +68,7 @@ public static void main(String[] args)
7368
params.setMultipleAxes(true);
7469

7570
//Run the alignment
76-
MultipleAlignment symmetry = ceSymm.align(atoms, params);
71+
MultipleAlignment symmetry = ceSymm.analyze(atoms, params);
7772

7873
//Display the results in jmol
7974
SymmetryDisplay.display(symmetry, ceSymm.getSymmetryAxes());

biojava-structure-gui/src/main/java/org/biojava/nbio/structure/symmetry/gui/SymmetryCalc.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,14 @@ public SymmetryCalc(SymmetryGui p, Structure s, String n) {
4848
public void run() {
4949

5050
//The structure has been downloaded, now calculate the alignment ...
51-
CeSymm algorithm = parent.getSymmetryAlgorithm();
52-
CESymmParameters params = (CESymmParameters) algorithm.getParameters();
51+
CeSymm ceSymm = parent.getSymmetryAlgorithm();
52+
CESymmParameters params = (CESymmParameters) ceSymm.getParameters();
5353

5454
try {
5555

56-
List<Atom[]> atoms = new ArrayList<Atom[]>();
57-
atoms.add(StructureTools.getRepresentativeAtomArray(structure));
56+
Atom[] atoms = StructureTools.getRepresentativeAtomArray(structure);
5857

59-
MultipleAlignment msa = algorithm.align(atoms);
58+
MultipleAlignment msa = ceSymm.analyze(atoms);
6059

6160
List<String> names = new ArrayList<String>();
6261
for (int su=0; su<msa.size(); su++){
@@ -65,7 +64,7 @@ public void run() {
6564
msa.getEnsemble().setStructureNames(names);
6665

6766
MultipleAlignmentJmol jmol =
68-
SymmetryDisplay.display(msa, algorithm.getSymmetryAxes());
67+
SymmetryDisplay.display(msa, ceSymm.getSymmetryAxes());
6968
String title = jmol.getTitle();
7069

7170
if (params != null)

biojava-structure/src/main/java/demo/DemoCeSymm.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
package demo;
22

33
import java.io.IOException;
4-
import java.util.ArrayList;
5-
import java.util.List;
6-
74
import org.biojava.nbio.structure.Atom;
85
import org.biojava.nbio.structure.Structure;
96
import org.biojava.nbio.structure.StructureException;
@@ -55,13 +52,11 @@ public static void main(String[] args)
5552

5653
//Set the name of the protein structure to analyze
5754
String name = "1u6d";
58-
List<Atom[]> atoms = new ArrayList<Atom[]>();
5955

6056
//Download the atoms
6157
AtomCache cache = new AtomCache();
6258
Structure s = cache.getStructure(name);
63-
Atom[] array = StructureTools.getRepresentativeAtomArray(s);
64-
atoms.add(array);
59+
Atom[] atoms = StructureTools.getRepresentativeAtomArray(s);
6560

6661
CeSymm ceSymm = new CeSymm();
6762

@@ -73,7 +68,7 @@ public static void main(String[] args)
7368
params.setMultipleAxes(true);
7469

7570
//Run the alignment
76-
MultipleAlignment symmetry = ceSymm.align(atoms, params);
71+
MultipleAlignment symmetry = ceSymm.analyze(atoms, params);
7772

7873
//Display the results in FatCat format
7974
System.out.println(MultipleAlignmentWriter.toFatCat(symmetry));

biojava-structure/src/main/java/org/biojava/nbio/structure/align/util/AlignmentTools.java

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
import org.slf4j.Logger;
2929
import org.slf4j.LoggerFactory;
3030

31+
import java.io.IOException;
32+
import java.io.Writer;
3133
import java.util.*;
3234
import java.util.Map.Entry;
3335
import java.util.regex.Matcher;
@@ -1114,4 +1116,80 @@ public static int[] calculateBlockGap(int[][][] optAln){
11141116
}
11151117
return blockGap;
11161118
}
1119+
1120+
/**
1121+
* Creates a simple interaction format (SIF) file for an alignment.
1122+
*
1123+
* The SIF file can be read by network software (eg Cytoscape) to analyze
1124+
* alignments as graphs.
1125+
*
1126+
* This function creates a graph with residues as nodes and two types of edges:
1127+
* 1. backbone edges, which connect adjacent residues in the aligned protein
1128+
* 2. alignment edges, which connect aligned residues
1129+
*
1130+
* @param out Stream to write to
1131+
* @param afpChain alignment to write
1132+
* @param ca1 First protein, used to generate node names
1133+
* @param ca2 Second protein, used to generate node names
1134+
* @param backboneInteraction Two-letter string used to identify backbone edges
1135+
* @param alignmentInteraction Two-letter string used to identify alignment edges
1136+
* @throws IOException
1137+
*/
1138+
public static void alignmentToSIF(Writer out,AFPChain afpChain,
1139+
Atom[] ca1,Atom[] ca2, String backboneInteraction,
1140+
String alignmentInteraction) throws IOException {
1141+
1142+
//out.write("Res1\tInteraction\tRes2\n");
1143+
String name1 = afpChain.getName1();
1144+
String name2 = afpChain.getName2();
1145+
if(name1==null) name1=""; else name1+=":";
1146+
if(name2==null) name2=""; else name2+=":";
1147+
1148+
// Print alignment edges
1149+
int nblocks = afpChain.getBlockNum();
1150+
int[] blockLen = afpChain.getOptLen();
1151+
int[][][] optAlign = afpChain.getOptAln();
1152+
for(int b=0;b<nblocks;b++) {
1153+
for(int r=0;r<blockLen[b];r++) {
1154+
int res1 = optAlign[b][0][r];
1155+
int res2 = optAlign[b][1][r];
1156+
1157+
ResidueNumber rn1 = ca1[res1].getGroup().getResidueNumber();
1158+
ResidueNumber rn2 = ca2[res2].getGroup().getResidueNumber();
1159+
1160+
String node1 = name1+rn1.getChainId()+rn1.toString();
1161+
String node2 = name2+rn2.getChainId()+rn2.toString();
1162+
1163+
out.write(String.format("%s\t%s\t%s\n",node1, alignmentInteraction, node2));
1164+
}
1165+
}
1166+
1167+
// Print first backbone edges
1168+
ResidueNumber rn = ca1[0].getGroup().getResidueNumber();
1169+
String last = name1+rn.getChainId()+rn.toString();
1170+
for(int i=1;i<ca1.length;i++) {
1171+
rn = ca1[i].getGroup().getResidueNumber();
1172+
String curr = name1+rn.getChainId()+rn.toString();
1173+
out.write(String.format("%s\t%s\t%s\n",last, backboneInteraction, curr));
1174+
last = curr;
1175+
}
1176+
1177+
// Print second backbone edges, if the proteins differ
1178+
// Do some quick checks for whether the proteins differ
1179+
// (Not perfect, but should detect major differences and CPs.)
1180+
if(!name1.equals(name2) ||
1181+
ca1.length!=ca2.length ||
1182+
(ca1.length>0 && ca1[0].getGroup()!=null && ca2[0].getGroup()!=null &&
1183+
!ca1[0].getGroup().getResidueNumber().equals(ca2[0].getGroup().getResidueNumber()) ) ) {
1184+
rn = ca2[0].getGroup().getResidueNumber();
1185+
last = name2+rn.getChainId()+rn.toString();
1186+
for(int i=1;i<ca2.length;i++) {
1187+
rn = ca2[i].getGroup().getResidueNumber();
1188+
String curr = name2+rn.getChainId()+rn.toString();
1189+
out.write(String.format("%s\t%s\t%s\n",last, backboneInteraction, curr));
1190+
last = curr;
1191+
}
1192+
}
1193+
}
1194+
11171195
}

biojava-structure/src/main/java/org/biojava/nbio/structure/symmetry/internal/CeSymm.java

Lines changed: 13 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,8 @@
1515
import org.biojava.nbio.structure.Calc;
1616
import org.biojava.nbio.structure.StructureException;
1717
import org.biojava.nbio.structure.StructureTools;
18-
import org.biojava.nbio.structure.align.AbstractStructureAlignment;
19-
import org.biojava.nbio.structure.align.MultipleStructureAligner;
2018
import org.biojava.nbio.structure.align.ce.CECalculator;
2119
import org.biojava.nbio.structure.align.ce.CeCPMain;
22-
import org.biojava.nbio.structure.align.ce.ConfigStrucAligParams;
2320
import org.biojava.nbio.structure.align.ce.MatrixListener;
2421
import org.biojava.nbio.structure.align.model.AFPChain;
2522
import org.biojava.nbio.structure.align.multiple.MultipleAlignment;
@@ -57,8 +54,7 @@
5754
* @since 4.2.0
5855
*
5956
*/
60-
public class CeSymm extends AbstractStructureAlignment
61-
implements MatrixListener, MultipleStructureAligner {
57+
public class CeSymm implements MatrixListener {
6258

6359
/**
6460
* Version History:<p>
@@ -92,13 +88,6 @@ public CeSymm() {
9288
refined = false;
9389
}
9490

95-
public static void main(String[] args) {
96-
// Responsible for creating a CeSymm instance
97-
CeSymmUserArgumentProcessor processor =
98-
new CeSymmUserArgumentProcessor();
99-
processor.process(args);
100-
}
101-
10291
public static String toDBSearchResult(AFPChain afpChain) {
10392
StringBuffer str = new StringBuffer();
10493

@@ -242,17 +231,7 @@ public void setCalculator(CECalculator calculator) {
242231
this.calculator = calculator;
243232
}
244233

245-
@Deprecated
246-
@Override
247-
public AFPChain align(Atom[] ca1, Atom[] ca2) throws StructureException {
248-
249-
if (params == null) params = new CESymmParameters();
250-
return align(ca1, ca2, params);
251-
}
252-
253-
@Deprecated
254-
@Override
255-
public AFPChain align(Atom[] ca10, Atom[] ca2O, Object param)
234+
private AFPChain align(Atom[] ca10, Atom[] ca2O, Object param)
256235
throws StructureException {
257236

258237
//STEP 0: prepare all the information for the symmetry alignment
@@ -433,27 +412,18 @@ public AFPChain align(Atom[] ca10, Atom[] ca2O, Object param)
433412
return afpChain;
434413
}
435414

436-
@Override
437-
public ConfigStrucAligParams getParameters() {
415+
public CESymmParameters getParameters() {
438416
return params;
439417
}
440418

441-
@Override
442-
public void setParameters(ConfigStrucAligParams parameters) {
443-
if (!(parameters instanceof CESymmParameters)) {
444-
throw new IllegalArgumentException(
445-
"Need to provide CESymmParameters, but provided "
446-
+ parameters.getClass().getName());
447-
}
448-
params = (CESymmParameters) parameters;
419+
public void setParameters(CESymmParameters parameters) {
420+
params = parameters;
449421
}
450422

451-
@Override
452423
public String getAlgorithmName() {
453424
return algorithmName;
454425
}
455426

456-
@Override
457427
public String getVersion() {
458428
return version;
459429
}
@@ -501,42 +471,34 @@ public List<AFPChain> getAfpAlignments() {
501471
return afpAlignments;
502472
}
503473

504-
@Override
505-
public MultipleAlignment align(List<Atom[]> atomArrays)
474+
public MultipleAlignment analyze(Atom[] atomArrays)
506475
throws StructureException {
507476

508477
if (params == null) params = new CESymmParameters();
509-
return align(atomArrays, params);
478+
return analyze(atomArrays, params);
510479
}
511480

512-
@Override
513-
public MultipleAlignment align(List<Atom[]> atomArrays, Object param)
481+
public MultipleAlignment analyze(Atom[] atoms, CESymmParameters param)
514482
throws StructureException {
515483

516-
if (atomArrays.size() != 1) {
517-
throw new IllegalArgumentException(
518-
"For symmetry analysis only one Structure is needed, "+
519-
atomArrays.size()+" Structures given.");
484+
if (atoms.length < 1) {
485+
throw new IllegalArgumentException("Empty Atom array given.");
520486
}
521-
if (!(params instanceof CESymmParameters)) {
522-
throw new IllegalArgumentException("CE-Symm algorithm needs an "
523-
+ "object of call CESymmParameters as argument.");
524-
}
525-
this.params = (CESymmParameters) param;
487+
this.params = param;
526488

527489
//If the multiple axes is called, run iterative version
528490
if (params.isMultipleAxes() &&
529491
params.getRefineMethod() != RefineMethod.NOT_REFINED){
530492

531493
logger.warn("Running iteratively CeSymm: ignore Warnings.");
532494
CeSymmIterative iterative = new CeSymmIterative(params);
533-
MultipleAlignment result = iterative.execute(atomArrays.get(0));
495+
MultipleAlignment result = iterative.execute(atoms);
534496
axes = iterative.getSymmetryAxes();
535497
return result;
536498
}
537499

538500
//Otherwise perform only one CeSymm alignment
539-
AFPChain afp = align(atomArrays.get(0), atomArrays.get(0), params);
501+
AFPChain afp = align(atoms, atoms, params);
540502

541503
if (refined){
542504
msa = SymmetryTools.fromAFP(afp, ca1);

biojava-structure/src/main/java/org/biojava/nbio/structure/symmetry/internal/CeSymmIterative.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public MultipleAlignment execute(Atom[] atoms)
108108
* This method runs iteratively CeSymm on the symmetric units
109109
* until no more symmetries exist.
110110
*
111-
* @param atoms Coordinates of the symmetric structure
111+
* @param atoms Coordinates of the structure atoms
112112
* @param first starting position of the atom array in the original array
113113
* @throws StructureException
114114
*/
@@ -118,9 +118,7 @@ private void iterate(Atom[] atoms, int first) throws StructureException {
118118

119119
//Perform the CeSymm alignment
120120
CeSymm aligner = new CeSymm();
121-
List<Atom[]> array = new ArrayList<Atom[]>();
122-
array.add(atoms);
123-
MultipleAlignment align = aligner.align(array, params);
121+
MultipleAlignment align = aligner.analyze(atoms, params);
124122
if (name == null)
125123
name = align.getEnsemble().getStructureNames().get(0);
126124

0 commit comments

Comments
 (0)