2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2006 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
27 * <p>Description: </p>
\r
29 * <p>Copyright: Copyright (c) 2004</p>
\r
31 * <p>Company: Dundee University</p>
\r
33 * @author not attributable
\r
36 public class AlignmentOrder
\r
38 // JBPNote : this method would return a vector containing all sequences in seqset
\r
39 // with those also contained in order at the beginning of the vector in the order
\r
40 // given by order. AlignmentSorter.vectorSubsetToArray already does this, but that method
\r
41 // should be here for completeness.
\r
43 /* public Vector getOrder(AlignmentI seqset)
\r
45 Vector perm = new Vector(seqset.getHeight());
\r
46 for (i=0, o = 0, n=seqset.getHeight(), p = Order.size(); i<n; i++)
\r
47 perm.setElement(i,...).
\r
52 /** DOCUMENT ME!! */
\r
53 public static final int FILE = 0;
\r
55 /** DOCUMENT ME!! */
\r
56 public static final int MSA = 1;
\r
58 /** DOCUMENT ME!! */
\r
59 public static final int USER = 2;
\r
60 private int Type = 0;
\r
61 private String Name;
\r
62 private Vector Order = null;
\r
65 * Creates a new AlignmentOrder object.
\r
67 public AlignmentOrder()
\r
74 * @param anOrder Vector
\r
76 public AlignmentOrder(Vector anOrder)
\r
84 * @param orderFrom AlignmentI
\r
86 public AlignmentOrder(AlignmentI orderFrom)
\r
88 Order = new Vector();
\r
90 for (int i = 0, ns = orderFrom.getHeight(); i < ns; i++)
\r
92 Order.addElement(orderFrom.getSequenceAt(i));
\r
97 * Creates a new AlignmentOrder object.
\r
99 * @param orderFrom DOCUMENT ME!
\r
101 public AlignmentOrder(SequenceI[] orderFrom)
\r
103 Order = new Vector();
\r
105 for (int i = 0, ns = orderFrom.length; i < ns; i++)
\r
107 Order.addElement(orderFrom[i]);
\r
114 * @param Type DOCUMENT ME!
\r
116 public void setType(int Type)
\r
124 * @return DOCUMENT ME!
\r
126 public int getType()
\r
134 * @param Name DOCUMENT ME!
\r
136 public void setName(String Name)
\r
144 * @return DOCUMENT ME!
\r
146 public String getName()
\r
154 * @param Order DOCUMENT ME!
\r
156 public void setOrder(Vector Order)
\r
158 this.Order = Order;
\r
164 * @return DOCUMENT ME!
\r
166 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
177 int found=Order.indexOf(oldref);
\r
179 Order.setElementAt(newref, found);
\r
184 * Exact equivalence of two AlignmentOrders
\r
186 * @return true if o orders the same sequenceI objects in the same way
\r
188 public boolean equals(AlignmentOrder o) {
\r
189 return equals(o, true);
\r
192 * Exact equivalence of two AlignmentOrders
\r
193 * // TODO: Weak SequenceI equivalence - will throw Error at moment
\r
195 * @param identity - false - use weak equivalence (refers to same or different parts of same sequence)
\r
196 * @return true if o orders equivalent sequenceI objects in the same way
\r
198 public boolean equals(AlignmentOrder o, boolean identity) {
\r
202 if (Order!=null && o.Order!=null && Order.size()==o.Order.size()) {
\r
204 throw new Error("Weak sequenceI equivalence not yet implemented.");
\r
206 for (int i=0,j=o.Order.size(); i<j; i++) {
\r
207 if (Order.elementAt(i)!=o.Order.elementAt(i))
\r
217 * Consistency test for alignmentOrders
\r
219 * @return true if o contains or is contained by this and the common SequenceI objects are ordered in the same way
\r
221 public boolean isConsistent(AlignmentOrder o) {
\r
222 return isConsistent(o, true);
\r
225 * Consistency test for alignmentOrders
\r
227 * // TODO: Weak SequenceI equivalence - will throw Error at moment
\r
228 * @param identity - false - use weak equivalence (refers to same or different parts of same sequence)
\r
229 * @return true if o contains or is contained by this and the common SequenceI objects are ordered in the same way
\r
231 public boolean isConsistent(AlignmentOrder o, boolean identity) {
\r
235 if (Order!=null && o.Order!=null) {
\r
237 if (o.Order.size()>Order.size()) {
\r
245 throw new Error("Weak sequenceI equivalence not yet implemented.");
\r
247 // test if c contains s and order in s is conserved in c
\r
249 for (int i=0,j=s.size(); i<j; i++) {
\r
250 int pos=c.indexOf(s.elementAt(i)); // JBPNote - optimize by incremental position search
\r
265 * @param orderThis AlignmentI
\r
266 * @param byThat AlignmentI
\r
269 /* public AlignmentOrder(AlignmentI orderThis, AlignmentI byThat)
\r
271 // Vector is an ordering of this alignment using the order of sequence objects in byThat,
\r
272 // where ids and unaligned sequences must match
\r