+ AlignedCodonFrame[] codonFrameList = null;
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * jalview.datamodel.AlignmentI#addCodonFrame(jalview.datamodel.AlignedCodonFrame
+ * )
+ */
+ public void addCodonFrame(AlignedCodonFrame codons)
+ {
+ if (codons == null)
+ return;
+ if (codonFrameList == null)
+ {
+ codonFrameList = new AlignedCodonFrame[]
+ { codons };
+ return;
+ }
+ AlignedCodonFrame[] t = new AlignedCodonFrame[codonFrameList.length + 1];
+ System.arraycopy(codonFrameList, 0, t, 0, codonFrameList.length);
+ t[codonFrameList.length] = codons;
+ codonFrameList = t;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see jalview.datamodel.AlignmentI#getCodonFrame(int)
+ */
+ public AlignedCodonFrame getCodonFrame(int index)
+ {
+ return codonFrameList[index];
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * jalview.datamodel.AlignmentI#getCodonFrame(jalview.datamodel.SequenceI)
+ */
+ public AlignedCodonFrame[] getCodonFrame(SequenceI seq)
+ {
+ if (seq == null || codonFrameList == null)
+ return null;
+ Vector cframes = new Vector();
+ for (int f = 0; f < codonFrameList.length; f++)
+ {
+ if (codonFrameList[f].involvesSequence(seq))
+ cframes.addElement(codonFrameList[f]);
+ }
+ if (cframes.size() == 0)
+ return null;
+ AlignedCodonFrame[] cfr = new AlignedCodonFrame[cframes.size()];
+ cframes.copyInto(cfr);
+ return cfr;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see jalview.datamodel.AlignmentI#getCodonFrames()
+ */
+ public AlignedCodonFrame[] getCodonFrames()
+ {
+ return codonFrameList;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @seejalview.datamodel.AlignmentI#removeCodonFrame(jalview.datamodel.
+ * AlignedCodonFrame)
+ */
+ public boolean removeCodonFrame(AlignedCodonFrame codons)
+ {
+ if (codons == null || codonFrameList == null)
+ return false;
+ boolean removed = false;
+ int i = 0, iSize = codonFrameList.length;
+ while (i < iSize)
+ {
+ if (codonFrameList[i] == codons)
+ {
+ removed = true;
+ if (i + 1 < iSize)
+ {
+ System.arraycopy(codonFrameList, i + 1, codonFrameList, i, iSize
+ - i - 1);
+ }
+ iSize--;
+ }
+ else
+ {
+ i++;
+ }
+ }
+ return removed;
+ }
+
+ public void append(AlignmentI toappend)
+ {
+ // TODO test this method for a future 2.5 release
+ // currently tested for use in jalview.gui.SequenceFetcher
+ boolean samegap = toappend.getGapCharacter() == getGapCharacter();
+ char oldc = toappend.getGapCharacter();
+ boolean hashidden = toappend.getHiddenSequences() != null
+ && toappend.getHiddenSequences().hiddenSequences != null;
+ // get all sequences including any hidden ones
+ Vector sqs = (hashidden) ? toappend.getHiddenSequences()
+ .getFullAlignment().getSequences() : toappend.getSequences();
+ if (sqs != null)
+ {
+ Enumeration sq = sqs.elements();
+ while (sq.hasMoreElements())
+ {
+ SequenceI addedsq = (SequenceI) sq.nextElement();
+ if (!samegap)
+ {
+ char[] oldseq = addedsq.getSequence();
+ for (int c = 0; c < oldseq.length; c++)
+ {
+ if (oldseq[c] == oldc)
+ {
+ oldseq[c] = gapCharacter;
+ }
+ }
+ }
+ addSequence(addedsq);
+ }
+ }
+ AlignmentAnnotation[] alan = toappend.getAlignmentAnnotation();
+ for (int a = 0; alan != null && a < alan.length; a++)
+ {
+ addAnnotation(alan[a]);
+ }
+ AlignedCodonFrame[] acod = toappend.getCodonFrames();
+ for (int a = 0; acod != null && a < acod.length; a++)
+ {
+ this.addCodonFrame(acod[a]);
+ }
+ Vector sg = toappend.getGroups();
+ if (sg != null)
+ {
+ Enumeration el = sg.elements();
+ while (el.hasMoreElements())
+ {
+ addGroup((SequenceGroup) el.nextElement());
+ }
+ }
+ if (toappend.getHiddenSequences() != null)
+ {
+ HiddenSequences hs = toappend.getHiddenSequences();
+ if (hiddenSequences == null)
+ {
+ hiddenSequences = new HiddenSequences(this);
+ }
+ if (hs.hiddenSequences != null)
+ {
+ for (int s = 0; s < hs.hiddenSequences.length; s++)
+ {
+ // hide the newly appended sequence in the alignment
+ if (hs.hiddenSequences[s] != null)
+ {
+ hiddenSequences.hideSequence(hs.hiddenSequences[s]);
+ }
+ }
+ }
+ }
+ if (toappend.getProperties() != null)
+ {
+ // we really can't do very much here - just try to concatenate strings
+ // where property collisions occur.
+ Enumeration key = toappend.getProperties().keys();
+ while (key.hasMoreElements())
+ {
+ Object k = key.nextElement();
+ Object ourval = this.getProperty(k);
+ Object toapprop = toappend.getProperty(k);
+ if (ourval != null)
+ {
+ if (ourval.getClass().equals(toapprop.getClass())
+ && !ourval.equals(toapprop))
+ {
+ if (ourval instanceof String)
+ {
+ // append strings
+ this.setProperty(k, ((String) ourval) + "; "
+ + ((String) toapprop));
+ }
+ else
+ {
+ if (ourval instanceof Vector)
+ {
+ // append vectors
+ Enumeration theirv = ((Vector) toapprop).elements();
+ while (theirv.hasMoreElements())
+ {
+ ((Vector) ourval).addElement(theirv);
+ }
+ }
+ }
+ }
+ }
+ else
+ {
+ // just add new property directly
+ setProperty(k, toapprop);
+ }
+
+ }
+ }
+ }
+