JAL-1919 refined structure view annotation settings to work for both PDB and mmCIF
authortcofoegbu <tcnofoegbu@dundee.ac.uk>
Tue, 15 Mar 2016 12:19:29 +0000 (12:19 +0000)
committertcofoegbu <tcnofoegbu@dundee.ac.uk>
Tue, 15 Mar 2016 12:19:29 +0000 (12:19 +0000)
src/MCview/PDBChain.java
src/MCview/PDBfile.java
src/jalview/ext/jmol/JmolParser.java
src/jalview/io/AppletFormatAdapter.java
src/jalview/io/StructureFile.java
test/jalview/structure/StructureViewSettings.java [new file with mode: 0644]

index f4263b1..91526e1 100755 (executable)
@@ -30,6 +30,7 @@ import jalview.datamodel.SequenceI;
 import jalview.schemes.ColourSchemeI;
 import jalview.schemes.ResidueProperties;
 import jalview.structure.StructureMapping;
+import jalview.structure.StructureViewSettings;
 
 import java.awt.Color;
 import java.util.List;
@@ -423,11 +424,15 @@ public class PDBChain
 
     // System.out.println("PDB Sequence is :\nSequence = " + seq);
     // System.out.println("No of residues = " + residues.size());
+
+    if (StructureViewSettings.isShowSeqFeatures())
+    {
     for (i = 0, iSize = resFeatures.size(); i < iSize; i++)
     {
       sequence.addSequenceFeature(resFeatures.elementAt(i));
       resFeatures.setElementAt(null, i);
     }
+    }
     if (visibleChainAnnotation)
     {
       Annotation[] annots = new Annotation[resAnnotation.size()];
index ed694f2..9a9b6f6 100755 (executable)
@@ -21,6 +21,7 @@
 package MCview;
 
 import jalview.datamodel.AlignmentAnnotation;
+import jalview.datamodel.DBRefSource;
 import jalview.datamodel.SequenceI;
 import jalview.io.FileParse;
 import jalview.io.StructureFile;
@@ -40,30 +41,25 @@ public class PDBfile extends StructureFile
           boolean predictSecondaryStructure, boolean externalSecStr)
   {
     super();
-    this.visibleChainAnnotation = addAlignmentAnnotations;
-    this.predictSecondaryStructure = predictSecondaryStructure;
-    this.externalSecondaryStructure = externalSecStr;
+    addSettings(addAlignmentAnnotations, predictSecondaryStructure,
+            externalSecStr);
   }
 
-  public PDBfile(boolean addAlignmentAnnotations,
-          boolean predictSecondaryStructure, boolean externalSecStr,
-          String file, String protocol) throws IOException
+  public PDBfile(boolean addAlignmentAnnotations, boolean predictSecStr,
+          boolean externalSecStr, String file, String protocol)
+          throws IOException
   {
     super(false, file, protocol);
-    this.visibleChainAnnotation = addAlignmentAnnotations;
-    this.predictSecondaryStructure = predictSecondaryStructure;
-    this.externalSecondaryStructure = externalSecStr;
+    addSettings(addAlignmentAnnotations, predictSecStr, externalSecStr);
     doParse();
   }
 
