1 package jalview.analysis;
3 import static org.junit.Assert.assertEquals;
4 import static org.junit.Assert.assertNull;
6 import org.junit.Before;
9 import jalview.datamodel.Alignment;
10 import jalview.datamodel.AlignmentAnnotation;
11 import jalview.datamodel.Sequence;
12 import jalview.datamodel.SequenceI;
14 public class ParsePropertiesTest
19 private ParseProperties pp;
22 * Construct an alignment with 4 sequences with varying description format
27 SequenceI[] seqs = new SequenceI[]
28 { new Sequence("sq1", "THISISAPLACEHOLDER"),
29 new Sequence("sq2", "THISISAPLACEHOLDER"),
30 new Sequence("sq3", "THISISAPLACEHOLDER"),
31 new Sequence("sq4", "THISISAPLACEHOLDER") };
32 seqs[0].setDescription("1 mydescription1");
33 seqs[1].setDescription("mydescription2");
34 seqs[2].setDescription("2. 0.1 mydescription+3");
35 seqs[3].setDescription("3 0.01 mydescription4");
36 al = new Alignment(seqs);
38 pp = new ParseProperties(al);
43 * Test with a description pattern that matches any string ending in one or
44 * more 'number characters' (0-9+.), i.e. greedily matches any trailing
45 * numeric part of the string
48 public void testGetScoresFromDescription()
50 // TODO - test the regex actually used by Jalview?
52 // see AlignFrame.extractScores_actionPerformed
53 String regex = ".*([-0-9.+]+)";
54 final int count = pp.getScoresFromDescription("my Score",
55 "my Score Description", regex, true);
56 System.out.println("Matched " + count + " for " + regex);
57 assertEquals(4, count);
60 * Verify values 1/2/3/4 have been parsed from sequence descriptions
62 AlignmentAnnotation[] anns = al.getSequenceAt(0).getAnnotation();
63 assertEquals(1, anns.length);
64 assertEquals(1d, anns[0].getScore(), 0.001d);
65 assertEquals("my Score Description", anns[0].description);
66 assertEquals("my Score", anns[0].label);
67 anns = al.getSequenceAt(1).getAnnotation();
68 assertEquals(1, anns.length);
69 assertEquals(2d, anns[0].getScore(), 0.001d);
70 assertEquals("my Score Description", anns[0].description);
71 assertEquals("my Score", anns[0].label);
72 anns = al.getSequenceAt(2).getAnnotation();
73 assertEquals(1, anns.length);
74 assertEquals(3d, anns[0].getScore(), 0.001d);
75 anns = al.getSequenceAt(3).getAnnotation();
76 assertEquals(1, anns.length);
77 assertEquals(4d, anns[0].getScore(), 0.001d);
81 * Test with a description pattern that matches any string (or none), followed
82 * by a 'number character' (0-9+.), followed by at least one separator
83 * character, followed by at least one 'number character', then any trailing
87 public void testGetScoresFromDescription_twoScores()
89 String regex = ".*([-0-9.+]+).+([-0-9.+]+).*";
90 final int count = pp.getScoresFromDescription("my Score",
91 "my Score Description", regex, true);
92 System.out.println("Matched " + count + " for " + regex);
93 assertEquals(3, count);
96 * Seq1 has two score values parsed out
98 AlignmentAnnotation[] anns = al.getSequenceAt(0).getAnnotation();
99 assertEquals(2, anns.length);
100 assertEquals(1d, anns[0].getScore(), 0.001d);
101 assertEquals("my Score Description", anns[0].description);
102 assertEquals("my Score", anns[0].label);
103 assertEquals(1d, anns[1].getScore(), 0.001d);
104 assertEquals("my Score Description (column 1)", anns[1].description);
105 assertEquals("my Score_1", anns[1].label);
108 * Seq2 has no score parsed out (is this right?)
110 assertNull(al.getSequenceAt(1).getAnnotation());
113 * Seq3 has two score values parsed out
115 // TODO parsed values (1.0 and 3.0) look wrong v description
116 // would expect 2.0 and 0.1
117 // undesired 'greedy' behaviour of regex?
118 anns = al.getSequenceAt(2).getAnnotation();
119 assertEquals(2, anns.length);
120 assertEquals(1d, anns[0].getScore(), 0.001d);
121 assertEquals("my Score Description", anns[0].description);
122 assertEquals("my Score", anns[0].label);
123 assertEquals(3d, anns[1].getScore(), 0.001d);
124 assertEquals("my Score Description (column 1)", anns[1].description);
125 assertEquals("my Score_1", anns[1].label);
128 * Seq3 has two score values parsed out
130 // TODO parsed values (1.0 and 4.0) look wrong v description
131 // would expect 3 and 0.01
132 anns = al.getSequenceAt(3).getAnnotation();
133 assertEquals(2, anns.length);
134 assertEquals(1d, anns[0].getScore(), 0.001d);
135 assertEquals("my Score Description", anns[0].description);
136 assertEquals("my Score", anns[0].label);
137 assertEquals(4d, anns[1].getScore(), 0.001d);
138 assertEquals("my Score Description (column 1)", anns[1].description);
139 assertEquals("my Score_1", anns[1].label);