From: gmungoc Date: Thu, 3 Dec 2015 10:05:22 +0000 (+0000) Subject: JAL-1827 code and comment tidy up X-Git-Tag: Release_2_10_0~331^2~1 X-Git-Url: http://source.jalview.org/gitweb/?p=jalview.git;a=commitdiff_plain;h=6e5b1229ad6b5fd71036fb14a15eec7382204a8b JAL-1827 code and comment tidy up --- diff --git a/src/jalview/ext/jmol/PDBFileWithJmol.java b/src/jalview/ext/jmol/PDBFileWithJmol.java index 49cb6d5..d32a10d 100644 --- a/src/jalview/ext/jmol/PDBFileWithJmol.java +++ b/src/jalview/ext/jmol/PDBFileWithJmol.java @@ -130,33 +130,34 @@ public class PDBFileWithJmol extends AlignFile implements switch (proteinStructureSubType) { case HELIX310: - if (secstr[pos] == 0) - { - secstr[pos] = '3'; - } + secstr[pos] = '3'; + break; + case HELIX: + case HELIXALPHA: + secstr[pos] = 'H'; + break; + case HELIXPI: + secstr[pos] = 'P'; + break; + case SHEET: + secstr[pos] = 'E'; + break; + default: + secstr[pos] = 0; + } + + switch (proteinStructureSubType) + { + case HELIX310: case HELIXALPHA: - if (secstr[pos] == 0) - { - secstr[pos] = 'H'; - } case HELIXPI: - if (secstr[pos] == 0) - { - secstr[pos] = 'P'; - } case HELIX: - if (secstr[pos] == 0) - { - secstr[pos] = 'H'; - } secstrcode[pos] = 'H'; break; case SHEET: - secstr[pos] = 'E'; secstrcode[pos] = 'E'; break; default: - secstr[pos] = 0; secstrcode[pos] = 0; } } @@ -365,7 +366,7 @@ public class PDBFileWithJmol extends AlignFile implements waitForScript(jmolModel); /* - * Convert one or more Jmol Model objects to Jalview objects. + * Convert one or more Jmol Model objects to Jalview sequences */ if (jmolModel.ms.mc > 0) { @@ -389,7 +390,7 @@ public class PDBFileWithJmol extends AlignFile implements String modelTitle = (String) ms.getInfo(modelIndex, "title"); /* - * as chains can span BioPolymers, we first make a flattened list, + * Chains can span BioPolymers, so first make a flattened list, * and then work out the lengths of chains present */ List monomers = getMonomers(ms, (BioModel) model); @@ -452,8 +453,9 @@ public class PDBFileWithJmol extends AlignFile implements /* * construct and add the Jalview sequence */ - SequenceI sq = new Sequence("" + getDataName() + "|" + modelTitle + "|" - + chainId, seq, firstResNum, firstResNum + length - 1); + String seqName = "" + getDataName() + "|" + modelTitle + "|" + + chainId; + SequenceI sq = new Sequence(seqName, seq, firstResNum, firstResNum + length - 1); seqs.add(sq); /* @@ -574,6 +576,8 @@ public class PDBFileWithJmol extends AlignFile implements } /** + * Add a PDBEntry giving the source of PDB data to the sequence + * * @param sq * @param chainId */ @@ -583,7 +587,6 @@ public class PDBFileWithJmol extends AlignFile implements pdbe.setFile(getDataName()); pdbe.setId(getDataName()); pdbe.setProperty(new Hashtable()); - // pdbe.getProperty().put("CHAIN", "" + _lastChainId); pdbe.setChainCode(chainId); sq.addPDBId(pdbe); } @@ -628,10 +631,10 @@ public class PDBFileWithJmol extends AlignFile implements } /** - * Returns a flattened list of Monomer (residue) in order, across all + * Returns a flattened list of Monomer (residues) in order, across all * BioPolymers in the model. This simplifies assembling chains which span - * BioPolymers. The result does not include any alternate residues reported - * for the same sequence position (RESNUM value). + * BioPolymers. The result omits any alternate residues reported for the same + * sequence position (RESNUM value). * * @param ms * @param model @@ -640,9 +643,10 @@ public class PDBFileWithJmol extends AlignFile implements protected List getMonomers(ModelSet ms, BioModel model) { List result = new ArrayList(); - String lastSeqCode = ""; + int lastResNo = Integer.MIN_VALUE; - for (BioPolymer bp : model.bioPolymers) { + for (BioPolymer bp : model.bioPolymers) + { for (int groupLeadAtoms : bp.getLeadAtomIndices()) { Group group = ms.at[groupLeadAtoms].group; @@ -650,18 +654,14 @@ public class PDBFileWithJmol extends AlignFile implements { /* * ignore alternate residue at same position - * example: 1ejg has residues A:LEU, B:ILE, C:ILE at RESNUM=25 + * example: 1ejg has residues A:LEU, B:ILE at RESNUM=25 */ - String seqcodeString = group.getSeqcodeString(); - if (!lastSeqCode.equals(seqcodeString)) + int resNo = group.getResno(); + if (lastResNo != resNo) { result.add((Monomer) group); } - else - { - System.out.println("skipping"); - } - lastSeqCode = seqcodeString; + lastResNo = resNo; } } } diff --git a/test/jalview/ext/jmol/PDBFileWithJmolTest.java b/test/jalview/ext/jmol/PDBFileWithJmolTest.java index fd02d00..4dc7095 100644 --- a/test/jalview/ext/jmol/PDBFileWithJmolTest.java +++ b/test/jalview/ext/jmol/PDBFileWithJmolTest.java @@ -33,6 +33,7 @@ import jalview.io.FileLoader; import java.util.Vector; +import org.jmol.c.STR; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; @@ -206,4 +207,35 @@ public class PDBFileWithJmolTest assertEquals("ALC", seqs.get(0).getSequenceAsString()); assertEquals("ALC", mcseqs.get(0).getSequenceAsString()); } + + @Test(groups = "Functional") + public void testSetSecondaryStructure() + { + PDBFileWithJmol testee = new PDBFileWithJmol(); + char[] struct = new char[10]; + char[] structCode = new char[10]; + struct[0] = '1'; + structCode[0] = '1'; + + testee.setSecondaryStructure(STR.NONE, 0, struct, structCode); + testee.setSecondaryStructure(STR.HELIX, 1, struct, structCode); + testee.setSecondaryStructure(STR.HELIX310, 2, struct, structCode); + testee.setSecondaryStructure(STR.HELIXALPHA, 3, struct, structCode); + testee.setSecondaryStructure(STR.HELIXPI, 4, struct, structCode); + testee.setSecondaryStructure(STR.SHEET, 5, struct, structCode); + + assertEquals(0, struct[0]); + assertEquals('H', struct[1]); + assertEquals('3', struct[2]); + assertEquals('H', struct[3]); + assertEquals('P', struct[4]); + assertEquals('E', struct[5]); + + assertEquals(0, structCode[0]); + assertEquals('H', structCode[1]); + assertEquals('H', structCode[2]); + assertEquals('H', structCode[3]); + assertEquals('H', structCode[4]); + assertEquals('E', structCode[5]); + } }