changeCase, removeGaps moved to commands package
authoramwaterhouse <Andrew Waterhouse>
Tue, 24 Oct 2006 11:21:25 +0000 (11:21 +0000)
committeramwaterhouse <Andrew Waterhouse>
Tue, 24 Oct 2006 11:21:25 +0000 (11:21 +0000)
src/jalview/datamodel/Sequence.java
src/jalview/datamodel/SequenceGroup.java
src/jalview/datamodel/SequenceI.java

index fc52190..be2e1c0 100755 (executable)
@@ -31,747 +31,639 @@ import java.util.*;
  */
 public class Sequence implements SequenceI
 {
-    SequenceI datasetSequence;
-    String name;
-    private String sequence;
-    String description;
-    int start;
-    int end;
-    Color color = Color.white;
-    Vector pdbIds;
-    String vamsasId;
-    DBRefEntry [] dbrefs;
-
-    /** This annotation is displayed below the alignment but the
-     * positions are tied to the residues of this sequence */
-    Vector annotation;
-
-    /** DOCUMENT ME!! */
-    public SequenceFeature [] sequenceFeatures;
-
-    /** This array holds hidden sequences
-     * of which this sequence is the representitive member of a group
-     */
-    SequenceGroup hiddenSequences;
-
-    /**
-     * Creates a new Sequence object.
-     *
-     * @param name DOCUMENT ME!
-     * @param sequence DOCUMENT ME!
-     * @param start DOCUMENT ME!
-     * @param end DOCUMENT ME!
-     */
-    public Sequence(String name, String sequence, int start, int end)
-    {
-      this.name = name;
-      this.sequence = sequence;
-      this.start = start;
-      this.end = end;
+  SequenceI datasetSequence;
+  String name;
+  private String sequence;
+  String description;
+  int start;
+  int end;
+  Color color = Color.white;
+  Vector pdbIds;
+  String vamsasId;
+  DBRefEntry[] dbrefs;
+
+  /** This annotation is displayed below the alignment but the
+   * positions are tied to the residues of this sequence */
+  Vector annotation;
+
+  /** DOCUMENT ME!! */
+  public SequenceFeature[] sequenceFeatures;
+
+  /** This array holds hidden sequences
+   * of which this sequence is the representitive member of a group
+   */
+  SequenceGroup hiddenSequences;
+
+  /**
+   * Creates a new Sequence object.
+   *
+   * @param name DOCUMENT ME!
+   * @param sequence DOCUMENT ME!
+   * @param start DOCUMENT ME!
+   * @param end DOCUMENT ME!
+   */
+  public Sequence(String name, String sequence, int start, int end)
+  {
+    this.name = name;
+    this.sequence = sequence;
+    this.start = start;
+    this.end = end;
 
-      parseId();
+    parseId();
 
-      checkValidRange();
-    }
+    checkValidRange();
+  }
 
-    com.stevesoft.pat.Regex limitrx = new com.stevesoft.pat.Regex(
-                        "[/][0-9]{1,}[-][0-9]{1,}$");
-    com.stevesoft.pat.Regex endrx = new com.stevesoft.pat.Regex(
-                        "[0-9]{1,}$");
+  com.stevesoft.pat.Regex limitrx = new com.stevesoft.pat.Regex(
+      "[/][0-9]{1,}[-][0-9]{1,}$");
+  com.stevesoft.pat.Regex endrx = new com.stevesoft.pat.Regex(
+      "[0-9]{1,}$");
 
-    void parseId()
+  void parseId()
+  {
+    // Does sequence have the /start-end signiature?
+    if (limitrx.search(name))
     {
-        // Does sequence have the /start-end signiature?
-         if(limitrx.search(name))
-         {
-            name = limitrx.left();
-            endrx.search(limitrx.stringMatched());
-            setStart( Integer.parseInt( limitrx.stringMatched().substring(1,endrx.matchedFrom()-1 )));
-            setEnd(   Integer.parseInt( endrx.stringMatched() ));
-         }
+      name = limitrx.left();
+      endrx.search(limitrx.stringMatched());
+      setStart(Integer.parseInt(limitrx.stringMatched().substring(1,
+          endrx.matchedFrom() - 1)));
+      setEnd(Integer.parseInt(endrx.stringMatched()));
     }
+  }
 
-    void checkValidRange()
+  void checkValidRange()
+  {
+    if (end < 1)
     {
-      if (end < 1)
+      int endRes = 0;
+      char ch;
+      for (int j = 0; j < sequence.length(); j++)
       {
-        int endRes = 0;
-        char ch;
-        for (int j = 0; j < sequence.length(); j++)
+        ch = sequence.charAt(j);
+        if (!jalview.util.Comparison.isGap( (ch)))
         {
-          ch = sequence.charAt(j);
-          if (!jalview.util.Comparison.isGap( (ch)))
-          {
-            endRes++;
-          }
+          endRes++;
         }
-        if (endRes > 0)
-        {
-          endRes += start - 1;
-        }
-
-        this.end = endRes;
-      }
-
-    }
-
-    /**
-     * Creates a new Sequence object.
-     *
-     * @param name DOCUMENT ME!
-     * @param sequence DOCUMENT ME!
-     */
-    public Sequence(String name, String sequence)
-    {
-        this(name, sequence, 1, -1);
-    }
-
-    /**
-     * Creates a new Sequence object.
-     *
-     * @param seq DOCUMENT ME!
-     */
-    public Sequence(SequenceI seq)
-    {
-        this(seq.getName(), seq.getSequence(), seq.getStart(), seq.getEnd());
-    }
-
-    /**
-     * DOCUMENT ME!
-     *
-     * @param v DOCUMENT ME!
-     */
-    public void setSequenceFeatures(SequenceFeature [] features)
-    {
-        sequenceFeatures = features;
-    }
-
-    public synchronized void addSequenceFeature(SequenceFeature sf)
-    {
-      if(sequenceFeatures==null)
-      {
-        sequenceFeatures = new SequenceFeature[0];
       }
-
-      for(int i=0; i<sequenceFeatures.length; i++)
+      if (endRes > 0)
       {
-        if(sequenceFeatures[i].equals(sf))
-        {
-          return;
-        }
+        endRes += start - 1;
       }
 
-      SequenceFeature [] temp = new SequenceFeature[sequenceFeatures.length+1];
-      System.arraycopy(sequenceFeatures, 0, temp, 0, sequenceFeatures.length);
-      temp[sequenceFeatures.length] = sf;
-
-      sequenceFeatures = temp;
+      this.end = endRes;
     }
 
+  }
 
-    /**
-     * DOCUMENT ME!
-     *
-     * @return DOCUMENT ME!
-     */
-    public SequenceFeature [] getSequenceFeatures()
-    {
-        return sequenceFeatures;
-    }
-
-    public void addPDBId(PDBEntry entry)
-    {
-      if(pdbIds == null)
-        pdbIds = new Vector();
+  /**
+   * Creates a new Sequence object.
+   *
+   * @param name DOCUMENT ME!
+   * @param sequence DOCUMENT ME!
+   */
+  public Sequence(String name, String sequence)
+  {
+    this(name, sequence, 1, -1);
+  }
 
-      pdbIds.addElement(entry);
-    }
+  /**
+   * Creates a new Sequence object.
+   *
+   * @param seq DOCUMENT ME!
+   */
+  public Sequence(SequenceI seq)
+  {
+    this(seq.getName(), seq.getSequence(), seq.getStart(), seq.getEnd());
+  }
 
-    /**
-     * DOCUMENT ME!
-     *
-     * @param id DOCUMENT ME!
-     */
-    public void setPDBId(Vector id)
-    {
-        pdbIds = id;
-    }
+  /**
+   * DOCUMENT ME!
+   *
+   * @param v DOCUMENT ME!
+   */
+  public void setSequenceFeatures(SequenceFeature[] features)
+  {
+    sequenceFeatures = features;
+  }
 
-    /**
-     * DOCUMENT ME!
-     *
-     * @return DOCUMENT ME!
-     */
-    public Vector getPDBId()
+  public synchronized void addSequenceFeature(SequenceFeature sf)
+  {
+    if (sequenceFeatures == null)
     {
-        return pdbIds;
+      sequenceFeatures = new SequenceFeature[0];
     }
 
-    /**
-     * DOCUMENT ME!
-     *
-     * @return DOCUMENT ME!
-     */
-    public String getDisplayId(boolean jvsuffix)
+    for (int i = 0; i < sequenceFeatures.length; i++)
     {
-      StringBuffer result = new StringBuffer(name);
-      if (jvsuffix)
+      if (sequenceFeatures[i].equals(sf))
       {
-        result.append("/" + start + "-" + end);
+        return;
       }
-
-      return result.toString();
     }
 
-    /**
-     * DOCUMENT ME!
-     *
-     * @param name DOCUMENT ME!
-     */
-    public void setName(String name)
-    {
-      this.name = name;
-      this.parseId();
-    }
+    SequenceFeature[] temp = new SequenceFeature[sequenceFeatures.length + 1];
+    System.arraycopy(sequenceFeatures, 0, temp, 0, sequenceFeatures.length);
+    temp[sequenceFeatures.length] = sf;
 
-    /**
-     * DOCUMENT ME!
-     *
-     * @return DOCUMENT ME!
-     */
-    public String getName()
-    {
-       return this.name;
-    }
+    sequenceFeatures = temp;
+  }
 
-    /**
-     * DOCUMENT ME!
-     *
-     * @param start DOCUMENT ME!
-     */
-    public void setStart(int start)
-    {
-        this.start = start;
-    }
+  /**
+   * DOCUMENT ME!
+   *
+   * @return DOCUMENT ME!
+   */
+  public SequenceFeature[] getSequenceFeatures()
+  {
+    return sequenceFeatures;
+  }
 
-    /**
-     * DOCUMENT ME!
-     *
-     * @return DOCUMENT ME!
-     */
-    public int getStart()
-    {
-        return this.start;
-    }
+  public void addPDBId(PDBEntry entry)
+  {
+    if (pdbIds == null)
+      pdbIds = new Vector();
 
-    /**
-     * DOCUMENT ME!
-     *
-     * @param end DOCUMENT ME!
-     */
-    public void setEnd(int end)
-    {
-        this.end = end;
-    }
+    pdbIds.addElement(entry);
+  }
 
-    /**
-     * DOCUMENT ME!
-     *
-     * @return DOCUMENT ME!
-     */
-    public int getEnd()
-    {
-        return this.end;
-    }
+  /**
+   * DOCUMENT ME!
+   *
+   * @param id DOCUMENT ME!
+   */
+  public void setPDBId(Vector id)
+  {
+    pdbIds = id;
+  }
 
-    /**
-     * DOCUMENT ME!
-     *
-     * @return DOCUMENT ME!
-     */
-    public int getLength()
-    {
-        return this.sequence.length();
-    }
+  /**
+   * DOCUMENT ME!
+   *
+   * @return DOCUMENT ME!
+   */
+  public Vector getPDBId()
+  {
+    return pdbIds;
+  }
 
-    /**
-     * DOCUMENT ME!
-     *
-     * @param seq DOCUMENT ME!
-     */
-    public void setSequence(String seq)
+  /**
+   * DOCUMENT ME!
+   *
+   * @return DOCUMENT ME!
+   */
+  public String getDisplayId(boolean jvsuffix)
+  {
+    StringBuffer result = new StringBuffer(name);
+    if (jvsuffix)
     {
-        this.sequence = seq;
-        checkValidRange();
+      result.append("/" + start + "-" + end);
     }
 
-    /**
-     * DOCUMENT ME!
-     *
-     * @return DOCUMENT ME!
-     */
-    public String getSequence()
-    {
-        return this.sequence;
-    }
+    return result.toString();
+  }
 
-    /**
-     * DOCUMENT ME!
-     *
-     * @param start DOCUMENT ME!
-     * @param end DOCUMENT ME!
-     *
-     * @return DOCUMENT ME!
-     */
-    public String getSequence(int start, int end)
-    {
-        // JBPNote - left to user to pad the result here (TODO:Decide on this policy)
-        if (start >= sequence.length())
-        {
-            return "";
-        }
+  /**
+   * DOCUMENT ME!
+   *
+   * @param name DOCUMENT ME!
+   */
+  public void setName(String name)
+  {
+    this.name = name;
+    this.parseId();
+  }
 
-        if (end >= sequence.length())
-        {
-            end = sequence.length();
-        }
+  /**
+   * DOCUMENT ME!
+   *
+   * @return DOCUMENT ME!
+   */
+  public String getName()
+  {
+    return this.name;
+  }
 
-        return this.sequence.substring(start, end);
-    }
-    /**
-     * make a new Sequence object from start to end (including gaps) over this seqeunce
-     * @param start int
-     * @param end int
-     * @return SequenceI
-     */
-    public SequenceI getSubSequence(int start, int end) {
-      if (start<0)
-        start = 0;
-      String seq = getSequence(start, end);
-      if (seq=="")
-        return null;
-      int nstart = findPosition(start);
-      int nend=findPosition(end)-1;
-      // JBPNote - this is an incomplete copy.
-      SequenceI nseq = new Sequence(this.getName(), seq, nstart, nend);
-      nseq.setDatasetSequence(getDatasetSequence());
-      return nseq;
-    }
-    /**
-     * DOCUMENT ME!
-     *
-     * @param i DOCUMENT ME!
-     *
-     * @return DOCUMENT ME!
-     */
-    public char getCharAt(int i)
-    {
-        if (i < sequence.length())
-        {
-            return sequence.charAt(i);
-        }
-        else
-        {
-            return ' ';
-        }
-    }
+  /**
+   * DOCUMENT ME!
+   *
+   * @param start DOCUMENT ME!
+   */
+  public void setStart(int start)
+  {
+    this.start = start;
+  }
 
-    /**
-     * DOCUMENT ME!
-     *
-     * @param desc DOCUMENT ME!
-     */
-    public void setDescription(String desc)
-    {
-        this.description = desc;
-    }
+  /**
+   * DOCUMENT ME!
+   *
+   * @return DOCUMENT ME!
+   */
+  public int getStart()
+  {
+    return this.start;
+  }
 
-    /**
-     * DOCUMENT ME!
-     *
-     * @return DOCUMENT ME!
-     */
-    public String getDescription()
-    {
-        return this.description;
-    }
+  /**
+   * DOCUMENT ME!
+   *
+   * @param end DOCUMENT ME!
+   */
+  public void setEnd(int end)
+  {
+    this.end = end;
+  }
 
-    /**
-     * DOCUMENT ME!
-     *
-     * @param pos DOCUMENT ME!
-     *
-     * @return DOCUMENT ME!
-     */
-    public int findIndex(int pos)
-    {
-        // returns the alignment position for a residue
-        int j = start;
-        int i = 0;
+  /**
+   * DOCUMENT ME!
+   *
+   * @return DOCUMENT ME!
+   */
+  public int getEnd()
+  {
+    return this.end;
+  }
 
-        while ((i < sequence.length()) && (j <= end) && (j <= pos))
-        {
-            if (!jalview.util.Comparison.isGap(sequence.charAt(i)))
-            {
-                j++;
-            }
+  /**
+   * DOCUMENT ME!
+   *
+   * @return DOCUMENT ME!
+   */
+  public int getLength()
+  {
+    return this.sequence.length();
+  }
 
-            i++;
-        }
+  /**
+   * DOCUMENT ME!
+   *
+   * @param seq DOCUMENT ME!
+   */
+  public void setSequence(String seq)
+  {
+    this.sequence = seq;
+    checkValidRange();
+  }
 
-        if ((j == end) && (j < pos))
-        {
-            return end + 1;
-        }
-        else
-        {
-            return i;
-        }
-    }
+  /**
+   * DOCUMENT ME!
+   *
+   * @return DOCUMENT ME!
+   */
+  public String getSequence()
+  {
+    return this.sequence;
+  }
 
-    /**
-     * Returns the sequence position for an alignment position
-     *
-     * @param i column index in alignment (from 1)
-     *
-     * @return residue number for residue (left of and) nearest ith column
-     */
-    public int findPosition(int i)
+  /**
+   * DOCUMENT ME!
+   *
+   * @param start DOCUMENT ME!
+   * @param end DOCUMENT ME!
+   *
+   * @return DOCUMENT ME!
+   */
+  public String getSequence(int start, int end)
+  {
+    // JBPNote - left to user to pad the result here (TODO:Decide on this policy)
+    if (start >= sequence.length())
     {
-        int j = 0;
-        int pos = start;
-        int seqlen=sequence.length();
-        while ((j < i) && (j < seqlen))
-        {
-            if (!jalview.util.Comparison.isGap((sequence.charAt(j))))
-            {
-                pos++;
-            }
-
-            j++;
-        }
-
-        return pos;
+      return "";
     }
 
-    /**
-     * Returns an int array where indices correspond to each residue in the sequence and the element value gives its position in the alignment
-     *
-     * @return int[SequenceI.getEnd()-SequenceI.getStart()+1] or null if no residues in SequenceI object
-     */
-    public int[] gapMap()
+    if (end >= sequence.length())
     {
-        String seq = jalview.analysis.AlignSeq.extractGaps(jalview.util.Comparison.GapChars, sequence);
-        int[] map = new int[seq.length()];
-        int j = 0;
-        int p = 0;
-
-        while (j < sequence.length())
-        {
-            if (!jalview.util.Comparison.isGap(sequence.charAt(j)))
-            {
-                map[p++] = j;
-            }
-
-            j++;
-        }
-
-        return map;
+      end = sequence.length();
     }
 
-    /**
-     * DOCUMENT ME!
-     *
-     * @param i DOCUMENT ME!
-     */
-    public void deleteCharAt(int i)
-    {
-        if (i >= sequence.length())
-        {
-            return;
-        }
+    return this.sequence.substring(start, end);
+  }
 
-        sequence = sequence.substring(0, i) + sequence.substring(i + 1);
-    }
+  /**
+   * make a new Sequence object from start to end (including gaps) over this seqeunce
+   * @param start int
+   * @param end int
+   * @return SequenceI
+   */
+  public SequenceI getSubSequence(int start, int end)
+  {
+    if (start < 0)
+      start = 0;
+    String seq = getSequence(start, end);
+    if (seq == "")
+      return null;
+    int nstart = findPosition(start);
+    int nend = findPosition(end) - 1;
+    // JBPNote - this is an incomplete copy.
+    SequenceI nseq = new Sequence(this.getName(), seq, nstart, nend);
+    nseq.setDatasetSequence(getDatasetSequence());
+    return nseq;
+  }
 
-    /**
-     * DOCUMENT ME!
-     *
-     * @param i DOCUMENT ME!
-     * @param j DOCUMENT ME!
-     */
-    public void deleteChars(int i, int j)
+  /**
+   * DOCUMENT ME!
+   *
+   * @param i DOCUMENT ME!
+   *
+   * @return DOCUMENT ME!
+   */
+  public char getCharAt(int i)
+  {
+    if (i < sequence.length())
     {
-        if (i >= sequence.length())
-        {
-            return;
-        }
-
-        if (j >= sequence.length())
-        {
-            sequence = sequence.substring(0, i);
-        }
-        else
-        {
-            sequence = sequence.substring(0, i) + sequence.substring(j);
-        }
+      return sequence.charAt(i);
     }
-
-
-    /**
-     * DOCUMENT ME!
-     *
-     * @param i DOCUMENT ME!
-     * @param c DOCUMENT ME!
-     * @param chop DOCUMENT ME!
-     */
-    public void insertCharAt(int i, char c)
+    else
     {
-        String tmp = new String(sequence);
+      return ' ';
+    }
+  }
 
-        if (i < sequence.length())
-        {
-            sequence = tmp.substring(0, i) + String.valueOf(c) +
-                tmp.substring(i);
-        }
-        else
-        {
-            // JBPNote : padding char at end of sequence. We'll not get away with this when we insert residues, I bet!
-            char[] ch = new char[(1 + i) - sequence.length()];
+  /**
+   * DOCUMENT ME!
+   *
+   * @param desc DOCUMENT ME!
+   */
+  public void setDescription(String desc)
+  {
+    this.description = desc;
+  }
 
-            for (int j = 0, k = ch.length; j < k; j++)
-                ch[j] = c;
+  /**
+   * DOCUMENT ME!
+   *
+   * @return DOCUMENT ME!
+   */
+  public String getDescription()
+  {
+    return this.description;
+  }
 
-            sequence = tmp + String.valueOf(ch);
-        }
-    }
+  /**
+   * DOCUMENT ME!
+   *
+   * @param pos DOCUMENT ME!
+   *
+   * @return DOCUMENT ME!
+   */
+  public int findIndex(int pos)
+  {
+    // returns the alignment position for a residue
+    int j = start;
+    int i = 0;
 
-    /**
-     * DOCUMENT ME!
-     *
-     * @param c DOCUMENT ME!
-     */
-    public void setColor(Color c)
+    while ( (i < sequence.length()) && (j <= end) && (j <= pos))
     {
-        this.color = c;
-    }
+      if (!jalview.util.Comparison.isGap(sequence.charAt(i)))
+      {
+        j++;
+      }
 
-    /**
-     * DOCUMENT ME!
-     *
-     * @return DOCUMENT ME!
-     */
-    public Color getColor()
-    {
-        return color;
+      i++;
     }
 
-    public String getVamsasId()
+    if ( (j == end) && (j < pos))
     {
-      return vamsasId;
+      return end + 1;
     }
-
-    public void setVamsasId(String id)
+    else
     {
-      vamsasId = id;
+      return i;
     }
+  }
 
