file format enum wip changes
[jalview.git] / src / jalview / ws / dbsources / Pdb.java
index b9fb8f3..6f266dd 100644 (file)
@@ -1,3 +1,4 @@
+
 /*
  * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
  * Copyright (C) $$Year-Rel$$ The Jalview Authors
@@ -20,6 +21,7 @@
  */
 package jalview.ws.dbsources;
 
+import jalview.api.FeatureSettingsModelI;
 import jalview.datamodel.AlignmentAnnotation;
 import jalview.datamodel.AlignmentI;
 import jalview.datamodel.DBRefEntry;
@@ -27,6 +29,8 @@ import jalview.datamodel.DBRefSource;
 import jalview.datamodel.PDBEntry;
 import jalview.datamodel.SequenceI;
 import jalview.io.FormatAdapter;
+import jalview.io.PDBFeatureSettings;
+import jalview.structure.StructureImportSettings;
 import jalview.util.MessageManager;
 import jalview.ws.ebi.EBIFetchClient;
 
@@ -47,6 +51,10 @@ public class Pdb extends EbiFileRetrievedProxy
     super();
   }
 
+  public static final String FEATURE_INSERTION = "INSERTION";
+
+  public static final String FEATURE_RES_NUM = "RESNUM";
+
   /*
    * (non-Javadoc)
    * 
@@ -100,7 +108,7 @@ public class Pdb extends EbiFileRetrievedProxy
   @Override
   public AlignmentI getSequenceRecords(String queries) throws Exception
   {
-    AlignmentI pdbfile = null;
+    AlignmentI pdbAlignment = null;
     Vector result = new Vector();
     String chain = null;
     String id = null;
@@ -124,8 +132,14 @@ public class Pdb extends EbiFileRetrievedProxy
       stopQuery();
       return null;
     }
+    String ext = StructureImportSettings.getCurrentDefaultFormat()
+            .equalsIgnoreCase("mmcif") ? ".cif"
+            : ".xml";
     EBIFetchClient ebi = new EBIFetchClient();
-    file = ebi.fetchDataAsFile("pdb:" + id, "pdb", "raw").getAbsolutePath();
+    file = ebi.fetchDataAsFile("pdb:" + id,
+            StructureImportSettings.getCurrentDefaultFormat().toLowerCase(),
+            ext)
+            .getAbsolutePath();
     stopQuery();
     if (file == null)
     {
@@ -134,12 +148,13 @@ public class Pdb extends EbiFileRetrievedProxy
     try
     {
 
-      pdbfile = new FormatAdapter().readFile(file,
-              jalview.io.AppletFormatAdapter.FILE, "PDB");
-      if (pdbfile != null)
+      pdbAlignment = new FormatAdapter().readFile(file,
+              jalview.io.DataSourceType.FILE,
+              StructureImportSettings.getCurrentDefaultFormat());
+      if (pdbAlignment != null)
       {
         List<SequenceI> toremove = new ArrayList<SequenceI>();
-        for (SequenceI pdbcs : pdbfile.getSequences())
+        for (SequenceI pdbcs : pdbAlignment.getSequences())
         {
           String chid = null;
           // Mapping map=null;
@@ -191,18 +206,18 @@ public class Pdb extends EbiFileRetrievedProxy
         // now remove marked sequences
         for (SequenceI pdbcs : toremove)
         {
-          pdbfile.deleteSequence(pdbcs);
+          pdbAlignment.deleteSequence(pdbcs);
           if (pdbcs.getAnnotation() != null)
           {
             for (AlignmentAnnotation aa : pdbcs.getAnnotation())
             {
-              pdbfile.deleteAnnotation(aa);
+              pdbAlignment.deleteAnnotation(aa);
             }
           }
         }
       }
 
-      if (pdbfile == null || pdbfile.getHeight() < 1)
+      if (pdbAlignment == null || pdbAlignment.getHeight() < 1)
       {
         throw new Exception(MessageManager.formatMessage(
                 "exception.no_pdb_records_for_chain", new String[] { id,
@@ -214,7 +229,7 @@ public class Pdb extends EbiFileRetrievedProxy
       stopQuery();
       throw (ex);
     }
-    return pdbfile;
+    return pdbAlignment;
   }
 
   /*
@@ -230,12 +245,12 @@ public class Pdb extends EbiFileRetrievedProxy
   }
 
   /**
-   * obtain human glyoxalase chain A sequence
+   * human glyoxalase
    */
   @Override
   public String getTestQuery()
   {
-    return "1QIPA";
+    return "1QIP";
   }
 
   @Override
@@ -249,4 +264,20 @@ public class Pdb extends EbiFileRetrievedProxy
   {
     return 0;
   }
+
+
+  /**
+   * Returns a descriptor for suitable feature display settings with
+   * <ul>
+   * <li>ResNums or insertions features visible</li>
+   * <li>insertions features coloured red</li>
+   * <li>ResNum features coloured by label</li>
+   * <li>Insertions displayed above (on top of) ResNums</li>
+   * </ul>
+   */
+  @Override
+  public FeatureSettingsModelI getFeatureColourScheme()
+  {
+    return new PDBFeatureSettings();
+  }
 }