Skip to content

Commit e18e02c

Browse files
committed
Remove the 3D transformations in MultipleAlignment
It was confusing to have the 3D information duplicated in MultipleAlignment and BlockSet, now this information is only stored in the last object type. Update all methods that used 3D information.
1 parent 8094a8e commit e18e02c

18 files changed

+136
-158
lines changed

biojava-structure-gui/src/main/java/org/biojava/nbio/structure/align/gui/MultipleAlignmentDisplay.java

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ public static MultipleAlignmentJmol display(MultipleAlignment multAln)
173173

174174
int size = multAln.size();
175175

176-
List<Atom[]> atomArrays = multAln.getEnsemble().getAtomArrays();
176+
List<Atom[]> atomArrays = multAln.getAtomArrays();
177177
for (int i=0; i<size; i++){
178178
if (atomArrays.get(i).length < 1)
179179
throw new StructureException(
@@ -183,26 +183,19 @@ public static MultipleAlignmentJmol display(MultipleAlignment multAln)
183183

184184
List<Atom[]> rotatedAtoms = new ArrayList<Atom[]>();
185185

186-
List<Matrix4d> transforms = multAln.getTransformations();
187186
//TODO implement independent BlockSet superposition of the structure
188-
if (multAln.getBlockSets().size() > 1) {
189-
transforms = multAln.getBlockSets().get(0).getTransformations();
190-
}
187+
List<Matrix4d> transf = multAln.getBlockSet(0).getTransformations();
191188

192-
if(transforms == null) {
189+
if(transf == null) {
193190

194191
logger.error("Alignment Transformations are not calculated. "
195192
+ "Superimposing to first structure as reference.");
196193

197194
multAln = multAln.clone();
198195
MultipleSuperimposer imposer = new ReferenceSuperimposer();
199196
imposer.superimpose(multAln);
200-
transforms = multAln.getTransformations();
201-
202-
if (multAln.getBlockSets().size() > 1) {
203-
transforms = multAln.getBlockSets().get(0).getTransformations();
204-
}
205-
assert(transforms != null);
197+
transf = multAln.getBlockSet(0).getTransformations();
198+
assert(transf != null);
206199
}
207200

208201
//Rotate the atom coordinates of all the structures
@@ -223,7 +216,7 @@ public static MultipleAlignmentJmol display(MultipleAlignment multAln)
223216
}
224217

225218
//Transform the structure to ensure a full rotation in the display
226-
Calc.transform(displayS, transforms.get(i));
219+
Calc.transform(displayS, transf.get(i));
227220
rotatedAtoms.add(rotCA);
228221
}
229222

biojava-structure-gui/src/main/java/org/biojava/nbio/structure/align/gui/aligpanel/MultipleAligPanel.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ public MultipleAligPanel(AFPChain afpChain, Atom[] ca1, Atom[] ca2,
136136
//Convert the apfChain into a MultipleAlignment object
137137
MultipleAlignmentEnsembleImpl ensemble =
138138
new MultipleAlignmentEnsembleImpl(afpChain, ca1, ca2, flex);
139-
this.multAln = ensemble.getMultipleAlignments().get(0);
139+
this.multAln = ensemble.getMultipleAlignment(0);
140140

141141
//Create the sequence alignment and the structure-sequence mapping.
142142
this.mapSeqToStruct = new ArrayList<Integer>();
@@ -486,7 +486,7 @@ private void colorBySimilarity(boolean flag) {
486486
}
487487

488488
public List<Atom[]> getAtomArrays() {
489-
return multAln.getEnsemble().getAtomArrays();
489+
return multAln.getAtomArrays();
490490
}
491491
public MultipleAlignment getMultipleAlignment(){
492492
return multAln;

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

Lines changed: 57 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,16 @@
22

33
import java.util.List;
44

5-
import javax.vecmath.Matrix4d;
5+
import org.biojava.nbio.structure.Atom;
66

77
/**
88
* A MultipleAlignment is a Data Structure to store the core information of a
99
* multiple structure alignment, as a return type.
1010
* <p>
1111
* Each alignment is described as a collection of:
12-
* <ul><li>{@link BlockSet}s that define the aligned positions,
12+
* <ul><li>{@link BlockSet}s that define the aligned positions and 3D
13+
* superposition,
1314
* <li>Structure identifiers (i,e. Atom arrays, structure names),
14-
* <li>Information about the 3D superimposition in a set of 4D transformation
15-
* matrices,
1615
* <li>Creation properties (algorithm, version, etc).
1716
* </ul>
1817
* A collection of MultipleAlignments that share the same structures and
@@ -26,35 +25,35 @@
2625
*
2726
*/
2827
public interface MultipleAlignment extends ScoresCache {
29-
28+
3029
/**
3130
* Creates and returns an identical copy of this alignment, including a
3231
* deep copy of all constituent BlockSets.
3332
*
3433
* @return MultipleAlignment identical copy of this object.
3534
*/
3635
public MultipleAlignment clone();
37-
36+
3837
/**
39-
* Returns the parent Ensemble of the MultipleAlignment.
40-
* Returns null if there is no referenced object.
41-
*
42-
* @return MultipleAlignmentEnsemble the parent MultipleAlignment of the
43-
* BlockSet, or null.
44-
* @see #setEnsemble(MultipleAlignmentEnsemble)
45-
*/
38+
* Returns the parent Ensemble of the MultipleAlignment.
39+
* Returns null if there is no referenced object.
40+
*
41+
* @return MultipleAlignmentEnsemble the parent MultipleAlignment of the
42+
* BlockSet, or null.
43+
* @see #setEnsemble(MultipleAlignmentEnsemble)
44+
*/
4645
public MultipleAlignmentEnsemble getEnsemble();
47-
46+
4847
/**
49-
* Set the back-reference to its parent Ensemble.
50-
* <p>
51-
* Neither removes this alignment from its previous ensemble, if any, nor
52-
* adds it to the new parent. Calling code should assure that links to
53-
* and from the ensemble are consistent and free of memory leaks.
54-
*
55-
* @param parent the parent MultipleAlignmentEnsemble.
56-
* @see #getEnsemble()
57-
*/
48+
* Set the back-reference to its parent Ensemble.
49+
* <p>
50+
* Neither removes this alignment from its previous ensemble, if any, nor
51+
* adds it to the new parent. Calling code should assure that links to
52+
* and from the ensemble are consistent and free of memory leaks.
53+
*
54+
* @param parent the parent MultipleAlignmentEnsemble.
55+
* @see #getEnsemble()
56+
*/
5857
public void setEnsemble(MultipleAlignmentEnsemble parent);
5958

6059
/**
@@ -68,6 +67,18 @@ public interface MultipleAlignment extends ScoresCache {
6867
*/
6968
public List<BlockSet> getBlockSets();
7069

70+
/**
71+
* Returns the BlockSet with the specified index of the MultipleAlignment.
72+
* Throws an Exception if the index is out of bounds, like accessing a
73+
* normal List.
74+
*
75+
* @param index of the BlockSet
76+
* @return BlockSets at the specified index
77+
* @see #getBlocks()
78+
* @see #getBlockSets()
79+
*/
80+
public BlockSet getBlockSet(int index);
81+
7182
/**
7283
* Sets the List of BlockSet List of the specified alignment.
7384
*
@@ -79,40 +90,37 @@ public interface MultipleAlignment extends ScoresCache {
7990

8091
/**
8192
* Convenience method to get a List of all Blocks from all BlockSets.
93+
* Modifications of this List will not alter the MultipleAlignment,
94+
* but modifications to the Blocks will.
8295
*
8396
* @return List of Blocks
8497
* @see #getBlockSets()
8598
*/
8699
public List<Block> getBlocks();
87100

88101
/**
89-
* Returns a transformation 4D matrix for each structure giving the
90-
* 3D superposition information of the multiple structure alignment.
91-
* <p>
92-
* Individual BlockSets may override the transformation matrix for
93-
* particular parts of the alignment. Flexible alignments will generally
94-
* return null from this method, while rigid-body methods would typically
95-
* store the transformation matrices here as well as in the only BlockSet:
96-
* {@link BlockSet#getTransformations()}.
102+
* Returns the Block with the specified index of the MultipleAlignment.
103+
* Throws an Exception if the index is out of bounds, like accessing a
104+
* normal List.
97105
*
98-
* @return the 3D superposition information of the alignment or null
99-
* if flexible
106+
* @param index of the BlockSet
107+
* @return Block at the specified index
108+
* @see #getBlocks()
109+
* @see #getBlockSets()
100110
*/
101-
public List<Matrix4d> getTransformations();
111+
public Block getBlock(int index);
102112

103113
/**
104-
* Set a new superposition for the structures.
105-
* <p>
106-
* This may trigger other properties to update which depend on the
107-
* superposition. In particular, the list of scores should be reset by
108-
* implementations after changing the transformation matrices.
114+
* Returns the array of Atoms for each structure from its parent
115+
* Ensemble.
116+
* Throws an Exception if the parent ensemble is null or the Atom
117+
* variables are not previously set.
109118
*
110-
* @param matrices 4D
111-
* @throws IllegalArgumentException when the size of the alignment and
112-
* the size of transformations do not match.
119+
* @return List of Atom arrays
120+
* @see #getEnsemble()
113121
*/
114-
public void setTransformations(List<Matrix4d> transformations);
115-
122+
public List<Atom[]> getAtomArrays();
123+
116124
/**
117125
* Returns the number of aligned structures in the MultipleAlignment.
118126
*
@@ -141,15 +149,16 @@ public interface MultipleAlignment extends ScoresCache {
141149
* @see #size()
142150
*/
143151
public int getCoreLength();
144-
152+
145153
/**
146154
* Clear scores and other properties which depend on the specific
147155
* alignment. This frees memory and ensures consistency of the cached
148-
* variables.<p>
156+
* variables.
157+
* <p>
149158
* Recursively clears member BlockSets.
150159
*/
151160
public void clear();
152-
161+
153162
/**
154163
* Return a summary of the MultipleAlignment, containing the structures,
155164
* the lengths and the cached scores. Can be used as a header for the
@@ -159,4 +168,5 @@ public interface MultipleAlignment extends ScoresCache {
159168
*/
160169
@Override
161170
public String toString();
171+
162172
}

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,17 +135,25 @@ public interface MultipleAlignmentEnsemble extends ScoresCache {
135135
*
136136
* @return List of MultipleAlignment in the ensemble.
137137
* @see #setMultipleAlignments()
138-
* @see #getOptimalMultipleAlignment()
139138
*/
140139
public List<MultipleAlignment> getMultipleAlignments();
140+
141+
/**
142+
* Returns the MultipleAlignments at the specified index
143+
* in the ensemble. Throws an exception equivalently to
144+
* accessing an index of a List
145+
*
146+
* @return MultipleAlignment at the index in the ensemble.
147+
* @see #setMultipleAlignments()
148+
*/
149+
public MultipleAlignment getMultipleAlignment(int index);
141150

142151
/**
143152
* Set the List of MultipleAlignments in the ensemble.
144153
*
145154
* @param alignments List of MultipleAlignments that are part of the
146155
* ensemble.
147-
* @see #getMultipleAlignments()
148-
* @see #getOptimalMultipleAlignment()
156+
* @see #addMultipleAlignment(MultipleAlignment)
149157
*/
150158
public void setMultipleAlignments(List<MultipleAlignment> alignments);
151159

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,15 +142,15 @@ public MultipleAlignmentEnsembleImpl(
142142
//Convert the rotation and translation to a Matrix4D and set it
143143
Matrix4d ident = new Matrix4d();
144144
ident.setIdentity();
145-
Matrix rot = afp.getBlockRotationMatrix()[0];
146-
Atom shift = afp.getBlockShiftVector()[0];
147-
Matrix4d transform = Calc.getTransformation(rot, shift);
148-
msa.setTransformations(Arrays.asList(ident, transform));
145+
Matrix[] rot = afp.getBlockRotationMatrix();
146+
Atom[] shift = afp.getBlockShiftVector();
149147

150148
//Create a BlockSet for every block in AFPChain if flexible
151149
if (flexible){
152150
for (int bs=0; bs<afp.getBlockNum(); bs++){
153151
BlockSet blockSet = new BlockSetImpl(msa);
152+
Matrix4d blockTr = Calc.getTransformation(rot[bs], shift[bs]);
153+
blockSet.setTransformations(Arrays.asList(ident, blockTr));
154154
Block block = new BlockImpl(blockSet);
155155
block.setAlignRes(new ArrayList<List<Integer>>());
156156
block.getAlignRes().add(new ArrayList<Integer>());
@@ -171,6 +171,8 @@ public MultipleAlignmentEnsembleImpl(
171171
} //Create a Block for every block in AFPChain if not flexible
172172
else {
173173
BlockSet blockSet = new BlockSetImpl(msa);
174+
Matrix4d blockTr = Calc.getTransformation(rot[0], shift[0]);
175+
blockSet.setTransformations(Arrays.asList(ident, blockTr));
174176
for (int bs=0; bs<afp.getBlockNum(); bs++){
175177
Block block = new BlockImpl(blockSet);
176178
block.setAlignRes(new ArrayList<List<Integer>>());
@@ -311,6 +313,11 @@ public List<MultipleAlignment> getMultipleAlignments() {
311313
}
312314
return multipleAlignments;
313315
}
316+
317+
@Override
318+
public MultipleAlignment getMultipleAlignment(int index) {
319+
return multipleAlignments.get(index);
320+
}
314321

315322
@Override
316323
public void setMultipleAlignments(List<MultipleAlignment> alignments) {

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

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import javax.vecmath.Matrix4d;
88

9+
import org.biojava.nbio.structure.Atom;
910
import org.biojava.nbio.structure.StructureException;
1011

1112
/**
@@ -146,17 +147,19 @@ public void setBlockSets(List<BlockSet> blockSets) {
146147
}
147148

148149
@Override
149-
public List<Matrix4d> getTransformations(){
150-
return pose;
150+
public BlockSet getBlockSet(int index){
151+
return blockSets.get(index);
152+
}
153+
154+
@Override
155+
public Block getBlock(int index){
156+
List<Block> blocks = getBlocks();
157+
return blocks.get(index);
151158
}
152159

153160
@Override
154-
public void setTransformations(List<Matrix4d> matrices) {
155-
if(size() != matrices.size())
156-
throw new IllegalArgumentException(
157-
"Wrong number of structures for this alignment");
158-
clear();
159-
pose = matrices;
161+
public List<Atom[]> getAtomArrays() {
162+
return parent.getAtomArrays();
160163
}
161164

162165
@Override

0 commit comments

Comments
 (0)