2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.5)
3 * Copyright (C) 2010 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
11 * Jalview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
18 package jalview.datamodel;
32 * Copyright: Copyright (c) 2004
36 * Company: Dundee University
39 * @author not attributable
42 public class AlignmentOrder
44 // JBPNote : this method would return a vector containing all sequences in
46 // with those also contained in order at the beginning of the vector in the
48 // given by order. AlignmentSorter.vectorSubsetToArray already does this, but
50 // should be here for completeness.
53 * public Vector getOrder(AlignmentI seqset) { Vector perm = new
54 * Vector(seqset.getHeight()); for (i=0, o = 0, n=seqset.getHeight(), p =
55 * Order.size(); i<n; i++) perm.setElement(i,...). return Order; }
59 public static final int FILE = 0;
62 public static final int MSA = 1;
65 public static final int USER = 2;
71 private Vector Order = null;
74 * Creates a new AlignmentOrder object.
76 public AlignmentOrder()
86 public AlignmentOrder(Vector anOrder)
97 public AlignmentOrder(AlignmentI orderFrom)
101 for (int i = 0, ns = orderFrom.getHeight(); i < ns; i++)
103 Order.addElement(orderFrom.getSequenceAt(i));
108 * Creates a new AlignmentOrder object.
113 public AlignmentOrder(SequenceI[] orderFrom)
115 Order = new Vector();
117 for (int i = 0, ns = orderFrom.length; i < ns; i++)
119 Order.addElement(orderFrom[i]);
129 public void setType(int Type)
137 * @return DOCUMENT ME!
150 public void setName(String Name)
158 * @return DOCUMENT ME!
160 public String getName()
171 public void setOrder(Vector Order)
179 * @return DOCUMENT ME!
181 public Vector getOrder()
187 * replaces oldref with newref in the alignment order.
191 * @return true if oldref was contained in order and replaced with newref
193 public boolean updateSequence(SequenceI oldref, SequenceI newref)
195 int found = Order.indexOf(oldref);
198 Order.setElementAt(newref, found);
204 * Exact equivalence of two AlignmentOrders
207 * @return true if o orders the same sequenceI objects in the same way
209 public boolean equals(AlignmentOrder o)
211 return equals(o, true);
215 * Exact equivalence of two AlignmentOrders // TODO: Weak SequenceI
216 * equivalence - will throw Error at moment
220 * - false - use weak equivalence (refers to same or different parts
222 * @return true if o orders equivalent sequenceI objects in the same way
224 public boolean equals(AlignmentOrder o, boolean identity)
232 if (Order != null && o.Order != null
233 && Order.size() == o.Order.size())
237 throw new Error("Weak sequenceI equivalence not yet implemented.");
241 for (int i = 0, j = o.Order.size(); i < j; i++)
243 if (Order.elementAt(i) != o.Order.elementAt(i))
259 * Consistency test for alignmentOrders
262 * @return true if o contains or is contained by this and the common SequenceI
263 * objects are ordered in the same way
265 public boolean isConsistent(AlignmentOrder o)
267 return isConsistent(o, true);
271 * Consistency test for alignmentOrders
274 * // TODO: Weak SequenceI equivalence - will throw Error at moment
276 * - false - use weak equivalence (refers to same or different parts
278 * @return true if o contains or is contained by this and the common SequenceI
279 * objects are ordered in the same way
281 public boolean isConsistent(AlignmentOrder o, boolean identity)
289 if (Order != null && o.Order != null)
292 if (o.Order.size() > Order.size())
304 throw new Error("Weak sequenceI equivalence not yet implemented.");
308 // test if c contains s and order in s is conserved in c
310 for (int i = 0, j = s.size(); i < j; i++)
312 int pos = c.indexOf(s.elementAt(i)); // JBPNote - optimize by
313 // incremental position search
342 * public AlignmentOrder(AlignmentI orderThis, AlignmentI byThat) { // Vector
343 * is an ordering of this alignment using the order of sequence objects in
344 * byThat, // where ids and unaligned sequences must match }