JAL-2344 corrected conversion of Type enum to FileFormat
[jalview.git] / src / jalview / ws / dbsources / Pdb.java
index a50ed14..68dda88 100644 (file)
@@ -29,6 +29,9 @@ import jalview.datamodel.DBRefSource;
 import jalview.datamodel.PDBEntry;
 import jalview.datamodel.PDBEntry.Type;
 import jalview.datamodel.SequenceI;
+import jalview.io.DataSourceType;
+import jalview.io.FileFormat;
+import jalview.io.FileFormatI;
 import jalview.io.FormatAdapter;
 import jalview.io.PDBFeatureSettings;
 import jalview.structure.StructureImportSettings;
@@ -47,9 +50,10 @@ import com.stevesoft.pat.Regex;
 public class Pdb extends EbiFileRetrievedProxy
 {
   private static final String SEPARATOR = "|";
+
   private static final String COLON = ":";
-  private static final int PDB_ID_LENGTH = 4;
 
+  private static final int PDB_ID_LENGTH = 4;
 
   public Pdb()
   {
@@ -137,12 +141,11 @@ public class Pdb extends EbiFileRetrievedProxy
       stopQuery();
       return null;
     }
-    String ext = StructureImportSettings.getDefaultStructureFileFormat()
-            .equalsIgnoreCase(Type.MMCIF.toString()) ? ".cif" : ".xml";
+    Type pdbFileFormat = StructureImportSettings
+            .getDefaultStructureFileFormat();
+    String ext = "." + pdbFileFormat.getExtension();
     EBIFetchClient ebi = new EBIFetchClient();
-    file = ebi.fetchDataAsFile("pdb:" + id,
-            StructureImportSettings.getDefaultStructureFileFormat().toLowerCase(),
-            ext)
+    file = ebi.fetchDataAsFile("pdb:" + id, pdbFileFormat.getFormat(), ext)
             .getAbsolutePath();
     stopQuery();
     if (file == null)
@@ -151,10 +154,12 @@ public class Pdb extends EbiFileRetrievedProxy
     }
     try
     {
-
+      // todo get rid of Type and use FileFormatI instead?
+      // todo get rid of "ext" and just use "tmp"?
+      FileFormatI fileFormat = pdbFileFormat == Type.PDB ? FileFormat.PDB
+              : FileFormat.MMCif;
       pdbAlignment = new FormatAdapter().readFile(file,
-              jalview.io.AppletFormatAdapter.FILE,
-              StructureImportSettings.getDefaultStructureFileFormat());
+              DataSourceType.FILE, fileFormat);
       if (pdbAlignment != null)
       {
         List<SequenceI> toremove = new ArrayList<SequenceI>();
@@ -177,8 +182,8 @@ public class Pdb extends EbiFileRetrievedProxy
           {
             // FIXME seems to result in 'PDB|1QIP|1qip|A' - 1QIP is redundant.
             // TODO: suggest simplify naming to 1qip|A as default name defined
-            pdbcs.setName(jalview.datamodel.DBRefSource.PDB + SEPARATOR + id
-                    + SEPARATOR + pdbcs.getName());
+            pdbcs.setName(jalview.datamodel.DBRefSource.PDB + SEPARATOR
+                    + id + SEPARATOR + pdbcs.getName());
             // Might need to add more metadata to the PDBEntry object
             // like below
             /*
@@ -269,7 +274,6 @@ public class Pdb extends EbiFileRetrievedProxy
     return 0;
   }
 
-
   /**
    * Returns a descriptor for suitable feature display settings with
    * <ul>