JAL-2783 accept Ensembl query of the form "human:braf"
[jalview.git] / src / jalview / ext / ensembl / EnsemblGene.java
index 50dfa90..7e04b95 100644 (file)
@@ -170,26 +170,32 @@ public class EnsemblGene extends EnsemblSeqProxy
    */
   List<String> getGeneIds(String accessions)
   {
-    List<String> geneIds = new ArrayList<String>();
+    List<String> geneIds = new ArrayList<>();
 
     for (String acc : accessions.split(getAccessionSeparator()))
     {
+      String geneId = null;
+
       /*
        * First try lookup as an Ensembl (gene or transcript) identifier
+       * unless query is of the form species:symbol e.g. human:braf
        */
-      String geneId = new EnsemblLookup(getDomain()).getGeneId(acc);
-      if (geneId != null)
+      if (acc.indexOf(":") == -1)
       {
-        if (!geneIds.contains(geneId))
+        geneId = new EnsemblLookup(getDomain()).getGeneId(acc);
+        if (geneId != null)
         {
-          geneIds.add(geneId);
+          if (!geneIds.contains(geneId))
+          {
+            geneIds.add(geneId);
+          }
         }
       }
-      else
+      if (geneId == null)
       {
         /*
-         * if given a gene or other external name, lookup and fetch 
-         * the corresponding gene for all model organisms 
+         * if given a gene or other external name, lookup and fetch the gene
+         * for the species (if specified in the query), else for all model organisms 
          */
         List<String> ids = new EnsemblSymbol(getDomain(), getDbSource(),
                 getDbVersion()).getGeneIds(acc);
@@ -305,7 +311,7 @@ public class EnsemblGene extends EnsemblSeqProxy
     int transcriptLength = 0;
     final char[] geneChars = gene.getSequence();
     int offset = gene.getStart(); // to convert to 0-based positions
-    List<int[]> mappedFrom = new ArrayList<int[]>();
+    List<int[]> mappedFrom = new ArrayList<>();
 
     for (SequenceFeature sf : splices)
     {
@@ -347,7 +353,7 @@ public class EnsemblGene extends EnsemblSeqProxy
      * transfer features to the new sequence; we use EnsemblCdna to do this,
      * to filter out unwanted features types (see method retainFeature)
      */
-    List<int[]> mapTo = new ArrayList<int[]>();
+    List<int[]> mapTo = new ArrayList<>();
     mapTo.add(new int[] { 1, transcriptLength });
     MapList mapping = new MapList(mappedFrom, mapTo, 1, 1);
     EnsemblCdna cdna = new EnsemblCdna(getDomain());
@@ -395,7 +401,7 @@ public class EnsemblGene extends EnsemblSeqProxy
   protected List<SequenceFeature> getTranscriptFeatures(String accId,
           SequenceI geneSequence)
   {
-    List<SequenceFeature> transcriptFeatures = new ArrayList<SequenceFeature>();
+    List<SequenceFeature> transcriptFeatures = new ArrayList<>();
 
     String parentIdentifier = GENE_PREFIX + accId;