Skip to content

Commit 01a8db4

Browse files
committed
Fix updateSuperposition() bug with Transformation Matrices
1 parent dffd286 commit 01a8db4

File tree

5 files changed

+75
-20
lines changed

5 files changed

+75
-20
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public static void main(String[] args) throws IOException, StructureException, I
3434
//TIM barrels (MUSTA paper)
3535
//List<String> names = Arrays.asList("1tim.A", "1vzw", "1nsj", "3tha.A", "4enl", "2mnr", "7tim.A", "1tml", "1btc", "a1piia1", "6xia", "5rub.A", "2taa.B");
3636
//Helix-bundle (MUSTA paper)
37-
//List<String> names = Arrays.asList("1bbh.A", "1aep", "1bge.B", "256b.A", "2ccy.A", "2hmz.A", "3ink.C");
37+
List<String> names = Arrays.asList("1bbh.A", "1aep", "1bge.B", "256b.A", "2ccy.A", "2hmz.A", "3ink.C");
3838
//Calcium Binding (MUSTA paper)
3939
//List<String> names = Arrays.asList("4cpv", "2scp.A", "2sas", "1top", "1scm.B", "3icb");
4040
//Serine Rich Proteins SERP (MUSTA paper)
@@ -48,7 +48,7 @@ public static void main(String[] args) throws IOException, StructureException, I
4848
//Globins (MAMMOTH and MUSTA papers)
4949
//List<String> names = Arrays.asList("1mbc", "1hlb", "1thb.A", "1ith.A", "1idr.A", "1dlw", "1kr7.A", "1ew6.A", "1it2.A", "1eco", "3sdh.A", "1cg5.B", "1fhj.B", "1ird.A", "1mba", "2gdm", "1b0b", "1h97.A", "1ash.A", "1jl7.A");
5050
//Rossman-Fold (POSA paper)
51-
List<String> names = Arrays.asList("d1heta2", "d1ek6a_", "d1obfo1", "2cmd", "d1np3a2", "d1bgva1", "d1id1a_", "d1id1a_", "d1oi7a1");
51+
//List<String> names = Arrays.asList("d1heta2", "d1ek6a_", "d1obfo1", "2cmd", "d1np3a2", "d1bgva1", "d1id1a_", "d1id1a_", "d1oi7a1");
5252
//Circular Permutations (Bliven CECP paper) - dynamin GTP-ase with CP G-domain
5353
//List<String> names = Arrays.asList("d1u0la2", "d1jwyb_");
5454
//Circular Permutations: SAND and MFPT domains

