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;
33 * Copyright: Copyright (c) 2004
37 * Company: Dundee University
40 * @author not attributable
43 public class AlignmentOrder
45 // JBPNote : this method would return a vector containing all sequences in
47 // with those also contained in order at the beginning of the vector in the
49 // given by order. AlignmentSorter.vectorSubsetToArray already does this, but
51 // should be here for completeness.
54 * public Vector getOrder(AlignmentI seqset) { Vector perm = new
55 * Vector(seqset.getHeight()); for (i=0, o = 0, n=seqset.getHeight(), p =
56 * Order.size(); i<n; i++) perm.setElement(i,...). return Order; }
60 public static final int FILE = 0;
63 public static final int MSA = 1;
66 public static final int USER = 2;
72 private Vector Order = null;
75 * Creates a new AlignmentOrder object.
77 public AlignmentOrder()
87 public AlignmentOrder(Vector anOrder)
98 public AlignmentOrder(AlignmentI orderFrom)
100 Order = new Vector();
102 for (int i = 0, ns = orderFrom.getHeight(); i < ns; i++)
104 Order.addElement(orderFrom.getSequenceAt(i));
109 * Creates a new AlignmentOrder object.
114 public AlignmentOrder(SequenceI[] orderFrom)
116 Order = new Vector();
118 for (int i = 0, ns = orderFrom.length; i < ns; i++)
120 Order.addElement(orderFrom[i]);
130 public void setType(int Type)
138 * @return DOCUMENT ME!
151 public void setName(String Name)
159 * @return DOCUMENT ME!
161 public String getName()
172 public void setOrder(Vector Order)
180 * @return DOCUMENT ME!
182 public Vector getOrder()
188 * replaces oldref with newref in the alignment order.
192 * @return true if oldref was contained in order and replaced with newref
194 public boolean updateSequence(SequenceI oldref, SequenceI newref)
196 int found = Order.indexOf(oldref);
199 Order.setElementAt(newref, found);
205 * Exact equivalence of two AlignmentOrders
208 * @return true if o orders the same sequenceI objects in the same way
210 public boolean equals(AlignmentOrder o)
212 return equals(o, true);
216 * Exact equivalence of two AlignmentOrders // TODO: Weak SequenceI
217 * equivalence - will throw Error at moment
221 * false - use weak equivalence (refers to same or different
222 * parts of same sequence)
223 * @return true if o orders equivalent sequenceI objects in the same way
225 public boolean equals(AlignmentOrder o, boolean identity)
233 if (Order != null && o.Order != null
234 && Order.size() == o.Order.size())
238 throw new Error("Weak sequenceI equivalence not yet implemented.");
242 for (int i = 0, j = o.Order.size(); i < j; i++)
244 if (Order.elementAt(i) != o.Order.elementAt(i))
260 * Consistency test for alignmentOrders
263 * @return true if o contains or is contained by this and the common SequenceI
264 * objects are ordered in the same way
266 public boolean isConsistent(AlignmentOrder o)
268 return isConsistent(o, true);
272 * Consistency test for alignmentOrders
275 * TODO: Weak SequenceI equivalence - will throw Error at
278 * false - use weak equivalence (refers to same or different
279 * parts of same sequence)
280 * @return true if o contains or is contained by this and the common SequenceI
281 * objects are ordered in the same way
283 public boolean isConsistent(AlignmentOrder o, boolean identity)
291 if (Order != null && o.Order != null)
294 if (o.Order.size() > Order.size())
306 throw new Error("Weak sequenceI equivalence not yet implemented.");
310 // test if c contains s and order in s is conserved in c
312 for (int i = 0, j = s.size(); i < j; i++)
314 int pos = c.indexOf(s.elementAt(i)); // JBPNote - optimize by
315 // incremental position search
344 * public AlignmentOrder(AlignmentI orderThis, AlignmentI byThat) { // Vector
345 * is an ordering of this alignment using the order of sequence objects in
346 * byThat, // where ids and unaligned sequences must match