X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=test%2Fjalview%2Fio%2FFeaturesFileTest.java;h=506ee91dcf1248a9506fe6592a3a3e799a8ec9e4;hb=2acdd7fdaa575dd5238585ad86597f808b30d281;hp=ed388a5f1aecae14f188fe16961174411d5c7cca;hpb=ab9351a591e5295be9e41bfa86238ccc2a8024f8;p=jalview.git diff --git a/test/jalview/io/FeaturesFileTest.java b/test/jalview/io/FeaturesFileTest.java index ed388a5..506ee91 100644 --- a/test/jalview/io/FeaturesFileTest.java +++ b/test/jalview/io/FeaturesFileTest.java @@ -24,10 +24,14 @@ import static org.testng.AssertJUnit.assertEquals; import static org.testng.AssertJUnit.assertFalse; import static org.testng.AssertJUnit.assertNotNull; import static org.testng.AssertJUnit.assertNull; +import static org.testng.AssertJUnit.assertSame; import static org.testng.AssertJUnit.assertTrue; +import static org.testng.internal.junit.ArrayAsserts.assertArrayEquals; +import jalview.datamodel.AlignedCodonFrame; import jalview.datamodel.Alignment; import jalview.datamodel.AlignmentI; +import jalview.datamodel.Mapping; import jalview.datamodel.SequenceDummy; import jalview.datamodel.SequenceFeature; import jalview.datamodel.SequenceI; @@ -38,16 +42,16 @@ import jalview.schemes.GraduatedColor; import java.awt.Color; import java.io.File; import java.io.IOException; +import java.util.Iterator; import java.util.Map; +import java.util.Set; import org.testng.annotations.Test; public class FeaturesFileTest { - private static String exonerateSeqs = "examples/testdata/exonerateseqs.fa", - exonerateOutput = "examples/testdata/exonerateoutput.gff", - simpleGffFile = "examples/testdata/simpleGff3.gff"; + private static String simpleGffFile = "examples/testdata/simpleGff3.gff"; @Test(groups = { "Functional" }) public void testParse() throws Exception @@ -144,8 +148,9 @@ public class FeaturesFileTest AlignFrame af = new AlignFrame(al, 500, 500); Map colours = af.getFeatureRenderer() .getFeatureColours(); + // GFF2 uses space as name/value separator in column 9 String gffData = "METAL\tcc9900\n" + "GFF\n" - + "FER_CAPAA\tuniprot\tMETAL\t44\t45\t4.0\t.\t.\n" + + "FER_CAPAA\tuniprot\tMETAL\t44\t45\t4.0\t.\t.\tNote Iron-sulfur; Note 2Fe-2S\n" + "FER1_SOLLC\tuniprot\tPfam\t55\t130\t2.0\t.\t."; FeaturesFile featuresFile = new FeaturesFile(gffData, FormatAdapter.PASTE); @@ -162,7 +167,7 @@ public class FeaturesFileTest .getSequenceFeatures(); assertEquals(1, sfs.length); SequenceFeature sf = sfs[0]; - assertEquals("uniprot", sf.description); + assertEquals("Iron-sulfur; 2Fe-2S", sf.description); assertEquals(44, sf.begin); assertEquals(45, sf.end); assertEquals("uniprot", sf.featureGroup); @@ -240,14 +245,15 @@ public class FeaturesFileTest * @throws Exception */ @Test(groups = { "Functional" }) - public void testParse_pureGff() throws Exception + public void testParse_pureGff3() throws Exception { File f = new File("examples/uniref50.fa"); AlignmentI al = readAlignmentFile(f); AlignFrame af = new AlignFrame(al, 500, 500); Map colours = af.getFeatureRenderer() .getFeatureColours(); - String gffData = "##gff-version 2\n" + // GFF3 uses '=' separator for name/value pairs in colum 9 + String gffData = "##gff-version 3\n" + "FER_CAPAA\tuniprot\tMETAL\t39\t39\t0.0\t.\t.\t" + "Note=Iron-sulfur (2Fe-2S);Note=another note;evidence=ECO:0000255|PROSITE-ProRule:PRU00465\n" + "FER1_SOLLC\tuniprot\tPfam\t55\t130\t3.0\t.\t."; @@ -389,14 +395,6 @@ public class FeaturesFileTest } @Test(groups = { "Functional" }) - public void simpleGff3FileIdentify() - { - assertEquals("Didn't recognise file correctly.", - IdentifyFile.FeaturesFile, - new IdentifyFile().identify(simpleGffFile, FormatAdapter.FILE)); - } - - @Test(groups = { "Functional" }) public void simpleGff3FileLoader() throws IOException { AlignFrame af = new FileLoader(false).LoadFileWaitTillLoaded( @@ -421,24 +419,63 @@ public class FeaturesFileTest checkDatasetfromSimpleGff3(dataset); } + /** + * Tests loading exonerate GFF2 output, including 'similarity' alignment + * feature, on to sequences + */ @Test(groups = { "Functional" }) public void testExonerateImport() { - // exonerate does not tag sequences after features, so we have a more - // conventional annotation import test here - FileLoader loader = new FileLoader(false); - - AlignFrame af = loader.LoadFileWaitTillLoaded(exonerateSeqs, + AlignFrame af = loader.LoadFileWaitTillLoaded( + "examples/testdata/exonerateseqs.fa", FormatAdapter.FILE); - assertEquals("Unexpected number of DNA protein associations", 0, af - .getViewport().getAlignment().getCodonFrames().size()); + af.loadJalviewDataFile("examples/testdata/exonerateoutput.gff", + FormatAdapter.FILE, null, null); - af.loadJalviewDataFile(exonerateOutput, FormatAdapter.FILE, null, null); - - assertTrue("Expected at least one DNA protein association", 0 != af - .getViewport().getAlignment().getDataset().getCodonFrames() - .size()); + /* + * verify one mapping to a dummy sequence, one to a real one + */ + Set mappings = af + .getViewport().getAlignment().getDataset().getCodonFrames(); + assertEquals(2, mappings.size()); + Iterator iter = mappings.iterator(); + + // first mapping is to dummy sequence + AlignedCodonFrame mapping = iter.next(); + Mapping[] mapList = mapping.getProtMappings(); + assertEquals(1, mapList.length); + assertTrue(mapList[0].getTo() instanceof SequenceDummy); + assertEquals("DDB_G0269124", mapList[0].getTo().getName()); + + // second mapping is to a sequence in the alignment + mapping = iter.next(); + mapList = mapping.getProtMappings(); + assertEquals(1, mapList.length); + SequenceI proteinSeq = af.getViewport().getAlignment() + .findName("DDB_G0280897"); + assertSame(proteinSeq.getDatasetSequence(), mapList[0].getTo()); + assertEquals(1, mapping.getdnaToProt().length); + + // 143 in protein should map to codon [11270, 11269, 11268] in dna + int[] mappedRegion = mapList[0].getMap().locateInFrom(143, 143); + assertArrayEquals(new int[] { 11270, 11268 }, mappedRegion); + + // 182 in protein should map to codon [11153, 11152, 11151] in dna + mappedRegion = mapList[0].getMap().locateInFrom(182, 182); + assertArrayEquals(new int[] { 11153, 11151 }, mappedRegion); + + // and the reverse mapping: + mappedRegion = mapList[0].getMap().locateInTo(11151, 11153); + assertArrayEquals(new int[] { 182, 182 }, mappedRegion); + + // 11150 in dna should _not_ map to protein + mappedRegion = mapList[0].getMap().locateInTo(11150, 11150); + assertNull(mappedRegion); + + // similarly 183 in protein should _not_ map to dna + mappedRegion = mapList[0].getMap().locateInFrom(183, 183); + assertNull(mappedRegion); } }