2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.datamodel;
23 import static org.testng.AssertJUnit.assertEquals;
24 import static org.testng.AssertJUnit.assertFalse;
25 import static org.testng.AssertJUnit.assertNotNull;
26 import static org.testng.AssertJUnit.assertNull;
27 import static org.testng.AssertJUnit.assertSame;
28 import static org.testng.AssertJUnit.assertTrue;
30 import java.io.IOException;
31 import java.util.Arrays;
32 import java.util.Iterator;
33 import java.util.List;
35 import org.testng.Assert;
36 import org.testng.annotations.BeforeClass;
37 import org.testng.annotations.BeforeMethod;
38 import org.testng.annotations.Test;
40 import jalview.analysis.AlignmentGenerator;
41 import jalview.datamodel.AlignedCodonFrame.SequenceToSequenceMapping;
42 import jalview.gui.JvOptionPane;
43 import jalview.io.DataSourceType;
44 import jalview.io.FileFormat;
45 import jalview.io.FileFormatI;
46 import jalview.io.FormatAdapter;
47 import jalview.util.Comparison;
48 import jalview.util.MapList;
51 * Unit tests for Alignment datamodel.
56 public class AlignmentTest
59 @BeforeClass(alwaysRun = true)
60 public void setUpJvOptionPane()
62 JvOptionPane.setInteractiveMode(false);
63 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
67 private static final String TEST_DATA =
69 "#=GS D.melanogaster.1 AC AY119185.1/838-902\n" +
70 "#=GS D.melanogaster.2 AC AC092237.1/57223-57161\n" +
71 "#=GS D.melanogaster.3 AC AY060611.1/560-627\n" +
72 "D.melanogaster.1 G.AGCC.CU...AUGAUCGA\n" +
73 "#=GR D.melanogaster.1 SS ................((((\n" +
74 "D.melanogaster.2 C.AUUCAACU.UAUGAGGAU\n" +
75 "#=GR D.melanogaster.2 SS ................((((\n" +
76 "D.melanogaster.3 G.UGGCGCU..UAUGACGCA\n" +
77 "#=GR D.melanogaster.3 SS (.(((...(....(((((((\n" +
80 private static final String AA_SEQS_1 =
86 private static final String CDNA_SEQS_1 =
87 ">Seq1Name/100-111\n" +
88 "AC-GG--CUC-CAA-CT\n" +
89 ">Seq2Name/200-211\n" +
90 "-CG-TTA--ACG---AAGT\n";
92 private static final String CDNA_SEQS_2 =
99 private AlignmentI al;
102 * Helper method to load an alignment and ensure dataset sequences are set up.
108 * @throws IOException
110 protected AlignmentI loadAlignment(final String data, FileFormatI format)
113 AlignmentI a = new FormatAdapter().readFile(data, DataSourceType.PASTE,
120 * assert wrapper: tests all references in the given alignment are consistent
124 public static void assertAlignmentDatasetRefs(AlignmentI alignment)
126 verifyAlignmentDatasetRefs(alignment, true, null);
130 * assert wrapper: tests all references in the given alignment are consistent
134 * - prefixed to any assert failed messages
136 public static void assertAlignmentDatasetRefs(AlignmentI alignment,
139 verifyAlignmentDatasetRefs(alignment, true, message);
143 * verify sequence and dataset references are properly contained within
147 * - the alignmentI object to verify (either alignment or dataset)
149 * - when set, testng assertions are raised.
151 * - null or a string message to prepend to the assert failed
153 * @return true if alignment references were in order, otherwise false.
155 public static boolean verifyAlignmentDatasetRefs(AlignmentI alignment,
156 boolean raiseAssert, String message)
162 if (alignment == null)
166 Assert.fail(message + "Alignment for verification was null.");
170 if (alignment.getDataset() != null)
172 AlignmentI dataset = alignment.getDataset();
173 // check all alignment sequences have their dataset within the dataset
174 for (SequenceI seq : alignment.getSequences())
176 SequenceI seqds = seq.getDatasetSequence();
177 if (seqds.getDatasetSequence() != null)
182 + " Alignment contained a sequence who's dataset sequence has a second dataset reference.");
186 if (dataset.findIndex(seqds) == -1)
191 + " Alignment contained a sequence who's dataset sequence was not in the dataset.");
196 return verifyAlignmentDatasetRefs(alignment.getDataset(), raiseAssert,
202 // verify all dataset sequences
203 for (SequenceI seqds : alignment.getSequences())
206 if (seqds.getDatasetSequence() != null)
211 + " Dataset contained a sequence with non-null dataset reference (ie not a dataset sequence!)");
215 int foundp = alignment.findIndex(seqds);
221 + " Dataset sequence array contains a reference at "
222 + dsp + " to a sequence first seen at " + foundp + " ("
223 + seqds.toString() + ")");
227 if (seqds.getDBRefs() != null)
229 for (DBRefEntry dbr : seqds.getDBRefs())
231 if (dbr.getMap() != null)
233 SequenceI seqdbrmapto = dbr.getMap().getTo();
234 if (seqdbrmapto != null)
236 if (seqdbrmapto.getDatasetSequence() != null)
241 + " DBRefEntry for sequence in alignment had map to sequence which was not a dataset sequence");
246 if (alignment.findIndex(dbr.getMap().getTo()) == -1)
250 Assert.fail(message + " DBRefEntry " + dbr
251 + " for sequence " + seqds
252 + " in alignment has map to sequence not in dataset");
261 // finally, verify codonmappings involve only dataset sequences.
262 if (alignment.getCodonFrames() != null)
264 for (AlignedCodonFrame alc : alignment.getCodonFrames())
266 for (SequenceToSequenceMapping ssm : alc.getMappings())
268 if (ssm.getFromSeq().getDatasetSequence() != null)
273 + " CodonFrame-SSM-FromSeq is not a dataset sequence");
277 if (alignment.findIndex(ssm.getFromSeq()) == -1)
283 + " CodonFrame-SSM-FromSeq is not contained in dataset");
287 if (ssm.getMapping().getTo().getDatasetSequence() != null)
292 + " CodonFrame-SSM-Mapping-ToSeq is not a dataset sequence");
296 if (alignment.findIndex(ssm.getMapping().getTo()) == -1)
302 + " CodonFrame-SSM-Mapping-ToSeq is not contained in dataset");
310 return true; // all relationships verified!
314 * call verifyAlignmentDatasetRefs with and without assertion raising enabled,
315 * to check expected pass/fail actually occurs in both conditions
321 private void assertVerifyAlignment(AlignmentI al, boolean expected,
329 Assert.assertTrue(verifyAlignmentDatasetRefs(al, true, null),
330 "Valid test alignment failed when raiseAsserts enabled:"
332 } catch (AssertionError ae)
334 ae.printStackTrace();
336 "Valid test alignment raised assertion errors when raiseAsserts enabled: "
340 // also check validation passes with asserts disabled
341 Assert.assertTrue(verifyAlignmentDatasetRefs(al, false, null),
342 "Valid test alignment tested false when raiseAsserts disabled:"
347 boolean assertRaised = false;
350 verifyAlignmentDatasetRefs(al, true, null);
351 } catch (AssertionError ae)
353 // expected behaviour
359 "Invalid test alignment passed when raiseAsserts enabled:"
362 // also check validation passes with asserts disabled
363 Assert.assertFalse(verifyAlignmentDatasetRefs(al, false, null),
364 "Invalid test alignment tested true when raiseAsserts disabled:"
369 @Test(groups = { "Functional" })
370 public void testVerifyAlignmentDatasetRefs()
372 SequenceI sq1 = new Sequence("sq1", "ASFDD"),
373 sq2 = new Sequence("sq2", "TTTTTT");
375 // construct simple valid alignment dataset
376 Alignment al = new Alignment(new SequenceI[] { sq1, sq2 });
377 // expect this to pass
378 assertVerifyAlignment(al, true, "Simple valid alignment didn't verify");
380 // check test for sequence->datasetSequence validity
381 sq1.setDatasetSequence(sq2);
382 assertVerifyAlignment(al, false,
383 "didn't detect dataset sequence with a dataset sequence reference.");
385 sq1.setDatasetSequence(null);
386 assertVerifyAlignment(al, true,
387 "didn't reinstate validity after nulling dataset sequence dataset reference");
389 // now create dataset and check again
390 al.createDatasetAlignment();
391 assertNotNull(al.getDataset());
393 assertVerifyAlignment(al, true,
394 "verify failed after createDatasetAlignment");
396 // create a dbref on sq1 with a sequence ref to sq2
397 DBRefEntry dbrs1tos2 = new DBRefEntry("UNIPROT", "1", "Q111111");
399 .setMap(new Mapping(sq2.getDatasetSequence(), new int[]
400 { 1, 5 }, new int[] { 2, 6 }, 1, 1));
401 sq1.getDatasetSequence().addDBRef(dbrs1tos2);
402 assertVerifyAlignment(al, true,
403 "verify failed after addition of valid DBRefEntry/map");
404 // now create a dbref on a new sequence which maps to another sequence
405 // outside of the dataset
406 SequenceI sqout = new Sequence("sqout", "ututututucagcagcag"),
407 sqnew = new Sequence("sqnew", "EEERRR");
408 DBRefEntry sqnewsqout = new DBRefEntry("ENAFOO", "1", "R000001");
410 .setMap(new Mapping(sqout, new int[]
411 { 1, 6 }, new int[] { 1, 18 }, 1, 3));
412 al.getDataset().addSequence(sqnew);
414 assertVerifyAlignment(al, true,
415 "verify failed after addition of new sequence to dataset");
416 // now start checking exception conditions
417 sqnew.addDBRef(sqnewsqout);
418 assertVerifyAlignment(al, false,
419 "verify passed when a dbref with map to sequence outside of dataset was added");
420 // make the verify pass by adding the outsider back in
421 al.getDataset().addSequence(sqout);
422 assertVerifyAlignment(al, true,
423 "verify should have passed after adding dbref->to sequence in to dataset");
424 // and now the same for a codon mapping...
425 SequenceI sqanotherout = new Sequence("sqanotherout",
426 "aggtutaggcagcagcag");
428 AlignedCodonFrame alc = new AlignedCodonFrame();
429 alc.addMap(sqanotherout, sqnew,
430 new MapList(new int[]
431 { 1, 6 }, new int[] { 1, 18 }, 3, 1));
433 al.addCodonFrame(alc);
434 Assert.assertEquals(al.getDataset().getCodonFrames().size(), 1);
436 assertVerifyAlignment(al, false,
437 "verify passed when alCodonFrame mapping to sequence outside of dataset was added");
438 // make the verify pass by adding the outsider back in
439 al.getDataset().addSequence(sqanotherout);
440 assertVerifyAlignment(al, true,
441 "verify should have passed once all sequences involved in alCodonFrame were added to dataset");
442 al.getDataset().addSequence(sqanotherout);
443 assertVerifyAlignment(al, false,
444 "verify should have failed when a sequence was added twice to the dataset");
445 al.getDataset().deleteSequence(sqanotherout);
446 assertVerifyAlignment(al, true,
447 "verify should have passed after duplicate entry for sequence was removed");
451 * checks that the sequence data for an alignment's dataset is non-redundant.
452 * Fails if there are sequences with same id, sequence, start, and.
455 public static void assertDatasetIsNormalised(AlignmentI al)
457 assertDatasetIsNormalised(al, null);
461 * checks that the sequence data for an alignment's dataset is non-redundant.
462 * Fails if there are sequences with same id, sequence, start, and.
465 * - alignment to verify
467 * - null or message prepended to exception message.
469 public static void assertDatasetIsNormalised(AlignmentI al,
472 if (al.getDataset() != null)
474 assertDatasetIsNormalised(al.getDataset(), message);
478 * look for pairs of sequences with same ID, start, end, and sequence
480 List<SequenceI> seqSet = al.getSequences();
481 for (int p = 0; p < seqSet.size(); p++)
483 SequenceI pSeq = seqSet.get(p);
484 for (int q = p + 1; q < seqSet.size(); q++)
486 SequenceI qSeq = seqSet.get(q);
487 if (pSeq.getStart() != qSeq.getStart())
491 if (pSeq.getEnd() != qSeq.getEnd())
495 if (!pSeq.getName().equals(qSeq.getName()))
499 if (!Arrays.equals(pSeq.getSequence(), qSeq.getSequence()))
503 Assert.fail((message == null ? "" : message + " :")
504 + "Found similar sequences at position " + p + " and " + q
505 + "\n" + pSeq.toString());
510 @Test(groups = { "Functional", "Asserts" })
511 public void testAssertDatasetIsNormalised()
513 Sequence sq1 = new Sequence("s1/1-4", "asdf");
514 Sequence sq1shift = new Sequence("s1/2-5", "asdf");
515 Sequence sq1seqd = new Sequence("s1/1-4", "asdt");
516 Sequence sq2 = new Sequence("s2/1-4", "asdf");
517 Sequence sq1dup = new Sequence("s1/1-4", "asdf");
519 Alignment al = new Alignment(new SequenceI[] { sq1 });
524 assertDatasetIsNormalised(al);
525 } catch (AssertionError ae)
527 Assert.fail("Single sequence should be valid normalised dataset.");
532 assertDatasetIsNormalised(al);
533 } catch (AssertionError ae)
536 "Two different sequences should be valid normalised dataset.");
539 * now change sq2's name in the alignment. should still be valid
541 al.findName(sq2.getName()).setName("sq1");
544 assertDatasetIsNormalised(al);
545 } catch (AssertionError ae)
548 "Two different sequences in dataset, but same name in alignment, should be valid normalised dataset.");
551 al.addSequence(sq1seqd);
554 assertDatasetIsNormalised(al);
555 } catch (AssertionError ae)
558 "sq1 and sq1 with different sequence should be distinct.");
561 al.addSequence(sq1shift);
564 assertDatasetIsNormalised(al);
565 } catch (AssertionError ae)
568 "sq1 and sq1 with different start/end should be distinct.");
571 * finally, the failure case
573 al.addSequence(sq1dup);
574 boolean ssertRaised = false;
577 assertDatasetIsNormalised(al);
579 } catch (AssertionError ae)
585 Assert.fail("Expected identical sequence to raise exception.");
590 * Read in Stockholm format test data including secondary structure
593 @BeforeMethod(alwaysRun = true)
594 public void setUp() throws IOException
596 al = loadAlignment(TEST_DATA, FileFormat.Stockholm);
598 for (AlignmentAnnotation ann : al.getAlignmentAnnotation())
600 ann.setCalcId("CalcIdFor" + al.getSequenceAt(i).getName());
606 * Test method that returns annotations that match on calcId.
608 @Test(groups = { "Functional" })
609 public void testFindAnnotation_byCalcId()
611 Iterable<AlignmentAnnotation> anns = al
612 .findAnnotation("CalcIdForD.melanogaster.2");
613 Iterator<AlignmentAnnotation> iter = anns.iterator();
614 assertTrue(iter.hasNext());
615 AlignmentAnnotation ann = iter.next();
616 assertEquals("D.melanogaster.2", ann.sequenceRef.getName());
617 assertFalse(iter.hasNext());
620 anns = al.findAnnotation("CalcIdForD.melanogaster.?");
621 assertFalse(iter.hasNext());
622 anns = al.findAnnotation(null);
623 assertFalse(iter.hasNext());
627 * Test method that returns annotations that match on reference sequence,
630 @Test(groups = { "Functional" })
631 public void testFindAnnotations_bySeqLabelandorCalcId()
633 // TODO: finish testFindAnnotations_bySeqLabelandorCalcId test
634 /* Note - this is an incomplete test - need to check null or
635 * non-null [ matches, not matches ] behaviour for each of the three
638 // search for a single, unique calcId with wildcards on other params
639 Iterable<AlignmentAnnotation> anns = al.findAnnotations(null,
640 "CalcIdForD.melanogaster.2", null);
641 Iterator<AlignmentAnnotation> iter = anns.iterator();
642 assertTrue(iter.hasNext());
643 AlignmentAnnotation ann = iter.next();
644 assertEquals("D.melanogaster.2", ann.sequenceRef.getName());
645 assertFalse(iter.hasNext());
647 // save reference to test sequence reference parameter
648 SequenceI rseq = ann.sequenceRef;
650 // search for annotation associated with a single sequence
651 anns = al.findAnnotations(rseq, null, null);
652 iter = anns.iterator();
653 assertTrue(iter.hasNext());
655 assertEquals("D.melanogaster.2", ann.sequenceRef.getName());
656 assertFalse(iter.hasNext());
658 // search for annotation with a non-existant calcId
659 anns = al.findAnnotations(null, "CalcIdForD.melanogaster.?", null);
660 iter = anns.iterator();
661 assertFalse(iter.hasNext());
663 // search for annotation with a particular label - expect three
664 anns = al.findAnnotations(null, null, "Secondary Structure");
665 iter = anns.iterator();
666 assertTrue(iter.hasNext());
668 assertTrue(iter.hasNext());
670 assertTrue(iter.hasNext());
673 assertFalse(iter.hasNext());
675 // search for annotation on one sequence with a particular label - expect
678 anns = al.findAnnotations(sqfound = al.getSequenceAt(1), null,
679 "Secondary Structure");
680 iter = anns.iterator();
681 assertTrue(iter.hasNext());
682 // expect reference to sequence 1 in the alignment
683 assertTrue(sqfound == iter.next().sequenceRef);
684 assertFalse(iter.hasNext());
686 // null on all parameters == find all annotations
687 anns = al.findAnnotations(null, null, null);
688 iter = anns.iterator();
689 int n = al.getAlignmentAnnotation().length;
690 while (iter.hasNext())
695 assertTrue("Found " + n + " fewer annotations from search.", n == 0);
698 @Test(groups = { "Functional" })
699 public void testDeleteAllAnnotations_includingAutocalculated()
701 AlignmentAnnotation aa = new AlignmentAnnotation("Consensus",
703 aa.autoCalculated = true;
704 al.addAnnotation(aa);
705 AlignmentAnnotation[] anns = al.getAlignmentAnnotation();
706 assertEquals("Wrong number of annotations before deleting", 4,
708 al.deleteAllAnnotations(true);
709 assertEquals("Not all deleted", 0, al.getAlignmentAnnotation().length);
712 @Test(groups = { "Functional" })
713 public void testDeleteAllAnnotations_excludingAutocalculated()
715 AlignmentAnnotation aa = new AlignmentAnnotation("Consensus",
717 aa.autoCalculated = true;
718 al.addAnnotation(aa);
719 AlignmentAnnotation[] anns = al.getAlignmentAnnotation();
720 assertEquals("Wrong number of annotations before deleting", 4,
722 al.deleteAllAnnotations(false);
723 assertEquals("Not just one annotation left", 1,
724 al.getAlignmentAnnotation().length);
728 * Tests for realigning as per a supplied alignment: Dna as Dna.
730 * Note: AlignedCodonFrame's state variables are named for protein-to-cDNA
731 * mapping, but can be exploited for a general 'sequence-to-sequence' mapping
734 * @throws IOException
736 @Test(groups = { "Functional" })
737 public void testAlignAs_dnaAsDna() throws IOException
740 AlignmentI al1 = loadAlignment(CDNA_SEQS_1, FileFormat.Fasta);
742 AlignmentI al2 = loadAlignment(CDNA_SEQS_2, FileFormat.Fasta);
745 * Make mappings between sequences. The 'aligned cDNA' is playing the role
746 * of what would normally be protein here.
748 makeMappings(al1, al2);
750 ((Alignment) al2).alignAs(al1, false, true);
751 assertEquals("GC-TC--GUC-GTACT",
752 al2.getSequenceAt(0).getSequenceAsString());
753 assertEquals("-GG-GTC--AGG--CAGT",
754 al2.getSequenceAt(1).getSequenceAsString());
758 * Aligning protein from cDNA.
760 * @throws IOException
762 @Test(groups = { "Functional" })
763 public void testAlignAs_proteinAsCdna() throws IOException
765 // see also AlignmentUtilsTests
766 AlignmentI al1 = loadAlignment(CDNA_SEQS_1, FileFormat.Fasta);
767 AlignmentI al2 = loadAlignment(AA_SEQS_1, FileFormat.Fasta);
768 makeMappings(al1, al2);
770 // Fudge - alignProteinAsCdna expects mappings to be on protein
771 al2.getCodonFrames().addAll(al1.getCodonFrames());
773 ((Alignment) al2).alignAs(al1, false, true);
774 assertEquals("K-Q-Y-L-", al2.getSequenceAt(0).getSequenceAsString());
775 assertEquals("-R-F-P-W", al2.getSequenceAt(1).getSequenceAsString());
779 * Test aligning cdna as per protein alignment.
781 * @throws IOException
783 @Test(groups = { "Functional" }, enabled = true)
784 // TODO review / update this test after redesign of alignAs method
785 public void testAlignAs_cdnaAsProtein() throws IOException
788 * Load alignments and add mappings for cDNA to protein
790 AlignmentI al1 = loadAlignment(CDNA_SEQS_1, FileFormat.Fasta);
791 AlignmentI al2 = loadAlignment(AA_SEQS_1, FileFormat.Fasta);
792 makeMappings(al1, al2);
795 * Realign DNA; currently keeping existing gaps in introns only
797 ((Alignment) al1).alignAs(al2, false, true);
798 assertEquals("ACG---GCUCCA------ACT---",
799 al1.getSequenceAt(0).getSequenceAsString());
800 assertEquals("---CGT---TAACGA---AGT---",
801 al1.getSequenceAt(1).getSequenceAsString());
805 * Test aligning cdna as per protein - single sequences
807 * @throws IOException
809 @Test(groups = { "Functional" }, enabled = true)
810 // TODO review / update this test after redesign of alignAs method
811 public void testAlignAs_cdnaAsProtein_singleSequence() throws IOException
814 * simple case insert one gap
816 verifyAlignAs(">dna\nCAAaaa\n", ">protein\nQ-K\n", "CAA---aaa");
819 * simple case but with sequence offsets
821 verifyAlignAs(">dna/5-10\nCAAaaa\n", ">protein/20-21\nQ-K\n",
825 * insert gaps as per protein, drop gaps within codons
827 verifyAlignAs(">dna/10-18\nCA-Aa-aa--AGA\n", ">aa/6-8\n-Q-K--R\n",
828 "---CAA---aaa------AGA");
832 * Helper method that makes mappings and then aligns the first alignment as
838 * @throws IOException
840 public void verifyAlignAs(String fromSeqs, String toSeqs, String expected)
844 * Load alignments and add mappings from nucleotide to protein (or from
845 * first to second if both the same type)
847 AlignmentI al1 = loadAlignment(fromSeqs, FileFormat.Fasta);
848 AlignmentI al2 = loadAlignment(toSeqs, FileFormat.Fasta);
849 makeMappings(al1, al2);
852 * Realign DNA; currently keeping existing gaps in introns only
854 ((Alignment) al1).alignAs(al2, false, true);
855 assertEquals(expected, al1.getSequenceAt(0).getSequenceAsString());
859 * Helper method to make mappings between sequences, and add the mappings to
860 * the 'mapped from' alignment
865 public void makeMappings(AlignmentI alFrom, AlignmentI alTo)
867 int ratio = (alFrom.isNucleotide() == alTo.isNucleotide() ? 1 : 3);
869 AlignedCodonFrame acf = new AlignedCodonFrame();
871 for (int i = 0; i < alFrom.getHeight(); i++)
873 SequenceI seqFrom = alFrom.getSequenceAt(i);
874 SequenceI seqTo = alTo.getSequenceAt(i);
875 MapList ml = new MapList(
877 { seqFrom.getStart(), seqFrom.getEnd() },
879 { seqTo.getStart(), seqTo.getEnd() }, ratio, 1);
880 acf.addMap(seqFrom, seqTo, ml);
884 * not sure whether mappings 'belong' or protein or nucleotide
885 * alignment, so adding to both ;~)
887 alFrom.addCodonFrame(acf);
888 alTo.addCodonFrame(acf);
892 * Test aligning dna as per protein alignment, for the case where there are
893 * introns (i.e. some dna sites have no mapping from a peptide).
895 * @throws IOException
897 @Test(groups = { "Functional" }, enabled = false)
898 // TODO review / update this test after redesign of alignAs method
899 public void testAlignAs_dnaAsProtein_withIntrons() throws IOException
902 * Load alignments and add mappings for cDNA to protein
904 String dna1 = "A-Aa-gG-GCC-cT-TT";
905 String dna2 = "c--CCGgg-TT--T-AA-A";
906 AlignmentI al1 = loadAlignment(
907 ">Dna1/6-17\n" + dna1 + "\n>Dna2/20-31\n" + dna2 + "\n",
909 AlignmentI al2 = loadAlignment(
910 ">Pep1/7-9\n-P--YK\n>Pep2/11-13\nG-T--F\n", FileFormat.Fasta);
911 AlignedCodonFrame acf = new AlignedCodonFrame();
912 // Seq1 has intron at dna positions 3,4,9 so splice is AAG GCC TTT
913 // Seq2 has intron at dna positions 1,5,6 so splice is CCG TTT AAA
914 MapList ml1 = new MapList(new int[] { 6, 7, 10, 13, 15, 17 },
917 acf.addMap(al1.getSequenceAt(0), al2.getSequenceAt(0), ml1);
918 MapList ml2 = new MapList(new int[] { 21, 23, 26, 31 },
921 acf.addMap(al1.getSequenceAt(1), al2.getSequenceAt(1), ml2);
922 al2.addCodonFrame(acf);
925 * Align ignoring gaps in dna introns and exons
927 ((Alignment) al1).alignAs(al2, false, false);
928 assertEquals("---AAagG------GCCcTTT",
929 al1.getSequenceAt(0).getSequenceAsString());
930 // note 1 gap in protein corresponds to 'gg-' in DNA (3 positions)
931 assertEquals("cCCGgg-TTT------AAA",
932 al1.getSequenceAt(1).getSequenceAsString());
935 * Reset and realign, preserving gaps in dna introns and exons
937 al1.getSequenceAt(0).setSequence(dna1);
938 al1.getSequenceAt(1).setSequence(dna2);
939 ((Alignment) al1).alignAs(al2, true, true);
940 // String dna1 = "A-Aa-gG-GCC-cT-TT";
941 // String dna2 = "c--CCGgg-TT--T-AA-A";
942 // assumption: we include 'the greater of' protein/dna gap lengths, not both
943 assertEquals("---A-Aa-gG------GCC-cT-TT",
944 al1.getSequenceAt(0).getSequenceAsString());
945 assertEquals("c--CCGgg-TT--T------AA-A",
946 al1.getSequenceAt(1).getSequenceAsString());
949 @Test(groups = "Functional")
950 public void testCopyConstructor() throws IOException
952 AlignmentI protein = loadAlignment(AA_SEQS_1, FileFormat.Fasta);
953 // create sequence and alignment datasets
954 protein.setDataset(null);
955 AlignedCodonFrame acf = new AlignedCodonFrame();
956 List<AlignedCodonFrame> acfList = Arrays
957 .asList(new AlignedCodonFrame[]
959 protein.getDataset().setCodonFrames(acfList);
960 AlignmentI copy = new Alignment(protein);
963 * copy has different aligned sequences but the same dataset sequences
965 assertFalse(copy.getSequenceAt(0) == protein.getSequenceAt(0));
966 assertFalse(copy.getSequenceAt(1) == protein.getSequenceAt(1));
967 assertSame(copy.getSequenceAt(0).getDatasetSequence(),
968 protein.getSequenceAt(0).getDatasetSequence());
969 assertSame(copy.getSequenceAt(1).getDatasetSequence(),
970 protein.getSequenceAt(1).getDatasetSequence());
972 // TODO should the copy constructor copy the dataset?
973 // or make a new one referring to the same dataset sequences??
974 assertNull(copy.getDataset());
975 // TODO test metadata is copied when AlignmentI is a dataset
977 // assertArrayEquals(copy.getDataset().getSequencesArray(), protein
978 // .getDataset().getSequencesArray());
982 * Test behaviour of createDataset
984 * @throws IOException
986 @Test(groups = "Functional")
987 public void testCreateDatasetAlignment() throws IOException
989 AlignmentI protein = new FormatAdapter().readFile(AA_SEQS_1,
990 DataSourceType.PASTE, FileFormat.Fasta);
992 * create a dataset sequence on first sequence
993 * leave the second without one
995 protein.getSequenceAt(0).createDatasetSequence();
996 assertNotNull(protein.getSequenceAt(0).getDatasetSequence());
997 assertNull(protein.getSequenceAt(1).getDatasetSequence());
1000 * add a mapping to the alignment
1002 AlignedCodonFrame acf = new AlignedCodonFrame();
1003 protein.addCodonFrame(acf);
1004 assertNull(protein.getDataset());
1005 assertTrue(protein.getCodonFrames().contains(acf));
1008 * create the alignment dataset
1009 * note this creates sequence datasets where missing
1010 * as a side-effect (in this case, on seq2
1012 // TODO promote this method to AlignmentI
1013 ((Alignment) protein).createDatasetAlignment();
1015 AlignmentI ds = protein.getDataset();
1017 // side-effect: dataset created on second sequence
1018 assertNotNull(protein.getSequenceAt(1).getDatasetSequence());
1019 // dataset alignment has references to dataset sequences
1020 assertEquals(ds.getSequenceAt(0),
1021 protein.getSequenceAt(0).getDatasetSequence());
1022 assertEquals(ds.getSequenceAt(1),
1023 protein.getSequenceAt(1).getDatasetSequence());
1025 // codon frames should have been moved to the dataset
1026 // getCodonFrames() should delegate to the dataset:
1027 assertTrue(protein.getCodonFrames().contains(acf));
1028 // prove the codon frames are indeed on the dataset:
1029 assertTrue(ds.getCodonFrames().contains(acf));
1033 * tests the addition of *all* sequences referred to by a sequence being added
1036 @Test(groups = "Functional")
1037 public void testCreateDatasetAlignmentWithMappedToSeqs()
1039 // Alignment with two sequences, gapped.
1040 SequenceI sq1 = new Sequence("sq1", "A--SDF");
1041 SequenceI sq2 = new Sequence("sq2", "G--TRQ");
1043 // cross-references to two more sequences.
1044 DBRefEntry dbr = new DBRefEntry("SQ1", "", "sq3");
1045 SequenceI sq3 = new Sequence("sq3", "VWANG");
1047 new Mapping(sq3, new MapList(new int[]
1048 { 1, 4 }, new int[] { 2, 5 }, 1, 1)));
1051 SequenceI sq4 = new Sequence("sq4", "ERKWI");
1052 DBRefEntry dbr2 = new DBRefEntry("SQ2", "", "sq4");
1054 new Mapping(sq4, new MapList(new int[]
1055 { 1, 4 }, new int[] { 2, 5 }, 1, 1)));
1057 // and a 1:1 codonframe mapping between them.
1058 AlignedCodonFrame alc = new AlignedCodonFrame();
1059 alc.addMap(sq1, sq2,
1060 new MapList(new int[]
1061 { 1, 4 }, new int[] { 1, 4 }, 1, 1));
1063 AlignmentI protein = new Alignment(new SequenceI[] { sq1, sq2 });
1066 * create the alignment dataset
1067 * note this creates sequence datasets where missing
1068 * as a side-effect (in this case, on seq2
1071 // TODO promote this method to AlignmentI
1072 ((Alignment) protein).createDatasetAlignment();
1074 AlignmentI ds = protein.getDataset();
1076 // should be 4 sequences in dataset - two materialised, and two propagated
1078 assertEquals(4, ds.getHeight());
1079 assertTrue(ds.getSequences().contains(sq1.getDatasetSequence()));
1080 assertTrue(ds.getSequences().contains(sq2.getDatasetSequence()));
1081 assertTrue(ds.getSequences().contains(sq3));
1082 assertTrue(ds.getSequences().contains(sq4));
1083 // Should have one codon frame mapping between sq1 and sq2 via dataset
1085 assertEquals(ds.getCodonFrame(sq1.getDatasetSequence()),
1086 ds.getCodonFrame(sq2.getDatasetSequence()));
1089 @Test(groups = "Functional")
1090 public void testAddCodonFrame()
1092 AlignmentI align = new Alignment(new SequenceI[] {});
1093 AlignedCodonFrame acf = new AlignedCodonFrame();
1094 align.addCodonFrame(acf);
1095 assertEquals(1, align.getCodonFrames().size());
1096 assertTrue(align.getCodonFrames().contains(acf));
1097 // can't add the same object twice:
1098 align.addCodonFrame(acf);
1099 assertEquals(1, align.getCodonFrames().size());
1101 // create dataset alignment - mappings move to dataset
1102 ((Alignment) align).createDatasetAlignment();
1103 assertSame(align.getCodonFrames(), align.getDataset().getCodonFrames());
1104 assertEquals(1, align.getCodonFrames().size());
1106 AlignedCodonFrame acf2 = new AlignedCodonFrame();
1107 align.addCodonFrame(acf2);
1108 assertTrue(align.getDataset().getCodonFrames().contains(acf));
1111 @Test(groups = "Functional")
1112 public void testAddSequencePreserveDatasetIntegrity()
1114 Sequence seq = new Sequence("testSeq", "ABCDEFGHIJKLMNOPQRSTUVWXYZ");
1115 Alignment align = new Alignment(new SequenceI[] { seq });
1116 align.createDatasetAlignment();
1117 AlignmentI ds = align.getDataset();
1118 SequenceI copy = new Sequence(seq);
1119 copy.insertCharAt(3, 5, '-');
1120 align.addSequence(copy);
1121 Assert.assertEquals(align.getDataset().getHeight(), 1,
1122 "Dataset shouldn't have more than one sequence.");
1124 Sequence seq2 = new Sequence("newtestSeq",
1125 "ABCDEFGHIJKLMNOPQRSTUVWXYZ");
1126 align.addSequence(seq2);
1127 Assert.assertEquals(align.getDataset().getHeight(), 2,
1128 "Dataset should now have two sequences.");
1130 assertAlignmentDatasetRefs(align,
1131 "addSequence broke dataset reference integrity");
1135 * Tests that dbrefs with mappings to sequence get updated if the sequence
1136 * acquires a dataset sequence
1138 @Test(groups = "Functional")
1139 public void testCreateDataset_updateDbrefMappings()
1141 SequenceI pep = new Sequence("pep", "ASD");
1142 SequenceI dna = new Sequence("dna", "aaaGCCTCGGATggg");
1143 SequenceI cds = new Sequence("cds", "GCCTCGGAT");
1145 // add dbref from dna to peptide
1146 DBRefEntry dbr = new DBRefEntry("UNIPROT", "", "pep");
1148 new Mapping(pep, new MapList(new int[]
1149 { 4, 15 }, new int[] { 1, 4 }, 3, 1)));
1152 // add dbref from dna to peptide
1153 DBRefEntry dbr2 = new DBRefEntry("UNIPROT", "", "pep");
1155 new Mapping(pep, new MapList(new int[]
1156 { 1, 12 }, new int[] { 1, 4 }, 3, 1)));
1159 // add dbref from peptide to dna
1160 DBRefEntry dbr3 = new DBRefEntry("EMBL", "", "dna");
1162 new Mapping(dna, new MapList(new int[]
1163 { 1, 4 }, new int[] { 4, 15 }, 1, 3)));
1166 // add dbref from peptide to cds
1167 DBRefEntry dbr4 = new DBRefEntry("EMBLCDS", "", "cds");
1169 new Mapping(cds, new MapList(new int[]
1170 { 1, 4 }, new int[] { 1, 12 }, 1, 3)));
1173 AlignmentI protein = new Alignment(new SequenceI[] { pep });
1176 * create the alignment dataset
1178 ((Alignment) protein).createDatasetAlignment();
1180 AlignmentI ds = protein.getDataset();
1182 // should be 3 sequences in dataset
1183 assertEquals(3, ds.getHeight());
1184 assertTrue(ds.getSequences().contains(pep.getDatasetSequence()));
1185 assertTrue(ds.getSequences().contains(dna));
1186 assertTrue(ds.getSequences().contains(cds));
1189 * verify peptide.cdsdbref.peptidedbref is now mapped to peptide dataset
1191 List<DBRefEntry> dbRefs = pep.getDBRefs();
1192 assertEquals(2, dbRefs.size());
1193 assertSame(dna, dbRefs.get(0).map.to);
1194 assertSame(cds, dbRefs.get(1).map.to);
1195 assertEquals(1, dna.getDBRefs().size());
1196 assertSame(pep.getDatasetSequence(), dna.getDBRefs().get(0).map.to);
1197 assertEquals(1, cds.getDBRefs().size());
1198 assertSame(pep.getDatasetSequence(), cds.getDBRefs().get(0).map.to);
1201 @Test(groups = { "Functional" })
1202 public void testFindGroup()
1204 SequenceI seq1 = new Sequence("seq1", "ABCDEF---GHI");
1205 SequenceI seq2 = new Sequence("seq2", "---JKLMNO---");
1206 AlignmentI a = new Alignment(new SequenceI[] { seq1, seq2 });
1208 assertNull(a.findGroup(null, 0));
1209 assertNull(a.findGroup(seq1, 1));
1210 assertNull(a.findGroup(seq1, -1));
1213 * add a group consisting of just "DEF"
1215 SequenceGroup sg1 = new SequenceGroup();
1216 sg1.addSequence(seq1, false);
1221 assertNull(a.findGroup(seq1, 2)); // position not in group
1222 assertNull(a.findGroup(seq1, 6)); // position not in group
1223 assertNull(a.findGroup(seq2, 5)); // sequence not in group
1224 assertSame(a.findGroup(seq1, 3), sg1); // yes
1225 assertSame(a.findGroup(seq1, 4), sg1);
1226 assertSame(a.findGroup(seq1, 5), sg1);
1229 * add a group consisting of
1233 SequenceGroup sg2 = new SequenceGroup();
1234 sg2.addSequence(seq1, false);
1235 sg2.addSequence(seq2, false);
1240 assertNull(a.findGroup(seq1, 2)); // unchanged
1241 assertSame(a.findGroup(seq1, 3), sg1); // unchanged
1243 * if a residue is in more than one group, method returns
1244 * the first found (in order groups were added)
1246 assertSame(a.findGroup(seq1, 4), sg1);
1247 assertSame(a.findGroup(seq1, 5), sg1);
1250 * seq2 only belongs to the second group
1252 assertSame(a.findGroup(seq2, 4), sg2);
1253 assertSame(a.findGroup(seq2, 5), sg2);
1254 assertSame(a.findGroup(seq2, 6), sg2);
1255 assertSame(a.findGroup(seq2, 7), sg2);
1256 assertNull(a.findGroup(seq2, 3));
1257 assertNull(a.findGroup(seq2, 8));
1260 @Test(groups = { "Functional" })
1261 public void testDeleteSequenceByIndex()
1263 // create random alignment
1264 AlignmentGenerator gen = new AlignmentGenerator(false);
1265 AlignmentI a = gen.generate(20, 15, 123, 5, 5);
1267 // delete sequence 10, alignment reduced by 1
1268 int height = a.getAbsoluteHeight();
1269 a.deleteSequence(10);
1270 assertEquals(a.getAbsoluteHeight(), height - 1);
1272 // try to delete -ve index, nothing happens
1273 a.deleteSequence(-1);
1274 assertEquals(a.getAbsoluteHeight(), height - 1);
1276 // try to delete beyond end of alignment, nothing happens
1277 a.deleteSequence(14);
1278 assertEquals(a.getAbsoluteHeight(), height - 1);
1281 @Test(groups = { "Functional" })
1282 public void testDeleteSequenceBySeq()
1284 // create random alignment
1285 AlignmentGenerator gen = new AlignmentGenerator(false);
1286 AlignmentI a = gen.generate(20, 15, 123, 5, 5);
1288 // delete sequence 10, alignment reduced by 1
1289 int height = a.getAbsoluteHeight();
1290 SequenceI seq = a.getSequenceAt(10);
1291 a.deleteSequence(seq);
1292 assertEquals(a.getAbsoluteHeight(), height - 1);
1294 // try to delete non-existent sequence, nothing happens
1295 seq = new Sequence("cds", "GCCTCGGAT");
1296 assertEquals(a.getAbsoluteHeight(), height - 1);
1299 @Test(groups = { "Functional" })
1300 public void testDeleteHiddenSequence()
1302 // create random alignment
1303 AlignmentGenerator gen = new AlignmentGenerator(false);
1304 AlignmentI a = gen.generate(20, 15, 123, 5, 5);
1306 // delete a sequence which is hidden, check it is NOT removed from hidden
1308 int height = a.getAbsoluteHeight();
1309 SequenceI seq = a.getSequenceAt(2);
1310 a.getHiddenSequences().hideSequence(seq);
1311 assertEquals(a.getHiddenSequences().getSize(), 1);
1312 a.deleteSequence(2);
1313 assertEquals(a.getAbsoluteHeight(), height - 1);
1314 assertEquals(a.getHiddenSequences().getSize(), 1);
1316 // delete a sequence which is not hidden, check hiddenSequences are not
1318 a.deleteSequence(10);
1319 assertEquals(a.getAbsoluteHeight(), height - 2);
1320 assertEquals(a.getHiddenSequences().getSize(), 1);
1324 groups = "Functional",
1325 expectedExceptions =
1326 { IllegalArgumentException.class })
1327 public void testSetDataset_selfReference()
1329 SequenceI seq = new Sequence("a", "a");
1330 AlignmentI alignment = new Alignment(new SequenceI[] { seq });
1331 alignment.setDataset(alignment);
1334 @Test(groups = "Functional")
1335 public void testAppend()
1337 SequenceI seq = new Sequence("seq1", "FRMLPSRT-A--L-");
1338 AlignmentI alignment = new Alignment(new SequenceI[] { seq });
1339 alignment.setGapCharacter('-');
1340 SequenceI seq2 = new Sequence("seq1", "KP..L.FQII.");
1341 AlignmentI alignment2 = new Alignment(new SequenceI[] { seq2 });
1342 alignment2.setGapCharacter('.');
1344 alignment.append(alignment2);
1346 assertEquals('-', alignment.getGapCharacter());
1347 assertSame(seq, alignment.getSequenceAt(0));
1348 assertEquals("KP--L-FQII-",
1349 alignment.getSequenceAt(1).getSequenceAsString());
1351 // todo test coverage for annotations, mappings, groups,
1352 // hidden sequences, properties
1356 * test that calcId == null on findOrCreate doesn't raise an NPE, and yields
1357 * an annotation with a null calcId
1360 @Test(groups = "Functional")
1361 public void testFindOrCreateForNullCalcId()
1363 SequenceI seq = new Sequence("seq1", "FRMLPSRT-A--L-");
1364 AlignmentI alignment = new Alignment(new SequenceI[] { seq });
1366 AlignmentAnnotation ala = alignment.findOrCreateAnnotation(
1367 "Temperature Factor", null, false, seq, null);
1369 assertEquals(seq, ala.sequenceRef);
1370 assertEquals("", ala.calcId);
1373 @Test(groups = "Functional")
1374 public void testPropagateInsertions()
1376 // create an alignment with no gaps - this will be the profile seq and other
1378 AlignmentGenerator gen = new AlignmentGenerator(false);
1379 AlignmentI al = gen.generate(25, 10, 1234, 0, 0);
1381 // get the profileseq
1382 SequenceI profileseq = al.getSequenceAt(0);
1383 SequenceI gappedseq = new Sequence(profileseq);
1384 gappedseq.insertCharAt(5, al.getGapCharacter());
1385 gappedseq.insertCharAt(6, al.getGapCharacter());
1386 gappedseq.insertCharAt(7, al.getGapCharacter());
1387 gappedseq.insertCharAt(8, al.getGapCharacter());
1389 // force different kinds of padding
1390 al.getSequenceAt(3).deleteChars(2, 23);
1391 al.getSequenceAt(4).deleteChars(2, 27);
1392 al.getSequenceAt(5).deleteChars(10, 27);
1394 // create an alignment view with the gapped sequence
1395 SequenceI[] seqs = new SequenceI[1];
1396 seqs[0] = gappedseq;
1397 AlignmentI newal = new Alignment(seqs);
1398 HiddenColumns hidden = new HiddenColumns();
1399 hidden.hideColumns(15, 17);
1401 AlignmentView view = new AlignmentView(newal, hidden, null, true, false,
1404 // confirm that original contigs are as expected
1405 Iterator<int[]> visible = hidden.getVisContigsIterator(0, 25, false);
1406 int[] region = visible.next();
1407 assertEquals("[0, 14]", Arrays.toString(region));
1408 region = visible.next();
1409 assertEquals("[18, 24]", Arrays.toString(region));
1411 // propagate insertions
1412 HiddenColumns result = al.propagateInsertions(profileseq, view);
1414 // confirm that the contigs have changed to account for the gaps
1415 visible = result.getVisContigsIterator(0, 25, false);
1416 region = visible.next();
1417 assertEquals("[0, 10]", Arrays.toString(region));
1418 region = visible.next();
1419 assertEquals("[14, 24]", Arrays.toString(region));
1421 // confirm the alignment has been changed so that the other sequences have
1422 // gaps inserted where the columns are hidden
1423 assertFalse(Comparison.isGap(al.getSequenceAt(1).getSequence()[10]));
1424 assertTrue(Comparison.isGap(al.getSequenceAt(1).getSequence()[11]));
1425 assertTrue(Comparison.isGap(al.getSequenceAt(1).getSequence()[12]));
1426 assertTrue(Comparison.isGap(al.getSequenceAt(1).getSequence()[13]));
1427 assertFalse(Comparison.isGap(al.getSequenceAt(1).getSequence()[14]));
1431 @Test(groups = "Functional")
1432 public void testPropagateInsertionsOverlap()
1434 // test propagateInsertions where gaps and hiddenColumns overlap
1436 // create an alignment with no gaps - this will be the profile seq and other
1438 AlignmentGenerator gen = new AlignmentGenerator(false);
1439 AlignmentI al = gen.generate(20, 10, 1234, 0, 0);
1441 // get the profileseq
1442 SequenceI profileseq = al.getSequenceAt(0);
1443 SequenceI gappedseq = new Sequence(profileseq);
1444 gappedseq.insertCharAt(5, al.getGapCharacter());
1445 gappedseq.insertCharAt(6, al.getGapCharacter());
1446 gappedseq.insertCharAt(7, al.getGapCharacter());
1447 gappedseq.insertCharAt(8, al.getGapCharacter());
1449 // create an alignment view with the gapped sequence
1450 SequenceI[] seqs = new SequenceI[1];
1451 seqs[0] = gappedseq;
1452 AlignmentI newal = new Alignment(seqs);
1454 // hide columns so that some overlap with the gaps
1455 HiddenColumns hidden = new HiddenColumns();
1456 hidden.hideColumns(7, 10);
1458 AlignmentView view = new AlignmentView(newal, hidden, null, true, false,
1461 // confirm that original contigs are as expected
1462 Iterator<int[]> visible = hidden.getVisContigsIterator(0, 20, false);
1463 int[] region = visible.next();
1464 assertEquals("[0, 6]", Arrays.toString(region));
1465 region = visible.next();
1466 assertEquals("[11, 19]", Arrays.toString(region));
1467 assertFalse(visible.hasNext());
1469 // propagate insertions
1470 HiddenColumns result = al.propagateInsertions(profileseq, view);
1472 // confirm that the contigs have changed to account for the gaps
1473 visible = result.getVisContigsIterator(0, 20, false);
1474 region = visible.next();
1475 assertEquals("[0, 4]", Arrays.toString(region));
1476 region = visible.next();
1477 assertEquals("[7, 19]", Arrays.toString(region));
1478 assertFalse(visible.hasNext());
1480 // confirm the alignment has been changed so that the other sequences have
1481 // gaps inserted where the columns are hidden
1482 assertFalse(Comparison.isGap(al.getSequenceAt(1).getSequence()[4]));
1483 assertTrue(Comparison.isGap(al.getSequenceAt(1).getSequence()[5]));
1484 assertTrue(Comparison.isGap(al.getSequenceAt(1).getSequence()[6]));
1485 assertFalse(Comparison.isGap(al.getSequenceAt(1).getSequence()[7]));
1488 @Test(groups = { "Functional" })
1489 public void testPadGaps()
1491 SequenceI seq1 = new Sequence("seq1", "ABCDEF--");
1492 SequenceI seq2 = new Sequence("seq2", "-JKLMNO--");
1493 SequenceI seq3 = new Sequence("seq2", "-PQR");
1494 AlignmentI a = new Alignment(new SequenceI[] { seq1, seq2, seq3 });
1495 a.setGapCharacter('.'); // this replaces existing gaps
1496 assertEquals("ABCDEF..", seq1.getSequenceAsString());
1498 // trailing gaps are pruned, short sequences padded with gap character
1499 assertEquals("ABCDEF.", seq1.getSequenceAsString());
1500 assertEquals(".JKLMNO", seq2.getSequenceAsString());
1501 assertEquals(".PQR...", seq3.getSequenceAsString());
1505 * Test for setHiddenColumns, to check it returns true if the hidden columns
1506 * have changed, else false
1508 @Test(groups = { "Functional" })
1509 public void testSetHiddenColumns()
1511 AlignmentI al = new Alignment(new SequenceI[] {});
1512 assertFalse(al.getHiddenColumns().hasHiddenColumns());
1514 HiddenColumns hc = new HiddenColumns();
1515 assertFalse(al.setHiddenColumns(hc)); // no change
1516 assertSame(hc, al.getHiddenColumns());
1518 hc.hideColumns(2, 4);
1519 assertTrue(al.getHiddenColumns().hasHiddenColumns());
1522 * set a different object but with the same columns hidden
1524 HiddenColumns hc2 = new HiddenColumns();
1525 hc2.hideColumns(2, 4);
1526 assertFalse(al.setHiddenColumns(hc2)); // no change
1527 assertSame(hc2, al.getHiddenColumns());
1529 assertTrue(al.setHiddenColumns(null));
1530 assertNull(al.getHiddenColumns());
1531 assertTrue(al.setHiddenColumns(hc));
1532 assertSame(hc, al.getHiddenColumns());
1534 al.getHiddenColumns().hideColumns(10, 12);
1535 hc2.hideColumns(10, 12);
1536 assertFalse(al.setHiddenColumns(hc2)); // no change
1539 * hide columns 15-16 then 17-18 in hc
1540 * hide columns 15-18 in hc2
1541 * these are not now 'equal' objects even though they
1542 * represent the same set of columns
1544 assertSame(hc2, al.getHiddenColumns());
1545 hc.hideColumns(15, 16);
1546 hc.hideColumns(17, 18);
1547 hc2.hideColumns(15, 18);
1548 assertFalse(hc.equals(hc2));
1549 assertTrue(al.setHiddenColumns(hc)); // 'changed'
1552 @Test(groups = { "Functional" })
1553 public void testGetWidth()
1555 SequenceI seq1 = new Sequence("seq1", "ABCDEF--");
1556 SequenceI seq2 = new Sequence("seq2", "-JKLMNO--");
1557 SequenceI seq3 = new Sequence("seq2", "-PQR");
1558 AlignmentI a = new Alignment(new SequenceI[] { seq1, seq2, seq3 });
1560 assertEquals(9, a.getWidth());
1562 // width includes hidden columns
1563 a.getHiddenColumns().hideColumns(2, 5);
1564 assertEquals(9, a.getWidth());
1567 @Test(groups = { "Functional" })
1568 public void testGetVisibleWidth()
1570 SequenceI seq1 = new Sequence("seq1", "ABCDEF--");
1571 SequenceI seq2 = new Sequence("seq2", "-JKLMNO--");
1572 SequenceI seq3 = new Sequence("seq2", "-PQR");
1573 AlignmentI a = new Alignment(new SequenceI[] { seq1, seq2, seq3 });
1575 assertEquals(9, a.getVisibleWidth());
1577 // width excludes hidden columns
1578 a.getHiddenColumns().hideColumns(2, 5);
1579 assertEquals(5, a.getVisibleWidth());
1582 @Test(groups = { "Functional" })
1583 public void testGetContactMap()
1586 // 1. test adding/removing/manipulating contact maps with/without associated
1587 // sequence(s) or groups
1588 // 2. For sequence associated - ensure that inserting a gap in sequence
1589 // results in the contact map being relocated accordingly
1590 // 3. RENDERER QUESTION - should contact maps reflect gaps in the alignment