JAL-1705 code tidy/comment only
[jalview.git] / src / jalview / ext / ensembl / EnsemblGene.java
index cec7a8d..0cecc59 100644 (file)
@@ -14,6 +14,8 @@ import jalview.util.MapList;
 import jalview.util.StringUtils;
 
 import java.awt.Color;
+import java.io.UnsupportedEncodingException;
+import java.net.URLDecoder;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
@@ -27,6 +29,9 @@ import com.stevesoft.pat.Regex;
  */
 public class EnsemblGene extends EnsemblSeqProxy
 {
+  private static final List<String> CROSS_REFERENCES = Arrays
+          .asList(new String[] { "CCDS" });
+
   private static final String GENE_PREFIX = "gene:";
 
   /*
@@ -292,10 +297,25 @@ public class EnsemblGene extends EnsemblSeqProxy
     }
 
     Sequence transcript = new Sequence(accId, seqChars, 1, transcriptLength);
-    String geneName = (String) transcriptFeature.getValue(NAME);
-    if (geneName != null)
+
+    /*
+     * Ensembl has gene name as transcript Name
+     * EnsemblGenomes doesn't, but has a url-encoded description field
+     */
+    String description = (String) transcriptFeature.getValue(NAME);
+    if (description == null)
     {
-      transcript.setDescription(geneName);
+      description = (String) transcriptFeature.getValue(DESCRIPTION);
+    }
+    if (description != null)
+    {
+      try
+      {
+        transcript.setDescription(URLDecoder.decode(description, "UTF-8"));
+      } catch (UnsupportedEncodingException e)
+      {
+        e.printStackTrace(); // as if
+      }
     }
     transcript.createDatasetSequence();
 
@@ -308,19 +328,19 @@ public class EnsemblGene extends EnsemblSeqProxy
     List<int[]> mapTo = new ArrayList<int[]>();
     mapTo.add(new int[] { 1, transcriptLength });
     MapList mapping = new MapList(mappedFrom, mapTo, 1, 1);
-    new EnsemblCdna(getDomain()).transferFeatures(
-            gene.getSequenceFeatures(), transcript.getDatasetSequence(),
-            mapping, parentId);
+    EnsemblCdna cdna = new EnsemblCdna(getDomain());
+    cdna.transferFeatures(gene.getSequenceFeatures(),
+            transcript.getDatasetSequence(), mapping, parentId);
 
     /*
      * fetch and save cross-references
      */
-    super.getCrossReferences(transcript);
+    cdna.getCrossReferences(transcript);
 
     /*
      * and finally fetch the protein product and save as a cross-reference
      */
-    new EnsemblCdna(getDomain()).addProteinProduct(transcript);
+    cdna.addProteinProduct(transcript);
 
     return transcript;
   }
@@ -451,7 +471,7 @@ public class EnsemblGene extends EnsemblSeqProxy
     // found these for ENSG00000157764 on 30/01/2016:
     // return new String[] {"Vega_gene", "OTTG", "ENS_LRG_gene", "ArrayExpress",
     // "EntrezGene", "HGNC", "MIM_GENE", "MIM_MORBID", "WikiGene"};
-    return super.getCrossReferenceDatabases();
+    return CROSS_REFERENCES;
   }
 
   /**