2 * Jalview - A Sequence Alignment Editor and Viewer
3 * Copyright (C) 2006 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 package jalview.datamodel;
27 * <p>Description: </p>
29 * <p>Copyright: Copyright (c) 2004</p>
31 * <p>Company: Dundee University</p>
33 * @author not attributable
36 public class AlignmentOrder
38 // JBPNote : this method would return a vector containing all sequences in seqset
39 // with those also contained in order at the beginning of the vector in the order
40 // given by order. AlignmentSorter.vectorSubsetToArray already does this, but that method
41 // should be here for completeness.
43 /* public Vector getOrder(AlignmentI seqset)
45 Vector perm = new Vector(seqset.getHeight());
46 for (i=0, o = 0, n=seqset.getHeight(), p = Order.size(); i<n; i++)
47 perm.setElement(i,...).
53 public static final int FILE = 0;
56 public static final int MSA = 1;
59 public static final int USER = 2;
62 private Vector Order = null;
65 * Creates a new AlignmentOrder object.
67 public AlignmentOrder()
74 * @param anOrder Vector
76 public AlignmentOrder(Vector anOrder)
84 * @param orderFrom AlignmentI
86 public AlignmentOrder(AlignmentI orderFrom)
90 for (int i = 0, ns = orderFrom.getHeight(); i < ns; i++)
92 Order.addElement(orderFrom.getSequenceAt(i));
97 * Creates a new AlignmentOrder object.
99 * @param orderFrom DOCUMENT ME!
101 public AlignmentOrder(SequenceI[] orderFrom)
103 Order = new Vector();
105 for (int i = 0, ns = orderFrom.length; i < ns; i++)
107 Order.addElement(orderFrom[i]);
114 * @param Type DOCUMENT ME!
116 public void setType(int Type)
124 * @return DOCUMENT ME!
134 * @param Name DOCUMENT ME!
136 public void setName(String Name)
144 * @return DOCUMENT ME!
146 public String getName()
154 * @param Order DOCUMENT ME!
156 public void setOrder(Vector Order)
164 * @return DOCUMENT ME!
166 public Vector getOrder()
171 * 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) {
177 int found=Order.indexOf(oldref);
179 Order.setElementAt(newref, found);
184 * Exact equivalence of two AlignmentOrders
186 * @return true if o orders the same sequenceI objects in the same way
188 public boolean equals(AlignmentOrder o) {
189 return equals(o, true);
192 * Exact equivalence of two AlignmentOrders
193 * // TODO: Weak SequenceI equivalence - will throw Error at moment
195 * @param identity - false - use weak equivalence (refers to same or different parts of same sequence)
196 * @return true if o orders equivalent sequenceI objects in the same way
198 public boolean equals(AlignmentOrder o, boolean identity) {
202 if (Order!=null && o.Order!=null && Order.size()==o.Order.size()) {
204 throw new Error("Weak sequenceI equivalence not yet implemented.");
206 for (int i=0,j=o.Order.size(); i<j; i++) {
207 if (Order.elementAt(i)!=o.Order.elementAt(i))
217 * Consistency test for alignmentOrders
219 * @return true if o contains or is contained by this and the common SequenceI objects are ordered in the same way
221 public boolean isConsistent(AlignmentOrder o) {
222 return isConsistent(o, true);
225 * Consistency test for alignmentOrders
227 * // TODO: Weak SequenceI equivalence - will throw Error at moment
228 * @param identity - false - use weak equivalence (refers to same or different parts of same sequence)
229 * @return true if o contains or is contained by this and the common SequenceI objects are ordered in the same way
231 public boolean isConsistent(AlignmentOrder o, boolean identity) {
235 if (Order!=null && o.Order!=null) {
237 if (o.Order.size()>Order.size()) {
245 throw new Error("Weak sequenceI equivalence not yet implemented.");
247 // test if c contains s and order in s is conserved in c
249 for (int i=0,j=s.size(); i<j; i++) {
250 int pos=c.indexOf(s.elementAt(i)); // JBPNote - optimize by incremental position search
265 * @param orderThis AlignmentI
266 * @param byThat AlignmentI
269 /* public AlignmentOrder(AlignmentI orderThis, AlignmentI byThat)
271 // Vector is an ordering of this alignment using the order of sequence objects in byThat,
272 // where ids and unaligned sequences must match