JAL-3397 impl.IntervalStore and nonc.IntervalStore unified api
[jalview.git] / src / jalview / ext / ensembl / EnsemblFeatures.java
index 6a0d67c..e4c4365 100644 (file)
@@ -28,7 +28,6 @@ import jalview.datamodel.SequenceI;
 import jalview.io.gff.SequenceOntologyI;
 import jalview.util.JSONUtils;
 
-import java.io.BufferedReader;
 import java.io.IOException;
 import java.net.MalformedURLException;
 import java.net.URL;
@@ -90,11 +89,10 @@ class EnsemblFeatures extends EnsemblRestClient
   public AlignmentI getSequenceRecords(String query) throws IOException
   {
     // TODO: use a vararg String... for getSequenceRecords instead?
+         
     List<String> queries = new ArrayList<>();
     queries.add(query);
     SequenceI seq = parseFeaturesJson(queries);
-    if (seq == null)
-       return null;
     return new Alignment(new SequenceI[] { seq });
   }
 
@@ -106,20 +104,18 @@ class EnsemblFeatures extends EnsemblRestClient
    * @return
    */
   @SuppressWarnings("unchecked")
-private SequenceI parseFeaturesJson(List<String> queries)
+  private SequenceI parseFeaturesJson(List<String> queries)
   {
-         
-         
     SequenceI seq = new Sequence("Dummy", "");
-
     try
     {
-       
       Iterator<Object> rvals = (Iterator<Object>) getJSON(null, queries, -1, MODE_ITERATOR, null);
       if (rvals == null)
+      {
          return null;
+      }
       while (rvals.hasNext())
-      {
+      {          
         try
         {
           Map<String, Object> obj = (Map<String, Object>) rvals.next();
@@ -147,7 +143,7 @@ private SequenceI parseFeaturesJson(List<String> queries)
           {
             type = SequenceOntologyI.CDS;
           }
-          
+
           String desc = getFirstNotNull(obj, "alleles", "external_name",
                   JSON_ID);
           SequenceFeature sf = new SequenceFeature(type, desc, start, end,
@@ -160,6 +156,7 @@ private SequenceI parseFeaturesJson(List<String> queries)
           sf.setValue("clinical_significance", clinSig);
 
           seq.addSequenceFeature(sf);
+          
         } catch (Throwable t)
         {
           // ignore - keep trying other features
@@ -174,31 +171,33 @@ private SequenceI parseFeaturesJson(List<String> queries)
     return seq;
   }
 
-  
-/**
-   * Returns the first non-null attribute found (if any) as a string
+  /**
+   * Returns the first non-null attribute found (if any) as a string, formatted
+   * suitably for display as feature description or tooltip. Answers null if
+   * none of the attribute keys is present.
    * 
    * @param obj
    * @param keys
    * @return
    */
+  @SuppressWarnings("unchecked")
   protected String getFirstNotNull(Map<String, Object> obj, String... keys)
   {
-    String desc = null;
-
     for (String key : keys)
     {
       Object val = obj.get(key);
       if (val != null)
       {
-        String s = val.toString();
+        String s = val instanceof List<?>
+                ? JSONUtils.arrayToStringList((List<Object>) val)
+                : val.toString();
         if (!s.isEmpty())
         {
           return s;
         }
       }
     }
-    return desc;
+    return null;
   }
 
   /**