-    public void setDBRef(DBRefEntry [] dbref)
+  /**
+   * Returns the sequence position for an alignment position
+   *
+   * @param i column index in alignment (from 1)
+   *
+   * @return residue number for residue (left of and) nearest ith column
+   */
+  public int findPosition(int i)
+  {
+    int j = 0;
+    int pos = start;
+    int seqlen = sequence.length();
+    while ( (j < i) && (j < seqlen))
     {
-      dbrefs = dbref;
-    }
+      if (!jalview.util.Comparison.isGap( (sequence.charAt(j))))
+      {
+        pos++;
+      }
 
-    public DBRefEntry [] getDBRef()
-    {
-      return dbrefs;
+      j++;
     }
 
-    public void addDBRef(DBRefEntry entry)
-    {
-      if(dbrefs == null)
-        dbrefs = new DBRefEntry[0];
+    return pos;
+  }
 
-      DBRefEntry [] temp = new DBRefEntry[dbrefs.length+1];
-      System.arraycopy(dbrefs, 0, temp, 0, dbrefs.length);
+  /**
+   * Returns an int array where indices correspond to each residue in the sequence and the element value gives its position in the alignment
+   *
+   * @return int[SequenceI.getEnd()-SequenceI.getStart()+1] or null if no residues in SequenceI object
+   */
+  public int[] gapMap()
+  {
+    String seq = jalview.analysis.AlignSeq.extractGaps(jalview.util.Comparison.
+        GapChars, sequence);
+    int[] map = new int[seq.length()];
+    int j = 0;
+    int p = 0;
 
-      temp[temp.length-1] = entry;
+    while (j < sequence.length())
+    {
+      if (!jalview.util.Comparison.isGap(sequence.charAt(j)))
+      {
+        map[p++] = j;
+      }
 
-      dbrefs = temp;
+      j++;
     }
 
-    public void setDatasetSequence(SequenceI seq)
+    return map;
+  }
+
+  /**
+   * DOCUMENT ME!
+   *
+   * @param i DOCUMENT ME!
+   */
+  public void deleteCharAt(int i)
+  {
+    if (i >= sequence.length())
     {
-      datasetSequence = seq;
+      return;
     }
 
-    public SequenceI getDatasetSequence()
+    sequence = sequence.substring(0, i) + sequence.substring(i + 1);
+  }
+
+  /**
+   * DOCUMENT ME!
+   *
+   * @param i DOCUMENT ME!
+   * @param j DOCUMENT ME!
+   */
+  public void deleteChars(int i, int j)
+  {
+    if (i >= sequence.length())
     {
-      return datasetSequence;
+      return;
     }
 
-    public AlignmentAnnotation [] getAnnotation()
+    if (j >= sequence.length())
     {
-      if(annotation==null)
-        return null;
-
-      AlignmentAnnotation [] ret = new AlignmentAnnotation[annotation.size()];
-      for(int r = 0; r<ret.length; r++)
-        ret[r] = (AlignmentAnnotation)annotation.elementAt(r);
-
-      return ret;
+      sequence = sequence.substring(0, i);
     }
-
-    public void addAlignmentAnnotation(AlignmentAnnotation annotation)
+    else
     {
-      if(this.annotation==null)
-        this.annotation = new Vector();
-
-      this.annotation.addElement( annotation );
+      sequence = sequence.substring(0, i) + sequence.substring(j);
     }
+  }
+
+  /**
+   * DOCUMENT ME!
+   *
+   * @param i DOCUMENT ME!
+   * @param c DOCUMENT ME!
+   * @param chop DOCUMENT ME!
+   */
+  public void insertCharAt(int i, int length, char c)
+  {
+    StringBuffer tmp;
 
-    public SequenceGroup getHiddenSequences()
+    if (i >= sequence.length())
     {
-      return hiddenSequences;
+      length = i - sequence.length() + 1;
+      tmp = new StringBuffer(sequence);
     }
+    else
+      tmp = new StringBuffer(sequence.substring(0, i));
 
-    public void addHiddenSequence(SequenceI seq)
+    while (length > 0)
     {
-      if(hiddenSequences==null)
-      {
-        hiddenSequences = new SequenceGroup();
-      }
-      hiddenSequences.addSequence(seq, false);
+      tmp.append(c);
+      length--;
     }
 
-    public void showHiddenSequence(SequenceI seq)
+    if (i < sequence.length())
     {
-      hiddenSequences.deleteSequence(seq, false);
-      if (hiddenSequences.getSize(false) < 1)
-      {
-        hiddenSequences = null;
-      }
+      tmp.append(sequence.substring(i));
     }
 
-    public void changeCase(boolean toUpper, int start, int end)
-    {
-      StringBuffer newSeq = new StringBuffer();
+    sequence = tmp.toString();
+  }
 
-      if(end>sequence.length())
-        end = sequence.length();
+  public void insertCharAt(int i, char c)
+  {
+    insertCharAt(i, 1, c);
+  }
 
-      if (start > 0)
-      {
-        newSeq.append(sequence.substring(0, start));
-      }
+  /**
+   * DOCUMENT ME!
+   *
+   * @param c DOCUMENT ME!
+   */
+  public void setColor(Color c)
+  {
+    this.color = c;
+  }
 
-      if (toUpper)
-        newSeq.append(sequence.substring(start, end).toUpperCase());
-      else
-        newSeq.append(sequence.substring(start, end).toLowerCase());
+  /**
+   * DOCUMENT ME!
+   *
+   * @return DOCUMENT ME!
+   */
+  public Color getColor()
+  {
+    return color;
+  }
 
-      if (end < sequence.length())
-        newSeq.append(sequence.substring(end));
+  public String getVamsasId()
+  {
+    return vamsasId;
+  }
 
-      sequence = newSeq.toString();
-    }
+  public void setVamsasId(String id)
+  {
+    vamsasId = id;
+  }
 
-    public void toggleCase(int start, int end)
-    {
-      StringBuffer newSeq = new StringBuffer();
+  public void setDBRef(DBRefEntry[] dbref)
+  {
+    dbrefs = dbref;
+  }
 
-     if(end>sequence.length())
-       end = sequence.length();
+  public DBRefEntry[] getDBRef()
+  {
+    return dbrefs;
+  }
 
-     if (start > 0)
-     {
-       newSeq.append(sequence.substring(0, start));
-     }
+  public void addDBRef(DBRefEntry entry)
+  {
+    if (dbrefs == null)
+      dbrefs = new DBRefEntry[0];
 
-     char nextChar;
-     for(int c=start; c<end; c++)
-     {
-       nextChar = sequence.charAt(c);
-       if(Character.isLetter(nextChar))
-       {
-         if(Character.isUpperCase(nextChar))
-           nextChar = Character.toLowerCase(nextChar);
-         else
-           nextChar = Character.toUpperCase(nextChar);
-       }
+    DBRefEntry[] temp = new DBRefEntry[dbrefs.length + 1];
+    System.arraycopy(dbrefs, 0, temp, 0, dbrefs.length);
 
+    temp[temp.length - 1] = entry;
 
-       newSeq.append(nextChar);
-     }
+    dbrefs = temp;
+  }
 
-     if (end < sequence.length())
-       newSeq.append(sequence.substring(end));
+  public void setDatasetSequence(SequenceI seq)
+  {
+    datasetSequence = seq;
+  }
 
-     sequence = newSeq.toString();
-    }
+  public SequenceI getDatasetSequence()
+  {
+    return datasetSequence;
+  }
 
-  public SequenceI getSubSequence(int start)
+  public AlignmentAnnotation[] getAnnotation()
   {
-    int e=getLength();
-    if (start>=e)
+    if (annotation == null)
       return null;
-    return getSubSequence(start, getLength());
-  }
 
-  public int removeGaps() {
-    if (sequence!=null)
-      return removeGaps(0, getLength());
-    return 0;
+    AlignmentAnnotation[] ret = new AlignmentAnnotation[annotation.size()];
+    for (int r = 0; r < ret.length; r++)
+      ret[r] = (AlignmentAnnotation) annotation.elementAt(r);
+
+    return ret;
   }
 
-  public int removeGaps(int start, int end) {
-    int jSize = getLength();
-    int oSize=jSize;
-    if (jSize<=start)
-      return 0;
-    if (end>jSize)
-      end = jSize;
+  public void addAlignmentAnnotation(AlignmentAnnotation annotation)
+  {
+    if (this.annotation == null)
+      this.annotation = new Vector();
 
-    // Removing a range is much quicker than removing gaps
-    // one by one for long sequences
-    int j = start;
-    int rangeStart=-1, rangeEnd=-1;
+    this.annotation.addElement(annotation);
+  }
 
-    do
+  public SequenceGroup getHiddenSequences()
+  {
+    return hiddenSequences;
+  }
+
+  public void addHiddenSequence(SequenceI seq)
+  {
+    if (hiddenSequences == null)
     {
-      if (jalview.util.Comparison.isGap(getCharAt(j)))
-      {
-        if(rangeStart==-1)
-         {
-           rangeStart = j;
-           rangeEnd = j+1;
-         }
-         else
-         {
-           rangeEnd++;
-         }
-         j++;
-      }
-      else
-      {
-        if(rangeStart>-1)
-        {
-          deleteChars(rangeStart, rangeEnd);
-          j-=rangeEnd-rangeStart;
-          jSize-=rangeEnd-rangeStart;
-          rangeStart = -1;
-          rangeEnd = -1;
-        }
-        else
-          j++;
-      }
+      hiddenSequences = new SequenceGroup();
     }
-    while (j < end && j < jSize);
-    if(rangeStart>-1)
+    hiddenSequences.addSequence(seq, false);
+  }
+
+  public void showHiddenSequence(SequenceI seq)
+  {
+    hiddenSequences.deleteSequence(seq, false);
+    if (hiddenSequences.getSize(false) < 1)
     {
-     deleteChars(rangeStart, rangeEnd);
-     jSize-=rangeEnd-rangeStart;
+      hiddenSequences = null;
     }
-    return oSize-jSize; // number of deleted characters.
   }
-
 }
+
+
index 679997e..2bdd5f8 100755 (executable)
@@ -200,6 +200,18 @@ public class SequenceGroup
       }\r
     }\r
 \r
