X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=test%2Fjalview%2Fio%2FFeaturesFileTest.java;h=5c7bf151fd7caa820572b50b2fa011f4421ef400;hb=refs%2Fheads%2Ffeature%2FJAL-3499featuresFileMotifs;hp=090de6f9891aa680d0e27019a92714d33526e11f;hpb=2c5026c454594e7299a58b57fe0df3aa563c8d8b;p=jalview.git diff --git a/test/jalview/io/FeaturesFileTest.java b/test/jalview/io/FeaturesFileTest.java index 090de6f..5c7bf15 100644 --- a/test/jalview/io/FeaturesFileTest.java +++ b/test/jalview/io/FeaturesFileTest.java @@ -23,6 +23,7 @@ package jalview.io; 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; @@ -62,6 +63,7 @@ import org.testng.annotations.Test; public class FeaturesFileTest { + private static final String TAB = "\t"; private static String simpleGffFile = "examples/testdata/simpleGff3.gff"; @AfterClass(alwaysRun = true) @@ -899,4 +901,145 @@ public class FeaturesFileTest + "ENDGROUP\tgrp2\n"; assertEquals(expected, exported); } + + /** + * Test parsing a features file with Jalview format features, including + * STARTMOTIFS/ENDMOTIFS lines with motifs to be matched to create features + * + * @throws Exception + */ + @Test(groups = { "Functional" }) + public void testParse_jalviewFeaturesWithMotifs() throws IOException + { + File f = new File("examples/uniref50.fa"); + AlignmentI al = readAlignmentFile(f); + AlignFrame af = new AlignFrame(al, 500, 500); + Map colours = af.getFeatureRenderer() + .getFeatureColours(); + + /* + * hide columns with YKV motif; these should not get + * matched by the Finder + */ + al.getHiddenColumns().hideColumns(62, 64); + + // @formatter:off + String featureData = + /* + * features in the null grup + */ + "HELIX" + TAB + "blue\n" + + "MOTIF1" + TAB + "green\n" + + "MOTIF2" + TAB + "250,200,150|100,50,0|-3.9|4.5|above|-2.0\n" + + "adescription" + TAB + "FER_CAPAN" + TAB + "-1" + TAB + "42" + TAB + "45" + TAB + "HELIX\n" + + "STARTMOTIFS\n" + + "FLP" + TAB + "MOTIF1" + TAB + "flxMotifP\n" + + "F[LR]N" + TAB + "MOTIF1" + TAB + "flxMotifN\n" + + "fld" + TAB + "MOTIF1" + TAB + "flxMotifD\n" + + "YKV" + TAB + "MOTIF1" + TAB + "ykvMotif\n" + + "ENDMOTIFS\n" + + /* + * features in group uniprot + */ + "STARTGROUP" + TAB + "uniprot\n" + + "bdescription" + TAB + "FER_CAPAN" + TAB + "-1" + TAB + "47" + TAB + "48" + TAB + "HELIX\n" + + "STARTMOTIFS\n" + + "FLG" + TAB + "MOTIF1" + TAB + "flxMotifG\n" + + "VTT" + TAB + "MOTIF2" + TAB + "vxtMotifT" + TAB + "-3.21\n" + + "VRT" + TAB + "MOTIF2" + TAB + "vxtMotifR\n" + + "ENDMOTIFS\n" + + "ENDGROUP"; + // @formatter:on + FeaturesFile featuresFile = new FeaturesFile(featureData, + DataSourceType.PASTE); + assertTrue("Failed to parse features file", + featuresFile.parse(al, colours, true)); + + // verify HELIX features were parsed as normal + List sfs = al.getSequenceAt(1).findFeatures(0, 999, + "HELIX"); + assertEquals(2, sfs.size()); + SequenceFeature sf = sfs.get(0); + assertNull(sf.getFeatureGroup()); + assertEquals(42, sf.getBegin()); + assertEquals(45, sf.getEnd()); + assertEquals("adescription", sf.getDescription()); + sf = sfs.get(1); + assertEquals("uniprot", sf.getFeatureGroup()); + assertEquals(47, sf.getBegin()); + assertEquals(48, sf.getEnd()); + assertEquals("bdescription", sf.getDescription()); + + /* + * feature type MOTIF1 + * FLP motif should match FER1_SOLLC/13-15 and Q93XJ9_SOLTU/13-15 + * F[LR]N should match O80429_MAIZE/107-109 + * fld should match nothing (as case sensitive) + * feature group should be null for the above + * FLG should match FER1_PEA/36-38, feature group uniprot + * YKV should match nothing as entirely within hidden columns + */ + for (SequenceI seq : al.getSequences()) + { + List features = seq.findFeatures(0, 9999, "MOTIF1"); + String name = seq.getName(); + if (name.equals("FER1_SOLLC") || name.equals("Q93XJ9_SOLTU")) + { + assertEquals(1, features.size()); + sf = features.get(0); + assertNull(sf.getFeatureGroup()); + assertEquals(13, sf.getBegin()); + assertEquals(15, sf.getEnd()); + assertEquals("flxMotifP", sf.getDescription()); + } + else if (name.equals("O80429_MAIZE")) + { + assertEquals(1, features.size()); + sf = features.get(0); + assertNull(sf.getFeatureGroup()); + assertEquals(107, sf.getBegin()); + assertEquals(109, sf.getEnd()); + assertEquals("flxMotifN", sf.getDescription()); + } + else if (name.equals("FER1_PEA")) + { + assertEquals(1, features.size()); + sf = features.get(0); + assertEquals("uniprot", sf.getFeatureGroup()); + assertEquals(36, sf.getBegin()); + assertEquals(38, sf.getEnd()); + assertEquals("flxMotifG", sf.getDescription()); + } + else + { + assertTrue("MOTIF1 features found for " + name, features.isEmpty()); + } + } + + /* + * feature type MOTIF2 + * VTT motif should match FER1_PEA/26-28 + * VRT should match nothing + */ + for (SequenceI seq : al.getSequences()) + { + List features = seq.findFeatures(0, 9999, "MOTIF2"); + String name = seq.getName(); + if (name.equals("FER1_PEA")) + { + assertEquals(1, features.size()); + sf = features.get(0); + assertEquals("uniprot", sf.getFeatureGroup()); + assertEquals(26, sf.getBegin()); + assertEquals(28, sf.getEnd()); + assertEquals("vxtMotifT", sf.getDescription()); + assertEquals(-3.21f, sf.getScore()); + } + else + { + assertTrue("MOTIF2 features found for " + name, features.isEmpty()); + assertTrue(features.isEmpty()); + } + } + } }