2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ 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 java.util.ArrayList;
24 import java.util.Arrays;
25 import java.util.List;
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 List<SequenceI> Order = null;
59 * Creates a new AlignmentOrder object.
61 public AlignmentOrder()
70 public AlignmentOrder(List<SequenceI> anOrder)
81 public AlignmentOrder(AlignmentI orderFrom)
83 Order = new ArrayList<SequenceI>();
85 for (SequenceI seq : orderFrom.getSequences())
92 * Creates a new AlignmentOrder object.
97 public AlignmentOrder(SequenceI[] orderFrom)
99 Order = new ArrayList<SequenceI>(Arrays.asList(orderFrom));
108 public void setType(int Type)
116 * @return DOCUMENT ME!
129 public void setName(String Name)
137 * @return DOCUMENT ME!
139 public String getName()
150 public void setOrder(List<SequenceI> Order)
158 * @return DOCUMENT ME!
160 public List<SequenceI> getOrder()
166 * replaces oldref with newref in the alignment order.
170 * @return true if oldref was contained in order and replaced with newref
172 public boolean updateSequence(SequenceI oldref, SequenceI newref)
174 int found = Order.indexOf(oldref);
177 Order.set(found, newref);
183 * Exact equivalence of two AlignmentOrders
186 * @return true if o orders the same sequenceI objects in the same way
189 public boolean equals(Object o)
191 if (o == null || !(o instanceof AlignmentOrder))
195 return equals((AlignmentOrder) o, true);
199 * Exact equivalence of two AlignmentOrders // TODO: Weak SequenceI
200 * equivalence - will throw Error at moment
204 * - false - use weak equivalence (refers to same or different parts
206 * @return true if o orders equivalent sequenceI objects in the same way
208 public boolean equals(AlignmentOrder o, boolean identity)
216 if (Order != null && o.Order != null
217 && Order.size() == o.Order.size())
222 "Weak sequenceI equivalence not yet implemented.");
226 for (int i = 0, j = o.Order.size(); i < j; i++)
228 if (Order.get(i) != o.Order.get(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)
276 List<SequenceI> c, s;
277 if (o.Order.size() > Order.size())
290 "Weak sequenceI equivalence not yet implemented.");
294 // test if c contains s and order in s is conserved in c
296 for (int i = 0, j = s.size(); i < j; i++)
298 int pos = c.indexOf(s.get(i)); // JBPNote - optimize by
299 // incremental position search
328 * public AlignmentOrder(AlignmentI orderThis, AlignmentI byThat) { // Vector
329 * is an ordering of this alignment using the order of sequence objects in
330 * byThat, // where ids and unaligned sequences must match }