From b80b8920baba71a797b3c17c2be4ca0a3ba2bf25 Mon Sep 17 00:00:00 2001 From: gmungoc Date: Mon, 29 Jun 2015 10:21:38 +0100 Subject: [PATCH] JAL-1759 correct conversion of Jmol Chain.chainId (int) to string + tests --- src/jalview/ext/jmol/PDBFileWithJmol.java | 17 ++++++++++------- test/MCview/PDBChainTest.java | 18 +++++++++++++----- test/MCview/PDBfileTest.java | 18 +++++++++++++++++- 3 files changed, 40 insertions(+), 13 deletions(-) diff --git a/src/jalview/ext/jmol/PDBFileWithJmol.java b/src/jalview/ext/jmol/PDBFileWithJmol.java index 2f117d3..3b6f0c2 100644 --- a/src/jalview/ext/jmol/PDBFileWithJmol.java +++ b/src/jalview/ext/jmol/PDBFileWithJmol.java @@ -144,7 +144,9 @@ public class PDBFileWithJmol extends AlignFile implements modelIndex++; for (BioPolymer bp : ((BioModel) model).bioPolymers) { - int _lastChainId = 0; + int lastChainId = 0; // int value of character e.g. 65 for A + String lastChainIdAlpha = ""; + int[] groups = bp.getLeadAtomIndices(); char seq[] = new char[groups.length], secstr[] = new char[groups.length], secstrcode[] = new char[groups.length]; int groupc = 0, len = 0, firstrnum = 1, lastrnum = 0; @@ -152,7 +154,7 @@ public class PDBFileWithJmol extends AlignFile implements do { if (groupc >= groups.length - || ms.at[groups[groupc]].group.chain.chainID != _lastChainId) + || ms.at[groups[groupc]].group.chain.chainID != lastChainId) { /* * on change of chain (or at end), construct the sequence and @@ -181,14 +183,14 @@ public class PDBFileWithJmol extends AlignFile implements String modelTitle = (String) ms .getInfo(modelIndex, "title"); SequenceI sq = new Sequence("" + getDataName() + "|" - + modelTitle + "|" + _lastChainId, newseq, + + modelTitle + "|" + lastChainIdAlpha, newseq, firstrnum, lastrnum); PDBEntry pdbe = new PDBEntry(); pdbe.setFile(getDataName()); pdbe.setId(getDataName()); pdbe.setProperty(new Hashtable()); // pdbe.getProperty().put("CHAIN", "" + _lastChainId); - pdbe.setChainCode(String.valueOf(_lastChainId)); + pdbe.setChainCode(lastChainIdAlpha); sq.addPDBId(pdbe); // JAL-1533 // Need to put the number of models for this polymer somewhere @@ -199,9 +201,9 @@ public class PDBFileWithJmol extends AlignFile implements { String mt = modelTitle == null ? getDataName() : modelTitle; - if (_lastChainId >= ' ') + if (lastChainId >= ' ') { - mt += _lastChainId; + mt += lastChainIdAlpha; } AlignmentAnnotation ann = new AlignmentAnnotation( "Secondary Structure", "Secondary Structure for " @@ -226,7 +228,8 @@ public class PDBFileWithJmol extends AlignFile implements if (len == 0) { firstrnum = group.getResno(); - _lastChainId = group.chain.chainID; + lastChainId = group.chain.chainID; + lastChainIdAlpha = group.chain.getIDStr(); } else { diff --git a/test/MCview/PDBChainTest.java b/test/MCview/PDBChainTest.java index 0df7851..07f9bd5 100644 --- a/test/MCview/PDBChainTest.java +++ b/test/MCview/PDBChainTest.java @@ -16,19 +16,27 @@ import jalview.schemes.TaylorColourScheme; import java.awt.Color; import java.util.Vector; +import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; public class PDBChainTest { - PDBChain c = new PDBChain("1GAQ", "A"); + PDBChain c; - Atom a1 = new Atom(1f, 2f, 3f); + final Atom a1 = new Atom(1f, 2f, 3f); - Atom a2 = new Atom(5f, 6f, 4f); + final Atom a2 = new Atom(5f, 6f, 4f); - Atom a3 = new Atom(2f, 5f, 6f); + final Atom a3 = new Atom(2f, 5f, 6f); - Atom a4 = new Atom(2f, 1f, 7f); + final Atom a4 = new Atom(2f, 1f, 7f); + + @BeforeMethod + public void setUp() + { + System.out.println("setup"); + c = new PDBChain("1GAQ", "A"); + } @Test public void testGetNewlineString() diff --git a/test/MCview/PDBfileTest.java b/test/MCview/PDBfileTest.java index a4fd286..03b60e6 100644 --- a/test/MCview/PDBfileTest.java +++ b/test/MCview/PDBfileTest.java @@ -15,6 +15,7 @@ import jalview.datamodel.SequenceI; import jalview.io.AppletFormatAdapter; import java.io.IOException; +import java.util.List; import org.testng.annotations.Test; @@ -96,6 +97,21 @@ public class PDBfileTest assertTrue(chainD.sequence.getSequenceAsString().startsWith("ATYNVK")); assertTrue(chainD.sequence.getSequenceAsString().endsWith("KEEELT")); assertEquals("3W5V|D", chainD.sequence.getName()); + + /* + * verify PDB-related data in parsed sequences + */ + List seqs = pf.getSeqs(); + assertEquals(4, seqs.size()); + assertEquals("3W5V|A", seqs.get(0).getName()); + assertEquals("3W5V|B", seqs.get(1).getName()); + assertEquals("3W5V|C", seqs.get(2).getName()); + assertEquals("3W5V|D", seqs.get(3).getName()); + assertEquals(1, seqs.get(0).getPDBId().size()); + PDBEntry pdbe = seqs.get(0).getPDBId().get(0); + assertEquals("A", pdbe.getChainCode()); + assertEquals("3W5V", pdbe.getId()); + assertEquals(PDBEntry.Type.PDB.toString(), pdbe.getType()); } /** @@ -265,7 +281,7 @@ public class PDBfileTest private AlignmentAnnotation[] getAlignmentAnnotations(PDBfile pf) { AlignmentI al = new Alignment(pf.getSeqsAsArray()); - pf.addAnnotations((Alignment) al); + pf.addAnnotations(al); return al.getAlignmentAnnotation(); } } -- 1.7.10.2