JAL-2909 mininal merge of bam import demo to Jalview 2.11.2 develop
[jalview.git] / src / jalview / io / IdentifyFile.java
index b312474..0c201e1 100755 (executable)
@@ -20,6 +20,8 @@
  */
 package jalview.io;
 
+import java.util.Locale;
+
 import java.io.File;
 import java.io.IOException;
 
@@ -162,14 +164,21 @@ public class IdentifyFile
         {
           // jar files are special - since they contain all sorts of random
           // characters.
-          if (source.inFile != null)
+          if (source.inFile != null || source.getDataName() != null)
           {
-            String fileStr = source.inFile.getName();
+            String fileStr = source.inFile == null ? source.getDataName()
+                    : source.inFile.getName();
             if (fileStr.contains(".jar")
                     || fileStr.contains(".zip") || fileStr.contains(".jvp"))
             {
               // possibly a Jalview archive (but check further)
               reply = FileFormat.Jalview;
+              // TODO shouldn't there be a break here?
+            }
+            else if (fileStr.lastIndexOf(".bam") > -1)
+            {
+              reply = FileFormat.Bam;
+              break;
             }
           }
           if (!lineswereskipped && data.startsWith("PK"))
@@ -178,13 +187,26 @@ public class IdentifyFile
             break;
           }
         }
-        data = data.toUpperCase();
+        data = data.toUpperCase(Locale.ROOT);
 
         if (data.startsWith(ScoreMatrixFile.SCOREMATRIX))
         {
           reply = FileFormat.ScoreMatrix;
           break;
         }
+        if (data.startsWith("LOCUS"))
+        {
+          reply = FileFormat.GenBank;
+          break;
+        }
+        if (data.startsWith("ID "))
+        {
+          if (data.substring(2).trim().split(";").length == 7)
+          {
+            reply = FileFormat.Embl;
+            break;
+          }
+        }
         if (data.startsWith("H ") && !aaIndexHeaderRead)
         {
           aaIndexHeaderRead = true;
@@ -319,7 +341,7 @@ public class IdentifyFile
         if ((lessThan > -1)) // possible Markup Language data i.e HTML,
                              // RNAML, XML
         {
-          String upper = data.toUpperCase();
+          String upper = data.toUpperCase(Locale.ROOT);
           if (upper.substring(lessThan).startsWith("<HTML"))
           {
             reply = FileFormat.Html;