X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=test%2Fjalview%2Fstructures%2Fmodels%2FAAStructureBindingModelTest.java;h=1a2cb84585dfafe22d09b1feb6cffe64b7a74905;hb=ca47f64efa144d68e7f6e01ad2c147a7832e97a7;hp=5e0e52f8bddfb7b14e02b36d6e7d07d99f1a26c1;hpb=42f4227ed213d422a87d3b22fc9e85d14ffaf53f;p=jalview.git diff --git a/test/jalview/structures/models/AAStructureBindingModelTest.java b/test/jalview/structures/models/AAStructureBindingModelTest.java index 5e0e52f..1a2cb84 100644 --- a/test/jalview/structures/models/AAStructureBindingModelTest.java +++ b/test/jalview/structures/models/AAStructureBindingModelTest.java @@ -25,6 +25,18 @@ import static org.testng.Assert.assertFalse; import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertTrue; +import java.awt.Color; +import java.io.IOException; +import java.util.Arrays; +import java.util.BitSet; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.testng.annotations.BeforeClass; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + import jalview.api.AlignmentViewPanel; import jalview.api.SequenceRenderer; import jalview.datamodel.Alignment; @@ -40,25 +52,14 @@ import jalview.gui.JvOptionPane; import jalview.gui.StructureViewer.ViewerType; import jalview.io.DataSourceType; import jalview.io.FileFormats; +import jalview.io.FileLoader; import jalview.schemes.JalviewColourScheme; import jalview.structure.AtomSpec; import jalview.structure.AtomSpecModel; import jalview.structure.StructureCommandI; +import jalview.structure.StructureCommandsI.AtomSpecType; import jalview.structure.StructureMapping; import jalview.structure.StructureSelectionManager; - -import java.awt.Color; -import java.io.IOException; -import java.util.Arrays; -import java.util.BitSet; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.testng.annotations.BeforeClass; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; - import junit.extensions.PA; /** @@ -126,7 +127,7 @@ public class AAStructureBindingModelTest // TODO: JAL-2227 - import mmCIF PISA assembly & identify master/copy chains - @Test(groups= {"Functional"}) + @Test(groups = { "Functional" }) public void testImportPDBPreservesChainMappings() throws IOException { AlignmentI importedAl = new jalview.io.FormatAdapter().readFile( @@ -135,38 +136,38 @@ public class AAStructureBindingModelTest // ideally, we would match on the actual data for the 'File' handle for // pasted files, // see JAL-623 - pasting is still not correctly handled... - PDBEntry importedPDB = new PDBEntry("3A6S", "", Type.PDB, - "Paste"); + PDBEntry importedPDB = new PDBEntry("3A6S", "", Type.PDB, "Paste"); AAStructureBindingModel binder = new AAStructureBindingModel( new StructureSelectionManager(), new PDBEntry[] { importedPDB }, new SequenceI[][] { importedAl.getSequencesArray() }, null) { - + @Override public void updateColours(Object source) { } - + @Override public void releaseReferences(Object svl) { } - + @Override public String[] getStructureFiles() { return null; } - + @Override public void highlightAtoms(List atoms) { } - + @Override - public SequenceRenderer getSequenceRenderer(AlignmentViewPanel alignment) + public SequenceRenderer getSequenceRenderer( + AlignmentViewPanel alignment) { return null; } @@ -197,6 +198,7 @@ public class AAStructureBindingModelTest assertEquals(chains[0][0], "A"); assertEquals(chains[0][1], "B"); } + AAStructureBindingModel testee; AlignmentI al = null; @@ -234,7 +236,7 @@ public class AAStructureBindingModelTest ssm.setMapping(new SequenceI[] { seq3 }, null, PDB_3, DataSourceType.PASTE, null); - testee = newBindingModel(pdbFiles, seqs, ssm); + testee = newBindingModel(pdbFiles, seqs, ssm, null); } /** @@ -243,10 +245,11 @@ public class AAStructureBindingModelTest * @param pdbFiles * @param seqs * @param ssm + * @param alignPanel */ protected AAStructureBindingModel newBindingModel(PDBEntry[] pdbFiles, - SequenceI[][] seqs, - StructureSelectionManager ssm) + SequenceI[][] seqs, StructureSelectionManager ssm, + AlignmentViewPanel avp) { AAStructureBindingModel model = new AAStructureBindingModel(ssm, pdbFiles, seqs, null) @@ -254,7 +257,12 @@ public class AAStructureBindingModelTest @Override public String[] getStructureFiles() { - return new String[] { "INLINE1YCS", "INLINE3A6S", "INLINE1OOT" }; + String[] files = new String[getPdbCount()]; + for (int i = 0; i < this.getPdbCount(); i++) + { + files[i] = getPdbEntry(i).getFile(); + } + return files; } @Override @@ -273,10 +281,10 @@ public class AAStructureBindingModelTest } @Override - public SequenceRenderer getSequenceRenderer( - AlignmentViewPanel alignment) + public SequenceRenderer getSequenceRenderer(AlignmentViewPanel avp) { - return null; + return avp == null ? null + : new jalview.gui.SequenceRenderer(avp.getAlignViewport()); } @Override @@ -286,9 +294,20 @@ public class AAStructureBindingModelTest return null; } + /* + * for this test, let structure model ids be 0, 1, ... + * corresponding to first, second etc pdbfile + */ @Override - protected String getModelIdForFile(String chainId) + protected String getModelIdForFile(String pdbfile) { + for (int i = 0; i < this.getPdbCount(); i++) + { + if (pdbfile.equals(this.getPdbEntry(i).getFile())) + { + return String.valueOf(i); + } + } return ""; } @@ -312,10 +331,12 @@ public class AAStructureBindingModelTest /* * create a data bean to hold data per structure file */ - AAStructureBindingModel.SuperposeData[] structs = new AAStructureBindingModel.SuperposeData[testee.getStructureFiles().length]; + AAStructureBindingModel.SuperposeData[] structs = new AAStructureBindingModel.SuperposeData[testee + .getStructureFiles().length]; for (int i = 0; i < structs.length; i++) { - structs[i] = new AAStructureBindingModel.SuperposeData(al.getWidth(), "0"); + structs[i] = new AAStructureBindingModel.SuperposeData(al.getWidth(), + "0"); } /* * initialise BitSet of 'superposable columns' to true (would be false for @@ -327,8 +348,8 @@ public class AAStructureBindingModelTest matched.set(i); } - int refStructure = testee - .findSuperposableResidues(al, matched, structs); + int refStructure = testee.findSuperposableResidues(al, matched, + structs); assertEquals(refStructure, 0); @@ -360,10 +381,12 @@ public class AAStructureBindingModelTest @Test(groups = { "Functional" }) public void testFindSuperposableResidues_hiddenColumn() { - AAStructureBindingModel.SuperposeData[] structs = new AAStructureBindingModel.SuperposeData[al.getHeight()]; + AAStructureBindingModel.SuperposeData[] structs = new AAStructureBindingModel.SuperposeData[al + .getHeight()]; for (int i = 0; i < structs.length; i++) { - structs[i] = new AAStructureBindingModel.SuperposeData(al.getWidth(), "0"); + structs[i] = new AAStructureBindingModel.SuperposeData(al.getWidth(), + "0"); } /* * initialise BitSet of 'superposable columns' to true (would be false for @@ -378,8 +401,8 @@ public class AAStructureBindingModelTest // treat column 5 of the alignment as hidden matched.clear(4); - int refStructure = testee - .findSuperposableResidues(al, matched, structs); + int refStructure = testee.findSuperposableResidues(al, matched, + structs); assertEquals(refStructure, 0); @@ -399,10 +422,10 @@ public class AAStructureBindingModelTest * load these sequences, coloured by Strand propensity, * with columns 2-4 hidden */ - SequenceI seq1 = new Sequence("seq1", "MHRSQSSSGG"); - SequenceI seq2 = new Sequence("seq2", "MVRSNGGSSS"); - AlignmentI al = new Alignment(new SequenceI[] { seq1, seq2 }); - AlignFrame af = new AlignFrame(al, 800, 500); + String fasta = ">seq1\nMHRSQSSSGG\n>seq2\nMVRSNGGSSS"; + AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(fasta, + DataSourceType.PASTE); + AlignmentI al = af.getViewport().getAlignment(); af.changeColour_actionPerformed(JalviewColourScheme.Strand.toString()); ColumnSelection cs = new ColumnSelection(); cs.addElement(2); @@ -410,15 +433,14 @@ public class AAStructureBindingModelTest cs.addElement(4); af.getViewport().setColumnSelection(cs); af.hideSelColumns_actionPerformed(null); - SequenceRenderer sr = new jalview.gui.SequenceRenderer( - af.getViewport()); + SequenceI seq1 = al.getSequenceAt(0); + SequenceI seq2 = al.getSequenceAt(1); SequenceI[][] seqs = new SequenceI[][] { { seq1 }, { seq2 } }; - String[] files = new String[] { "seq1.pdb", "seq2.pdb" }; PDBEntry[] pdbFiles = new PDBEntry[2]; - pdbFiles[0] = new PDBEntry("PDB1", "A", Type.PDB, "INLINEPDB1"); - pdbFiles[1] = new PDBEntry("PDB2", "B", Type.PDB, "INLINEPDB2"); + pdbFiles[0] = new PDBEntry("PDB1", "A", Type.PDB, "seq1.pdb"); + pdbFiles[1] = new PDBEntry("PDB2", "B", Type.PDB, "seq2.pdb"); StructureSelectionManager ssm = new StructureSelectionManager(); - + /* * map residues 1-10 to residues 21-30 (atoms 105-150) in structures */ @@ -434,16 +456,17 @@ public class AAStructureBindingModelTest "B", map, null); ssm.addStructureMapping(sm2); - AAStructureBindingModel binding = newBindingModel(pdbFiles, seqs, ssm); + AAStructureBindingModel binding = newBindingModel(pdbFiles, seqs, ssm, + af.alignPanel); /* * method under test builds a map of structures residues by colour * verify the map holds what it should */ - Map colours = binding.buildColoursMap(ssm, files, - seqs, sr, af.alignPanel); + Map colours = binding.buildColoursMap(ssm, seqs, + af.alignPanel); ChimeraCommands helper = new ChimeraCommands(); - + /* * M colour is #82827d (see strand.html help page) * sequence residue 1 mapped to structure residue 21 @@ -451,7 +474,8 @@ public class AAStructureBindingModelTest Color mColor = new Color(0x82827d); AtomSpecModel atomSpec = colours.get(mColor); assertNotNull(atomSpec); - assertEquals(helper.getAtomSpec(atomSpec, false), "#0:21.A|#1:21.B"); + assertEquals(helper.getAtomSpec(atomSpec, AtomSpecType.RESIDUE_ONLY), + "#0:21.A|#1:21.B"); /* * H colour is #60609f, seq1.2 mapped to structure 0 residue 22 @@ -459,7 +483,8 @@ public class AAStructureBindingModelTest Color hColor = new Color(0x60609f); atomSpec = colours.get(hColor); assertNotNull(atomSpec); - assertEquals(helper.getAtomSpec(atomSpec, false), "#0:22.A"); + assertEquals(helper.getAtomSpec(atomSpec, AtomSpecType.RESIDUE_ONLY), + "#0:22.A"); /* * V colour is #ffff00, seq2.2 mapped to structure 1 residue 22 @@ -467,7 +492,8 @@ public class AAStructureBindingModelTest Color vColor = new Color(0xffff00); atomSpec = colours.get(vColor); assertNotNull(atomSpec); - assertEquals(helper.getAtomSpec(atomSpec, false), "#1:22.B"); + assertEquals(helper.getAtomSpec(atomSpec, AtomSpecType.RESIDUE_ONLY), + "#1:22.B"); /* * hidden columns are Gray (128, 128, 128) @@ -476,7 +502,8 @@ public class AAStructureBindingModelTest Color gray = new Color(128, 128, 128); atomSpec = colours.get(gray); assertNotNull(atomSpec); - assertEquals(helper.getAtomSpec(atomSpec, false), "#0:23-25.A|#1:23-25.B"); + assertEquals(helper.getAtomSpec(atomSpec, AtomSpecType.RESIDUE_ONLY), + "#0:23-25.A|#1:23-25.B"); /* * S and G are both coloured #4949b6, structure residues 26-30 @@ -484,7 +511,7 @@ public class AAStructureBindingModelTest Color sgColour = new Color(0x4949b6); atomSpec = colours.get(sgColour); assertNotNull(atomSpec); - assertEquals(helper.getAtomSpec(atomSpec, false), + assertEquals(helper.getAtomSpec(atomSpec, AtomSpecType.RESIDUE_ONLY), "#0:26-30.A|#1:26-30.B"); } } \ No newline at end of file