create dataset sequence method
[jalview.git] / src / jalview / datamodel / Sequence.java
index 16ba407..65857ce 100755 (executable)
@@ -24,7 +24,8 @@ import java.util.*;
 import jalview.analysis.*;
 
 /**
- * DOCUMENT ME!
+ * 
+ * Implements the SequenceI interface for a char[] based sequence object.
  *
  * @author $author$
  * @version $Revision$
@@ -46,17 +47,17 @@ public class Sequence
    * positions are tied to the residues of this sequence */
   Vector annotation;
 
-  /** DOCUMENT ME!! */
+  /** array of seuqence features - may not be null for a valid sequence object */
   public SequenceFeature[] sequenceFeatures;
 
 
   /**
    * Creates a new Sequence object.
    *
-   * @param name DOCUMENT ME!
-   * @param sequence DOCUMENT ME!
-   * @param start DOCUMENT ME!
-   * @param end DOCUMENT ME!
+   * @param name display name string
+   * @param sequence string to form a possibly gapped sequence out of
+   * @param start first position of non-gap residue in the sequence
+   * @param end last position of ungapped residues (nearly always only used for display purposes)
    */
   public Sequence(String name, String sequence, int start, int end)
   {
@@ -85,6 +86,11 @@ public class Sequence
 
   void parseId()
   {
+    if (name==null)
+    {
+      System.err.println("POSSIBLE IMPLEMENTATION ERROR: null sequence name passed to constructor.");
+      name = "";
+    }
     // Does sequence have the /start-end signiature?
     if (limitrx.search(name))
     {
@@ -759,8 +765,16 @@ public class Sequence
 
     for(i=0; i<iSize; i++)
     {
-      if(dbrefs[i].equals(entry))
+      if(dbrefs[i].equalRef(entry))
       {
+        if (entry.getMap()!=null)
+        {
+          if (dbrefs[i].getMap()==null)
+          {
+            // overwrite with 'superior' entry that contains a mapping.
+            dbrefs[i] = entry;
+          }
+        }
         return;
       }
     }
@@ -868,6 +882,29 @@ public class Sequence
     }
     return seq;
   }
+
+  /* (non-Javadoc)
+   * @see jalview.datamodel.SequenceI#createDatasetSequence()
+   */
+  public SequenceI createDatasetSequence()
+  {
+    if (datasetSequence==null)
+    {
+      datasetSequence = new Sequence(getName(),
+              AlignSeq.extractGaps(
+                jalview.util.Comparison.GapChars,
+                getSequenceAsString()),
+            getStart(),
+            getEnd());
+      datasetSequence.setSequenceFeatures(getSequenceFeatures());
+      datasetSequence.setDescription(getDescription());
+      setSequenceFeatures(null);
+      // move database references onto dataset sequence
+      datasetSequence.setDBRef(getDBRef());
+      setDBRef(null);
+    }
+    return datasetSequence;
+  }
   /* (non-Javadoc)
    * @see jalview.datamodel.SequenceI#setAlignmentAnnotation(AlignmmentAnnotation[] annotations)
    */