1 package jalview.datamodel;
3 import static org.junit.Assert.assertEquals;
4 import static org.junit.Assert.assertFalse;
5 import static org.junit.Assert.assertTrue;
6 import static org.junit.Assert.fail;
7 import jalview.io.AppletFormatAdapter;
8 import jalview.io.FormatAdapter;
10 import java.io.IOException;
11 import java.util.Iterator;
13 import org.junit.Before;
14 import org.junit.Test;
17 * Unit tests for Alignment datamodel.
22 public class AlignmentTest
25 private static final String TEST_DATA =
27 "#=GS D.melanogaster.1 AC AY119185.1/838-902\n" +
28 "#=GS D.melanogaster.2 AC AC092237.1/57223-57161\n" +
29 "#=GS D.melanogaster.3 AC AY060611.1/560-627\n" +
30 "D.melanogaster.1 G.AGCC.CU...AUGAUCGA\n" +
31 "#=GR D.melanogaster.1 SS ................((((\n" +
32 "D.melanogaster.2 C.AUUCAACU.UAUGAGGAU\n" +
33 "#=GR D.melanogaster.2 SS ................((((\n" +
34 "D.melanogaster.3 G.UGGCGCU..UAUGACGCA\n" +
35 "#=GR D.melanogaster.3 SS (.(((...(....(((((((\n" +
38 private static final String TEST_DATA2 =
40 "AC-GG--CUC-CAA-CT\n" +
42 "-CG-TTA--ACG---AAGT\n";
44 private static final String TEST_DATA3 =
50 private static final String TEST_DATA4 =
60 * Read in Stockholm format test data including secondary structure
64 public void setUp() throws IOException
66 al = new FormatAdapter().readFile(TEST_DATA,
67 AppletFormatAdapter.PASTE, "STH");
69 for (AlignmentAnnotation ann : al.getAlignmentAnnotation())
71 ann.setCalcId("CalcIdFor"
72 + al.getSequenceAt(i).getName());
78 * Test method that returns annotations that match on calcId.
81 public void testFindAnnotation_byCalcId()
83 Iterable<AlignmentAnnotation> anns = al
84 .findAnnotation("CalcIdForD.melanogaster.2");
85 Iterator<AlignmentAnnotation> iter = anns.iterator();
86 assertTrue(iter.hasNext());
87 AlignmentAnnotation ann = iter.next();
88 assertEquals("D.melanogaster.2", ann.sequenceRef.getName());
89 assertFalse(iter.hasNext());
93 * Tests for method that checks for alignment 'mappability'.
98 public void testIsMappableTo() throws IOException
100 al = new FormatAdapter().readFile(TEST_DATA2,
101 AppletFormatAdapter.PASTE, "FASTA");
104 // not mappable to self
105 assertFalse(al.isMappableTo(al));
107 // dna mappable to protein and vice versa
108 AlignmentI alp = new FormatAdapter().readFile(TEST_DATA3,
109 AppletFormatAdapter.PASTE, "FASTA");
110 alp.setDataset(null);
111 assertTrue(al.isMappableTo(alp));
112 assertTrue(alp.isMappableTo(al));
113 assertFalse(alp.isMappableTo(alp));
115 // not mappable if any sequence length mismatch
116 alp.getSequenceAt(1).setSequence("-R--FP-");
117 alp.getSequenceAt(1).setDatasetSequence(new Sequence("", "RFP"));
118 assertFalse(alp.isMappableTo(al));
119 assertFalse(al.isMappableTo(alp));
121 // not mappable if number of sequences differs
122 alp.deleteSequence(1);
123 assertFalse(alp.isMappableTo(al));
124 assertFalse(al.isMappableTo(alp));
128 * Tests for realigning as per a supplied alignment.
130 * @throws IOException
133 public void testAlignAs_dnaAsDna() throws IOException
136 Alignment al1 = new FormatAdapter().readFile(TEST_DATA2,
137 AppletFormatAdapter.PASTE, "FASTA");
138 al1.setDataset(null);
140 Alignment al2 = new FormatAdapter().readFile(TEST_DATA4,
141 AppletFormatAdapter.PASTE, "FASTA");
142 al2.setDataset(null);
145 assertEquals("GC-TC--GUC-GTA-CT", al2.getSequenceAt(0)
146 .getSequenceAsString());
147 assertEquals("-GG-GTC--AGG---CAGT", al2.getSequenceAt(1)
148 .getSequenceAsString());
152 * Aligning protein from cDNA yet to be implemented.
154 * @throws IOException
157 public void testAlignAs_proteinAsCdna() throws IOException
160 Alignment al1 = new FormatAdapter().readFile(TEST_DATA2,
161 AppletFormatAdapter.PASTE, "FASTA");
162 al1.setDataset(null);
164 Alignment al2 = new FormatAdapter().readFile(TEST_DATA3,
165 AppletFormatAdapter.PASTE, "FASTA");
166 al2.setDataset(null);
171 fail("No exception thrown");
172 } catch (UnsupportedOperationException e)
179 * Test aligning cdna as per protein alignment.
181 * @throws IOException
184 public void testAlignAs_cdnaAsProtein() throws IOException
187 Alignment al1 = new FormatAdapter().readFile(TEST_DATA2,
188 AppletFormatAdapter.PASTE, "FASTA");
189 al1.setDataset(null);
191 Alignment al2 = new FormatAdapter().readFile(TEST_DATA3,
192 AppletFormatAdapter.PASTE, "FASTA");
193 al2.setDataset(null);
196 assertEquals("ACG---GCUCCA------ACT", al1.getSequenceAt(0)
197 .getSequenceAsString());
198 assertEquals("---CGT---TAACGA---AGT---", al1.getSequenceAt(1)
199 .getSequenceAsString());