Skip to content

Commit 6cc075a

Browse files
committed
Support flexible alignments in the MC optimization
Some bugs in the cloning have also been fixed
1 parent 751e6f0 commit 6cc075a

File tree

10 files changed

+215
-121
lines changed

10 files changed

+215
-121
lines changed

biojava-structure/src/main/java/org/biojava/nbio/structure/align/multiple/BlockImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public BlockImpl(BlockSet blockSet) {
4141
public BlockImpl(BlockImpl b) {
4242

4343
this.parent = b.parent;
44-
this.coreLength = b.coreLength;
44+
this.coreLength = -1;
4545

4646
this.alignRes = null;
4747
if (b.alignRes!=null){

biojava-structure/src/main/java/org/biojava/nbio/structure/align/multiple/BlockSetImpl.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import javax.vecmath.Matrix4d;
88

99
/**
10-
* A general implementation of a BlockSet to store multiple alignments.
10+
* A general implementation of a BlockSet to store flexible parts of a multiple alignments.
1111
*
1212
* @author Aleix Lafita
1313
*
@@ -49,10 +49,18 @@ public BlockSetImpl(MultipleAlignment multipleAlignment) {
4949
public BlockSetImpl(BlockSetImpl bs){
5050

5151
this.parent = bs.parent;
52-
this.length = bs.length;
53-
this.coreLength = bs.coreLength;
52+
this.length = -1;
53+
this.coreLength = -1;
5454

55-
this.pose = null; pose = null; //Because the pose is a cache variable it has to be updated/calculated again.
55+
this.pose = null;
56+
if (bs.pose != null){
57+
//Make a deep copy of everything
58+
this.pose = new ArrayList<Matrix4d>();
59+
for (Matrix4d trans:bs.pose){
60+
Matrix4d newTrans = (Matrix4d) trans.clone();
61+
pose.add(newTrans);
62+
}
63+
}
5664

5765
blocks = null;
5866
if (bs.blocks!=null){

biojava-structure/src/main/java/org/biojava/nbio/structure/align/multiple/MultipleAlignmentImpl.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,18 @@ public MultipleAlignmentImpl(MultipleAlignmentImpl ma) {
7575
super(ma);
7676

7777
parent = ma.parent;
78-
pose = null; //Because the pose is a cache variable it has to be updated/calculated again.
78+
pose = null;
79+
if (ma.pose != null){
80+
//Make a deep copy of everything
81+
this.pose = new ArrayList<Matrix4d>();
82+
for (Matrix4d trans:ma.pose){
83+
Matrix4d newTrans = (Matrix4d) trans.clone();
84+
pose.add(newTrans);
85+
}
86+
}
87+
88+
length = -1;
89+
coreLength = -1;
7990

8091
blockSets = null;
8192
if (ma.blockSets!=null){

biojava-structure/src/main/java/org/biojava/nbio/structure/align/multiple/MultipleAlignmentScorer.java

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
import java.util.Arrays;
55
import java.util.List;
66

7-
import javax.vecmath.Matrix4d;
8-
97
import org.biojava.nbio.structure.Atom;
108
import org.biojava.nbio.structure.Calc;
119
import org.biojava.nbio.structure.SVDSuperimposer;
@@ -23,12 +21,12 @@ public class MultipleAlignmentScorer {
2321

2422
//Names for commonly used properties
2523
public static final String PROBABILITY = "Probability"; //AFPChain conversion
26-
public static final String CE_SCORE = "CEscore"; //AFPChain conversion
24+
public static final String CE_SCORE = "CE-score"; //AFPChain conversion
2725
public static final String RMSD = "RMSD";
28-
public static final String AVG_TMSCORE = "Avg-TMscore";
29-
public static final String CEMC_SCORE = "CEMCscore";
26+
public static final String AVGTM_SCORE = "AvgTM-score";
27+
public static final String MC_SCORE = "MultipleMC-score";
3028
public static final String REF_RMSD = "Ref-RMSD";
31-
public static final String REF_TMSCORE = "Ref-TMscore";
29+
public static final String REFTM_SCORE = "RefTM-score";
3230

3331
/**
3432
* Calculates and puts the RMSD and the average TM-Score of the MultipleAlignment.
@@ -49,7 +47,7 @@ public static void calculateScores(MultipleAlignment alignment) throws Structure
4947
for(Atom[] atoms : alignment.getEnsemble().getAtomArrays()) {
5048
lengths.add(atoms.length);
5149
}
52-
alignment.putScore(AVG_TMSCORE, getAvgTMScore(transformed,lengths));
50+
alignment.putScore(AVGTM_SCORE, getAvgTMScore(transformed,lengths));
5351
}
5452

5553
/**
@@ -279,45 +277,57 @@ private static double getRefTMScore(List<Atom[]> transformed, List<Integer> leng
279277
}
280278

281279
/**
282-
* Calculates the CEMC score, specific for the MultipleAlignment algorithm.
280+
* Calculates the MC score, specific for the MultipleAlignment algorithm.
283281
* The score function is modified from the original CEMC paper, making it
284-
* continuous and differentiable.<p>
282+
* continuous and differentiable.
283+
* <p>
284+
* The maximum score of a match is 20, and the penalties for gaps are part of
285+
* the input. The half-score distance, d0, is chosen as in the TM-score.
286+
* <p>
285287
* Complexity: T(n,l) = O(l*n^2), if n=number of structures and l=alignment length.
286288
*
287289
* @param alignment
290+
* @param gapOpen penalty for gap opening (reasonable values are in the range (1.0-20.0)
291+
* @param gapExtension penalty for extending a gap (reasonable values are in the range (0.5-10)
288292
* @return
289293
* @throws StructureException
290294
*/
291-
public static double getCEMCScore(MultipleAlignment alignment) throws StructureException {
295+
public static double getMultipleMCScore(MultipleAlignment alignment, double gapOpen, double gapExtension) throws StructureException {
292296
//Transform Atoms
293297
List<Atom[]> transformed = MultipleAlignmentTools.transformAtoms(alignment);
294298
//Calculate d0
295299
int minLen = Integer.MAX_VALUE;
296300
for(Atom[] atoms : alignment.getEnsemble().getAtomArrays())
297301
if (atoms.length < minLen) minLen = atoms.length;
298302
double d0 = 1.24 * Math.cbrt((minLen) - 15.) - 1.8; //d0 is calculated as in the TM-score
299-
return getCEMCScore(transformed, d0);
303+
return getMultipleMCScore(transformed, d0, gapOpen, gapExtension);
300304
}
301305

302306
/**
303-
* Calculates the CEMC score, specific for the MultipleAlignment algorithm.
307+
* Calculates the MC score, specific for the MultipleAlignment algorithm.
304308
* The score function is modified from the original CEMC paper, making it
305-
* continuous and differentiable.<p>
309+
* continuous and differentiable.
310+
* <p>
311+
* The maximum score of a match is 20, and the penalties for gaps are part of
312+
* the input.
313+
* <p>
306314
* Complexity: T(n,l) = O(l*n^2), if n=number of structures and l=alignment length.
307315
*
308316
* @param transformed List of transformed Atom arrays
309-
* @param d0 parameter for the distance evaluation
317+
* @param d0 parameter for the half-score distance
318+
* @param gapOpen penalty for gap opening (reasonable values are in the range (1.0-20.0)
319+
* @param gapExtension penalty for extending a gap (reasonable values are in the range (0.5-10)
310320
* @return
311321
* @throws StructureException
312322
*/
313-
private static double getCEMCScore(List<Atom[]> transformed, double d0) throws StructureException {
323+
private static double getMultipleMCScore(List<Atom[]> transformed, double d0, double gapOpen, double gapExtension) throws StructureException {
314324

315325
int size = transformed.size();
316326
int length = transformed.get(0).length;
317327
Matrix residueDistances = new Matrix(size,length,-1); //A residue distance is the average distance to all others
318328
double scoreMC = 0.0;
319-
int gapOpen = 0;
320-
int gapExtend = 0;
329+
int gapsOpen = 0;
330+
int gapsExtend = 0;
321331

322332
//Calculate the average residue distances
323333
for (int r1=0; r1<size; r1++){
@@ -326,10 +336,10 @@ private static double getCEMCScore(List<Atom[]> transformed, double d0) throws S
326336
Atom refAtom = transformed.get(r1)[c];
327337
//Calculate the gap extension and opening on the fly
328338
if(refAtom == null) {
329-
if (gapped) gapExtend++;
339+
if (gapped) gapsExtend++;
330340
else {
331341
gapped = true;
332-
gapOpen++;
342+
gapsOpen++;
333343
}
334344
continue;
335345
} else gapped = false;
@@ -366,6 +376,6 @@ private static double getCEMCScore(List<Atom[]> transformed, double d0) throws S
366376
}
367377
}
368378
//Apply the Gap penalty and return
369-
return scoreMC - (gapOpen*10.0 + gapExtend*5.0);
379+
return scoreMC - (gapsOpen*gapOpen + gapsExtend*gapExtension);
370380
}
371381
}

biojava-structure/src/main/java/org/biojava/nbio/structure/align/multiple/MultipleAlignmentTools.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ public static List<Atom[]> transformAtoms(MultipleAlignment alignment) {
498498
blockTrans = transform;
499499
}
500500

501-
for(Atom a : blocksetAtoms) {
501+
for (Atom a : blocksetAtoms) {
502502
if (a!=null) Calc.transform(a, blockTrans);
503503
transformedAtoms[transformedAtomsLength] = a;
504504
transformedAtomsLength++;

0 commit comments

Comments
 (0)