biojava-structure/src/main/java/org/biojava/nbio/structure/align/cemc/CeMcOptimizer.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
* It assumes that the seed alignment is not flexible, since only CP are supported but not
2929
* alignment flexibility.
3030
* <p>
31-
* It implements Callable to be run in parallel along other optimization instances.
31+
* It implements Callable to be run in parallel.
3232
*
3333
* @author Aleix Lafita
3434
*
@@ -160,7 +160,7 @@ private void optimizeMC(int maxIter) throws StructureException {
160160
scoreHistory = new ArrayList<Double>();
161161

162162
int conv = 0; //Number of steps without an alignment improvement
163-
int stepsToConverge =maxIter/20;
163+
int stepsToConverge = Math.max(maxIter/50,1000);
164164
int i = 1;
165165

166166
while (i<maxIter && conv<stepsToConverge){
@@ -295,6 +295,7 @@ private boolean insertGap() {
295295

296296
int str = rnd.nextInt(size); //Select randomly the subunit
297297
int bk = rnd.nextInt(blockNr); //Select randomly the Block if more than 1
298+
if (block.getBlocks().get(bk).length() <= Lmin) return false; //Let gaps insertion only if the subunit is larger than the minimum length
298299
int res = rnd.nextInt(block.getBlocks().get(bk).length()); //Position to insert a gap
299300

300301
//Insert the gap at the position

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,6 @@ public static List<String> getSequenceAlignment(MultipleAlignment alignment, Lis
8383

8484
//Loop through all the alignment Blocks in the order given
8585
for (int b=0; b<alignment.getBlocks().size(); b++){
86-
if (b!=0){
87-
//Add a gap to all structures in order to separate visually the blocks in the alignment
88-
for (int str=0; str<alignment.size(); str++) alnSequences.set(str,alnSequences.get(str).concat("-"));
89-
mapSeqToStruct.add(-1); //means no aligned position
90-
}
9186
//Store the previous position added to the sequence alignment for this structure
9287
int[] previousPos = new int[alignment.size()];
9388
Arrays.fill(previousPos, -1);

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -841,7 +841,7 @@ public static void updateSuperposition(AFPChain afpChain, Atom[] ca1, Atom[] ca2
841841
afpChain.setCa1Length(ca1.length);
842842
afpChain.setCa2Length(ca2.length);
843843

844-
// we need this to get the correct superposition
844+
//We need this to get the correct superposition
845845
int[] focusRes1 = afpChain.getFocusRes1();
846846
int[] focusRes2 = afpChain.getFocusRes2();
847847
if (focusRes1 == null) {
@@ -923,7 +923,7 @@ public static void updateSuperposition(AFPChain afpChain, Atom[] ca1, Atom[] ca2
923923
position++;
924924
}
925925
if (position != afpChain.getOptLen()[k]){
926-
logger.warn("AFPChainScorer getTMScore: Problems reconstructing alignment! nr of loaded atoms is " + pos + " but should be " + afpChain.getOptLen()[k]);
926+
logger.warn("AFPChainScorer getTMScore: Problems reconstructing block alignment! nr of loaded atoms is " + pos + " but should be " + afpChain.getOptLen()[k]);
927927
// we need to resize the array, because we allocated too many atoms earlier on.
928928
ca1block = (Atom[]) resizeArray(ca1block, position);
929929
ca2block = (Atom[]) resizeArray(ca2block, position);
@@ -932,9 +932,6 @@ public static void updateSuperposition(AFPChain afpChain, Atom[] ca1, Atom[] ca2
932932
SVDSuperimposer svdb = new SVDSuperimposer(ca1block, ca2block);
933933
Matrix matrixb = svdb.getRotation();
934934
Atom shiftb = svdb.getTranslation();
935-
afpChain.getBlockRotationMatrix()[k] = matrixb;
936-
afpChain.getBlockShiftVector()[k] = shiftb;
937-
afpChain.setBlockShiftVector(blockShifts);
938935
for (Atom a : ca2block) {
939936
Calc.rotate(a, matrixb);
940937
Calc.shift(a, shiftb);

biojava-structure/src/test/java/org/biojava/nbio/structure/align/multiple/MultipleAlignmentWriterTest.java

Lines changed: 68 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
package org.biojava.nbio.structure.align.multiple;
22

3+
import java.io.File;
4+
import java.io.IOException;
5+
import java.util.ArrayList;
6+
import java.util.Arrays;
37
import java.util.List;
48

5-
import org.biojava.nbio.core.sequence.ProteinSequence;
9+
import org.biojava.nbio.structure.Atom;
610
import org.biojava.nbio.structure.Structure;
11+
import org.biojava.nbio.structure.StructureException;
12+
import org.biojava.nbio.structure.StructureTools;
713
import org.biojava.nbio.structure.align.util.AtomCache;
14+
import org.biojava.nbio.structure.io.PDBFileReader;
15+
import org.biojava.nbio.structure.io.StructureIOFile;
816
import org.junit.Test;
917

1018
import static org.junit.Assert.*;
@@ -24,24 +32,78 @@
2432
public class MultipleAlignmentWriterTest {
2533

2634
@Test
27-
public void testFASTA(){
35+
public void testFASTA() throws StructureException, IOException{
36+
37+
MultipleAlignment alignment = generateTestMultipleAlignment();
38+
String result = MultipleAlignmentWriter.toFASTA(alignment);
39+
System.out.println(result);
40+
41+
StringBuffer expected = new StringBuffer();
42+
expected.append(">2gox\n");
43+
expected.append("---S-tDaErLkhl--IvTpSgAgeq----NmIgMtPt-viAv---HyL-dEt-eqWe-\n");
44+
expected.append(">2gox\n");
45+
expected.append("GsrS-tDAeRLkh--LiVTpSGaGEqn---MiGMtPTviA-vh--YlDE-tEqwE-Kf-\n");
46+
expected.append(">2gox\n");
47+
expected.append("GS-rsTDaERLkhl-IvTPSgAGEqnmig--MTPtVIavH-Yld-ETEqwEKf-G-LE-\n");
48+
49+
assertEquals(result,expected.toString());
2850

2951
}
3052

3153
@Test
3254
public void testFatCat(){
3355

56+
3457
}
3558

3659
@Test
3760
public void testAlignedPairs(){
3861

3962
}
4063

41-
private List<String> generateTestMSA(){
64+
private MultipleAlignment generateTestMultipleAlignment() throws StructureException, IOException{
4265

43-
//TODO load a file structure and generate a multiple alignment with multiple blocks
44-
45-
return null;
66+
//Obtain the structure atoms
67+
StructureIOFile reader = new PDBFileReader();
68+
File f = new File("src/main/resources/2gox.pdb");
69+
Structure structure = null;
70+
try {
71+
structure = reader.getStructure(f);
72+
} catch (IOException e){
73+
AtomCache cache = new AtomCache();
74+
structure = cache.getStructure("2gox");
75+
}
76+
List<Atom[]> atomArrays = new ArrayList<Atom[]>(3);
77+
for (int str=0; str<3; str++){
78+
Atom[] atoms = StructureTools.getRepresentativeAtomArray(structure);
79+
atomArrays.add(StructureTools.cloneAtomArray(atoms));
80+
}
81+
82+
//Generate the MultipleAlignment - 2 blocks with 2 blocksets each
83+
MultipleAlignment msa = new MultipleAlignmentImpl();
84+
msa.getEnsemble().setStructureNames(Arrays.asList("2gox","2gox","2gox"));
85+
msa.getEnsemble().setAtomArrays(atomArrays);
86+
int[] nextResidue = new int[3];
87+
for (int bs=0; bs<2; bs++){
88+
BlockSet blockSet = new BlockSetImpl(msa);
89+
for (int b=0; b<2; b++){
90+
List<List<Integer>> alnRes = new ArrayList<List<Integer>>(3);
91+
for (int str=0; str<3; str++){
92+
List<Integer> chain = new ArrayList<Integer>(50);
93+
for (int res=0; res<10; res++){
94+
//Introduce gaps and discontinuities to test for all cases
95+
if (nextResidue[str] % (2+str) == str)chain.add(null);
96+
else chain.add(nextResidue[str]);
97+
if (nextResidue[str] % (10) == str) nextResidue[str] ++;
98+
nextResidue[str]++;
99+
}
100+
alnRes.add(chain);
101+
nextResidue[str]+=str; //Spacing between Blocks
102+
}
103+
Block block = new BlockImpl(blockSet);
104+
block.setAlignRes(alnRes);
105+
}
106+
}
107+
return msa;
46108
}
47109
}

0 commit comments

Comments
 (0)