Merge branch 'patch/JAL-3874_newJmolAndGradleDedup' into develop
[jalview.git] / src / jalview / io / FeaturesFile.java
index 9a4dc0e..dda59a7 100755 (executable)
  */
 package jalview.io;
 
+import java.util.Locale;
+
+import java.awt.Color;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.TreeMap;
+
 import jalview.analysis.AlignmentUtils;
 import jalview.analysis.SequenceIdMatcher;
 import jalview.api.AlignViewportI;
@@ -44,18 +58,6 @@ import jalview.util.MapList;
 import jalview.util.ParseHtmlBodyAndLinks;
 import jalview.util.StringUtils;
 
-import java.awt.Color;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.TreeMap;
-
 /**
  * Parses and writes features files, which may be in Jalview, GFF2 or GFF3
  * format. These are tab-delimited formats but with differences in the use of
@@ -74,11 +76,7 @@ import java.util.TreeMap;
  */
 public class FeaturesFile extends AlignFile implements FeaturesSourceI
 {
-  /*
-   * map-valued attributes are prefixed with this for output to GFF3;
-   * the prefix is removed if found on reading
-   */
-  public static final String MAP_ATTRIBUTE_PREFIX = "jvmap_";
+  private static final String EQUALS = "=";
 
   private static final String TAB_REGEX = "\\t";
 
@@ -92,8 +90,6 @@ public class FeaturesFile extends AlignFile implements FeaturesSourceI
 
   private static final String ID_NOT_SPECIFIED = "ID_NOT_SPECIFIED";
 
-  private static final String NOTE = "Note";
-
   protected static final String GFF_VERSION = "##gff-version";
 
   private AlignmentI lastmatchedAl = null;
@@ -114,11 +110,11 @@ public class FeaturesFile extends AlignFile implements FeaturesSourceI
   /**
    * Constructor which does not parse the file immediately
    * 
-   * @param file
+   * @param file File or String filename
    * @param paste
    * @throws IOException
    */
-  public FeaturesFile(String file, DataSourceType paste)
+  public FeaturesFile(Object file, DataSourceType paste)
           throws IOException
   {
     super(false, file, paste);
@@ -141,7 +137,7 @@ public class FeaturesFile extends AlignFile implements FeaturesSourceI
    * @param type
    * @throws IOException
    */
-  public FeaturesFile(boolean parseImmediately, String file,
+  public FeaturesFile(boolean parseImmediately, Object file,
           DataSourceType type) throws IOException
   {
     super(parseImmediately, file, type);
@@ -240,7 +236,7 @@ public class FeaturesFile extends AlignFile implements FeaturesSourceI
         // skip comments/process pragmas
         if (line.length() == 0 || line.startsWith("#"))
         {
-          if (line.toLowerCase().startsWith("##"))
+          if (line.toLowerCase(Locale.ROOT).startsWith("##"))
           {
             processGffPragma(line, gffProps, align, newseqs);
           }
@@ -352,7 +348,7 @@ public class FeaturesFile extends AlignFile implements FeaturesSourceI
     String line;
     while ((line = nextLine()) != null)
     {
-      if (line.toUpperCase().startsWith(ENDFILTERS))
+      if (line.toUpperCase(Locale.ROOT).startsWith(ENDFILTERS))
       {
         return;
       }
@@ -742,7 +738,6 @@ public class FeaturesFile extends AlignFile implements FeaturesSourceI
 
       if (mf != null)
       {
-        MapList mapping = mf.mapping.getMap();
         for (SequenceFeature sf : mf.features)
         {
           /*
@@ -758,9 +753,7 @@ public class FeaturesFile extends AlignFile implements FeaturesSourceI
             found.add(sf);
             int begin = sf.getBegin();
             int end = sf.getEnd();
-            int[] range = mf.mapping.getTo() == seq.getDatasetSequence()
-                    ? mapping.locateInTo(begin, end)
-                    : mapping.locateInFrom(begin, end);
+            int[] range = mf.getMappedPositions(begin, end);
             SequenceFeature sf2 = new SequenceFeature(sf, range[0],
                     range[1], group, sf.getScore());
             complementary.add(sf2);
@@ -1192,7 +1185,7 @@ public class FeaturesFile extends AlignFile implements FeaturesSourceI
       {
         String formatted = StringUtils.urlEncode(value.toString(),
                 GffHelperI.GFF_ENCODABLE);
-        sb.append(key).append("=").append(formatted);
+        sb.append(key).append(EQUALS).append(formatted);
       }
     }
   }
@@ -1201,7 +1194,7 @@ public class FeaturesFile extends AlignFile implements FeaturesSourceI
    * Formats the map entries as
    * 
    * <pre>
-   * jvmap_key={key1=value1,key2=value2,...}
+   * key=key1=value1,key2=value2,...
    * </pre>
    * 
    * and appends this to the string buffer
@@ -1222,7 +1215,7 @@ public class FeaturesFile extends AlignFile implements FeaturesSourceI
      * AbstractMap.toString would be a shortcut here, but more reliable
      * to code the required format in case toString changes in future
      */
-    sb.append(MAP_ATTRIBUTE_PREFIX).append(key).append("={");
+    sb.append(key).append(EQUALS);
     boolean first = true;
     for (Entry<?, ?> entry : map.entrySet())
     {
@@ -1231,12 +1224,11 @@ public class FeaturesFile extends AlignFile implements FeaturesSourceI
         sb.append(",");
       }
       first = false;
-      sb.append(entry.getKey().toString()).append("=");
+      sb.append(entry.getKey().toString()).append(EQUALS);
       String formatted = StringUtils.urlEncode(entry.getValue().toString(),
               GffHelperI.GFF_ENCODABLE);
       sb.append(formatted);
     }
-    sb.append("}");
   }
 
   /**