1. Project Clover database Fri Dec 6 2024 13:47:14 GMT
  2. Package jalview.datamodel

File AlignmentOrder.java

 

Coverage histogram

../../img/srcFileCovDistChart1.png
56% of files have more coverage

Code metrics

30
50
15
1
332
162
34
0.68
3.33
15
2.27

Classes

Class
Line #
Actions
AlignmentOrder 27 50 34
0.0421052654.2%
 

Contributing tests

No tests hitting this source file were found.

Source view

1    /*
2    * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3    * Copyright (C) $$Year-Rel$$ The Jalview Authors
4    *
5    * This file is part of Jalview.
6    *
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.
11    *
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.
16    *
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.
20    */
21    package jalview.datamodel;
22   
23    import java.util.ArrayList;
24    import java.util.Arrays;
25    import java.util.List;
26   
 
27    public class AlignmentOrder
28    {
29    // JBPNote : this method would return a vector containing all sequences in
30    // seqset
31    // with those also contained in order at the beginning of the vector in the
32    // order
33    // given by order. AlignmentSorter.vectorSubsetToArray already does this, but
34    // that method
35    // should be here for completeness.
36   
37    /*
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; }
41    */
42   
43    /** DOCUMENT ME!! */
44    public static final int FILE = 0;
45   
46    /** DOCUMENT ME!! */
47    public static final int MSA = 1;
48   
49    /** DOCUMENT ME!! */
50    public static final int USER = 2;
51   
52    private int Type = 0;
53   
54    private String Name;
55   
56    private List<SequenceI> Order = null;
57   
58    /**
59    * Creates a new AlignmentOrder object.
60    */
 
61  0 toggle public AlignmentOrder()
62    {
63    }
64   
65    /**
66    * AlignmentOrder
67    *
68    * @param anOrder
69    */
 
70  0 toggle public AlignmentOrder(List<SequenceI> anOrder)
71    {
72  0 Order = anOrder;
73    }
74   
75    /**
76    * AlignmentOrder
77    *
78    * @param orderFrom
79    * AlignmentI
80    */
 
81  3 toggle public AlignmentOrder(AlignmentI orderFrom)
82    {
83  3 Order = new ArrayList<SequenceI>();
84   
85  3 for (SequenceI seq : orderFrom.getSequences())
86    {
87  99 Order.add(seq);
88    }
89    }
90   
91    /**
92    * Creates a new AlignmentOrder object.
93    *
94    * @param orderFrom
95    * DOCUMENT ME!
96    */
 
97  0 toggle public AlignmentOrder(SequenceI[] orderFrom)
98    {
99  0 Order = new ArrayList<SequenceI>(Arrays.asList(orderFrom));
100    }
101   
102    /**
103    * DOCUMENT ME!
104    *
105    * @param Type
106    * DOCUMENT ME!
107    */
 
108  0 toggle public void setType(int Type)
109    {
110  0 this.Type = Type;
111    }
112   
113    /**
114    * DOCUMENT ME!
115    *
116    * @return DOCUMENT ME!
117    */
 
118  0 toggle public int getType()
119    {
120  0 return Type;
121    }
122   
123    /**
124    * DOCUMENT ME!
125    *
126    * @param Name
127    * DOCUMENT ME!
128    */
 
129  0 toggle public void setName(String Name)
130    {
131  0 this.Name = Name;
132    }
133   
134    /**
135    * DOCUMENT ME!
136    *
137    * @return DOCUMENT ME!
138    */
 
139  0 toggle public String getName()
140    {
141  0 return Name;
142    }
143   
144    /**
145    * DOCUMENT ME!
146    *
147    * @param Order
148    * DOCUMENT ME!
149    */
 
150  0 toggle public void setOrder(List<SequenceI> Order)
151    {
152  0 this.Order = Order;
153    }
154   
155    /**
156    * DOCUMENT ME!
157    *
158    * @return DOCUMENT ME!
159    */
 
160  0 toggle public List<SequenceI> getOrder()
161    {
162  0 return Order;
163    }
164   
165    /**
166    * replaces oldref with newref in the alignment order.
167    *
168    * @param oldref
169    * @param newref
170    * @return true if oldref was contained in order and replaced with newref
171    */
 
172  0 toggle public boolean updateSequence(SequenceI oldref, SequenceI newref)
173    {
174  0 int found = Order.indexOf(oldref);
175  0 if (found > -1)
176    {
177  0 Order.set(found, newref);
178    }
179  0 return found > -1;
180    }
181   
182    /**
183    * Exact equivalence of two AlignmentOrders
184    *
185    * @param o
186    * @return true if o orders the same sequenceI objects in the same way
187    */
 
188  0 toggle @Override
189    public boolean equals(Object o)
190    {
191  0 if (o == null || !(o instanceof AlignmentOrder))
192    {
193  0 return false;
194    }
195  0 return equals((AlignmentOrder) o, true);
196    }
197   
198    /**
199    * Exact equivalence of two AlignmentOrders // TODO: Weak SequenceI
200    * equivalence - will throw Error at moment
201    *
202    * @param o
203    * @param identity
204    * - false - use weak equivalence (refers to same or different parts
205    * of same sequence)
206    * @return true if o orders equivalent sequenceI objects in the same way
207    */
 
208  0 toggle public boolean equals(AlignmentOrder o, boolean identity)
209    {
210  0 if (o != this)
211    {
212  0 if (o == null)
213    {
214  0 return false;
215    }
216  0 if (Order != null && o.Order != null
217    && Order.size() == o.Order.size())
218    {
219  0 if (!identity)
220    {
221  0 throw new Error(
222    "Weak sequenceI equivalence not yet implemented.");
223    }
224    else
225    {
226  0 for (int i = 0, j = o.Order.size(); i < j; i++)
227    {
228  0 if (Order.get(i) != o.Order.get(i))
229    {
230  0 return false;
231    }
232    }
233    }
234    }
235    else
236    {
237  0 return false;
238    }
239    }
240  0 return true;
241    }
242   
243    /**
244    * Consistency test for alignmentOrders
245    *
246    * @param o
247    * @return true if o contains or is contained by this and the common SequenceI
248    * objects are ordered in the same way
249    */
 
250  0 toggle public boolean isConsistent(AlignmentOrder o)
251    {
252  0 return isConsistent(o, true);
253    }
254   
255    /**
256    * Consistency test for alignmentOrders
257    *
258    * @param o
259    * // TODO: Weak SequenceI equivalence - will throw Error at moment
260    * @param identity
261    * - false - use weak equivalence (refers to same or different parts
262    * of same sequence)
263    * @return true if o contains or is contained by this and the common SequenceI
264    * objects are ordered in the same way
265    */
 
266  0 toggle public boolean isConsistent(AlignmentOrder o, boolean identity)
267    {
268  0 if (o != this)
269    {
270  0 if (o == null)
271    {
272  0 return false;
273    }
274  0 if (Order != null && o.Order != null)
275    {
276  0 List<SequenceI> c, s;
277  0 if (o.Order.size() > Order.size())
278    {
279  0 c = o.Order;
280  0 s = Order;
281    }
282    else
283    {
284  0 c = Order;
285  0 s = o.Order;
286    }
287  0 if (!identity)
288    {
289  0 throw new Error(
290    "Weak sequenceI equivalence not yet implemented.");
291    }
292    else
293    {
294    // test if c contains s and order in s is conserved in c
295  0 int last = -1;
296  0 for (int i = 0, j = s.size(); i < j; i++)
297    {
298  0 int pos = c.indexOf(s.get(i)); // JBPNote - optimize by
299    // incremental position search
300  0 if (pos > last)
301    {
302  0 last = pos;
303    }
304    else
305    {
306  0 return false;
307    }
308    }
309    }
310    }
311    else
312    {
313  0 return false;
314    }
315    }
316  0 return true;
317    }
318    /**
319    * AlignmentOrder
320    *
321    * @param orderThis
322    * AlignmentI
323    * @param byThat
324    * AlignmentI
325    */
326   
327    /*
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 }
331    */
332    }