2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.4)
3 * Copyright (C) 2008 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 package jalview.datamodel;
26 * <p>Description: </p>
28 * <p>Copyright: Copyright (c) 2004</p>
30 * <p>Company: Dundee University</p>
32 * @author not attributable
35 public class AlignmentOrder
37 // JBPNote : this method would return a vector containing all sequences in seqset
38 // with those also contained in order at the beginning of the vector in the order
39 // given by order. AlignmentSorter.vectorSubsetToArray already does this, but that method
40 // should be here for completeness.
42 /* public Vector getOrder(AlignmentI seqset)
44 Vector perm = new Vector(seqset.getHeight());
45 for (i=0, o = 0, n=seqset.getHeight(), p = Order.size(); i<n; i++)
46 perm.setElement(i,...).
52 public static final int FILE = 0;
55 public static final int MSA = 1;
58 public static final int USER = 2;
61 private Vector Order = null;
64 * Creates a new AlignmentOrder object.
66 public AlignmentOrder()
73 * @param anOrder Vector
75 public AlignmentOrder(Vector anOrder)
83 * @param orderFrom AlignmentI
85 public AlignmentOrder(AlignmentI orderFrom)
89 for (int i = 0, ns = orderFrom.getHeight(); i < ns; i++)
91 Order.addElement(orderFrom.getSequenceAt(i));
96 * Creates a new AlignmentOrder object.
98 * @param orderFrom DOCUMENT ME!
100 public AlignmentOrder(SequenceI[] orderFrom)
102 Order = new Vector();
104 for (int i = 0, ns = orderFrom.length; i < ns; i++)
106 Order.addElement(orderFrom[i]);
113 * @param Type DOCUMENT ME!
115 public void setType(int Type)
123 * @return DOCUMENT ME!
133 * @param Name DOCUMENT ME!
135 public void setName(String Name)
143 * @return DOCUMENT ME!
145 public String getName()
153 * @param Order DOCUMENT ME!
155 public void setOrder(Vector Order)
163 * @return DOCUMENT ME!
165 public Vector getOrder()
171 * replaces oldref with newref in the alignment order.
174 * @return true if oldref was contained in order and replaced with newref
176 public boolean updateSequence(SequenceI oldref, SequenceI newref)
178 int found = Order.indexOf(oldref);
181 Order.setElementAt(newref, found);
187 * Exact equivalence of two AlignmentOrders
189 * @return true if o orders the same sequenceI objects in the same way
191 public boolean equals(AlignmentOrder o)
193 return equals(o, true);
197 * Exact equivalence of two AlignmentOrders
198 * // TODO: Weak SequenceI equivalence - will throw Error at moment
200 * @param identity - false - use weak equivalence (refers to same or different parts of same sequence)
201 * @return true if o orders equivalent sequenceI objects in the same way
203 public boolean equals(AlignmentOrder o, boolean identity)
211 if (Order != null && o.Order != null && Order.size() == o.Order.size())
215 throw new Error("Weak sequenceI equivalence not yet implemented.");
219 for (int i = 0, j = o.Order.size(); i < j; i++)
221 if (Order.elementAt(i) != o.Order.elementAt(i))
237 * Consistency test for alignmentOrders
239 * @return true if o contains or is contained by this and the common SequenceI objects are ordered in the same way
241 public boolean isConsistent(AlignmentOrder o)
243 return isConsistent(o, true);
247 * Consistency test for alignmentOrders
249 * // TODO: Weak SequenceI equivalence - will throw Error at moment
250 * @param identity - false - use weak equivalence (refers to same or different parts of same sequence)
251 * @return true if o contains or is contained by this and the common SequenceI objects are ordered in the same way
253 public boolean isConsistent(AlignmentOrder o, boolean identity)
261 if (Order != null && o.Order != null)
264 if (o.Order.size() > Order.size())
276 throw new Error("Weak sequenceI equivalence not yet implemented.");
280 // test if c contains s and order in s is conserved in c
282 for (int i = 0, j = s.size(); i < j; i++)
284 int pos = c.indexOf(s.elementAt(i)); // JBPNote - optimize by incremental position search
306 * @param orderThis AlignmentI
307 * @param byThat AlignmentI
310 /* public AlignmentOrder(AlignmentI orderThis, AlignmentI byThat)
312 // Vector is an ordering of this alignment using the order of sequence objects in byThat,
313 // where ids and unaligned sequences must match