2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)
3 * Copyright (C) 2011 J Procter, AM Waterhouse, J Engelhardt, LM Lui, 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;
22 public class AlignmentOrder
24 // JBPNote : this method would return a vector containing all sequences in
26 // with those also contained in order at the beginning of the vector in the
28 // given by order. AlignmentSorter.vectorSubsetToArray already does this, but
30 // should be here for completeness.
33 * public Vector getOrder(AlignmentI seqset) { Vector perm = new
34 * Vector(seqset.getHeight()); for (i=0, o = 0, n=seqset.getHeight(), p =
35 * Order.size(); i<n; i++) perm.setElement(i,...). return Order; }
39 public static final int FILE = 0;
42 public static final int MSA = 1;
45 public static final int USER = 2;
51 private Vector Order = null;
54 * Creates a new AlignmentOrder object.
56 public AlignmentOrder()
66 public AlignmentOrder(Vector anOrder)
77 public AlignmentOrder(AlignmentI orderFrom)
81 for (int i = 0, ns = orderFrom.getHeight(); i < ns; i++)
83 Order.addElement(orderFrom.getSequenceAt(i));
88 * Creates a new AlignmentOrder object.
93 public AlignmentOrder(SequenceI[] orderFrom)
97 for (int i = 0, ns = orderFrom.length; i < ns; i++)
99 Order.addElement(orderFrom[i]);
109 public void setType(int Type)
117 * @return DOCUMENT ME!
130 public void setName(String Name)
138 * @return DOCUMENT ME!
140 public String getName()
151 public void setOrder(Vector Order)
159 * @return DOCUMENT ME!
161 public Vector getOrder()
167 * replaces oldref with newref in the alignment order.
171 * @return true if oldref was contained in order and replaced with newref
173 public boolean updateSequence(SequenceI oldref, SequenceI newref)
175 int found = Order.indexOf(oldref);
178 Order.setElementAt(newref, found);
184 * Exact equivalence of two AlignmentOrders
187 * @return true if o orders the same sequenceI objects in the same way
189 public boolean equals(AlignmentOrder o)
191 return equals(o, true);
195 * Exact equivalence of two AlignmentOrders // TODO: Weak SequenceI
196 * equivalence - will throw Error at moment
200 * - false - use weak equivalence (refers to same or different parts
202 * @return true if o orders equivalent sequenceI objects in the same way
204 public boolean equals(AlignmentOrder o, boolean identity)
212 if (Order != null && o.Order != null
213 && Order.size() == o.Order.size())
217 throw new Error("Weak sequenceI equivalence not yet implemented.");
221 for (int i = 0, j = o.Order.size(); i < j; i++)
223 if (Order.elementAt(i) != o.Order.elementAt(i))
239 * Consistency test for alignmentOrders
242 * @return true if o contains or is contained by this and the common SequenceI
243 * objects are ordered in the same way
245 public boolean isConsistent(AlignmentOrder o)
247 return isConsistent(o, true);
251 * Consistency test for alignmentOrders
254 * // TODO: Weak SequenceI equivalence - will throw Error at moment
256 * - false - use weak equivalence (refers to same or different parts
258 * @return true if o contains or is contained by this and the common SequenceI
259 * objects are ordered in the same way
261 public boolean isConsistent(AlignmentOrder o, boolean identity)
269 if (Order != null && o.Order != null)
272 if (o.Order.size() > Order.size())
284 throw new Error("Weak sequenceI equivalence not yet implemented.");
288 // test if c contains s and order in s is conserved in c
290 for (int i = 0, j = s.size(); i < j; i++)
292 int pos = c.indexOf(s.elementAt(i)); // JBPNote - optimize by
293 // incremental position search
322 * public AlignmentOrder(AlignmentI orderThis, AlignmentI byThat) { // Vector
323 * is an ordering of this alignment using the order of sequence objects in
324 * byThat, // where ids and unaligned sequences must match }