JAL-2196 refactor PDBEntry.getProperty,setProperty,getProperties
[jalview.git] / src / jalview / io / StructureFile.java
index af5a1fa..6ce907a 100644 (file)
@@ -8,13 +8,13 @@ import jalview.datamodel.AlignmentI;
 import jalview.datamodel.DBRefEntry;
 import jalview.datamodel.DBRefSource;
 import jalview.datamodel.PDBEntry;
+import jalview.datamodel.PDBEntry.Type;
 import jalview.datamodel.SequenceI;
-import jalview.structure.StructureViewSettings;
+import jalview.structure.StructureImportSettings;
 
 import java.awt.Color;
 import java.io.IOException;
 import java.lang.reflect.Constructor;
-import java.util.Hashtable;
 import java.util.List;
 import java.util.Vector;
 
@@ -25,7 +25,7 @@ public abstract class StructureFile extends AlignFile
 
   private String id;
 
-  private String dbRefType;
+  private PDBEntry.Type dbRefType;
 
   /**
    * set to true to add derived sequence annotations (temp factor read from
@@ -67,19 +67,19 @@ public abstract class StructureFile extends AlignFile
 
   public void xferSettings()
   {
-    this.visibleChainAnnotation = StructureViewSettings
+    this.visibleChainAnnotation = StructureImportSettings
             .isVisibleChainAnnotation();
-    this.predictSecondaryStructure = StructureViewSettings
-            .isPredictSecondaryStructure();
-    this.externalSecondaryStructure = StructureViewSettings
+    this.predictSecondaryStructure = StructureImportSettings
+            .isProcessSecondaryStructure();
+    this.externalSecondaryStructure = StructureImportSettings
             .isExternalSecondaryStructure();
 
   }
 
-  public StructureFile(boolean parseImmediately, String inFile, String type)
+  public StructureFile(boolean parseImmediately, String dataObject, String type)
           throws IOException
   {
-    super(parseImmediately, inFile, type);
+    super(parseImmediately, dataObject, type);
   }
 
   public StructureFile(boolean a, FileParse fp) throws IOException
@@ -91,18 +91,16 @@ public abstract class StructureFile extends AlignFile
   {
   }
 
-  @SuppressWarnings("rawtypes")
   protected SequenceI postProcessChain(PDBChain chain)
   {
     SequenceI pdbSequence = chain.sequence;
     pdbSequence.setName(getId() + "|" + pdbSequence.getName());
     PDBEntry entry = new PDBEntry();
     entry.setId(getId());
-    entry.setType(this.dbRefType);
-    entry.setProperty(new Hashtable());
+    entry.setType(getStructureFileType());
     if (chain.id != null)
     {
-      entry.setChainCode(String.valueOf(chain.id));
+      entry.setChainCode(chain.id);
     }
     if (inFile != null)
     {
@@ -116,9 +114,9 @@ public abstract class StructureFile extends AlignFile
     DBRefEntry sourceDBRef = new DBRefEntry();
     sourceDBRef.setAccessionId(getId());
     sourceDBRef.setSource(DBRefSource.PDB);
-    sourceDBRef.setStartRes(pdbSequence.getStart());
-    sourceDBRef.setEndRes(pdbSequence.getEnd());
-    pdbSequence.setSourceDBRef(sourceDBRef);
+    // TODO: specify version for 'PDB' database ref if it is read from a file.
+    // TODO: decide if jalview.io should be creating primary refs!
+    sourceDBRef.setVersion("");
     pdbSequence.addPDBId(entry);
     pdbSequence.addDBRef(sourceDBRef);
     SequenceI chainseq = pdbSequence;
@@ -136,6 +134,26 @@ public abstract class StructureFile extends AlignFile
     return chainseq;
   }
 
+  /**
+   * filetype of structure file - default is PDB
+   */
+  String structureFileType = PDBEntry.Type.PDB.toString();
+
+  protected void setStructureFileType(String structureFileType)
+  {
+    this.structureFileType = structureFileType;
+  }
+
+  /**
+   * filetype of last file processed
+   * 
+   * @return
+   */
+  public String getStructureFileType()
+  {
+    return structureFileType;
+  }
+
   @SuppressWarnings({ "unchecked", "rawtypes" })
   protected void processPdbFileWithAnnotate3d(List<SequenceI> rna)
           throws Exception
@@ -270,11 +288,11 @@ public abstract class StructureFile extends AlignFile
             predictSecondaryStructure, externalSecondaryStructure,
             new FileParse(getDataName(), type) };
 
-        StructureViewSettings.setShowSeqFeatures(false);
-        StructureViewSettings.setVisibleChainAnnotation(false);
-        StructureViewSettings
-                .setPredictSecondaryStructure(predictSecondaryStructure);
-        StructureViewSettings
+        StructureImportSettings.setShowSeqFeatures(false);
+        StructureImportSettings.setVisibleChainAnnotation(false);
+        StructureImportSettings
+                .setProcessSecondaryStructure(predictSecondaryStructure);
+        StructureImportSettings
                 .setExternalSecondaryStructure(externalSecondaryStructure);
         Object jmf = constructor.newInstance(args);
         AlignmentI al = new Alignment((SequenceI[]) cl.getMethod(
@@ -297,13 +315,14 @@ public abstract class StructureFile extends AlignFile
     } catch (ClassNotFoundException q)
     {
     }
+    StructureImportSettings.setShowSeqFeatures(true);
   }
 
   public PDBChain findChain(String id) throws Exception
   {
     for (PDBChain chain : getChains())
     {
-      if (chain.id.equalsIgnoreCase(id))
+      if (chain.id.equals(id))
       {
         return chain;
       }
@@ -400,13 +419,18 @@ public abstract class StructureFile extends AlignFile
     this.chains = chains;
   }
 
-  public String getDbRefType()
+  public Type getDbRefType()
   {
     return dbRefType;
   }
 
   public void setDbRefType(String dbRefType)
   {
+    this.dbRefType = Type.getType(dbRefType);
+  }
+
+  public void setDbRefType(Type dbRefType)
+  {
     this.dbRefType = dbRefType;
   }