JAL-1796 GeneLociI as distinguished DBRefEntry
[jalview.git] / src / jalview / datamodel / Sequence.java
index d09d845..cd743d1 100755 (executable)
@@ -106,8 +106,6 @@ public class Sequence extends ASequence implements SequenceI
    */
   private int changeCount;
 
-  private GeneLoci geneLoci;
-
   /**
    * Creates a new Sequence object.
    * 
@@ -656,45 +654,14 @@ public class Sequence extends ASequence implements SequenceI
   public void setDescription(String desc)
   {
     this.description = desc;
-    parseDescription();
-  }
-
-  /**
-   * Parses and saves fields of an Ensembl-style description e.g.
-   * chromosome:GRCh38:17:45051610:45109016:1
-   */
-  protected void parseDescription()
-  {
-    if (description == null)
-    {
-      return;
-    }
-    String[] tokens = description.split(":");
-    if (tokens.length == 6 && "chromosome".equals(tokens[0])) {
-      String ref = tokens[1];
-      String chrom = tokens[2];
-      try {
-        int chStart = Integer.parseInt(tokens[3]);
-        int chEnd = Integer.parseInt(tokens[4]);
-        boolean forwardStrand = "1".equals(tokens[5]);
-        String species = ""; // dunno yet!
-        int[] from = new int[] { start, end };
-        int[] to = new int[] { forwardStrand ? chStart : chEnd,
-            forwardStrand ? chEnd : chStart };
-        MapList map = new MapList(from, to, 1, 1);
-        GeneLoci gl = new GeneLoci(species, ref, chrom, map);
-        setGeneLoci(gl);
-      } catch (NumberFormatException e)
-      {
-        System.err.println("Bad integers in description " + description);
-      }
-    }
   }
 
   @Override
-  public void setGeneLoci(GeneLoci gl)
+  public void setGeneLoci(String speciesId, String assemblyId,
+          String chromosomeId, MapList map)
   {
-    geneLoci = gl;
+    addDBRef(new DBRefEntry(speciesId, assemblyId, DBRefEntry.CHROMOSOME
+            + ":" + chromosomeId, new Mapping(map)));
   }
 
   /**
@@ -703,9 +670,47 @@ public class Sequence extends ASequence implements SequenceI
    * @return
    */
   @Override
-  public GeneLoci getGeneLoci()
+  public GeneLociI getGeneLoci()
   {
-    return geneLoci;
+    DBRefEntry[] refs = getDBRefs();
+    if (refs != null)
+    {
+      for (final DBRefEntry ref : refs)
+      {
+        if (ref.isChromosome())
+        {
+          return new GeneLociI()
+          {
+            @Override
+            public String getSpeciesId()
+            {
+              return ref.getSource();
+            }
+
+            @Override
+            public String getAssemblyId()
+            {
+              return ref.getVersion();
+            }
+
+            @Override
+            public String getChromosomeId()
+            {
+              // strip of "chromosome:" prefix to chrId
+              return ref.getAccessionId().substring(
+                      DBRefEntry.CHROMOSOME.length() + 1);
+            }
+
+            @Override
+            public MapList getMap()
+            {
+              return ref.getMap().getMap();
+            }
+          };
+        }
+      }
+    }
+    return null;
   }
 
   /**