2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
\r
5 * This program is free software; you can redistribute it and/or
\r
6 * modify it under the terms of the GNU General Public License
\r
7 * as published by the Free Software Foundation; either version 2
\r
8 * of the License, or (at your option) any later version.
\r
10 * This program is distributed in the hope that it will be useful,
\r
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 * GNU General Public License for more details.
\r
15 * You should have received a copy of the GNU General Public License
\r
16 * along with this program; if not, write to the Free Software
\r
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
\r
19 package jalview.datamodel;
\r
26 * <p>Description: </p>
\r
28 * <p>Copyright: Copyright (c) 2004</p>
\r
30 * <p>Company: Dundee University</p>
\r
32 * @author not attributable
\r
35 public class AlignmentOrder
\r
37 // JBPNote : this method would return a vector containing all sequences in seqset
\r
38 // with those also contained in order at the beginning of the vector in the order
\r
39 // given by order. AlignmentSorter.vectorSubsetToArray already does this, but that method
\r
40 // should be here for completeness.
\r
42 /* public Vector getOrder(AlignmentI seqset)
\r
44 Vector perm = new Vector(seqset.getHeight());
\r
45 for (i=0, o = 0, n=seqset.getHeight(), p = Order.size(); i<n; i++)
\r
46 perm.setElement(i,...).
\r
51 /** DOCUMENT ME!! */
\r
52 public static final int FILE = 0;
\r
54 /** DOCUMENT ME!! */
\r
55 public static final int MSA = 1;
\r
57 /** DOCUMENT ME!! */
\r
58 public static final int USER = 2;
\r
59 private int Type = 0;
\r
60 private String Name;
\r
61 private Vector Order = null;
\r
64 * Creates a new AlignmentOrder object.
\r
66 public AlignmentOrder()
\r
73 * @param anOrder Vector
\r
75 public AlignmentOrder(Vector anOrder)
\r
83 * @param orderFrom AlignmentI
\r
85 public AlignmentOrder(AlignmentI orderFrom)
\r
87 Order = new Vector();
\r
89 for (int i = 0, ns = orderFrom.getHeight(); i < ns; i++)
\r
91 Order.addElement(orderFrom.getSequenceAt(i));
\r
96 * Creates a new AlignmentOrder object.
\r
98 * @param orderFrom DOCUMENT ME!
\r
100 public AlignmentOrder(SequenceI[] orderFrom)
\r
102 Order = new Vector();
\r
104 for (int i = 0, ns = orderFrom.length; i < ns; i++)
\r
106 Order.addElement(orderFrom[i]);
\r
113 * @param Type DOCUMENT ME!
\r
115 public void setType(int Type)
\r
123 * @return DOCUMENT ME!
\r
125 public int getType()
\r
133 * @param Name DOCUMENT ME!
\r
135 public void setName(String Name)
\r
143 * @return DOCUMENT ME!
\r
145 public String getName()
\r
153 * @param Order DOCUMENT ME!
\r
155 public void setOrder(Vector Order)
\r
157 this.Order = Order;
\r
163 * @return DOCUMENT ME!
\r
165 public Vector getOrder()
\r
171 * replaces oldref with newref in the alignment order.
\r
174 * @return true if oldref was contained in order and replaced with newref
\r
176 public boolean updateSequence(SequenceI oldref, SequenceI newref)
\r
178 int found = Order.indexOf(oldref);
\r
181 Order.setElementAt(newref, found);
\r
187 * Exact equivalence of two AlignmentOrders
\r
189 * @return true if o orders the same sequenceI objects in the same way
\r
191 public boolean equals(AlignmentOrder o)
\r
193 return equals(o, true);
\r
197 * Exact equivalence of two AlignmentOrders
\r
198 * // TODO: Weak SequenceI equivalence - will throw Error at moment
\r
200 * @param identity - false - use weak equivalence (refers to same or different parts of same sequence)
\r
201 * @return true if o orders equivalent sequenceI objects in the same way
\r
203 public boolean equals(AlignmentOrder o, boolean identity)
\r
211 if (Order != null && o.Order != null && Order.size() == o.Order.size())
\r
215 throw new Error("Weak sequenceI equivalence not yet implemented.");
\r
219 for (int i = 0, j = o.Order.size(); i < j; i++)
\r
221 if (Order.elementAt(i) != o.Order.elementAt(i))
\r
237 * Consistency test for alignmentOrders
\r
239 * @return true if o contains or is contained by this and the common SequenceI objects are ordered in the same way
\r
241 public boolean isConsistent(AlignmentOrder o)
\r
243 return isConsistent(o, true);
\r
247 * Consistency test for alignmentOrders
\r
249 * // TODO: Weak SequenceI equivalence - will throw Error at moment
\r
250 * @param identity - false - use weak equivalence (refers to same or different parts of same sequence)
\r
251 * @return true if o contains or is contained by this and the common SequenceI objects are ordered in the same way
\r
253 public boolean isConsistent(AlignmentOrder o, boolean identity)
\r
261 if (Order != null && o.Order != null)
\r
264 if (o.Order.size() > Order.size())
\r
276 throw new Error("Weak sequenceI equivalence not yet implemented.");
\r
280 // test if c contains s and order in s is conserved in c
\r
282 for (int i = 0, j = s.size(); i < j; i++)
\r
284 int pos = c.indexOf(s.elementAt(i)); // JBPNote - optimize by incremental position search
\r
306 * @param orderThis AlignmentI
\r
307 * @param byThat AlignmentI
\r
310 /* public AlignmentOrder(AlignmentI orderThis, AlignmentI byThat)
\r
312 // Vector is an ordering of this alignment using the order of sequence objects in byThat,
\r
313 // where ids and unaligned sequences must match
\r