Clover icon

Coverage Report

  1. Project Clover database Wed Nov 6 2024 00:56:24 GMT
  2. Package jalview.analysis

File AlignmentSorterTest.java

 

Code metrics

0
48
2
1
153
84
2
0.04
24
2
1

Classes

Class Line # Actions
AlignmentSorterTest 38 48 2
1.0100%
 

Contributing tests

This file is covered by 2 tests. .

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.analysis;
22   
23    import static org.testng.Assert.assertSame;
24   
25    import jalview.datamodel.Alignment;
26    import jalview.datamodel.AlignmentI;
27    import jalview.datamodel.Sequence;
28    import jalview.datamodel.SequenceFeature;
29    import jalview.datamodel.SequenceI;
30   
31    import java.util.Arrays;
32    import java.util.List;
33   
34    import junit.extensions.PA;
35   
36    import org.testng.annotations.Test;
37   
 
38    public class AlignmentSorterTest
39    {
 
40  1 toggle @Test(groups = "Functional")
41    public void testSortByFeature_score()
42    {
43  1 SequenceI seq1 = new Sequence("Seq1", "ABC--D-EFGHIJ");
44  1 SequenceI seq2 = new Sequence("Seq2", "ABCDEFGHIJ");
45  1 SequenceI seq3 = new Sequence("Seq3", "ABCDE-FGHIJ");
46  1 SequenceI seq4 = new Sequence("Seq4", "ABCDEFGHIJ");
47  1 SequenceI[] seqs = new SequenceI[] { seq1, seq2, seq3, seq4 };
48  1 AlignmentI al = new Alignment(seqs);
49  1 al.setDataset(null);
50   
51    /*
52    * sort with no score features does nothing
53    */
54  1 PA.setValue(AlignmentSorter.class, "sortByFeatureCriteria", null);
55   
56  1 AlignmentSorter.sortByFeature(null, null, 0, al.getWidth(), al,
57    AlignmentSorter.FEATURE_SCORE);
58  1 assertSame(al.getSequenceAt(0), seq1);
59  1 assertSame(al.getSequenceAt(1), seq2);
60  1 assertSame(al.getSequenceAt(2), seq3);
61  1 assertSame(al.getSequenceAt(3), seq4);
62   
63    /*
64    * add score and non-score features
65    * seq1 Cath(2.0) Pfam(4.0) average 3.0
66    * seq2 Cath(2.5) Metal(NaN) average 2.5
67    * seq3 KD(-4), KD(3.0) average -0.5
68    * seq4 Helix(NaN) - should sort as if largest score
69    */
70  1 seq1.addSequenceFeature(
71    new SequenceFeature("Cath", "", 2, 3, 2.0f, "g1"));
72  1 seq1.addSequenceFeature(
73    new SequenceFeature("Pfam", "", 4, 5, 4.0f, "g2"));
74  1 seq2.addSequenceFeature(
75    new SequenceFeature("Cath", "", 2, 3, 2.5f, "g3"));
76  1 seq2.addSequenceFeature(
77    new SequenceFeature("Metal", "", 2, 3, Float.NaN, "g4"));
78  1 seq3.addSequenceFeature(new SequenceFeature("kD", "", 2, 3, -4f, "g5"));
79  1 seq3.addSequenceFeature(
80    new SequenceFeature("kD", "", 5, 6, 3.0f, "g6"));
81  1 seq4.addSequenceFeature(
82    new SequenceFeature("Helix", "", 2, 3, Float.NaN, "g7"));
83   
84    /*
85    * sort by ascending score, no filter on feature type or group
86    * NB sort order for the same feature set (none) gets toggled, so descending
87    */
88  1 PA.setValue(AlignmentSorter.class, "sortByFeatureAscending", true);
89  1 AlignmentSorter.sortByFeature(null, null, 0, al.getWidth(), al,
90    AlignmentSorter.FEATURE_SCORE);
91  1 assertSame(al.getSequenceAt(3), seq3); // -0.5
92  1 assertSame(al.getSequenceAt(2), seq2); // 2.5
93  1 assertSame(al.getSequenceAt(1), seq1); // 3.0
94  1 assertSame(al.getSequenceAt(0), seq4); // maximum 'score'
95   
96    /*
97    * repeat sort toggles order - now ascending
98    */
99  1 AlignmentSorter.sortByFeature(null, null, 0, al.getWidth(), al,
100    AlignmentSorter.FEATURE_SCORE);
101  1 assertSame(al.getSequenceAt(0), seq3); // -0.5
102  1 assertSame(al.getSequenceAt(1), seq2); // 2.5
103  1 assertSame(al.getSequenceAt(2), seq1); // 3.0
104  1 assertSame(al.getSequenceAt(3), seq4);
105   
106    /*
107    * specify features, excluding Pfam
108    * seq1 average is now 2.0
109    * next sort is ascending (not toggled) as for a different feature set
110    */
111  1 List<String> types = Arrays.asList(new String[] { "Cath", "kD" });
112  1 AlignmentSorter.sortByFeature(types, null, 0, al.getWidth(), al,
113    AlignmentSorter.FEATURE_SCORE);
114  1 assertSame(al.getSequenceAt(0), seq3); // -0.5
115  1 assertSame(al.getSequenceAt(1), seq1); // 2.0
116  1 assertSame(al.getSequenceAt(2), seq2); // 2.5
117  1 assertSame(al.getSequenceAt(3), seq4);
118   
119    /*
120    * specify groups, excluding g5 (kD -4 score)
121    * seq3 average is now 3.0
122    * next sort is ascending (not toggled) as for a different group spec
123    */
124  1 List<String> groups = Arrays
125    .asList(new String[]
126    { "g1", "g2", "g3", "g6" });
127  1 AlignmentSorter.sortByFeature(types, groups, 0, al.getWidth(), al,
128    AlignmentSorter.FEATURE_SCORE);
129  1 assertSame(al.getSequenceAt(0), seq1); // 2.0
130  1 assertSame(al.getSequenceAt(1), seq2); // 2.5
131  1 assertSame(al.getSequenceAt(2), seq3); // 3.0
132  1 assertSame(al.getSequenceAt(3), seq4);
133   
134    /*
135    * limit to columns 0-4, excluding 2nd feature of seq1 and seq3
136    * seq1 is now 2.0, seq3 is now -4
137    */
138    // fails because seq1.findPosition(4) returns 4
139    // although residue 4 is in column 5! - JAL-2544
140  1 AlignmentSorter.sortByFeature(null, null, 0, 4, al,
141    AlignmentSorter.FEATURE_SCORE);
142  1 assertSame(al.getSequenceAt(0), seq3); // -4
143  1 assertSame(al.getSequenceAt(1), seq1); // 2.0
144  1 assertSame(al.getSequenceAt(2), seq2); // 2.5
145  1 assertSame(al.getSequenceAt(3), seq4);
146    }
147   
 
148  1 toggle @Test(groups = "Functional")
149    public void testSortByFeature_density()
150    {
151    // TODO
152    }
153    }