| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
|
| 21 |
|
package jalview.io; |
| 22 |
|
|
| 23 |
|
import static org.testng.AssertJUnit.assertEquals; |
| 24 |
|
import static org.testng.AssertJUnit.assertNotNull; |
| 25 |
|
import static org.testng.AssertJUnit.assertTrue; |
| 26 |
|
|
| 27 |
|
import java.awt.Color; |
| 28 |
|
import java.io.File; |
| 29 |
|
import java.util.Hashtable; |
| 30 |
|
import java.util.List; |
| 31 |
|
|
| 32 |
|
import org.testng.Assert; |
| 33 |
|
import org.testng.annotations.BeforeClass; |
| 34 |
|
import org.testng.annotations.Test; |
| 35 |
|
|
| 36 |
|
import jalview.datamodel.AlignmentI; |
| 37 |
|
import jalview.datamodel.HiddenColumns; |
| 38 |
|
import jalview.datamodel.SequenceGroup; |
| 39 |
|
import jalview.gui.AlignFrame; |
| 40 |
|
import jalview.gui.JvOptionPane; |
| 41 |
|
import jalview.io.AnnotationFile.ViewDef; |
| 42 |
|
|
| |
|
| 92.1% |
Uncovered Elements: 5 (63) |
Complexity: 8 |
Complexity Density: 0.14 |
|
| 43 |
|
public class AnnotationFileIOTest |
| 44 |
|
{ |
| 45 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 46 |
1 |
@BeforeClass(alwaysRun = true)... |
| 47 |
|
public void setUpJvOptionPane() |
| 48 |
|
{ |
| 49 |
1 |
JvOptionPane.setInteractiveMode(false); |
| 50 |
1 |
JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION); |
| 51 |
|
} |
| 52 |
|
|
| 53 |
|
static String TestFiles[][] = { { "Test example annotation import/export", |
| 54 |
|
"examples/uniref50.fa", "examples/testdata/example_annot_file.jva" }, |
| 55 |
|
{ "Test multiple combine annotation statements import/export", |
| 56 |
|
"examples/uniref50.fa", |
| 57 |
|
"examples/testdata/test_combine_annot.jva" }, |
| 58 |
|
{ "Test multiple combine annotation statements with sequence_ref import/export", |
| 59 |
|
"examples/uniref50.fa", "examples/testdata/uniref50_iupred.jva" }, |
| 60 |
|
{ "Test group only annotation file parsing results in parser indicating annotation was parsed", |
| 61 |
|
"examples/uniref50.fa", "examples/testdata/test_grpannot.jva" }, |
| 62 |
|
{ "Test hiding/showing of insertions on sequence_ref", |
| 63 |
|
"examples/uniref50.fa", |
| 64 |
|
"examples/testdata/uniref50_seqref.jva" } }; |
| 65 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
| 66 |
1 |
@Test(groups = { "Functional" })... |
| 67 |
|
public void exampleAnnotationFileIO() throws Exception |
| 68 |
|
{ |
| 69 |
1 |
for (String[] testPair : TestFiles) |
| 70 |
|
{ |
| 71 |
5 |
testAnnotationFileIO(testPair[0], new File(testPair[1]), |
| 72 |
|
new File(testPair[2])); |
| 73 |
|
} |
| 74 |
|
} |
| 75 |
|
|
| |
|
| 78.6% |
Uncovered Elements: 3 (14) |
Complexity: 3 |
Complexity Density: 0.25 |
|
| 76 |
10 |
protected AlignmentI readAlignmentFile(File f)... |
| 77 |
|
{ |
| 78 |
10 |
System.out.println("Reading file: " + f); |
| 79 |
10 |
String ff = f.getPath(); |
| 80 |
10 |
try |
| 81 |
|
{ |
| 82 |
10 |
FormatAdapter rf = new FormatAdapter(); |
| 83 |
|
|
| 84 |
10 |
AlignmentI al = rf.readFile(ff, DataSourceType.FILE, |
| 85 |
|
new IdentifyFile().identify(ff, DataSourceType.FILE)); |
| 86 |
|
|
| 87 |
|
|
| 88 |
160 |
for (int i = 0; i < al.getSequencesArray().length; ++i) |
| 89 |
|
{ |
| 90 |
150 |
al.getSequenceAt(i).createDatasetSequence(); |
| 91 |
|
} |
| 92 |
10 |
assertNotNull("Couldn't read supplied alignment data.", al); |
| 93 |
10 |
return al; |
| 94 |
|
} catch (Exception e) |
| 95 |
|
{ |
| 96 |
0 |
e.printStackTrace(); |
| 97 |
|
} |
| 98 |
0 |
Assert.fail( |
| 99 |
|
"Couln't read the alignment in file '" + f.toString() + "'"); |
| 100 |
0 |
return null; |
| 101 |
|
} |
| 102 |
|
|
| 103 |
|
|
| 104 |
|
|
| 105 |
|
|
| 106 |
|
|
| 107 |
|
@param |
| 108 |
|
|
| 109 |
|
@param |
| 110 |
|
|
| 111 |
|
|
| 112 |
|
|
| |
|
| 88.9% |
Uncovered Elements: 2 (18) |
Complexity: 2 |
Complexity Density: 0.11 |
|
| 113 |
5 |
void testAnnotationFileIO(String testname, File f, File annotFile)... |
| 114 |
|
{ |
| 115 |
5 |
System.out.println("Test: " + testname + "\nReading annotation file '" |
| 116 |
|
+ annotFile + "' onto : " + f); |
| 117 |
5 |
String af = annotFile.getPath(); |
| 118 |
5 |
try |
| 119 |
|
{ |
| 120 |
5 |
AlignmentI al = readAlignmentFile(f); |
| 121 |
5 |
HiddenColumns cs = new HiddenColumns(); |
| 122 |
5 |
assertTrue("Test " + testname |
| 123 |
|
+ "\nAlignment was not annotated - annotation file not imported.", |
| 124 |
|
new AnnotationFile().readAnnotationFile(al, cs, af, |
| 125 |
|
DataSourceType.FILE)); |
| 126 |
|
|
| 127 |
5 |
AnnotationFile aff = new AnnotationFile(); |
| 128 |
|
|
| 129 |
5 |
ViewDef v = aff.new ViewDef(null, al.getHiddenSequences(), cs, |
| 130 |
|
new Hashtable()); |
| 131 |
5 |
String anfileout = new AnnotationFile().printAnnotations( |
| 132 |
|
al.getAlignmentAnnotation(), al.getGroups(), |
| 133 |
|
al.getProperties(), null, al, v); |
| 134 |
5 |
assertTrue("Test " + testname |
| 135 |
|
+ "\nAlignment annotation file was not regenerated. Null string", |
| 136 |
|
anfileout != null); |
| 137 |
5 |
assertTrue("Test " + testname |
| 138 |
|
+ "\nAlignment annotation file was not regenerated. Empty string", |
| 139 |
|
anfileout.length() > "JALVIEW_ANNOTATION".length()); |
| 140 |
|
|
| 141 |
5 |
System.out.println( |
| 142 |
|
"Output annotation file:\n" + anfileout + "\n<<EOF\n"); |
| 143 |
|
|
| 144 |
5 |
AlignmentI al_new = readAlignmentFile(f); |
| 145 |
5 |
assertTrue("Test " + testname |
| 146 |
|
+ "\nregenerated annotation file did not annotate alignment.", |
| 147 |
|
new AnnotationFile().readAnnotationFile(al_new, anfileout, |
| 148 |
|
DataSourceType.PASTE)); |
| 149 |
|
|
| 150 |
|
|
| 151 |
5 |
StockholmFileTest.testAlignmentEquivalence(al, al_new, false, false, |
| 152 |
|
false); |
| 153 |
5 |
return; |
| 154 |
|
} catch (Exception e) |
| 155 |
|
{ |
| 156 |
0 |
e.printStackTrace(); |
| 157 |
|
} |
| 158 |
0 |
Assert.fail("Test " + testname |
| 159 |
|
+ "\nCouldn't complete Annotation file roundtrip input/output/input test for '" |
| 160 |
|
+ annotFile + "'."); |
| 161 |
|
} |
| 162 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (22) |
Complexity: 1 |
Complexity Density: 0.05 |
1PASS
|
|
| 163 |
1 |
@Test(groups = "Functional")... |
| 164 |
|
public void testAnnotateAlignmentView() |
| 165 |
|
{ |
| 166 |
1 |
long t1 = System.currentTimeMillis(); |
| 167 |
|
|
| 168 |
|
|
| 169 |
|
|
| 170 |
1 |
AlignFrame af = new FileLoader().LoadFileWaitTillLoaded( |
| 171 |
|
">Seq1\nQRSIL\n>Seq2\nFTHND\n>Seq3\nRPVSL\n", |
| 172 |
|
DataSourceType.PASTE); |
| 173 |
1 |
long t2 = System.currentTimeMillis(); |
| 174 |
1 |
System.err.println("t0: " + (t2 - t1)); |
| 175 |
|
|
| 176 |
1 |
String annotationFile = "JALVIEW_ANNOTATION\nSEQUENCE_GROUP\tGroup1\t*\t*\t1\n" |
| 177 |
|
+ "SEQUENCE_GROUP\tGroup2\t*\t*\t2\n" |
| 178 |
|
+ "SEQUENCE_GROUP\tGroup1\t*\t*\t3\n" |
| 179 |
|
+ "PROPERTIES\tGroup1\toutlineColour=blue\tidColour=red\n"; |
| 180 |
1 |
new AnnotationFile().annotateAlignmentView(af.getViewport(), |
| 181 |
|
annotationFile, DataSourceType.PASTE); |
| 182 |
|
|
| 183 |
1 |
AlignmentI al = af.getViewport().getAlignment(); |
| 184 |
1 |
List<SequenceGroup> groups = al.getGroups(); |
| 185 |
1 |
assertEquals(3, groups.size()); |
| 186 |
1 |
SequenceGroup sg = groups.get(0); |
| 187 |
1 |
assertEquals("Group1", sg.getName()); |
| 188 |
1 |
assertTrue(sg.contains(al.getSequenceAt(0))); |
| 189 |
1 |
assertEquals(Color.BLUE, sg.getOutlineColour()); |
| 190 |
1 |
assertEquals(Color.RED, sg.getIdColour()); |
| 191 |
1 |
sg = groups.get(1); |
| 192 |
1 |
assertEquals("Group2", sg.getName()); |
| 193 |
1 |
assertTrue(sg.contains(al.getSequenceAt(1))); |
| 194 |
|
|
| 195 |
|
|
| 196 |
|
|
| 197 |
|
|
| 198 |
1 |
sg = groups.get(2); |
| 199 |
1 |
assertEquals("Group1", sg.getName()); |
| 200 |
1 |
assertTrue(sg.contains(al.getSequenceAt(2))); |
| 201 |
1 |
assertEquals(Color.BLUE, sg.getOutlineColour()); |
| 202 |
1 |
assertEquals(Color.RED, sg.getIdColour()); |
| 203 |
|
} |
| 204 |
|
} |