2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
3 * Copyright (C) 2014 The Jalview Authors
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
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.datamodel;
25 public class AlignmentOrder
27 // JBPNote : this method would return a vector containing all sequences in
29 // with those also contained in order at the beginning of the vector in the
31 // given by order. AlignmentSorter.vectorSubsetToArray already does this, but
33 // should be here for completeness.
36 * public Vector getOrder(AlignmentI seqset) { Vector perm = new
37 * Vector(seqset.getHeight()); for (i=0, o = 0, n=seqset.getHeight(), p =
38 * Order.size(); i<n; i++) perm.setElement(i,...). return Order; }
42 public static final int FILE = 0;
45 public static final int MSA = 1;
48 public static final int USER = 2;
54 private Vector Order = null;
57 * Creates a new AlignmentOrder object.
59 public AlignmentOrder()
69 public AlignmentOrder(Vector anOrder)
80 public AlignmentOrder(AlignmentI orderFrom)
84 for (int i = 0, ns = orderFrom.getHeight(); i < ns; i++)
86 Order.addElement(orderFrom.getSequenceAt(i));
91 * Creates a new AlignmentOrder object.
96 public AlignmentOrder(SequenceI[] orderFrom)
100 for (int i = 0, ns = orderFrom.length; i < ns; i++)
102 Order.addElement(orderFrom[i]);
112 public void setType(int Type)
120 * @return DOCUMENT ME!
133 public void setName(String Name)
141 * @return DOCUMENT ME!
143 public String getName()
154 public void setOrder(Vector Order)
162 * @return DOCUMENT ME!
164 public Vector getOrder()
170 * 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
190 * @return true if o orders the same sequenceI objects in the same way
192 public boolean equals(AlignmentOrder o)
194 return equals(o, true);
198 * Exact equivalence of two AlignmentOrders // TODO: Weak SequenceI
199 * equivalence - will throw Error at moment
203 * - false - use weak equivalence (refers to same or different parts
205 * @return true if o orders equivalent sequenceI objects in the same way
207 public boolean equals(AlignmentOrder o, boolean identity)
215 if (Order != null && o.Order != null
216 && Order.size() == o.Order.size())
220 throw new Error("Weak sequenceI equivalence not yet implemented.");
224 for (int i = 0, j = o.Order.size(); i < j; i++)
226 if (Order.elementAt(i) != o.Order.elementAt(i))
242 * Consistency test for alignmentOrders
245 * @return true if o contains or is contained by this and the common SequenceI
246 * objects are ordered in the same way
248 public boolean isConsistent(AlignmentOrder o)
250 return isConsistent(o, true);
254 * Consistency test for alignmentOrders
257 * // TODO: Weak SequenceI equivalence - will throw Error at moment
259 * - false - use weak equivalence (refers to same or different parts
261 * @return true if o contains or is contained by this and the common SequenceI
262 * objects are ordered in the same way
264 public boolean isConsistent(AlignmentOrder o, boolean identity)
272 if (Order != null && o.Order != null)
275 if (o.Order.size() > Order.size())
287 throw new Error("Weak sequenceI equivalence not yet implemented.");
291 // test if c contains s and order in s is conserved in c
293 for (int i = 0, j = s.size(); i < j; i++)
295 int pos = c.indexOf(s.elementAt(i)); // JBPNote - optimize by
296 // incremental position search
325 * public AlignmentOrder(AlignmentI orderThis, AlignmentI byThat) { // Vector
326 * is an ordering of this alignment using the order of sequence objects in
327 * byThat, // where ids and unaligned sequences must match }