2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.1)
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 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/>.
17 * The Jalview Authors are detailed in the 'AUTHORS' file.
19 package jalview.datamodel;
23 public class AlignmentOrder
25 // JBPNote : this method would return a vector containing all sequences in
27 // with those also contained in order at the beginning of the vector in the
29 // given by order. AlignmentSorter.vectorSubsetToArray already does this, but
31 // should be here for completeness.
34 * public Vector getOrder(AlignmentI seqset) { Vector perm = new
35 * Vector(seqset.getHeight()); for (i=0, o = 0, n=seqset.getHeight(), p =
36 * Order.size(); i<n; i++) perm.setElement(i,...). return Order; }
40 public static final int FILE = 0;
43 public static final int MSA = 1;
46 public static final int USER = 2;
52 private Vector Order = null;
55 * Creates a new AlignmentOrder object.
57 public AlignmentOrder()
67 public AlignmentOrder(Vector anOrder)
78 public AlignmentOrder(AlignmentI orderFrom)
82 for (int i = 0, ns = orderFrom.getHeight(); i < ns; i++)
84 Order.addElement(orderFrom.getSequenceAt(i));
89 * Creates a new AlignmentOrder object.
94 public AlignmentOrder(SequenceI[] orderFrom)
98 for (int i = 0, ns = orderFrom.length; i < ns; i++)
100 Order.addElement(orderFrom[i]);
110 public void setType(int Type)
118 * @return DOCUMENT ME!
131 public void setName(String Name)
139 * @return DOCUMENT ME!
141 public String getName()
152 public void setOrder(Vector Order)
160 * @return DOCUMENT ME!
162 public Vector getOrder()
168 * replaces oldref with newref in the alignment order.
172 * @return true if oldref was contained in order and replaced with newref
174 public boolean updateSequence(SequenceI oldref, SequenceI newref)
176 int found = Order.indexOf(oldref);
179 Order.setElementAt(newref, found);
185 * Exact equivalence of two AlignmentOrders
188 * @return true if o orders the same sequenceI objects in the same way
190 public boolean equals(AlignmentOrder o)
192 return equals(o, true);
196 * Exact equivalence of two AlignmentOrders // TODO: Weak SequenceI
197 * equivalence - will throw Error at moment
201 * - false - use weak equivalence (refers to same or different parts
203 * @return true if o orders equivalent sequenceI objects in the same way
205 public boolean equals(AlignmentOrder o, boolean identity)
213 if (Order != null && o.Order != null
214 && Order.size() == o.Order.size())
218 throw new Error("Weak sequenceI equivalence not yet implemented.");
222 for (int i = 0, j = o.Order.size(); i < j; i++)
224 if (Order.elementAt(i) != o.Order.elementAt(i))
240 * Consistency test for alignmentOrders
243 * @return true if o contains or is contained by this and the common SequenceI
244 * objects are ordered in the same way
246 public boolean isConsistent(AlignmentOrder o)
248 return isConsistent(o, true);
252 * Consistency test for alignmentOrders
255 * // TODO: Weak SequenceI equivalence - will throw Error at moment
257 * - false - use weak equivalence (refers to same or different parts
259 * @return true if o contains or is contained by this and the common SequenceI
260 * objects are ordered in the same way
262 public boolean isConsistent(AlignmentOrder o, boolean identity)
270 if (Order != null && o.Order != null)
273 if (o.Order.size() > Order.size())
285 throw new Error("Weak sequenceI equivalence not yet implemented.");
289 // test if c contains s and order in s is conserved in c
291 for (int i = 0, j = s.size(); i < j; i++)
293 int pos = c.indexOf(s.elementAt(i)); // JBPNote - optimize by
294 // incremental position search
323 * public AlignmentOrder(AlignmentI orderThis, AlignmentI byThat) { // Vector
324 * is an ordering of this alignment using the order of sequence objects in
325 * byThat, // where ids and unaligned sequences must match }