+    public SequenceI[] getSequencesAsArray(boolean includeHidden)\r
+    {\r
+      Vector tmp = getSequences(includeHidden);\r
+      if(tmp==null)\r
+        return null;\r
+      SequenceI [] result = new SequenceI[tmp.size()];\r
+      for(int i=0; i<result.length; i++)\r
+        result[i] = (SequenceI)tmp.elementAt(i);\r
+\r
+      return result;\r
+    }\r
+\r
     /**\r
      * DOCUMENT ME!\r
      *\r
index 8291026..eb7cda6 100755 (executable)
@@ -189,6 +189,15 @@ public interface SequenceI
      */
     public void insertCharAt(int i, char c);
 
+    /**
+     * DOCUMENT ME!
+     *
+     * @param i DOCUMENT ME!
+     * @param c DOCUMENT ME!
+     */
+    public void insertCharAt(int i, int length, char c);
+
+
 
     /**
      * DOCUMENT ME!
@@ -260,27 +269,4 @@ public interface SequenceI
 
     public void showHiddenSequence(SequenceI seq);
 
-    public void changeCase(boolean toUpper, int start, int end);
-
-    public void toggleCase(int start, int end);
-
-  /**
-   * getSubSequence from start to end of sequence
-   * @param start first residue in subSequence
-   * @return SequenceI
-   */
-  public SequenceI getSubSequence(int start);
-  /**
-   * remove all gaps in the sequence
-   * @return number of gaps removed
-   */
-  public int removeGaps();
-  /**
-   * remove all gaps from start to end columns in sequence
-   * @param start
-   * @param end
-   * @return number of gaps removed
-   */
-  public int removeGaps(int start, int end);
-
 }