import static org.testng.AssertJUnit.assertTrue;
import jalview.datamodel.AlignedCodonFrame.SequenceToSequenceMapping;
-import jalview.io.AppletFormatAdapter;
+import jalview.gui.JvOptionPane;
+import jalview.io.DataSourceType;
+import jalview.io.FileFormat;
+import jalview.io.FileFormatI;
import jalview.io.FormatAdapter;
import jalview.util.MapList;
import java.util.List;
import org.testng.Assert;
+import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
*/
public class AlignmentTest
{
+
+ @BeforeClass(alwaysRun = true)
+ public void setUpJvOptionPane()
+ {
+ JvOptionPane.setInteractiveMode(false);
+ JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
+ }
+
// @formatter:off
private static final String TEST_DATA =
"# STOCKHOLM 1.0\n" +
* @return
* @throws IOException
*/
- protected AlignmentI loadAlignment(final String data, String format)
+ protected AlignmentI loadAlignment(final String data, FileFormatI format)
throws IOException
{
- AlignmentI a = new FormatAdapter().readFile(data,
- AppletFormatAdapter.PASTE, format);
+ AlignmentI a = new FormatAdapter().readFile(data, DataSourceType.PASTE,
+ format);
a.setDataset(null);
return a;
}
* - the alignmentI object to verify (either alignment or dataset)
* @param raiseAssert
* - when set, testng assertions are raised.
- * @param message
- * - null or a string message to prepend to the assert failed messages.
+ * @param message
+ * - null or a string message to prepend to the assert failed
+ * messages.
* @return true if alignment references were in order, otherwise false.
*/
public static boolean verifyAlignmentDatasetRefs(AlignmentI alignment,
boolean raiseAssert, String message)
{
- if (message==null) { message = ""; }
+ if (message == null)
+ {
+ message = "";
+ }
if (alignment == null)
{
if (raiseAssert)
{
- Assert.fail(message+"Alignment for verification was null.");
+ Assert.fail(message + "Alignment for verification was null.");
}
return false;
}
{
if (raiseAssert)
{
- Assert.fail(message+" Alignment contained a sequence who's dataset sequence has a second dataset reference.");
+ Assert.fail(message
+ + " Alignment contained a sequence who's dataset sequence has a second dataset reference.");
}
return false;
}
{
if (raiseAssert)
{
- Assert.fail(message+" Alignment contained a sequence who's dataset sequence was not in the dataset.");
+ Assert.fail(message
+ + " Alignment contained a sequence who's dataset sequence was not in the dataset.");
}
return false;
}
}
- return verifyAlignmentDatasetRefs(alignment.getDataset(), raiseAssert, message);
+ return verifyAlignmentDatasetRefs(alignment.getDataset(),
+ raiseAssert, message);
}
else
{
{
if (raiseAssert)
{
- Assert.fail(message+" Dataset contained a sequence with non-null dataset reference (ie not a dataset sequence!)");
+ Assert.fail(message
+ + " Dataset contained a sequence with non-null dataset reference (ie not a dataset sequence!)");
}
return false;
}
{
if (raiseAssert)
{
- Assert.fail(message+" DBRefEntry for sequence in alignment had map to sequence which was not a dataset sequence");
+ Assert.fail(message
+ + " DBRefEntry for sequence in alignment had map to sequence which was not a dataset sequence");
}
return false;
{
if (raiseAssert)
{
- Assert.fail(message+" DBRefEntry for sequence in alignment had map to sequence not in dataset");
+ Assert.fail(message
+ + " DBRefEntry for sequence in alignment had map to sequence not in dataset");
}
return false;
}
{
if (raiseAssert)
{
- Assert.fail(message+" CodonFrame-SSM-FromSeq is not a dataset sequence");
+ Assert.fail(message
+ + " CodonFrame-SSM-FromSeq is not a dataset sequence");
}
return false;
}
if (raiseAssert)
{
- Assert.fail(message+" CodonFrame-SSM-FromSeq is not contained in dataset");
+ Assert.fail(message
+ + " CodonFrame-SSM-FromSeq is not contained in dataset");
}
return false;
}
{
if (raiseAssert)
{
- Assert.fail(message+" CodonFrame-SSM-Mapping-ToSeq is not a dataset sequence");
+ Assert.fail(message
+ + " CodonFrame-SSM-Mapping-ToSeq is not a dataset sequence");
}
return false;
}
if (raiseAssert)
{
- Assert.fail(message+" CodonFrame-SSM-Mapping-ToSeq is not contained in dataset");
+ Assert.fail(message
+ + " CodonFrame-SSM-Mapping-ToSeq is not contained in dataset");
}
return false;
}
+ msg);
}
}
+
@Test(groups = { "Functional" })
public void testVerifyAlignmentDatasetRefs()
{
"TTTTTT");
// construct simple valid alignment dataset
- Alignment al = new Alignment(new SequenceI[] {
- sq1, sq2 });
+ Alignment al = new Alignment(new SequenceI[] { sq1, sq2 });
// expect this to pass
assertVerifyAlignment(al, true, "Simple valid alignment didn't verify");
// check test for sequence->datasetSequence validity
sq1.setDatasetSequence(sq2);
- assertVerifyAlignment(
- al,
- false,
+ assertVerifyAlignment(al, false,
"didn't detect dataset sequence with a dataset sequence reference.");
sq1.setDatasetSequence(null);
*/
public static void assertDatasetIsNormalised(AlignmentI al, String message)
{
- if (al.getDataset()!=null)
+ if (al.getDataset() != null)
{
assertDatasetIsNormalised(al.getDataset(), message);
return;
* look for pairs of sequences with same ID, start, end, and sequence
*/
List<SequenceI> seqSet = al.getSequences();
- for (int p=0;p<seqSet.size(); p++)
+ for (int p = 0; p < seqSet.size(); p++)
{
SequenceI pSeq = seqSet.get(p);
- for (int q=p+1; q<seqSet.size(); q++)
+ for (int q = p + 1; q < seqSet.size(); q++)
{
SequenceI qSeq = seqSet.get(q);
- if (pSeq.getStart()!=qSeq.getStart())
+ if (pSeq.getStart() != qSeq.getStart())
{
continue;
}
- if (pSeq.getEnd()!=qSeq.getEnd())
+ if (pSeq.getEnd() != qSeq.getEnd())
{
continue;
}
}
}
}
-
+
@Test(groups = { "Functional", "Asserts" })
public void testAssertDatasetIsNormalised()
{
Assert.fail("Expected identical sequence to raise exception.");
}
}
+
/*
* Read in Stockholm format test data including secondary structure
* annotations.
@BeforeMethod(alwaysRun = true)
public void setUp() throws IOException
{
- al = loadAlignment(TEST_DATA, "STH");
+ al = loadAlignment(TEST_DATA, FileFormat.Stockholm);
int i = 0;
for (AlignmentAnnotation ann : al.getAlignmentAnnotation())
{
AlignmentAnnotation ann = iter.next();
assertEquals("D.melanogaster.2", ann.sequenceRef.getName());
assertFalse(iter.hasNext());
+
+ // invalid id
+ anns = al.findAnnotation("CalcIdForD.melanogaster.?");
+ assertFalse(iter.hasNext());
+ anns = al.findAnnotation(null);
+ assertFalse(iter.hasNext());
}
@Test(groups = { "Functional" })
public void testAlignAs_dnaAsDna() throws IOException
{
// aligned cDNA:
- AlignmentI al1 = loadAlignment(CDNA_SEQS_1, "FASTA");
+ AlignmentI al1 = loadAlignment(CDNA_SEQS_1, FileFormat.Fasta);
// unaligned cDNA:
- AlignmentI al2 = loadAlignment(CDNA_SEQS_2, "FASTA");
+ AlignmentI al2 = loadAlignment(CDNA_SEQS_2, FileFormat.Fasta);
/*
* Make mappings between sequences. The 'aligned cDNA' is playing the role
public void testAlignAs_proteinAsCdna() throws IOException
{
// see also AlignmentUtilsTests
- AlignmentI al1 = loadAlignment(CDNA_SEQS_1, "FASTA");
- AlignmentI al2 = loadAlignment(AA_SEQS_1, "FASTA");
+ AlignmentI al1 = loadAlignment(CDNA_SEQS_1, FileFormat.Fasta);
+ AlignmentI al2 = loadAlignment(AA_SEQS_1, FileFormat.Fasta);
makeMappings(al1, al2);
// Fudge - alignProteinAsCdna expects mappings to be on protein
/*
* Load alignments and add mappings for cDNA to protein
*/
- AlignmentI al1 = loadAlignment(CDNA_SEQS_1, "FASTA");
- AlignmentI al2 = loadAlignment(AA_SEQS_1, "FASTA");
+ AlignmentI al1 = loadAlignment(CDNA_SEQS_1, FileFormat.Fasta);
+ AlignmentI al2 = loadAlignment(AA_SEQS_1, FileFormat.Fasta);
makeMappings(al1, al2);
/*
* Load alignments and add mappings from nucleotide to protein (or from
* first to second if both the same type)
*/
- AlignmentI al1 = loadAlignment(fromSeqs, "FASTA");
- AlignmentI al2 = loadAlignment(toSeqs, "FASTA");
+ AlignmentI al1 = loadAlignment(fromSeqs, FileFormat.Fasta);
+ AlignmentI al2 = loadAlignment(toSeqs, FileFormat.Fasta);
makeMappings(al1, al2);
/*
String dna1 = "A-Aa-gG-GCC-cT-TT";
String dna2 = "c--CCGgg-TT--T-AA-A";
AlignmentI al1 = loadAlignment(">Dna1/6-17\n" + dna1
- + "\n>Dna2/20-31\n" + dna2 + "\n", "FASTA");
+ + "\n>Dna2/20-31\n" + dna2 + "\n", FileFormat.Fasta);
AlignmentI al2 = loadAlignment(
- ">Pep1/7-9\n-P--YK\n>Pep2/11-13\nG-T--F\n", "FASTA");
+ ">Pep1/7-9\n-P--YK\n>Pep2/11-13\nG-T--F\n", FileFormat.Fasta);
AlignedCodonFrame acf = new AlignedCodonFrame();
// Seq1 has intron at dna positions 3,4,9 so splice is AAG GCC TTT
// Seq2 has intron at dna positions 1,5,6 so splice is CCG TTT AAA
@Test(groups = "Functional")
public void testCopyConstructor() throws IOException
{
- AlignmentI protein = loadAlignment(AA_SEQS_1, FormatAdapter.PASTE);
+ AlignmentI protein = loadAlignment(AA_SEQS_1, FileFormat.Fasta);
// create sequence and alignment datasets
protein.setDataset(null);
AlignedCodonFrame acf = new AlignedCodonFrame();
public void testCreateDatasetAlignment() throws IOException
{
AlignmentI protein = new FormatAdapter().readFile(AA_SEQS_1,
- AppletFormatAdapter.PASTE, "FASTA");
+ DataSourceType.PASTE, FileFormat.Fasta);
/*
* create a dataset sequence on first sequence
* leave the second without one
assertAlignmentDatasetRefs(align,
"addSequence broke dataset reference integrity");
}
+
@Test(groups = "Functional")
public void getVisibleStartAndEndIndexTest()
{
SequenceI pep = new Sequence("pep", "ASD");
SequenceI dna = new Sequence("dna", "aaaGCCTCGGATggg");
SequenceI cds = new Sequence("cds", "GCCTCGGAT");
-
+
// add dbref from dna to peptide
DBRefEntry dbr = new DBRefEntry("UNIPROT", "", "pep");
dbr.setMap(new Mapping(pep, new MapList(new int[] { 4, 15 }, new int[] {
pep.addDBRef(dbr4);
AlignmentI protein = new Alignment(new SequenceI[] { pep });
-
+
/*
* create the alignment dataset
*/
((Alignment) protein).createDatasetAlignment();
-
+
AlignmentI ds = protein.getDataset();
-
+
// should be 3 sequences in dataset
assertEquals(3, ds.getHeight());
assertTrue(ds.getSequences().contains(pep.getDatasetSequence()));
assertSame(pep.getDatasetSequence(), cds.getDBRefs()[0].map.to);
}
+ @Test(groups = { "Functional" })
+ public void testFindGroup()
+ {
+ SequenceI seq1 = new Sequence("seq1", "ABCDEF---GHI");
+ SequenceI seq2 = new Sequence("seq2", "---JKLMNO---");
+ AlignmentI a = new Alignment(new SequenceI[] { seq1, seq2 });
+
+ assertNull(a.findGroup(null, 0));
+ assertNull(a.findGroup(seq1, 1));
+ assertNull(a.findGroup(seq1, -1));
+
+ /*
+ * add a group consisting of just "DEF"
+ */
+ SequenceGroup sg1 = new SequenceGroup();
+ sg1.addSequence(seq1, false);
+ sg1.setStartRes(3);
+ sg1.setEndRes(5);
+ a.addGroup(sg1);
+
+ assertNull(a.findGroup(seq1, 2)); // position not in group
+ assertNull(a.findGroup(seq1, 6)); // position not in group
+ assertNull(a.findGroup(seq2, 5)); // sequence not in group
+ assertSame(a.findGroup(seq1, 3), sg1); // yes
+ assertSame(a.findGroup(seq1, 4), sg1);
+ assertSame(a.findGroup(seq1, 5), sg1);
+
+ /*
+ * add a group consisting of
+ * EF--
+ * KLMN
+ */
+ SequenceGroup sg2 = new SequenceGroup();
+ sg2.addSequence(seq1, false);
+ sg2.addSequence(seq2, false);
+ sg2.setStartRes(4);
+ sg2.setEndRes(7);
+ a.addGroup(sg2);
+
+ assertNull(a.findGroup(seq1, 2)); // unchanged
+ assertSame(a.findGroup(seq1, 3), sg1); // unchanged
+ /*
+ * if a residue is in more than one group, method returns
+ * the first found (in order groups were added)
+ */
+ assertSame(a.findGroup(seq1, 4), sg1);
+ assertSame(a.findGroup(seq1, 5), sg1);
+
+ /*
+ * seq2 only belongs to the second group
+ */
+ assertSame(a.findGroup(seq2, 4), sg2);
+ assertSame(a.findGroup(seq2, 5), sg2);
+ assertSame(a.findGroup(seq2, 6), sg2);
+ assertSame(a.findGroup(seq2, 7), sg2);
+ assertNull(a.findGroup(seq2, 3));
+ assertNull(a.findGroup(seq2, 8));
+ }
+
}