insert annotation at specific position
[jalview.git] / src / jalview / datamodel / Sequence.java
index 722edf2..7670452 100755 (executable)
@@ -1,17 +1,17 @@
 /*
- * Jalview - A Sequence Alignment Editor and Viewer
- * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
- *
+ * Jalview - A Sequence Alignment Editor and Viewer (Development Version 2.4.1)
+ * Copyright (C) 2009 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
+ * 
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
  * as published by the Free Software Foundation; either version 2
  * of the License, or (at your option) any later version.
- *
+ * 
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
- *
+ * 
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
@@ -185,15 +185,16 @@ public class Sequence implements SequenceI
         addSequenceFeature(new SequenceFeature(sf[i]));
       }
     }
-    if (seq.getDBRef() != null)
+    setDatasetSequence(seq.getDatasetSequence());
+    if (datasetSequence == null && seq.getDBRef() != null)
     {
+      // only copy DBRefs if we really are a dataset sequence
       DBRefEntry[] dbr = seq.getDBRef();
       for (int i = 0; i < dbr.length; i++)
       {
         addDBRef(new DBRefEntry(dbr[i]));
       }
     }
-    setDatasetSequence(seq.getDatasetSequence());
     if (seq.getAnnotation() != null)
     {
       AlignmentAnnotation[] sqann = seq.getAnnotation();
@@ -660,6 +661,30 @@ public class Sequence implements SequenceI
   /*
    * (non-Javadoc)
    * 
+   * @see jalview.datamodel.SequenceI#findPositionMap()
+   */
+  public int[] findPositionMap()
+  {
+    int map[] = new int[sequence.length];
+    int j = 0;
+    int pos = start;
+    int seqlen = sequence.length;
+    while ((j < seqlen))
+    {
+      map[j] = pos;
+      if (!jalview.util.Comparison.isGap(sequence[j]))
+      {
+        pos++;
+      }
+
+      j++;
+    }
+    return map;
+  }
+
+  /*
+   * (non-Javadoc)
+   * 
    * @see jalview.datamodel.SequenceI#deleteChars(int, int)
    */
   public void deleteChars(int i, int j)
@@ -715,7 +740,7 @@ public class Sequence implements SequenceI
             {
               createNewDs = true;
               newend--; // decrease end position by one for the deleted residue
-                        // and search further
+              // and search further
             }
           }
         }
@@ -797,6 +822,11 @@ public class Sequence implements SequenceI
 
   public DBRefEntry[] getDBRef()
   {
+    if (dbrefs == null && datasetSequence != null
+            && this != datasetSequence)
+    {
+      return datasetSequence.getDBRef();
+    }
     return dbrefs;
   }