From: tcofoegbu Date: Thu, 21 Jul 2016 16:12:10 +0000 (+0100) Subject: JAL-2148 fix to heuristically determine chain termination positions. This aids in... X-Git-Tag: Release_2_10_0~136 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=4e3166c6b7348b10af5ee6526a83eaa78191b1b6;p=jalview.git JAL-2148 fix to heuristically determine chain termination positions. This aids in decision making w.r.t CA HETATMs inclusion --- diff --git a/src/MCview/PDBfile.java b/src/MCview/PDBfile.java index 9acc2e7..2746807 100755 --- a/src/MCview/PDBfile.java +++ b/src/MCview/PDBfile.java @@ -25,7 +25,6 @@ import jalview.datamodel.DBRefSource; import jalview.datamodel.SequenceI; import jalview.io.FileParse; import jalview.io.StructureFile; -import jalview.structure.StructureImportSettings; import jalview.util.MessageManager; import java.io.IOException; @@ -132,8 +131,7 @@ public class PDBfile extends StructureFile break; } if (line.indexOf("ATOM") == 0 - || (StructureImportSettings.isProcessHETATMs() - && line.indexOf("HETATM") == 0 && !terFlag)) + || (line.indexOf("HETATM") == 0 && !terFlag)) { terFlag = false; diff --git a/src/jalview/bin/Cache.java b/src/jalview/bin/Cache.java index 23277a4..5f0ed2c 100755 --- a/src/jalview/bin/Cache.java +++ b/src/jalview/bin/Cache.java @@ -433,8 +433,6 @@ public class Cache StructureImportSettings .setDefaultPDBFileParser(jalview.bin.Cache.getDefault( "DEFAULT_PDB_FILE_PARSER", DEFAULT_PDB_FILE_PARSER)); - StructureImportSettings.setProcessHETATMs(jalview.bin.Cache.getDefault( - "PROCESS_HETATM", false)); // jnlpVersion will be null if we're using InstallAnywhere // Dont do this check if running in headless mode if (jnlpVersion == null diff --git a/src/jalview/ext/jmol/JmolParser.java b/src/jalview/ext/jmol/JmolParser.java index ea347ae..ca412d0 100644 --- a/src/jalview/ext/jmol/JmolParser.java +++ b/src/jalview/ext/jmol/JmolParser.java @@ -31,6 +31,7 @@ import jalview.util.MessageManager; import java.io.IOException; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Vector; @@ -194,17 +195,17 @@ public class JmolParser extends StructureFile implements JmolStatusListener private List convertSignificantAtoms(ModelSet ms) { List significantAtoms = new ArrayList(); + HashMap chainTerMap = new HashMap(); + org.jmol.modelset.Atom prevAtom = null; for (org.jmol.modelset.Atom atom : ms.at) { - // System.out.println("Seq Id : " + atom.getSeqID()); - // System.out.println("To String : " + atom.toString()); - if (!StructureImportSettings.isProcessHETATMs() && atom.isHetero()) - { - continue; - } if (atom.getAtomName().equalsIgnoreCase("CA") || atom.getAtomName().equalsIgnoreCase("P")) { + if (!atomValidated(atom, prevAtom, chainTerMap)) + { + continue; + } Atom curAtom = new Atom(atom.x, atom.y, atom.z); curAtom.atomIndex = atom.getIndex(); curAtom.chain = atom.getChainIDStr(); @@ -219,11 +220,57 @@ public class JmolParser extends StructureFile implements JmolStatusListener curAtom.tfactor = atom.getBfactor100() / 100f; curAtom.type = 0; significantAtoms.add(curAtom); + prevAtom = atom; } } return significantAtoms; } + private boolean atomValidated(org.jmol.modelset.Atom curAtom, + org.jmol.modelset.Atom prevAtom, + HashMap chainTerMap) + { + if (chainTerMap == null || prevAtom == null) + { + return true; + } + String curAtomChId = curAtom.getChainIDStr(); + String prevAtomChId = prevAtom.getChainIDStr(); + // new chain encoutered + if (!prevAtomChId.equals(curAtomChId)) + { + // On chain switch add previous chain termination to xTerMap if not exists + if (!chainTerMap.containsKey(prevAtomChId)) + { + chainTerMap.put(prevAtomChId, prevAtom); + } + // if current atom belongs to an already terminated chain and the resNum + // diff < 5 then mark as valid and update termination Atom + if (chainTerMap.containsKey(curAtomChId)) + { + if ((curAtom.getResno() - chainTerMap.get(curAtomChId).getResno()) < 5) + { + chainTerMap.put(curAtomChId, curAtom); + return true; + } + return false; + } + } + // atom with previously terminated chain encountered + else if (chainTerMap.containsKey(curAtomChId)) + { + if ((curAtom.getResno() - chainTerMap.get(curAtomChId).getResno()) < 5) + { + chainTerMap.put(curAtomChId, curAtom); + return true; + } + return false; + } + // HETATM with resNum jump > 2 + return !(curAtom.isHetero() && ((curAtom.getResno() - prevAtom + .getResno()) > 2)); + } + private void createAnnotation(SequenceI sequence, PDBChain chain, org.jmol.modelset.Atom[] jmolAtoms) { diff --git a/src/jalview/structure/StructureImportSettings.java b/src/jalview/structure/StructureImportSettings.java index 4c06e0f..c49b141 100644 --- a/src/jalview/structure/StructureImportSettings.java +++ b/src/jalview/structure/StructureImportSettings.java @@ -24,8 +24,6 @@ public class StructureImportSettings private static boolean showSeqFeatures = true; - private static boolean processHETATMs = false; - public static final String JMOL_PARSER = "JMolParser"; public static final String JALVIEW_PARSER = "JalViewParser"; @@ -108,16 +106,6 @@ public class StructureImportSettings StructureImportSettings.defaultStructureFileFormat = defaultStructureFileFormat; } - public static boolean isProcessHETATMs() - { - return processHETATMs; - } - - public static void setProcessHETATMs(boolean processHETATMs) - { - StructureImportSettings.processHETATMs = processHETATMs; - } - public static String getDefaultPDBFileParser() { return defaultPDBFileParser; diff --git a/test/jalview/ext/jmol/JmolParserTest.java b/test/jalview/ext/jmol/JmolParserTest.java index 0010321..b0e0718 100644 --- a/test/jalview/ext/jmol/JmolParserTest.java +++ b/test/jalview/ext/jmol/JmolParserTest.java @@ -109,7 +109,6 @@ public class JmolParserTest @Test(groups = { "Functional" }) public void testFileParser() throws Exception { - StructureImportSettings.setProcessHETATMs(false); for (String pdbStr : testFile) { PDBfile mctest = new PDBfile(false, false, false, pdbStr, @@ -133,30 +132,7 @@ public class JmolParserTest validateSecStrRows(al); } } - StructureImportSettings.setProcessHETATMs(true); - for (String pdbStr : testFile) - { - PDBfile mctest = new PDBfile(false, false, false, pdbStr, - AppletFormatAdapter.FILE); - JmolParser jtest = new JmolParser(false, false, false, pdbStr, - jalview.io.AppletFormatAdapter.FILE); - Vector seqs = jtest.getSeqs(), mcseqs = mctest.getSeqs(); - assertTrue( - "No sequences extracted from testfile\n" - + (jtest.hasWarningMessage() ? jtest.getWarningMessage() - : "(No warnings raised)"), seqs != null - && seqs.size() > 0); - for (SequenceI sq : seqs) - { - assertEquals("JMol didn't process " + pdbStr - + " to the same sequence as MCView", - sq.getSequenceAsString(), mcseqs.remove(0) - .getSequenceAsString()); - AlignmentI al = new Alignment(new SequenceI[] { sq }); - validateSecStrRows(al); - } - } } private void validateSecStrRows(AlignmentI al)