Merge branch 'develop' into update_212_Dec_merge_with_21125_chamges
[jalview.git] / src / jalview / ws / dbsources / Pdb.java
index 982c399..d502f74 100644 (file)
@@ -36,6 +36,7 @@ import jalview.io.FormatAdapter;
 import jalview.io.PDBFeatureSettings;
 import jalview.structure.StructureImportSettings;
 import jalview.util.MessageManager;
+import jalview.util.Platform;
 import jalview.ws.ebi.EBIFetchClient;
 
 import java.io.File;
@@ -56,6 +57,8 @@ public class Pdb extends EbiFileRetrievedProxy
 
   private static final int PDB_ID_LENGTH = 4;
 
+  private static Regex ACCESSION_REGEX;
+
   public Pdb()
   {
     super();
@@ -80,7 +83,12 @@ public class Pdb extends EbiFileRetrievedProxy
   @Override
   public Regex getAccessionValidator()
   {
-    return new Regex("([1-9][0-9A-Za-z]{3}):?([ _A-Za-z0-9]?)");
+    if (ACCESSION_REGEX == null)
+    {
+      ACCESSION_REGEX = Platform
+              .newRegex("([1-9][0-9A-Za-z]{3}):?([ _A-Za-z0-9]?)");
+    }
+    return ACCESSION_REGEX;
   }
 
   /*
@@ -165,7 +173,7 @@ public class Pdb extends EbiFileRetrievedProxy
       // todo get rid of Type and use FileFormatI instead?
       FileFormatI fileFormat = (pdbFileFormat == Type.PDB) ? FileFormat.PDB
               : FileFormat.MMCif;
-      pdbAlignment = new FormatAdapter().readFile(file,
+      pdbAlignment = new FormatAdapter().readFile(tmpFile,
               DataSourceType.FILE, fileFormat);
       if (pdbAlignment != null)
       {
@@ -182,15 +190,14 @@ public class Pdb extends EbiFileRetrievedProxy
 
             }
           }
-          if (chain == null
-                  || (chid != null && (chid.equals(chain)
-                          || chid.trim().equals(chain.trim()) || (chain
-                          .trim().length() == 0 && chid.equals("_")))))
+          if (chain == null || (chid != null && (chid.equals(chain)
+                  || chid.trim().equals(chain.trim())
+                  || (chain.trim().length() == 0 && chid.equals("_")))))
           {
             // 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
             /*
@@ -236,8 +243,8 @@ public class Pdb extends EbiFileRetrievedProxy
       if (pdbAlignment == null || pdbAlignment.getHeight() < 1)
       {
         throw new Exception(MessageManager.formatMessage(
-                "exception.no_pdb_records_for_chain", new String[] { id,
-                    ((chain == null) ? "' '" : chain) }));
+                "exception.no_pdb_records_for_chain", new String[]
+                { id, ((chain == null) ? "' '" : chain) }));
       }
 
     } catch (Exception ex) // Problem parsing PDB file