JAL-1793 apply URL decoding when saving VCF attribute values (%3D -> =)
[jalview.git] / src / jalview / io / vcf / VCFLoader.java
index 1ac9ad7..d461811 100644 (file)
@@ -22,6 +22,8 @@ import jalview.util.MessageManager;
 
 import java.io.File;
 import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.net.URLDecoder;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
@@ -50,6 +52,8 @@ import htsjdk.variant.vcf.VCFInfoHeaderLine;
  */
 public class VCFLoader
 {
+  private static final String UTF_8 = "UTF-8";
+
   private static final String DEFAULT_SPECIES = "homo_sapiens";
 
   /**
@@ -1189,14 +1193,6 @@ public class VCFLoader
       }
 
       /*
-       * filter out fields we don't want to capture
-       */
-      if (!vcfFieldsOfInterest.contains(key))
-      {
-        continue;
-      }
-
-      /*
        * we extract values for other data which are allele-specific; 
        * these may be per alternate allele (INFO[key].Number = 'A') 
        * or per allele including reference (INFO[key].Number = 'R') 
@@ -1235,6 +1231,16 @@ public class VCFLoader
       String value = getAttributeValue(variant, key, index);
       if (value != null)
       {
+        /*
+         * VCF spec requires encoding of special characters e.g. '='
+         * so decode them here before storing
+         */
+        try
+        {
+          value = URLDecoder.decode(value, UTF_8);
+        } catch (UnsupportedEncodingException e)
+        {
+        }
         sf.setValue(key, value);
       }
     }
@@ -1288,6 +1294,16 @@ public class VCFLoader
             String id = vepFieldsOfInterest.get(i);
             if (id != null)
             {
+              /*
+               * VCF spec requires encoding of special characters e.g. '='
+               * so decode them here before storing
+               */
+              try
+              {
+                field = URLDecoder.decode(field, UTF_8);
+              } catch (UnsupportedEncodingException e)
+              {
+              }
               csqValues.put(id, field);
             }
           }