import static org.testng.AssertJUnit.assertSame;
import static org.testng.AssertJUnit.assertTrue;
-import jalview.analysis.AlignmentGenerator;
-import jalview.datamodel.AlignedCodonFrame.SequenceToSequenceMapping;
-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.io.IOException;
-import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
+import jalview.analysis.AlignmentGenerator;
+import jalview.analysis.AlignmentUtils;
+import jalview.analysis.CrossRef;
+import jalview.datamodel.AlignedCodonFrame.SequenceToSequenceMapping;
+import jalview.gui.JvOptionPane;
+import jalview.io.DataSourceType;
+import jalview.io.FastaFile;
+import jalview.io.FileFormat;
+import jalview.io.FileFormatI;
+import jalview.io.FormatAdapter;
+import jalview.util.Comparison;
+import jalview.util.MapList;
+
/**
* Unit tests for Alignment datamodel.
*
"GCTCGUCGTACT\n" +
">Seq2Name/60-71\n" +
"GGGTCAGGCAGT\n";
+
+ private static final String AA_SEQS_2 =
+ ">Seq1Name/5-8\n" +
+ "K-QY-L\n" +
+ ">Seq2Name/12-15\n" +
+ "-R-FPW\n";
+ private static final String AA_SEQS_2_DS =
+ ">Seq1Name/5-8\n" +
+ "KQYL\n" +
+ ">Seq2Name/12-15\n" +
+ "RFPW\n";
+ private static final String TD_SEQS_2_DS =
+ ">Seq1Name/5-8\n" +
+ "NMPR\n" +
+ ">Seq2Name/12-15\n" +
+ "VXYA\n";
+ private static final String TD_SEQS_2 =
+ ">Seq1Name/5-8\n" +
+ "-NMP-R\n" +
+ ">Seq2Name/12-15\n" +
+ "VX--YA\n";
+
// @formatter:on
private AlignmentI al;
return false;
}
}
- return verifyAlignmentDatasetRefs(alignment.getDataset(),
- raiseAssert, message);
+ return verifyAlignmentDatasetRefs(alignment.getDataset(), raiseAssert,
+ message);
}
else
{
{
if (raiseAssert)
{
- Assert.fail(message
- + " DBRefEntry for sequence in alignment had map to sequence not in dataset");
+ Assert.fail(message + " DBRefEntry " + dbr
+ + " for sequence " + seqds
+ + " in alignment has map to sequence not in dataset");
}
return false;
}
ae.printStackTrace();
Assert.fail(
"Valid test alignment raised assertion errors when raiseAsserts enabled: "
- + msg, ae);
+ + msg,
+ ae);
}
// also check validation passes with asserts disabled
Assert.assertTrue(verifyAlignmentDatasetRefs(al, false, null),
}
if (!assertRaised)
{
- Assert.fail("Invalid test alignment passed when raiseAsserts enabled:"
- + msg);
+ Assert.fail(
+ "Invalid test alignment passed when raiseAsserts enabled:"
+ + msg);
}
// also check validation passes with asserts disabled
Assert.assertFalse(verifyAlignmentDatasetRefs(al, false, null),
@Test(groups = { "Functional" })
public void testVerifyAlignmentDatasetRefs()
{
- SequenceI sq1 = new Sequence("sq1", "ASFDD"), sq2 = new Sequence("sq2",
- "TTTTTT");
+ SequenceI sq1 = new Sequence("sq1", "ASFDD"),
+ sq2 = new Sequence("sq2", "TTTTTT");
// construct simple valid alignment dataset
Alignment al = new Alignment(new SequenceI[] { sq1, sq2 });
"didn't detect dataset sequence with a dataset sequence reference.");
sq1.setDatasetSequence(null);
- assertVerifyAlignment(
- al,
- true,
+ assertVerifyAlignment(al, true,
"didn't reinstate validity after nulling dataset sequence dataset reference");
// now create dataset and check again
// create a dbref on sq1 with a sequence ref to sq2
DBRefEntry dbrs1tos2 = new DBRefEntry("UNIPROT", "1", "Q111111");
- dbrs1tos2.setMap(new Mapping(sq2.getDatasetSequence(),
- new int[] { 1, 5 }, new int[] { 2, 6 }, 1, 1));
+ dbrs1tos2
+ .setMap(new Mapping(sq2.getDatasetSequence(), new int[]
+ { 1, 5 }, new int[] { 2, 6 }, 1, 1));
sq1.getDatasetSequence().addDBRef(dbrs1tos2);
assertVerifyAlignment(al, true,
"verify failed after addition of valid DBRefEntry/map");
// now create a dbref on a new sequence which maps to another sequence
// outside of the dataset
- SequenceI sqout = new Sequence("sqout", "ututututucagcagcag"), sqnew = new Sequence(
- "sqnew", "EEERRR");
+ SequenceI sqout = new Sequence("sqout", "ututututucagcagcag"),
+ sqnew = new Sequence("sqnew", "EEERRR");
DBRefEntry sqnewsqout = new DBRefEntry("ENAFOO", "1", "R000001");
- sqnewsqout.setMap(new Mapping(sqout, new int[] { 1, 6 }, new int[] { 1,
- 18 }, 1, 3));
+ sqnewsqout
+ .setMap(new Mapping(sqout, new int[]
+ { 1, 6 }, new int[] { 1, 18 }, 1, 3));
al.getDataset().addSequence(sqnew);
assertVerifyAlignment(al, true,
"verify failed after addition of new sequence to dataset");
// now start checking exception conditions
sqnew.addDBRef(sqnewsqout);
- assertVerifyAlignment(
- al,
- false,
+ assertVerifyAlignment(al, false,
"verify passed when a dbref with map to sequence outside of dataset was added");
// make the verify pass by adding the outsider back in
al.getDataset().addSequence(sqout);
"aggtutaggcagcagcag");
AlignedCodonFrame alc = new AlignedCodonFrame();
- alc.addMap(sqanotherout, sqnew, new MapList(new int[] { 1, 6 },
- new int[] { 1, 18 }, 3, 1));
+ alc.addMap(sqanotherout, sqnew,
+ new MapList(new int[]
+ { 1, 6 }, new int[] { 1, 18 }, 3, 1));
al.addCodonFrame(alc);
Assert.assertEquals(al.getDataset().getCodonFrames().size(), 1);
- assertVerifyAlignment(
- al,
- false,
+ assertVerifyAlignment(al, false,
"verify passed when alCodonFrame mapping to sequence outside of dataset was added");
// make the verify pass by adding the outsider back in
al.getDataset().addSequence(sqanotherout);
- assertVerifyAlignment(
- al,
- true,
+ assertVerifyAlignment(al, true,
"verify should have passed once all sequences involved in alCodonFrame were added to dataset");
al.getDataset().addSequence(sqanotherout);
assertVerifyAlignment(al, false,
* @param message
* - null or message prepended to exception message.
*/
- public static void assertDatasetIsNormalised(AlignmentI al, String message)
+ public static void assertDatasetIsNormalised(AlignmentI al,
+ String message)
{
if (al.getDataset() != null)
{
assertDatasetIsNormalised(al);
} catch (AssertionError ae)
{
- Assert.fail("Two different sequences should be valid normalised dataset.");
+ Assert.fail(
+ "Two different sequences should be valid normalised dataset.");
}
/*
* now change sq2's name in the alignment. should still be valid
assertDatasetIsNormalised(al);
} catch (AssertionError ae)
{
- Assert.fail("Two different sequences in dataset, but same name in alignment, should be valid normalised dataset.");
+ Assert.fail(
+ "Two different sequences in dataset, but same name in alignment, should be valid normalised dataset.");
}
al.addSequence(sq1seqd);
assertDatasetIsNormalised(al);
} catch (AssertionError ae)
{
- Assert.fail("sq1 and sq1 with different sequence should be distinct.");
+ Assert.fail(
+ "sq1 and sq1 with different sequence should be distinct.");
}
al.addSequence(sq1shift);
assertDatasetIsNormalised(al);
} catch (AssertionError ae)
{
- Assert.fail("sq1 and sq1 with different start/end should be distinct.");
+ Assert.fail(
+ "sq1 and sq1 with different start/end should be distinct.");
}
/*
* finally, the failure case
// third found.. so
assertFalse(iter.hasNext());
+ // search for annotation on one sequence with a particular label - expect
+ // one
+ SequenceI sqfound;
+ anns = al.findAnnotations(sqfound = al.getSequenceAt(1), null,
+ "Secondary Structure");
+ iter = anns.iterator();
+ assertTrue(iter.hasNext());
+ // expect reference to sequence 1 in the alignment
+ assertTrue(sqfound == iter.next().sequenceRef);
+ assertFalse(iter.hasNext());
+
// null on all parameters == find all annotations
anns = al.findAnnotations(null, null, null);
iter = anns.iterator();
makeMappings(al1, al2);
((Alignment) al2).alignAs(al1, false, true);
- assertEquals("GC-TC--GUC-GTACT", al2.getSequenceAt(0)
- .getSequenceAsString());
- assertEquals("-GG-GTC--AGG--CAGT", al2.getSequenceAt(1)
- .getSequenceAsString());
+ assertEquals("GC-TC--GUC-GTACT",
+ al2.getSequenceAt(0).getSequenceAsString());
+ assertEquals("-GG-GTC--AGG--CAGT",
+ al2.getSequenceAt(1).getSequenceAsString());
}
/**
assertEquals("-R-F-P-W", al2.getSequenceAt(1).getSequenceAsString());
}
+
+ /**
+ * Recover protein MSA from tdi msa
+ *
+ * @throws IOException
+ */
+ @Test(groups = { "Functional" })
+ public void testAlignAs_prot_tdi() throws Exception
+ {
+ // see also AlignmentUtilsTests
+ AlignmentI al1 = loadAlignment(TD_SEQS_2, FileFormat.Fasta);
+ AlignmentI al2 = loadAlignment(AA_SEQS_2_DS, FileFormat.Fasta);
+ al1.setDataset(null);
+ al2.setDataset(al1.getDataset());
+ AlignmentI al1copy = new Alignment(al1);
+ AlignmentI al2copy = new Alignment(al2);
+ AlignmentUtils.map3diPeptideToProteinAligment(al2, al1);
+ if (al2.getCodonFrames().isEmpty()) {al2.getCodonFrames().addAll(al1.getCodonFrames()); }
+ else {al1.getCodonFrames().addAll(al2.getCodonFrames()); };
+
+ ((Alignment) al2).alignAs(al1);
+ assertEquals("-NMP-R", al1.getSequenceAt(0).getSequenceAsString());
+ assertEquals("VX--YA", al1.getSequenceAt(1).getSequenceAsString());
+ assertEquals("-KQY-L", al2.getSequenceAt(0).getSequenceAsString());
+ assertEquals("RF--PW", al2.getSequenceAt(1).getSequenceAsString());
+
+ }
+ /**
+ * Recover TdI MSA from protein msa
+ *
+ * @throws IOException
+ */
+ @Test(groups = { "Functional" })
+ public void testAlignAs_tdi_prot() throws Exception
+ {
+ // see also AlignmentUtilsTests
+ AlignmentI al1 = loadAlignment(AA_SEQS_2, FileFormat.Fasta);
+ AlignmentI al2 = loadAlignment(TD_SEQS_2_DS, FileFormat.Fasta);
+ al1.setDataset(null);
+ al2.setDataset(al1.getDataset());
+ AlignmentI al1copy = new Alignment(al1);
+ AlignmentI al2copy = new Alignment(al2);
+ AlignmentUtils.map3diPeptideToProteinAligment(al1, al2);
+ if (al2.getCodonFrames().isEmpty()) {al2.getCodonFrames().addAll(al1.getCodonFrames()); }
+ else {al1.getCodonFrames().addAll(al2.getCodonFrames()); };
+
+ ((Alignment) al2).alignAs(al1);
+ assertEquals("K-QY-L", al1.getSequenceAt(0).getSequenceAsString());
+ assertEquals("-R-FPW", al1.getSequenceAt(1).getSequenceAsString());
+ assertEquals("N-MP-R", al2.getSequenceAt(0).getSequenceAsString());
+ assertEquals("-V-XYA", al2.getSequenceAt(1).getSequenceAsString());
+
+ }
/**
* Test aligning cdna as per protein alignment.
*
* Realign DNA; currently keeping existing gaps in introns only
*/
((Alignment) al1).alignAs(al2, false, true);
- assertEquals("ACG---GCUCCA------ACT---", al1.getSequenceAt(0)
- .getSequenceAsString());
- assertEquals("---CGT---TAACGA---AGT---", al1.getSequenceAt(1)
- .getSequenceAsString());
+ assertEquals("ACG---GCUCCA------ACT---",
+ al1.getSequenceAt(0).getSequenceAsString());
+ assertEquals("---CGT---TAACGA---AGT---",
+ al1.getSequenceAt(1).getSequenceAsString());
}
/**
}
/**
+ * test mapping between a protein and 3di sequence alignment. Assumes 1:1
+ * @throws IOException
+ */
+ @Test(groups={"Functional"},enabled=true)
+ public void testAlignAs_3di() throws IOException
+ {
+ String protAl = ">1ji5_A\n"
+ + "-----------------------------DQPVLLLLLLQLLLLLVLLLQQLVVCLVQAD\n"
+ + "DPCNVVSNVVSVVSSVVSVVSNVVSQVVCVVVVHHHDDDVSSVVRYPQDHHDPP--DYPL\n"
+ + "RSLVSLLVSLVVVLVSLVVSLVSCVVVVNVVSNVSSVVVSVVSVVSNVVSCVVVVD----\n"
+ + "---------------------------------------------------\n"
+ + ">1jig_A\n"
+ + "---------------------------DALLVVLLLLLLQLLLALVLLLQQLVLCLVLAD\n"
+ + "DPCNVVSNVVSVVVSVVSVVSNVVSQVVCVVSVHHHDDDVSSVVRYPQDHDDSP--DYPL\n"
+ + "RSLVSLLVSLVVLLVSLVVSLVSCVVNVNPVSNVSSVVSSVVSVVSNVVSVVVND-----\n"
+ + "---------------------------------------------------\n"
+ + "\n";
+ String tdiAl = ">1ji5_A\n"
+ + "-----------------------------MNKQVIEVLNKQVADWSVLFTKLHNFHWYVK\n"
+ + "GPQFFTLHEKFEELYTESATHIDEIAERILAIGGKPVATKEYLEISSIQEAAYG--ETAE\n"
+ + "GMVEAIMKDYEMMLVELKKGMEIAQNSDDEMTSDLLLGIYTELEKHAWMLRAFLNQ----\n"
+ + "---------------------------------------------------\n"
+ + ">1jig_A\n"
+ + "---------------------------MSTKTNVVEVLNKQVANWNVLYVKLHNYHWYVT\n"
+ + "GPHFFTLHEKFEEFYNEAGTYIDELAERILALEGKPLATKEYLATSSVNEGTSK--ESAE\n"
+ + "EMVQTLVNDYSALIQELKEGMEVAGEAGDATSADMLLAIHTTLEQHVWMLSAFLK-----\n"
+ + "---------------------------------------------------\n" + "";
+ AlignmentI prot = loadAlignment(protAl, FileFormat.Fasta);
+ ((Alignment) prot).createDatasetAlignment();
+
+ AlignmentI tdi = loadAlignment(tdiAl, FileFormat.Fasta);
+ assertTrue(AlignmentUtils.map3diPeptideToProteinAligment(prot, tdi));
+
+ AlignmentI newProt = new Alignment(
+ new SequenceI[]
+ { prot.getSequenceAt(0).getSubSequence(25, 35),
+ prot.getSequenceAt(1).getSubSequence(35, 45) });
+ newProt.setDataset(prot.getDataset());
+
+ // TODO Find matching tdi sequence and construct alignment mirroring
+ // the protein alignment
+ // Alignment newTdi = new CrossRef(newProt.getSequencesArray(),
+ // newProt.getDataset()).findXrefSequences("", false);
+ //
+ // newTdi.alignAs(newProt);
+ //
+ // System.out.println("newProt - aa\n"+new
+ // FastaFile().print(newProt.getSequencesArray(), true));
+ // System.out.println("newProt - 3di\n"+new
+ // FastaFile().print(newTdi.getSequencesArray(), true));
+
+ }
+ /**
* Helper method that makes mappings and then aligns the first alignment as
* the second
*
/**
* Helper method to make mappings between sequences, and add the mappings to
- * the 'mapped from' alignment
+ * the 'mapped from' alignment. If alFrom.isNucleotide() == alTo.isNucleotide() then ratio is always 1:1
*
* @param alFrom
* @param alTo
{
SequenceI seqFrom = alFrom.getSequenceAt(i);
SequenceI seqTo = alTo.getSequenceAt(i);
- MapList ml = new MapList(new int[] { seqFrom.getStart(),
- seqFrom.getEnd() },
- new int[] { seqTo.getStart(), seqTo.getEnd() }, ratio, 1);
+ MapList ml = new MapList(
+ new int[]
+ { seqFrom.getStart(), seqFrom.getEnd() },
+ new int[]
+ { seqTo.getStart(), seqTo.getEnd() }, ratio, 1);
acf.addMap(seqFrom, seqTo, ml);
}
*/
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", FileFormat.Fasta);
+ AlignmentI al1 = loadAlignment(
+ ">Dna1/6-17\n" + dna1 + "\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", 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
- MapList ml1 = new MapList(new int[] { 6, 7, 10, 13, 15, 17 }, new int[]
- { 7, 9 }, 3, 1);
+ MapList ml1 = new MapList(new int[] { 6, 7, 10, 13, 15, 17 },
+ new int[]
+ { 7, 9 }, 3, 1);
acf.addMap(al1.getSequenceAt(0), al2.getSequenceAt(0), ml1);
- MapList ml2 = new MapList(new int[] { 21, 23, 26, 31 }, new int[] { 11,
- 13 }, 3, 1);
+ MapList ml2 = new MapList(new int[] { 21, 23, 26, 31 },
+ new int[]
+ { 11, 13 }, 3, 1);
acf.addMap(al1.getSequenceAt(1), al2.getSequenceAt(1), ml2);
al2.addCodonFrame(acf);
* Align ignoring gaps in dna introns and exons
*/
((Alignment) al1).alignAs(al2, false, false);
- assertEquals("---AAagG------GCCcTTT", al1.getSequenceAt(0)
- .getSequenceAsString());
+ assertEquals("---AAagG------GCCcTTT",
+ al1.getSequenceAt(0).getSequenceAsString());
// note 1 gap in protein corresponds to 'gg-' in DNA (3 positions)
- assertEquals("cCCGgg-TTT------AAA", al1.getSequenceAt(1)
- .getSequenceAsString());
+ assertEquals("cCCGgg-TTT------AAA",
+ al1.getSequenceAt(1).getSequenceAsString());
/*
* Reset and realign, preserving gaps in dna introns and exons
// String dna1 = "A-Aa-gG-GCC-cT-TT";
// String dna2 = "c--CCGgg-TT--T-AA-A";
// assumption: we include 'the greater of' protein/dna gap lengths, not both
- assertEquals("---A-Aa-gG------GCC-cT-TT", al1.getSequenceAt(0)
- .getSequenceAsString());
- assertEquals("c--CCGgg-TT--T------AA-A", al1.getSequenceAt(1)
- .getSequenceAsString());
+ assertEquals("---A-Aa-gG------GCC-cT-TT",
+ al1.getSequenceAt(0).getSequenceAsString());
+ assertEquals("c--CCGgg-TT--T------AA-A",
+ al1.getSequenceAt(1).getSequenceAsString());
}
@Test(groups = "Functional")
// create sequence and alignment datasets
protein.setDataset(null);
AlignedCodonFrame acf = new AlignedCodonFrame();
- List<AlignedCodonFrame> acfList = Arrays.asList(new AlignedCodonFrame[]
- { acf });
+ List<AlignedCodonFrame> acfList = Arrays
+ .asList(new AlignedCodonFrame[]
+ { acf });
protein.getDataset().setCodonFrames(acfList);
AlignmentI copy = new Alignment(protein);
*/
assertFalse(copy.getSequenceAt(0) == protein.getSequenceAt(0));
assertFalse(copy.getSequenceAt(1) == protein.getSequenceAt(1));
- assertSame(copy.getSequenceAt(0).getDatasetSequence(), protein
- .getSequenceAt(0).getDatasetSequence());
- assertSame(copy.getSequenceAt(1).getDatasetSequence(), protein
- .getSequenceAt(1).getDatasetSequence());
+ assertSame(copy.getSequenceAt(0).getDatasetSequence(),
+ protein.getSequenceAt(0).getDatasetSequence());
+ assertSame(copy.getSequenceAt(1).getDatasetSequence(),
+ protein.getSequenceAt(1).getDatasetSequence());
// TODO should the copy constructor copy the dataset?
// or make a new one referring to the same dataset sequences??
// side-effect: dataset created on second sequence
assertNotNull(protein.getSequenceAt(1).getDatasetSequence());
// dataset alignment has references to dataset sequences
- assertEquals(ds.getSequenceAt(0), protein.getSequenceAt(0)
- .getDatasetSequence());
- assertEquals(ds.getSequenceAt(1), protein.getSequenceAt(1)
- .getDatasetSequence());
+ assertEquals(ds.getSequenceAt(0),
+ protein.getSequenceAt(0).getDatasetSequence());
+ assertEquals(ds.getSequenceAt(1),
+ protein.getSequenceAt(1).getDatasetSequence());
// codon frames should have been moved to the dataset
// getCodonFrames() should delegate to the dataset:
// cross-references to two more sequences.
DBRefEntry dbr = new DBRefEntry("SQ1", "", "sq3");
SequenceI sq3 = new Sequence("sq3", "VWANG");
- dbr.setMap(new Mapping(sq3, new MapList(new int[] { 1, 4 }, new int[] {
- 2, 5 }, 1, 1)));
+ dbr.setMap(
+ new Mapping(sq3, new MapList(new int[]
+ { 1, 4 }, new int[] { 2, 5 }, 1, 1)));
sq1.addDBRef(dbr);
SequenceI sq4 = new Sequence("sq4", "ERKWI");
DBRefEntry dbr2 = new DBRefEntry("SQ2", "", "sq4");
- dbr2.setMap(new Mapping(sq4, new MapList(new int[] { 1, 4 }, new int[] {
- 2, 5 }, 1, 1)));
+ dbr2.setMap(
+ new Mapping(sq4, new MapList(new int[]
+ { 1, 4 }, new int[] { 2, 5 }, 1, 1)));
sq2.addDBRef(dbr2);
// and a 1:1 codonframe mapping between them.
AlignedCodonFrame alc = new AlignedCodonFrame();
- alc.addMap(sq1, sq2, new MapList(new int[] { 1, 4 },
- new int[] { 1, 4 }, 1, 1));
+ alc.addMap(sq1, sq2,
+ new MapList(new int[]
+ { 1, 4 }, new int[] { 1, 4 }, 1, 1));
AlignmentI protein = new Alignment(new SequenceI[] { sq1, sq2 });
Assert.assertEquals(align.getDataset().getHeight(), 1,
"Dataset shouldn't have more than one sequence.");
- Sequence seq2 = new Sequence("newtestSeq", "ABCDEFGHIJKLMNOPQRSTUVWXYZ");
+ Sequence seq2 = new Sequence("newtestSeq",
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZ");
align.addSequence(seq2);
Assert.assertEquals(align.getDataset().getHeight(), 2,
"Dataset should now have two sequences.");
"addSequence broke dataset reference integrity");
}
- @Test(groups = "Functional")
- public void getVisibleStartAndEndIndexTest()
- {
- Sequence seq = new Sequence("testSeq", "ABCDEFGHIJKLMNOPQRSTUVWXYZ");
- AlignmentI align = new Alignment(new SequenceI[] { seq });
- ArrayList<int[]> hiddenCols = new ArrayList<int[]>();
-
- int[] startEnd = align.getVisibleStartAndEndIndex(hiddenCols);
- assertEquals(0, startEnd[0]);
- assertEquals(25, startEnd[1]);
-
- hiddenCols.add(new int[] { 0, 0 });
- startEnd = align.getVisibleStartAndEndIndex(hiddenCols);
- assertEquals(1, startEnd[0]);
- assertEquals(25, startEnd[1]);
-
- hiddenCols.add(new int[] { 6, 9 });
- hiddenCols.add(new int[] { 11, 12 });
- startEnd = align.getVisibleStartAndEndIndex(hiddenCols);
- assertEquals(1, startEnd[0]);
- assertEquals(25, startEnd[1]);
-
- hiddenCols.add(new int[] { 24, 25 });
- startEnd = align.getVisibleStartAndEndIndex(hiddenCols);
- System.out.println(startEnd[0] + " : " + startEnd[1]);
- assertEquals(1, startEnd[0]);
- assertEquals(23, startEnd[1]);
- }
-
/**
* Tests that dbrefs with mappings to sequence get updated if the sequence
* acquires a dataset sequence
// 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[] {
- 1, 4 }, 3, 1)));
+ dbr.setMap(
+ new Mapping(pep, new MapList(new int[]
+ { 4, 15 }, new int[] { 1, 4 }, 3, 1)));
dna.addDBRef(dbr);
// add dbref from dna to peptide
DBRefEntry dbr2 = new DBRefEntry("UNIPROT", "", "pep");
- dbr2.setMap(new Mapping(pep, new MapList(new int[] { 1, 12 }, new int[]
- { 1, 4 }, 3, 1)));
+ dbr2.setMap(
+ new Mapping(pep, new MapList(new int[]
+ { 1, 12 }, new int[] { 1, 4 }, 3, 1)));
cds.addDBRef(dbr2);
// add dbref from peptide to dna
DBRefEntry dbr3 = new DBRefEntry("EMBL", "", "dna");
- dbr3.setMap(new Mapping(dna, new MapList(new int[] { 1, 4 }, new int[] {
- 4, 15 }, 1, 3)));
+ dbr3.setMap(
+ new Mapping(dna, new MapList(new int[]
+ { 1, 4 }, new int[] { 4, 15 }, 1, 3)));
pep.addDBRef(dbr3);
// add dbref from peptide to cds
DBRefEntry dbr4 = new DBRefEntry("EMBLCDS", "", "cds");
- dbr4.setMap(new Mapping(cds, new MapList(new int[] { 1, 4 }, new int[] {
- 1, 12 }, 1, 3)));
+ dbr4.setMap(
+ new Mapping(cds, new MapList(new int[]
+ { 1, 4 }, new int[] { 1, 12 }, 1, 3)));
pep.addDBRef(dbr4);
AlignmentI protein = new Alignment(new SequenceI[] { pep });
/*
* verify peptide.cdsdbref.peptidedbref is now mapped to peptide dataset
*/
- DBRefEntry[] dbRefs = pep.getDBRefs();
- assertEquals(2, dbRefs.length);
- assertSame(dna, dbRefs[0].map.to);
- assertSame(cds, dbRefs[1].map.to);
- assertEquals(1, dna.getDBRefs().length);
- assertSame(pep.getDatasetSequence(), dna.getDBRefs()[0].map.to);
- assertEquals(1, cds.getDBRefs().length);
- assertSame(pep.getDatasetSequence(), cds.getDBRefs()[0].map.to);
+ List<DBRefEntry> dbRefs = pep.getDBRefs();
+ assertEquals(2, dbRefs.size());
+ assertSame(dna, dbRefs.get(0).map.to);
+ assertSame(cds, dbRefs.get(1).map.to);
+ assertEquals(1, dna.getDBRefs().size());
+ assertSame(pep.getDatasetSequence(), dna.getDBRefs().get(0).map.to);
+ assertEquals(1, cds.getDBRefs().size());
+ assertSame(pep.getDatasetSequence(), cds.getDBRefs().get(0).map.to);
}
@Test(groups = { "Functional" })
@Test(
groups = "Functional",
- expectedExceptions = { IllegalArgumentException.class })
+ expectedExceptions =
+ { IllegalArgumentException.class })
public void testSetDataset_selfReference()
{
SequenceI seq = new Sequence("a", "a");
assertEquals('-', alignment.getGapCharacter());
assertSame(seq, alignment.getSequenceAt(0));
- assertEquals("KP--L-FQII-", alignment.getSequenceAt(1)
- .getSequenceAsString());
+ assertEquals("KP--L-FQII-",
+ alignment.getSequenceAt(1).getSequenceAsString());
// todo test coverage for annotations, mappings, groups,
// hidden sequences, properties
}
+
+ /**
+ * test that calcId == null on findOrCreate doesn't raise an NPE, and yields
+ * an annotation with a null calcId
+ *
+ */
+ @Test(groups = "Functional")
+ public void testFindOrCreateForNullCalcId()
+ {
+ SequenceI seq = new Sequence("seq1", "FRMLPSRT-A--L-");
+ AlignmentI alignment = new Alignment(new SequenceI[] { seq });
+
+ AlignmentAnnotation ala = alignment.findOrCreateAnnotation(
+ "Temperature Factor", null, false, seq, null);
+ assertNotNull(ala);
+ assertEquals(seq, ala.sequenceRef);
+ assertEquals("", ala.calcId);
+ }
+
+ @Test(groups = "Functional")
+ public void testPropagateInsertions()
+ {
+ // create an alignment with no gaps - this will be the profile seq and other
+ // JPRED seqs
+ AlignmentGenerator gen = new AlignmentGenerator(false);
+ AlignmentI al = gen.generate(25, 10, 1234, 0, 0);
+
+ // get the profileseq
+ SequenceI profileseq = al.getSequenceAt(0);
+ SequenceI gappedseq = new Sequence(profileseq);
+ gappedseq.insertCharAt(5, al.getGapCharacter());
+ gappedseq.insertCharAt(6, al.getGapCharacter());
+ gappedseq.insertCharAt(7, al.getGapCharacter());
+ gappedseq.insertCharAt(8, al.getGapCharacter());
+
+ // force different kinds of padding
+ al.getSequenceAt(3).deleteChars(2, 23);
+ al.getSequenceAt(4).deleteChars(2, 27);
+ al.getSequenceAt(5).deleteChars(10, 27);
+
+ // create an alignment view with the gapped sequence
+ SequenceI[] seqs = new SequenceI[1];
+ seqs[0] = gappedseq;
+ AlignmentI newal = new Alignment(seqs);
+ HiddenColumns hidden = new HiddenColumns();
+ hidden.hideColumns(15, 17);
+
+ AlignmentView view = new AlignmentView(newal, hidden, null, true, false,
+ false);
+
+ // confirm that original contigs are as expected
+ Iterator<int[]> visible = hidden.getVisContigsIterator(0, 25, false);
+ int[] region = visible.next();
+ assertEquals("[0, 14]", Arrays.toString(region));
+ region = visible.next();
+ assertEquals("[18, 24]", Arrays.toString(region));
+
+ // propagate insertions
+ HiddenColumns result = al.propagateInsertions(profileseq, view);
+
+ // confirm that the contigs have changed to account for the gaps
+ visible = result.getVisContigsIterator(0, 25, false);
+ region = visible.next();
+ assertEquals("[0, 10]", Arrays.toString(region));
+ region = visible.next();
+ assertEquals("[14, 24]", Arrays.toString(region));
+
+ // confirm the alignment has been changed so that the other sequences have
+ // gaps inserted where the columns are hidden
+ assertFalse(Comparison.isGap(al.getSequenceAt(1).getSequence()[10]));
+ assertTrue(Comparison.isGap(al.getSequenceAt(1).getSequence()[11]));
+ assertTrue(Comparison.isGap(al.getSequenceAt(1).getSequence()[12]));
+ assertTrue(Comparison.isGap(al.getSequenceAt(1).getSequence()[13]));
+ assertFalse(Comparison.isGap(al.getSequenceAt(1).getSequence()[14]));
+
+ }
+
+ @Test(groups = "Functional")
+ public void testPropagateInsertionsOverlap()
+ {
+ // test propagateInsertions where gaps and hiddenColumns overlap
+
+ // create an alignment with no gaps - this will be the profile seq and other
+ // JPRED seqs
+ AlignmentGenerator gen = new AlignmentGenerator(false);
+ AlignmentI al = gen.generate(20, 10, 1234, 0, 0);
+
+ // get the profileseq
+ SequenceI profileseq = al.getSequenceAt(0);
+ SequenceI gappedseq = new Sequence(profileseq);
+ gappedseq.insertCharAt(5, al.getGapCharacter());
+ gappedseq.insertCharAt(6, al.getGapCharacter());
+ gappedseq.insertCharAt(7, al.getGapCharacter());
+ gappedseq.insertCharAt(8, al.getGapCharacter());
+
+ // create an alignment view with the gapped sequence
+ SequenceI[] seqs = new SequenceI[1];
+ seqs[0] = gappedseq;
+ AlignmentI newal = new Alignment(seqs);
+
+ // hide columns so that some overlap with the gaps
+ HiddenColumns hidden = new HiddenColumns();
+ hidden.hideColumns(7, 10);
+
+ AlignmentView view = new AlignmentView(newal, hidden, null, true, false,
+ false);
+
+ // confirm that original contigs are as expected
+ Iterator<int[]> visible = hidden.getVisContigsIterator(0, 20, false);
+ int[] region = visible.next();
+ assertEquals("[0, 6]", Arrays.toString(region));
+ region = visible.next();
+ assertEquals("[11, 19]", Arrays.toString(region));
+ assertFalse(visible.hasNext());
+
+ // propagate insertions
+ HiddenColumns result = al.propagateInsertions(profileseq, view);
+
+ // confirm that the contigs have changed to account for the gaps
+ visible = result.getVisContigsIterator(0, 20, false);
+ region = visible.next();
+ assertEquals("[0, 4]", Arrays.toString(region));
+ region = visible.next();
+ assertEquals("[7, 19]", Arrays.toString(region));
+ assertFalse(visible.hasNext());
+
+ // confirm the alignment has been changed so that the other sequences have
+ // gaps inserted where the columns are hidden
+ assertFalse(Comparison.isGap(al.getSequenceAt(1).getSequence()[4]));
+ assertTrue(Comparison.isGap(al.getSequenceAt(1).getSequence()[5]));
+ assertTrue(Comparison.isGap(al.getSequenceAt(1).getSequence()[6]));
+ assertFalse(Comparison.isGap(al.getSequenceAt(1).getSequence()[7]));
+ }
+
+ @Test(groups = { "Functional" })
+ public void testPadGaps()
+ {
+ SequenceI seq1 = new Sequence("seq1", "ABCDEF--");
+ SequenceI seq2 = new Sequence("seq2", "-JKLMNO--");
+ SequenceI seq3 = new Sequence("seq2", "-PQR");
+ AlignmentI a = new Alignment(new SequenceI[] { seq1, seq2, seq3 });
+ a.setGapCharacter('.'); // this replaces existing gaps
+ assertEquals("ABCDEF..", seq1.getSequenceAsString());
+ a.padGaps();
+ // trailing gaps are pruned, short sequences padded with gap character
+ assertEquals("ABCDEF.", seq1.getSequenceAsString());
+ assertEquals(".JKLMNO", seq2.getSequenceAsString());
+ assertEquals(".PQR...", seq3.getSequenceAsString());
+ }
+
+ /**
+ * Test for setHiddenColumns, to check it returns true if the hidden columns
+ * have changed, else false
+ */
+ @Test(groups = { "Functional" })
+ public void testSetHiddenColumns()
+ {
+ AlignmentI al = new Alignment(new SequenceI[] {});
+ assertFalse(al.getHiddenColumns().hasHiddenColumns());
+
+ HiddenColumns hc = new HiddenColumns();
+ assertFalse(al.setHiddenColumns(hc)); // no change
+ assertSame(hc, al.getHiddenColumns());
+
+ hc.hideColumns(2, 4);
+ assertTrue(al.getHiddenColumns().hasHiddenColumns());
+
+ /*
+ * set a different object but with the same columns hidden
+ */
+ HiddenColumns hc2 = new HiddenColumns();
+ hc2.hideColumns(2, 4);
+ assertFalse(al.setHiddenColumns(hc2)); // no change
+ assertSame(hc2, al.getHiddenColumns());
+
+ assertTrue(al.setHiddenColumns(null));
+ assertNull(al.getHiddenColumns());
+ assertTrue(al.setHiddenColumns(hc));
+ assertSame(hc, al.getHiddenColumns());
+
+ al.getHiddenColumns().hideColumns(10, 12);
+ hc2.hideColumns(10, 12);
+ assertFalse(al.setHiddenColumns(hc2)); // no change
+
+ /*
+ * hide columns 15-16 then 17-18 in hc
+ * hide columns 15-18 in hc2
+ * these are not now 'equal' objects even though they
+ * represent the same set of columns
+ */
+ assertSame(hc2, al.getHiddenColumns());
+ hc.hideColumns(15, 16);
+ hc.hideColumns(17, 18);
+ hc2.hideColumns(15, 18);
+ assertFalse(hc.equals(hc2));
+ assertTrue(al.setHiddenColumns(hc)); // 'changed'
+ }
+
+ @Test(groups = { "Functional" })
+ public void testGetWidth()
+ {
+ SequenceI seq1 = new Sequence("seq1", "ABCDEF--");
+ SequenceI seq2 = new Sequence("seq2", "-JKLMNO--");
+ SequenceI seq3 = new Sequence("seq2", "-PQR");
+ AlignmentI a = new Alignment(new SequenceI[] { seq1, seq2, seq3 });
+
+ assertEquals(9, a.getWidth());
+
+ // width includes hidden columns
+ a.getHiddenColumns().hideColumns(2, 5);
+ assertEquals(9, a.getWidth());
+ }
+
+ @Test(groups = { "Functional" })
+ public void testGetVisibleWidth()
+ {
+ SequenceI seq1 = new Sequence("seq1", "ABCDEF--");
+ SequenceI seq2 = new Sequence("seq2", "-JKLMNO--");
+ SequenceI seq3 = new Sequence("seq2", "-PQR");
+ AlignmentI a = new Alignment(new SequenceI[] { seq1, seq2, seq3 });
+
+ assertEquals(9, a.getVisibleWidth());
+
+ // width excludes hidden columns
+ a.getHiddenColumns().hideColumns(2, 5);
+ assertEquals(5, a.getVisibleWidth());
+ }
+
+ @Test(groups = { "Functional" })
+ public void testGetContactMap()
+ {
+ // TODO
+ // 1. test adding/removing/manipulating contact maps with/without associated
+ // sequence(s) or groups
+ // 2. For sequence associated - ensure that inserting a gap in sequence
+ // results in the contact map being relocated accordingly
+ // 3. RENDERER QUESTION - should contact maps reflect gaps in the alignment
+ // ?
+
+ }
+
+ @Test(groups = { "Functional" })
+ public void testEquals()
+ {
+ SequenceI seq1 = new Sequence("seq1", "ABCDEF--");
+ SequenceI seq2 = new Sequence("seq2", "-JKLMNO--");
+ SequenceI seq3 = new Sequence("seq2", "-PQR");
+ AlignmentI a = new Alignment(new SequenceI[] { seq1, seq2, seq3 });
+ a.setDataset(null);
+ assertEquals(a.getDataset(), a.getDataset());
+ }
}