-  public PDBfile(boolean addAlignmentAnnotations,
-          boolean predictSecondaryStructure, boolean externalSecStr,
+  public PDBfile(boolean addAlignmentAnnotations, boolean predictSecStr,
+          boolean externalSecStr,
           FileParse source) throws IOException
   {
     super(false, source);
-    this.visibleChainAnnotation = addAlignmentAnnotations;
-    this.predictSecondaryStructure = predictSecondaryStructure;
-    this.externalSecondaryStructure = externalSecStr;
+    addSettings(addAlignmentAnnotations, predictSecStr, externalSecStr);
     doParse();
   }
 
@@ -76,6 +72,7 @@ public class PDBfile extends StructureFile
   @Override
   public void parse() throws IOException
   {
+    setDbRefType(DBRefSource.PDB);
     // TODO set the filename sensibly - try using data source name.
     setId(safeName(getDataName()));
 
index a339c6b..c9243ed 100644 (file)
@@ -22,10 +22,12 @@ package jalview.ext.jmol;
 
 import jalview.datamodel.AlignmentAnnotation;
 import jalview.datamodel.Annotation;
+import jalview.datamodel.DBRefSource;
 import jalview.datamodel.SequenceI;
 import jalview.io.FileParse;
 import jalview.io.StructureFile;
 import jalview.schemes.ResidueProperties;
+import jalview.structure.StructureViewSettings;
 import jalview.util.MessageManager;
 
 import java.io.IOException;
@@ -57,34 +59,19 @@ public class JmolParser extends StructureFile implements JmolStatusListener
 {
   Viewer viewer = null;
 
-  public JmolParser(boolean addAlignmentAnnotations,
-          boolean predictSecondaryStructure, boolean externalSecStr,
-          String inFile, String type) throws IOException
+  public JmolParser(boolean addAlignmentAnnotations, boolean predictSecStr,
+          boolean externalSecStr, String inFile, String type)
+          throws IOException
   {
     super(inFile, type);
-    this.visibleChainAnnotation = addAlignmentAnnotations;
-    this.predictSecondaryStructure = predictSecondaryStructure;
-    this.externalSecondaryStructure = externalSecStr;
+    // addSettings(addAlignmentAnnotations, predictSecStr, externalSecStr);
   }
 
-  public JmolParser(boolean addAlignmentAnnotations,
-          boolean predictSecondaryStructure, boolean externalSecStr,
-          FileParse fp) throws IOException
+  public JmolParser(boolean addAlignmentAnnotations, boolean predictSecStr,
+          boolean externalSecStr, FileParse fp) throws IOException
   {
     super(fp);
-    this.visibleChainAnnotation = addAlignmentAnnotations;
-    this.predictSecondaryStructure = predictSecondaryStructure;
-    this.externalSecondaryStructure = externalSecStr;
-  }
-
-  public JmolParser(FileParse fp) throws IOException
-  {
-    super(fp);
-  }
-
-  public JmolParser(String inFile, String type) throws IOException
-  {
-    super(inFile, type);
+    // addSettings(addAlignmentAnnotations, predictSecStr, externalSecStr);
   }
 
   public JmolParser()
@@ -102,7 +89,15 @@ public class JmolParser extends StructureFile implements JmolStatusListener
   @Override
   public void parse() throws IOException
   {
-
+    String dataName = getDataName();
+    if (dataName.endsWith(".cif"))
+    {
+      setDbRefType(DBRefSource.MMCIF);
+    }
+    else
+    {
+      setDbRefType(DBRefSource.PDB);
+    }
     setChains(new Vector<PDBChain>());
     Viewer jmolModel = getJmolData();
     jmolModel.openReader(getDataName(), getDataName(), getReader());
@@ -182,7 +177,6 @@ public class JmolParser extends StructureFile implements JmolStatusListener
       for (PDBChain chain : getChains())
       {
         SequenceI chainseq = postProcessChain(chain);
-        createAnnotation(chainseq, chain, ms.at);
         if (isRNA(chainseq))
         {
           rna.add(chainseq);
@@ -191,6 +185,11 @@ public class JmolParser extends StructureFile implements JmolStatusListener
         {
           prot.add(chainseq);
         }
+
+        if (StructureViewSettings.isPredictSecondaryStructure())
+        {
+          createAnnotation(chainseq, chain, ms.at);
+        }
       }
     } catch (OutOfMemoryError er)
     {
index e19db81..285a953 100755 (executable)
@@ -26,6 +26,7 @@ import jalview.datamodel.Alignment;
 import jalview.datamodel.AlignmentAnnotation;
 import jalview.datamodel.AlignmentI;
 import jalview.datamodel.AlignmentView;
+import jalview.structure.StructureViewSettings;
 import jalview.util.MessageManager;
 
 import java.io.File;
@@ -282,12 +283,15 @@ public class AppletFormatAdapter
         boolean isParseWithJMOL = false;
         if (isParseWithJMOL)
         {
+          StructureViewSettings.addSettings(annotFromStructure,
+                  localSecondaryStruct, serviceSecondaryStruct);
           alignFile = new jalview.ext.jmol.JmolParser(annotFromStructure,
                   localSecondaryStruct, serviceSecondaryStruct, inFile,
                   type);
         }
         else
         {
+          StructureViewSettings.setShowSeqFeatures(true);
           alignFile = new MCview.PDBfile(annotFromStructure,
                   localSecondaryStruct, serviceSecondaryStruct, inFile,
                   type);
@@ -295,6 +299,8 @@ public class AppletFormatAdapter
       }
       else if (format.equals("mmCIF"))
       {
+        StructureViewSettings.addSettings(annotFromStructure,
+                localSecondaryStruct, serviceSecondaryStruct);
         alignFile = new jalview.ext.jmol.JmolParser(annotFromStructure,
                 localSecondaryStruct, serviceSecondaryStruct, inFile, type);
       }
@@ -427,17 +433,22 @@ public class AppletFormatAdapter
         boolean isParseWithJMOL = false;
         if (isParseWithJMOL)
         {
+          StructureViewSettings.addSettings(annotFromStructure,
+                  localSecondaryStruct, serviceSecondaryStruct);
           alignFile = new jalview.ext.jmol.JmolParser(annotFromStructure,
                   localSecondaryStruct, serviceSecondaryStruct, source);
         }
         else
         {
+          StructureViewSettings.setShowSeqFeatures(true);
           alignFile = new MCview.PDBfile(annotFromStructure,
                   localSecondaryStruct, serviceSecondaryStruct, source);
         }
       }
       else if (format.equals("mmCIF"))
       {
+        StructureViewSettings.addSettings(annotFromStructure,
+                localSecondaryStruct, serviceSecondaryStruct);
         alignFile = new jalview.ext.jmol.JmolParser(annotFromStructure,
                 localSecondaryStruct, serviceSecondaryStruct, source);
       }
index 4ba4c10..7262443 100644 (file)
@@ -8,6 +8,7 @@ import jalview.datamodel.DBRefEntry;
 import jalview.datamodel.DBRefSource;
 import jalview.datamodel.PDBEntry;
 import jalview.datamodel.SequenceI;
+import jalview.structure.StructureViewSettings;
 
 import java.awt.Color;
 import java.io.IOException;
@@ -23,19 +24,20 @@ public abstract class StructureFile extends AlignFile
 
   private String id;
 
+  private String dbRefType;
   /**
    * set to true to add derived sequence annotations (temp factor read from
    * file, or computed secondary structure) to the alignment
    */
   protected boolean visibleChainAnnotation = false;
 
-  /*
+  /**
    * Set true to predict secondary structure (using JMol for protein, Annotate3D
    * for RNA)
    */
-  protected boolean predictSecondaryStructure = true;
+  protected boolean predictSecondaryStructure = false;
 
-  /*
+  /**
    * Set true (with predictSecondaryStructure=true) to predict secondary
    * structure using an external service (currently Annotate3D for RNA only)
    */
@@ -53,6 +55,13 @@ public abstract class StructureFile extends AlignFile
     super(fp);
   }
 
+  public void addSettings(boolean addAlignmentAnnotations,
+          boolean predictSecondaryStructure, boolean externalSecStr)
+  {
+    this.visibleChainAnnotation = addAlignmentAnnotations;
+    this.predictSecondaryStructure = predictSecondaryStructure;
+    this.externalSecondaryStructure = externalSecStr;
+  }
   public StructureFile(boolean parseImmediately, String inFile, String type)
           throws IOException
   {
@@ -75,7 +84,7 @@ public abstract class StructureFile extends AlignFile
     pdbSequence.setName(getId() + "|" + pdbSequence.getName());
     PDBEntry entry = new PDBEntry();
     entry.setId(getId());
-    entry.setType(PDBEntry.Type.PDB);
+    entry.setType(this.dbRefType);
     entry.setProperty(new Hashtable());
     if (chain.id != null)
     {
@@ -247,9 +256,14 @@ public abstract class StructureFile extends AlignFile
       if (cl != null)
       {
         final Constructor constructor = cl
-                .getConstructor(new Class[] { FileParse.class });
-        final Object[] args = new Object[] { new FileParse(getDataName(),
+.getConstructor(new Class[] {
+            boolean.class, boolean.class, boolean.class, FileParse.class });
+        final Object[] args = new Object[] { true, true, true,
+            new FileParse(getDataName(),
                 type) };
+
+        StructureViewSettings.setShowSeqFeatures(false);
+        StructureViewSettings.setPredictSecondaryStructure(true);
         Object jmf = constructor.newInstance(args);
         AlignmentI al = new Alignment((SequenceI[]) cl.getMethod(
                 "getSeqsAsArray", new Class[] {}).invoke(jmf));
@@ -373,4 +387,14 @@ public abstract class StructureFile extends AlignFile
   {
     this.chains = chains;
   }
+
+  public String getDbRefType()
+  {
+    return dbRefType;
+  }
+
+  public void setDbRefType(String dbRefType)
+  {
+    this.dbRefType = dbRefType;
+  }
 }
diff --git a/test/jalview/structure/StructureViewSettings.java b/test/jalview/structure/StructureViewSettings.java
new file mode 100644 (file)
index 0000000..2fcb3e5
--- /dev/null
@@ -0,0 +1,79 @@
+package jalview.structure;
+
+public class StructureViewSettings
+{
+  private String dbRefType;
+
+  /**
+   * set to true to add derived sequence annotations (temp factor read from
+   * file, or computed secondary structure) to the alignment
+   */
+  private static boolean visibleChainAnnotation = false;
+
+  /**
+   * Set true to predict secondary structure (using JMol for protein, Annotate3D
+   * for RNA)
+   */
+  private static boolean predictSecStr = false;
+
+  /**
+   * Set true (with predictSecondaryStructure=true) to predict secondary
+   * structure using an external service (currently Annotate3D for RNA only)
+   */
+  private static boolean externalSecondaryStructure = false;
+
+  private static boolean showSeqFeatures = true;
+
+  public static void addSettings(boolean addAlignmentAnnotations,
+          boolean predictSecStr, boolean externalSecStr)
+  {
+    StructureViewSettings.visibleChainAnnotation = addAlignmentAnnotations;
+    StructureViewSettings.predictSecStr = predictSecStr;
+    StructureViewSettings.externalSecondaryStructure = externalSecStr;
+    StructureViewSettings.showSeqFeatures = true;
+  }
+
+  public static boolean isVisibleChainAnnotation()
+  {
+    return visibleChainAnnotation;
+  }
+
+  public static void setVisibleChainAnnotation(
+          boolean visibleChainAnnotation)
+  {
+    StructureViewSettings.visibleChainAnnotation = visibleChainAnnotation;
+  }
+
+  public static boolean isPredictSecondaryStructure()
+  {
+    return predictSecStr;
+  }
+
+  public static void setPredictSecondaryStructure(
+          boolean predictSecondaryStructure)
+  {
+    StructureViewSettings.predictSecStr = predictSecondaryStructure;
+  }
+
+  public static boolean isExternalSecondaryStructure()
+  {
+    return externalSecondaryStructure;
+  }
+
+  public static void setExternalSecondaryStructure(
+          boolean externalSecondaryStructure)
+  {
+    StructureViewSettings.externalSecondaryStructure = externalSecondaryStructure;
+  }
+
+  public static boolean isShowSeqFeatures()
+  {
+    return showSeqFeatures;
+  }
+
+  public static void setShowSeqFeatures(boolean showSeqFeatures)
+  {
+    StructureViewSettings.showSeqFeatures = showSeqFeatures;
+  }
+
+}