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;
23 import jalview.util.MessageManager;
27 public class AlignmentOrder
29 // JBPNote : this method would return a vector containing all sequences in
31 // with those also contained in order at the beginning of the vector in the
33 // given by order. AlignmentSorter.vectorSubsetToArray already does this, but
35 // should be here for completeness.
38 * public Vector getOrder(AlignmentI seqset) { Vector perm = new
39 * Vector(seqset.getHeight()); for (i=0, o = 0, n=seqset.getHeight(), p =
40 * Order.size(); i<n; i++) perm.setElement(i,...). return Order; }
44 public static final int FILE = 0;
47 public static final int MSA = 1;
50 public static final int USER = 2;
56 private Vector Order = null;
59 * Creates a new AlignmentOrder object.
61 public AlignmentOrder()
71 public AlignmentOrder(Vector anOrder)
82 public AlignmentOrder(AlignmentI orderFrom)
86 for (int i = 0, ns = orderFrom.getHeight(); i < ns; i++)
88 Order.addElement(orderFrom.getSequenceAt(i));
93 * Creates a new AlignmentOrder object.
98 public AlignmentOrder(SequenceI[] orderFrom)
100 Order = new Vector();
102 for (int i = 0, ns = orderFrom.length; i < ns; i++)
104 Order.addElement(orderFrom[i]);
114 public void setType(int Type)
122 * @return DOCUMENT ME!
135 public void setName(String Name)
143 * @return DOCUMENT ME!
145 public String getName()
156 public void setOrder(Vector Order)
164 * @return DOCUMENT ME!
166 public Vector getOrder()
172 * replaces oldref with newref in the alignment order.
176 * @return true if oldref was contained in order and replaced with newref
178 public boolean updateSequence(SequenceI oldref, SequenceI newref)
180 int found = Order.indexOf(oldref);
183 Order.setElementAt(newref, found);
189 * Exact equivalence of two AlignmentOrders
192 * @return true if o orders the same sequenceI objects in the same way
194 public boolean equals(AlignmentOrder o)
196 return equals(o, true);
200 * Exact equivalence of two AlignmentOrders // TODO: Weak SequenceI
201 * equivalence - will throw Error at moment
205 * - false - use weak equivalence (refers to same or different parts
207 * @return true if o orders equivalent sequenceI objects in the same way
209 public boolean equals(AlignmentOrder o, boolean identity)
217 if (Order != null && o.Order != null
218 && Order.size() == o.Order.size())
222 throw new Error(MessageManager.getString("error.weak_sequencei_equivalence_not_yet_implemented"));
226 for (int i = 0, j = o.Order.size(); i < j; i++)
228 if (Order.elementAt(i) != o.Order.elementAt(i))
244 * Consistency test for alignmentOrders
247 * @return true if o contains or is contained by this and the common SequenceI
248 * objects are ordered in the same way
250 public boolean isConsistent(AlignmentOrder o)
252 return isConsistent(o, true);
256 * Consistency test for alignmentOrders
259 * // TODO: Weak SequenceI equivalence - will throw Error at moment
261 * - false - use weak equivalence (refers to same or different parts
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, boolean identity)
274 if (Order != null && o.Order != null)
277 if (o.Order.size() > Order.size())
289 throw new Error(MessageManager.getString("error.weak_sequencei_equivalence_not_yet_implemented"));
293 // test if c contains s and order in s is conserved in c
295 for (int i = 0, j = s.size(); i < j; i++)
297 int pos = c.indexOf(s.elementAt(i)); // JBPNote - optimize by
298 // incremental position search
327 * public AlignmentOrder(AlignmentI orderThis, AlignmentI byThat) { // Vector
328 * is an ordering of this alignment using the order of sequence objects in
329 * byThat, // where ids and unaligned sequences must match }