From 13317fa1bc7bf640dc1967ce4438676e89390ad3 Mon Sep 17 00:00:00 2001 From: Jim Procter Date: Tue, 18 Nov 2014 09:52:35 +0000 Subject: [PATCH] JAL-674 make temperature factor, local secondary structure and service based secondary structure processing configurable --- src/MCview/PDBChain.java | 32 ++++--- src/MCview/PDBViewer.java | 2 +- src/MCview/PDBfile.java | 100 +++++++++++--------- src/jalview/analysis/AlignSeq.java | 2 +- src/jalview/gui/Desktop.java | 24 ++++- src/jalview/gui/Preferences.java | 3 +- src/jalview/io/AppletFormatAdapter.java | 21 +++- src/jalview/io/FormatAdapter.java | 30 +++++- .../structure/StructureSelectionManager.java | 69 +++++++++++++- test/jalview/ext/jmol/PDBFileWithJmolTest.java | 2 +- test/jalview/ext/paradise/TestAnnotate3D.java | 9 +- 11 files changed, 220 insertions(+), 74 deletions(-) diff --git a/src/MCview/PDBChain.java b/src/MCview/PDBChain.java index 2dd6d37..e8f1bc9 100755 --- a/src/MCview/PDBChain.java +++ b/src/MCview/PDBChain.java @@ -267,7 +267,7 @@ public class PDBChain bonds.addElement(new Bond(start, end, at1, at2)); } - public void makeResidueList() + public void makeResidueList(boolean visibleChainAnnotation) { int count = 0; Object symbol; @@ -377,23 +377,27 @@ public class PDBChain .elementAt(i)); resFeatures.setElementAt(null, i); } - Annotation[] annots = new Annotation[resAnnotation.size()]; - float max = 0; - for (i = 0, iSize = annots.length; i < iSize; i++) + if (visibleChainAnnotation) { - annots[i] = (Annotation) resAnnotation.elementAt(i); - if (annots[i].value > max) + Annotation[] annots = new Annotation[resAnnotation.size()]; + float max = 0; + for (i = 0, iSize = annots.length; i < iSize; i++) { - max = annots[i].value; + annots[i] = (Annotation) resAnnotation.elementAt(i); + if (annots[i].value > max) + { + max = annots[i].value; + } + resAnnotation.setElementAt(null, i); } - resAnnotation.setElementAt(null, i); + + AlignmentAnnotation tfactorann = new AlignmentAnnotation( + "PDB.TempFactor", "Temperature Factor for " + + sequence.getName(), annots, 0, max, + AlignmentAnnotation.LINE_GRAPH); + tfactorann.setSequenceRef(sequence); + sequence.addAlignmentAnnotation(tfactorann); } - AlignmentAnnotation tfactorann = new AlignmentAnnotation( - "PDB.TempFactor", "Temperature Factor for " - + sequence.getName(), annots, 0, max, - AlignmentAnnotation.LINE_GRAPH); - tfactorann.setSequenceRef(sequence); - sequence.addAlignmentAnnotation(tfactorann); } public void setChargeColours() diff --git a/src/MCview/PDBViewer.java b/src/MCview/PDBViewer.java index d3535c0..bf285b9 100755 --- a/src/MCview/PDBViewer.java +++ b/src/MCview/PDBViewer.java @@ -113,7 +113,7 @@ public class PDBViewer extends JInternalFrame implements Runnable try { tmpPDBFile = pdbentry.getFile(); - PDBfile pdbfile = new PDBfile(false,false,tmpPDBFile, + PDBfile pdbfile = new PDBfile(false, false, false, tmpPDBFile, jalview.io.AppletFormatAdapter.FILE); pdbcanvas.init(pdbentry, seq, chains, ap, protocol); diff --git a/src/MCview/PDBfile.java b/src/MCview/PDBfile.java index b22eb29..e1c4dc5 100755 --- a/src/MCview/PDBfile.java +++ b/src/MCview/PDBfile.java @@ -47,32 +47,38 @@ public class PDBfile extends jalview.io.AlignFile */ boolean VisibleChainAnnotation = false; - boolean processSecondaryStructure=true; - + boolean processSecondaryStructure = true; + + boolean externalSecondaryStructure = false; public PDBfile(boolean visibleChainAnnotation, - boolean processSecondaryStructure) + boolean processSecondaryStructure, boolean externalSecStr) { super(); VisibleChainAnnotation = visibleChainAnnotation; this.processSecondaryStructure = processSecondaryStructure; + this.externalSecondaryStructure = externalSecStr; } public PDBfile(boolean visibleChainAnnotation, - boolean processSecondaryStructure, String file, String protocol) throws IOException + boolean processSecondaryStructure, boolean externalSecStr, + String file, String protocol) throws IOException { super(false, file, protocol); VisibleChainAnnotation = visibleChainAnnotation; this.processSecondaryStructure = processSecondaryStructure; + this.externalSecondaryStructure = externalSecStr; doParse(); } public PDBfile(boolean visibleChainAnnotation, - boolean processSecondaryStructure, FileParse source) throws IOException + boolean processSecondaryStructure, boolean externalSecStr, + FileParse source) throws IOException { super(false, source); VisibleChainAnnotation = visibleChainAnnotation; this.processSecondaryStructure = processSecondaryStructure; + this.externalSecondaryStructure = externalSecStr; doParse(); } @@ -189,8 +195,7 @@ public class PDBfile extends jalview.io.AlignFile entry.setProperty(new Hashtable()); if (chains.elementAt(i).id != null) { - entry.getProperty().put("CHAIN", - chains.elementAt(i).id); + entry.getProperty().put("CHAIN", chains.elementAt(i).id); } if (inFile != null) { @@ -217,7 +222,7 @@ public class PDBfile extends jalview.io.AlignFile AlignmentAnnotation[] chainannot = chainseq.getAnnotation(); - if (chainannot != null) + if (chainannot != null && VisibleChainAnnotation) { for (int ai = 0; ai < chainannot.length; ai++) { @@ -228,34 +233,34 @@ public class PDBfile extends jalview.io.AlignFile } if (processSecondaryStructure) { - if (rna.size() > 0) - { - try + if (externalSecondaryStructure && rna.size() > 0) { - processPdbFileWithAnnotate3d(rna); - } catch (Exception x) - { - System.err - .println("Exceptions when dealing with RNA in pdb file"); - x.printStackTrace(); + try + { + processPdbFileWithAnnotate3d(rna); + } catch (Exception x) + { + System.err + .println("Exceptions when dealing with RNA in pdb file"); + x.printStackTrace(); + } } - } - ; - if (prot.size() > 0) - { - try + ; + if (prot.size() > 0) { - processPdbFileWithJmol(prot); - } catch (Exception x) - { - System.err - .println("Exceptions from Jmol when processing data in pdb file"); - x.printStackTrace(); + try + { + processPdbFileWithJmol(prot); + } catch (Exception x) + { + System.err + .println("Exceptions from Jmol when processing data in pdb file"); + x.printStackTrace(); + } } } - } } catch (OutOfMemoryError er) { System.out.println("OUT OF MEMORY LOADING PDB FILE"); @@ -277,11 +282,11 @@ public class PDBfile extends jalview.io.AlignFile public static boolean isCalcIdHandled(String calcId) { - return calcId != null - && (calcIdPrefix.equals(calcId)); + return calcId != null && (calcIdPrefix.equals(calcId)); } - public static boolean isCalcIdForFile(AlignmentAnnotation alan, String pdbFile) + public static boolean isCalcIdForFile(AlignmentAnnotation alan, + String pdbFile) { return alan.getCalcId() != null && calcIdPrefix.equals(alan.getCalcId()) @@ -301,19 +306,23 @@ public class PDBfile extends jalview.io.AlignFile { for (SequenceI sq : seqs) { - for (AlignmentAnnotation aa : sq.getAnnotation()) + if (sq.getAnnotation() != null) { - String oldId = aa.getCalcId(); - if (oldId == null) + for (AlignmentAnnotation aa : sq.getAnnotation()) { - oldId = ""; + String oldId = aa.getCalcId(); + if (oldId == null) + { + oldId = ""; + } + aa.setCalcId(calcIdPrefix); + aa.setProperty("PDBID", id); + aa.setProperty("oldCalcId", oldId); } - aa.setCalcId(calcIdPrefix); - aa.setProperty("PDBID", id); - aa.setProperty("oldCalcId", oldId); } } } + private void processPdbFileWithJmol(ArrayList prot) throws Exception { @@ -352,8 +361,8 @@ public class PDBfile extends jalview.io.AlignFile AlignmentI al, String pep, boolean b) { List> replaced = AlignSeq - .replaceMatchingSeqsWith(seqs, - annotations, prot, al, AlignSeq.PEP, false); + .replaceMatchingSeqsWith(seqs, annotations, prot, al, + AlignSeq.PEP, false); for (PDBChain ch : chains) { int p = 0; @@ -371,8 +380,7 @@ public class PDBfile extends jalview.io.AlignFile p = -p - 1; // set shadow entry for chains ch.shadow = (SequenceI) replaced.get(1).get(p); - ch.shadowMap = ((AlignSeq) replaced.get(2) -.get(p)) + ch.shadowMap = ((AlignSeq) replaced.get(2).get(p)) .getMappingFromS1(false); } } @@ -445,7 +453,7 @@ public class PDBfile extends jalview.io.AlignFile { for (int i = 0; i < chains.size(); i++) { - chains.elementAt(i).makeResidueList(); + chains.elementAt(i).makeResidueList(VisibleChainAnnotation); } } @@ -490,8 +498,8 @@ public class PDBfile extends jalview.io.AlignFile { for (int i = 0; i < chains.size(); i++) { - chains.elementAt(i).setChainColours(Color.getHSBColor( - 1.0f / i, .4f, 1.0f)); + chains.elementAt(i).setChainColours( + Color.getHSBColor(1.0f / i, .4f, 1.0f)); } } diff --git a/src/jalview/analysis/AlignSeq.java b/src/jalview/analysis/AlignSeq.java index 307a06f..ba7e520 100755 --- a/src/jalview/analysis/AlignSeq.java +++ b/src/jalview/analysis/AlignSeq.java @@ -1153,7 +1153,7 @@ public class AlignSeq ap++; } } - if (sq.getAnnotation() != null) + if (sq.getAnnotation() != null && sq.getAnnotation().length > 0) { annotations.addAll(inspos, Arrays.asList(sq.getAnnotation())); } diff --git a/src/jalview/gui/Desktop.java b/src/jalview/gui/Desktop.java index faffd89..23ba893 100644 --- a/src/jalview/gui/Desktop.java +++ b/src/jalview/gui/Desktop.java @@ -26,6 +26,7 @@ import jalview.io.FormatAdapter; import jalview.io.IdentifyFile; import jalview.io.JalviewFileChooser; import jalview.io.JalviewFileView; +import jalview.structure.StructureSelectionManager; import jalview.util.ImageMaker; import jalview.util.MessageManager; import jalview.ws.params.ParamManager; @@ -286,7 +287,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements instance = this; doVamsasClientCheck(); doGroovyCheck(); - + doConfigureStructurePrefs(); setTitle("Jalview " + jalview.bin.Cache.getProperty("VERSION")); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); boolean selmemusage = jalview.bin.Cache.getDefault("SHOW_MEMUSAGE", @@ -416,6 +417,27 @@ public class Desktop extends jalview.jbgui.GDesktop implements }); } + public void doConfigureStructurePrefs() + { + // configure services + StructureSelectionManager ssm = StructureSelectionManager + .getStructureSelectionManager(this); + if (jalview.bin.Cache.getDefault(Preferences.ADD_SS_ANN, true)) + { + ssm.setAddTempFacAnnot(jalview.bin.Cache.getDefault( + Preferences.ADD_TEMPFACT_ANN, true)); + ssm.setProcessSecondaryStructure(jalview.bin.Cache.getDefault(Preferences.STRUCT_FROM_PDB, true)); + ssm.setSecStructServices(jalview.bin.Cache.getDefault(Preferences.USE_RNAVIEW, + true)); + } + else + { + ssm.setAddTempFacAnnot(false); + ssm.setProcessSecondaryStructure(false); + ssm.setSecStructServices(false); + } + } + public void checkForNews() { final Desktop me = this; diff --git a/src/jalview/gui/Preferences.java b/src/jalview/gui/Preferences.java index ab4f94f..09f3686 100755 --- a/src/jalview/gui/Preferences.java +++ b/src/jalview/gui/Preferences.java @@ -590,9 +590,8 @@ public class Preferences extends GPreferences dasSource.saveProperties(Cache.applicationProperties); wsPrefs.updateAndRefreshWsMenuConfig(false); - Cache.saveProperties(); - + Desktop.instance.doConfigureStructurePrefs(); try { frame.setClosed(true); diff --git a/src/jalview/io/AppletFormatAdapter.java b/src/jalview/io/AppletFormatAdapter.java index 5366cb4..d3b19fa 100755 --- a/src/jalview/io/AppletFormatAdapter.java +++ b/src/jalview/io/AppletFormatAdapter.java @@ -123,6 +123,21 @@ public class AppletFormatAdapter public static String CLASSLOADER = "ClassLoader"; + /** + * add jalview-derived non-secondary structure annotation from PDB structure + */ + boolean annotFromStructure = false; + + /** + * add secondary structure from PDB data with built-in algorithms + */ + boolean localSecondaryStruct = false; + + /** + * process PDB data with web services + */ + boolean serviceSecondaryStruct = false; + AlignFile afile = null; String inFile; @@ -236,7 +251,8 @@ public class AppletFormatAdapter } else if (format.equals("PDB")) { - afile = new MCview.PDBfile(true,true,inFile, type); + afile = new MCview.PDBfile(annotFromStructure, + localSecondaryStruct, serviceSecondaryStruct, inFile, type); // Uncomment to test Jmol data based PDB processing: JAL-1213 // afile = new jalview.ext.jmol.PDBFileWithJmol(inFile, type); } @@ -357,7 +373,8 @@ public class AppletFormatAdapter } else if (format.equals("PDB")) { - afile = new MCview.PDBfile(true,true,source); + afile = new MCview.PDBfile(annotFromStructure, + localSecondaryStruct, serviceSecondaryStruct, source); } else if (format.equals("STH")) { diff --git a/src/jalview/io/FormatAdapter.java b/src/jalview/io/FormatAdapter.java index c2a317a..8ca0c35 100755 --- a/src/jalview/io/FormatAdapter.java +++ b/src/jalview/io/FormatAdapter.java @@ -21,7 +21,13 @@ package jalview.io; import jalview.api.AlignViewportI; -import jalview.datamodel.*; +import jalview.datamodel.Alignment; +import jalview.datamodel.AlignmentAnnotation; +import jalview.datamodel.AlignmentI; +import jalview.datamodel.ColumnSelection; +import jalview.datamodel.Sequence; +import jalview.datamodel.SequenceGroup; +import jalview.datamodel.SequenceI; /** * Additional formatting methods used by the application in a number of places. @@ -32,6 +38,26 @@ import jalview.datamodel.*; public class FormatAdapter extends AppletFormatAdapter { + public FormatAdapter() + { + super(); + if (jalview.bin.Cache.getDefault("STRUCT_FROM_PDB", true)) + { + annotFromStructure = jalview.bin.Cache.getDefault("ADD_TEMPFACT_ANN", + true); + localSecondaryStruct = jalview.bin.Cache.getDefault("ADD_SS_ANN", + true); + serviceSecondaryStruct = jalview.bin.Cache.getDefault("USE_RNAVIEW", + true); + } + else + { + // disable all PDB annotation options + annotFromStructure = false; + localSecondaryStruct = false; + serviceSecondaryStruct = false; + } + } public String formatSequences(String format, SequenceI[] seqs, String[] omitHiddenColumns) { @@ -154,8 +180,10 @@ public class FormatAdapter extends AppletFormatAdapter public boolean getCacheSuffixDefault(String format) { if (isValidFormat(format)) + { return jalview.bin.Cache.getDefault(format.toUpperCase() + "_JVSUFFIX", true); + } return false; } diff --git a/src/jalview/structure/StructureSelectionManager.java b/src/jalview/structure/StructureSelectionManager.java index ac2897d..4359879 100644 --- a/src/jalview/structure/StructureSelectionManager.java +++ b/src/jalview/structure/StructureSelectionManager.java @@ -46,6 +46,70 @@ public class StructureSelectionManager StructureMapping[] mappings; + private boolean processSecondaryStructure = false, + secStructServices = false, addTempFacAnnot = false; + + /** + * @return true if will try to use external services for processing secondary + * structure + */ + public boolean isSecStructServices() + { + return secStructServices; + } + + /** + * control use of external services for processing secondary structure + * + * @param secStructServices + */ + public void setSecStructServices(boolean secStructServices) + { + this.secStructServices = secStructServices; + } + + /** + * flag controlling addition of any kind of structural annotation + * + * @return true if temperature factor annotation will be added + */ + public boolean isAddTempFacAnnot() + { + return addTempFacAnnot; + } + + /** + * set flag controlling addition of structural annotation + * + * @param addTempFacAnnot + */ + public void setAddTempFacAnnot(boolean addTempFacAnnot) + { + this.addTempFacAnnot = addTempFacAnnot; + } + + /** + * + * @return if true, the structure manager will attempt to add secondary + * structure lines for unannotated sequences + */ + + public boolean isProcessSecondaryStructure() + { + return processSecondaryStructure; + } + + /** + * Control whether structure manager will try to annotate mapped sequences + * with secondary structure from PDB data. + * + * @param enable + */ + public void setProcessSecondaryStructure(boolean enable) + { + processSecondaryStructure = enable; + } + /** * debug function - write all mappings to stdout */ @@ -245,7 +309,7 @@ public class StructureSelectionManager * the tried and tested MCview pdb mapping */ MCview.PDBfile pdb = null; - boolean parseSecStr=true; + boolean parseSecStr = processSecondaryStructure; if (isPDBFileRegistered(pdbFile)) { for (SequenceI sq : sequence) @@ -274,7 +338,8 @@ public class StructureSelectionManager } try { - pdb = new MCview.PDBfile(true, parseSecStr, pdbFile, protocol); + pdb = new MCview.PDBfile(addTempFacAnnot, parseSecStr, + secStructServices, pdbFile, protocol); if (pdb.id != null && pdb.id.trim().length() > 0 && AppletFormatAdapter.FILE.equals(protocol)) { diff --git a/test/jalview/ext/jmol/PDBFileWithJmolTest.java b/test/jalview/ext/jmol/PDBFileWithJmolTest.java index 79e3eae..7bcf902 100644 --- a/test/jalview/ext/jmol/PDBFileWithJmolTest.java +++ b/test/jalview/ext/jmol/PDBFileWithJmolTest.java @@ -64,7 +64,7 @@ public class PDBFileWithJmolTest { for (String pdbStr : testFile) { - PDBfile mctest = new PDBfile(false, false, pdbStr, + PDBfile mctest = new PDBfile(false, false, false, pdbStr, AppletFormatAdapter.FILE); PDBFileWithJmol jtest = new PDBFileWithJmol(pdbStr, jalview.io.AppletFormatAdapter.FILE); diff --git a/test/jalview/ext/paradise/TestAnnotate3D.java b/test/jalview/ext/paradise/TestAnnotate3D.java index d2322ef..a7c439f 100644 --- a/test/jalview/ext/paradise/TestAnnotate3D.java +++ b/test/jalview/ext/paradise/TestAnnotate3D.java @@ -21,10 +21,8 @@ package jalview.ext.paradise; import static org.junit.Assert.assertTrue; - import jalview.datamodel.AlignmentI; import jalview.datamodel.SequenceI; -import jalview.ext.paradise.Annotate3D; import jalview.io.FastaFile; import jalview.io.FormatAdapter; @@ -72,9 +70,13 @@ public class TestAnnotate3D iline = id.readLine(); fline = file.readLine(); if (iline != null) + { System.out.println(iline); + } if (fline != null) + { System.out.println(fline); + } // next assert fails for latest RNAview - because the XMLID entries // change between file and ID based RNAML generation. assertTrue( @@ -96,7 +98,8 @@ public class TestAnnotate3D @Test public void testPDBfileVsRNAML() throws Exception { - PDBfile pdbf = new PDBfile(true,true,"examples/2GIS.pdb", FormatAdapter.FILE); + PDBfile pdbf = new PDBfile(true, false, true, "examples/2GIS.pdb", + FormatAdapter.FILE); Assert.assertTrue(pdbf.isValid()); // Comment - should add new FileParse constructor like new FileParse(Reader // ..). for direct reading -- 1.7.10.2