93170b7ef7ac9b2d0ffdbefda9080092e9ebd586
[jalview.git] / test / jalview / datamodel / AlignmentTest.java
1 package jalview.datamodel;
2
3 import static org.junit.Assert.assertEquals;
4 import static org.junit.Assert.assertFalse;
5 import static org.junit.Assert.assertTrue;
6 import jalview.io.AppletFormatAdapter;
7
8 import java.io.IOException;
9 import java.util.Iterator;
10
11 import org.junit.Before;
12 import org.junit.Test;
13
14 /**
15  * Unit tests for Alignment datamodel.
16  * 
17  * @author gmcarstairs
18  *
19  */
20 public class AlignmentTest
21 {
22   // @formatter:off
23   private static final String TEST_DATA = 
24           "# STOCKHOLM 1.0\n" +
25           "#=GS D.melanogaster.1 AC AY119185.1/838-902\n" +
26           "#=GS D.melanogaster.2 AC AC092237.1/57223-57161\n" +
27           "#=GS D.melanogaster.3 AC AY060611.1/560-627\n" +
28           "D.melanogaster.1          G.AGCC.CU...AUGAUCGA\n" +
29           "#=GR D.melanogaster.1 SS  ................((((\n" +
30           "D.melanogaster.2          C.AUUCAACU.UAUGAGGAU\n" +
31           "#=GR D.melanogaster.2 SS  ................((((\n" +
32           "D.melanogaster.3          G.UGGCGCU..UAUGACGCA\n" +
33           "#=GR D.melanogaster.3 SS  (.(((...(....(((((((\n" +
34           "//";
35   // @formatter:on
36
37
38   private Alignment al;
39
40   /*
41    * Read in Stockholm format test data including secondary structure
42    * annotations.
43    */
44   @Before
45   public void setUp() throws IOException
46   {
47     al = new jalview.io.FormatAdapter().readFile(TEST_DATA,
48             AppletFormatAdapter.PASTE, "STH");
49     for (int i = 0; i < al.getSequencesArray().length; ++i)
50     {
51       al.addAnnotation(al.getSequenceAt(i).getAnnotation()[0]);
52       al.getSequenceAt(i).getAnnotation()[0].setCalcId("CalcIdFor"
53               + al.getSequenceAt(i).getName());
54     }
55   }
56
57   /**
58    * Test method that returns annotations that match on calcId.
59    */
60   @Test
61   public void testFindAnnotation_byCalcId()
62   {
63     Iterable<AlignmentAnnotation> anns = al
64             .findAnnotation("CalcIdForD.melanogaster.2");
65     Iterator<AlignmentAnnotation> iter = anns.iterator();
66     assertTrue(iter.hasNext());
67     AlignmentAnnotation ann = iter.next();
68     assertEquals("D.melanogaster.2", ann.sequenceRef.getName());
69     assertFalse(iter.hasNext());
70   }
71 }