JAL-1705 code tidy/comment only
[jalview.git] / src / jalview / ext / ensembl / EnsemblGene.java
index 6507ff5..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:";
 
   /*
@@ -40,10 +45,28 @@ public class EnsemblGene extends EnsemblSeqProxy
       EnsemblFeatureType.exon, EnsemblFeatureType.cds,
       EnsemblFeatureType.variation };
 
+  /**
+   * Default constructor (to use rest.ensembl.org)
+   */
+  public EnsemblGene()
+  {
+    super();
+  }
+
+  /**
+   * Constructor given the target domain to fetch data from
+   * 
+   * @param d
+   */
+  public EnsemblGene(String d)
+  {
+    super(d);
+  }
+
   @Override
   public String getDbName()
   {
-    return "ENSEMBL (GENE)";
+    return "ENSEMBL";
   }
 
   @Override
@@ -97,7 +120,7 @@ public class EnsemblGene extends EnsemblSeqProxy
     if (isTranscriptIdentifier(query))
     {
       // we are assuming all transcripts have the same gene parent here
-      query = new EnsemblLookup().getParent(queries[0]);
+      query = new EnsemblLookup(getDomain()).getParent(queries[0]);
       if (query == null)
       {
         return null;
@@ -110,7 +133,7 @@ public class EnsemblGene extends EnsemblSeqProxy
      */
     if (!isGeneIdentifier(query))
     {
-      List<String> geneIds = new EnsemblSymbol().getIds(query);
+      List<String> geneIds = new EnsemblSymbol(getDomain()).getIds(query);
       if (geneIds.isEmpty())
       {
         return null;
@@ -145,7 +168,7 @@ public class EnsemblGene extends EnsemblSeqProxy
    */
   protected String getGeneIdentifiersForName(String query)
   {
-    List<String> ids = new EnsemblSymbol().getIds(query);
+    List<String> ids = new EnsemblSymbol(getDomain()).getIds(query);
     if (ids != null)
     {
       for (String id : ids)
@@ -274,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();
 
@@ -290,18 +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().transferFeatures(gene.getSequenceFeatures(),
+    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().addProteinProduct(transcript);
+    cdna.addProteinProduct(transcript);
 
     return transcript;
   }
@@ -432,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;
   }
 
   /**