X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=test%2Fjalview%2Fext%2Fensembl%2FEnsemblGeneTest.java;h=8b1e8404f7bb01e9f66cdc198d423df0d47e9bd5;hb=f501ebf56839e4115d9d48d20a6c936856dc0e37;hp=1f1a84e3f1302eb691159d6ec666106d47b1e10d;hpb=e96f5e8ce137e879dd4b4f37fb5c4d134e2778e2;p=jalview.git
diff --git a/test/jalview/ext/ensembl/EnsemblGeneTest.java b/test/jalview/ext/ensembl/EnsemblGeneTest.java
index 1f1a84e..8b1e840 100644
--- a/test/jalview/ext/ensembl/EnsemblGeneTest.java
+++ b/test/jalview/ext/ensembl/EnsemblGeneTest.java
@@ -1,17 +1,41 @@
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
+ *
+ * This file is part of Jalview.
+ *
+ * Jalview is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * Jalview is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview. If not, see .
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
+ */
package jalview.ext.ensembl;
import static org.testng.AssertJUnit.assertEquals;
import static org.testng.AssertJUnit.assertFalse;
-import static org.testng.AssertJUnit.assertSame;
import static org.testng.AssertJUnit.assertTrue;
+import jalview.api.FeatureSettingsModelI;
+import jalview.bin.Cache;
+import jalview.datamodel.Sequence;
import jalview.datamodel.SequenceDummy;
import jalview.datamodel.SequenceFeature;
import jalview.datamodel.SequenceI;
+import jalview.gui.JvOptionPane;
import jalview.io.gff.SequenceOntologyFactory;
import jalview.io.gff.SequenceOntologyLite;
import jalview.util.MapList;
+import java.awt.Color;
import java.util.List;
import org.testng.annotations.AfterClass;
@@ -20,13 +44,22 @@ import org.testng.annotations.Test;
public class EnsemblGeneTest
{
- @BeforeClass
+
+ @BeforeClass(alwaysRun = true)
+ public void setUpJvOptionPane()
+ {
+ JvOptionPane.setInteractiveMode(false);
+ JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
+ }
+
+ @BeforeClass(alwaysRun = true)
public void setUp()
{
+ Cache.loadProperties("test/jalview/io/testProps.jvprops");
SequenceOntologyFactory.setInstance(new SequenceOntologyLite());
}
- @AfterClass
+ @AfterClass(alwaysRun = true)
public void tearDown()
{
SequenceOntologyFactory.setInstance(null);
@@ -45,17 +78,10 @@ public class EnsemblGeneTest
genomic.setEnd(50000);
String geneId = "ABC123";
- // gene at (start+10000) length 501
- SequenceFeature sf = new SequenceFeature("gene", "", 20000, 20500, 0f,
- null);
- sf.setValue("ID", "gene:" + geneId);
- sf.setStrand("+");
- genomic.addSequenceFeature(sf);
-
// gene at (start + 10500) length 101
- // should be ignored - the first 'gene' found defines the whole range
- sf = new SequenceFeature("gene", "", 10500, 10600, 0f, null);
- sf.setValue("ID", "gene:" + geneId);
+ SequenceFeature sf = new SequenceFeature("gene", "", 10500, 10600, 0f,
+ null);
+ sf.setValue("id", geneId);
sf.setStrand("+");
genomic.addSequenceFeature(sf);
@@ -63,13 +89,13 @@ public class EnsemblGeneTest
23);
List fromRanges = ranges.getFromRanges();
assertEquals(1, fromRanges.size());
- assertEquals(20000, fromRanges.get(0)[0]);
- assertEquals(20500, fromRanges.get(0)[1]);
+ assertEquals(10500, fromRanges.get(0)[0]);
+ assertEquals(10600, fromRanges.get(0)[1]);
// to range should start from given start numbering
List toRanges = ranges.getToRanges();
assertEquals(1, toRanges.size());
assertEquals(23, toRanges.get(0)[0]);
- assertEquals(523, toRanges.get(0)[1]);
+ assertEquals(123, toRanges.get(0)[1]);
}
/**
@@ -84,18 +110,10 @@ public class EnsemblGeneTest
genomic.setEnd(50000);
String geneId = "ABC123";
- // gene at (start+10000) length 501
- SequenceFeature sf = new SequenceFeature("ncRNA_gene", "", 20000,
- 20500, 0f, null);
- sf.setValue("ID", "gene:" + geneId);
- sf.setStrand("-");
- genomic.addSequenceFeature(sf);
-
// gene at (start + 10500) length 101
- // should be ignored - the first 'gene' found defines the whole range
- // (real data would only have one such feature)
- sf = new SequenceFeature("gene", "", 10500, 10600, 0f, null);
- sf.setValue("ID", "gene:" + geneId);
+ SequenceFeature sf = new SequenceFeature("gene", "", 10500, 10600, 0f,
+ null);
+ sf.setValue("id", geneId);
sf.setStrand("+");
genomic.addSequenceFeature(sf);
@@ -104,13 +122,13 @@ public class EnsemblGeneTest
List fromRanges = ranges.getFromRanges();
assertEquals(1, fromRanges.size());
// from range on reverse strand:
- assertEquals(20500, fromRanges.get(0)[0]);
- assertEquals(20000, fromRanges.get(0)[1]);
+ assertEquals(10500, fromRanges.get(0)[0]);
+ assertEquals(10600, fromRanges.get(0)[1]);
// to range should start from given start numbering
List toRanges = ranges.getToRanges();
assertEquals(1, toRanges.size());
assertEquals(23, toRanges.get(0)[0]);
- assertEquals(523, toRanges.get(0)[1]);
+ assertEquals(123, toRanges.get(0)[1]);
}
/**
@@ -128,34 +146,43 @@ public class EnsemblGeneTest
// transcript feature
SequenceFeature sf1 = new SequenceFeature("transcript", "", 20000,
20500, 0f, null);
- sf1.setValue("Parent", "gene:" + geneId);
+ sf1.setValue("Parent", geneId);
+ sf1.setValue("id", "transcript1");
genomic.addSequenceFeature(sf1);
// transcript sub-type feature
- SequenceFeature sf2 = new SequenceFeature("snRNA", "", 20000,
- 20500, 0f, null);
- sf2.setValue("Parent", "gene:" + geneId);
+ SequenceFeature sf2 = new SequenceFeature("snRNA", "", 21000, 21500,
+ 0f, null);
+ sf2.setValue("Parent", geneId);
+ sf2.setValue("id", "transcript2");
genomic.addSequenceFeature(sf2);
// NMD_transcript_variant treated like transcript in Ensembl
SequenceFeature sf3 = new SequenceFeature("NMD_transcript_variant", "",
- 20000, 20500, 0f, null);
- sf3.setValue("Parent", "gene:" + geneId);
+ 22000, 22500, 0f, null);
+ // id matching should not be case-sensitive
+ sf3.setValue("Parent", geneId.toLowerCase());
+ sf3.setValue("id", "transcript3");
genomic.addSequenceFeature(sf3);
// transcript for a different gene - ignored
- SequenceFeature sf4 = new SequenceFeature("snRNA", "", 20000, 20500,
+ SequenceFeature sf4 = new SequenceFeature("snRNA", "", 23000, 23500,
0f, null);
- sf4.setValue("Parent", "gene:XYZ");
+ sf4.setValue("Parent", "XYZ");
+ sf4.setValue("id", "transcript4");
genomic.addSequenceFeature(sf4);
EnsemblGene testee = new EnsemblGene();
+
+ /*
+ * with no filter
+ */
List features = testee.getTranscriptFeatures(geneId,
genomic);
assertEquals(3, features.size());
- assertSame(sf1, features.get(0));
- assertSame(sf2, features.get(1));
- assertSame(sf3, features.get(2));
+ assertTrue(features.contains(sf1));
+ assertTrue(features.contains(sf2));
+ assertTrue(features.contains(sf3));
}
/**
@@ -167,27 +194,29 @@ public class EnsemblGeneTest
{
String geneId = "ABC123";
EnsemblGene testee = new EnsemblGene();
- SequenceFeature sf = new SequenceFeature("gene", "", 20000,
- 20500, 0f, null);
- sf.setValue("ID", "gene:" + geneId);
+ SequenceFeature sf = new SequenceFeature("gene", "", 20000, 20500, 0f,
+ null);
+ sf.setValue("id", geneId);
assertFalse(testee.retainFeature(sf, geneId));
- sf.setType("transcript");
- sf.setValue("Parent", "gene:" + geneId);
+ sf = new SequenceFeature("transcript", "", 20000, 20500, 0f, null);
+ sf.setValue("Parent", geneId);
assertTrue(testee.retainFeature(sf, geneId));
- sf.setType("mature_transcript");
- sf.setValue("Parent", "gene:" + geneId);
+ sf = new SequenceFeature("mature_transcript", "", 20000, 20500, 0f,
+ null);
+ sf.setValue("Parent", geneId);
assertTrue(testee.retainFeature(sf, geneId));
- sf.setType("NMD_transcript_variant");
- sf.setValue("Parent", "gene:" + geneId);
+ sf = new SequenceFeature("NMD_transcript_variant", "", 20000, 20500,
+ 0f, null);
+ sf.setValue("Parent", geneId);
assertTrue(testee.retainFeature(sf, geneId));
- sf.setValue("Parent", "gene:XYZ");
+ sf.setValue("Parent", "ÃXYZ");
assertFalse(testee.retainFeature(sf, geneId));
- sf.setType("anything");
+ sf = new SequenceFeature("anything", "", 20000, 20500, 0f, null);
assertTrue(testee.retainFeature(sf, geneId));
}
@@ -196,33 +225,98 @@ public class EnsemblGeneTest
* accession id as ID
*/
@Test(groups = "Functional")
- public void testIdentifiesSequence()
+ public void testGetIdentifyingFeatures()
{
String accId = "ABC123";
- EnsemblGene testee = new EnsemblGene();
-
+ SequenceI seq = new Sequence(accId, "HIBEES");
+
// gene with no ID not valid
- SequenceFeature sf = new SequenceFeature("gene", "", 1, 2, 0f, null);
- assertFalse(testee.identifiesSequence(sf, accId));
-
+ SequenceFeature sf1 = new SequenceFeature("gene", "", 1, 2, 0f, null);
+ seq.addSequenceFeature(sf1);
+
// gene with wrong ID not valid
- sf.setValue("ID", "gene:XYZ");
- assertFalse(testee.identifiesSequence(sf, accId));
-
+ SequenceFeature sf2 = new SequenceFeature("gene", "a", 1, 2, 0f, null);
+ sf2.setValue("id", "XYZ");
+ seq.addSequenceFeature(sf2);
+
// gene with right ID is valid
- sf.setValue("ID", "gene:" + accId);
- assertTrue(testee.identifiesSequence(sf, accId));
-
+ SequenceFeature sf3 = new SequenceFeature("gene", "b", 1, 2, 0f, null);
+ sf3.setValue("id", accId);
+ seq.addSequenceFeature(sf3);
+
// gene sub-type with right ID is valid
- sf.setType("snRNA_gene");
- assertTrue(testee.identifiesSequence(sf, accId));
-
+ SequenceFeature sf4 = new SequenceFeature("snRNA_gene", "", 1, 2, 0f, null);
+ sf4.setValue("id", accId);
+ seq.addSequenceFeature(sf4);
+
// transcript not valid:
- sf.setType("transcript");
- assertFalse(testee.identifiesSequence(sf, accId));
-
+ SequenceFeature sf5 = new SequenceFeature("transcript", "", 1, 2, 0f, null);
+ sf5.setValue("id", accId);
+ seq.addSequenceFeature(sf5);
+
// exon not valid:
- sf.setType("exon");
- assertFalse(testee.identifiesSequence(sf, accId));
+ SequenceFeature sf6 = new SequenceFeature("exon", "", 1, 2, 0f, null);
+ sf6.setValue("id", accId);
+ seq.addSequenceFeature(sf6);
+
+ List sfs = new EnsemblGene()
+ .getIdentifyingFeatures(seq, accId);
+ assertFalse(sfs.contains(sf1));
+ assertFalse(sfs.contains(sf2));
+ assertTrue(sfs.contains(sf3));
+ assertTrue(sfs.contains(sf4));
+ assertFalse(sfs.contains(sf5));
+ assertFalse(sfs.contains(sf6));
+ }
+
+ /**
+ * Check behaviour of feature colour scheme for EnsemblGene sequences.
+ * Currently coded to display exon and sequence_variant (or sub-types) only,
+ * with sequence_variant in red above exon coloured by label.
+ */
+ @Test(groups = "Functional")
+ public void testGetFeatureColourScheme()
+ {
+ FeatureSettingsModelI fc = new EnsemblGene().getFeatureColourScheme();
+ assertTrue(fc.isFeatureDisplayed("exon"));
+ assertTrue(fc.isFeatureDisplayed("coding_exon")); // subtype of exon
+ assertTrue(fc.isFeatureDisplayed("sequence_variant"));
+ assertTrue(fc.isFeatureDisplayed("feature_variant")); // subtype
+ assertFalse(fc.isFeatureDisplayed("transcript"));
+ assertEquals(Color.RED, fc.getFeatureColour("sequence_variant")
+ .getColour());
+ assertEquals(Color.RED, fc.getFeatureColour("feature_variant")
+ .getColour());
+ assertTrue(fc.getFeatureColour("exon").isColourByLabel());
+ assertTrue(fc.getFeatureColour("coding_exon").isColourByLabel());
+ assertEquals(1, fc.compare("sequence_variant", "exon"));
+ assertEquals(-1, fc.compare("exon", "sequence_variant"));
+ assertEquals(1, fc.compare("feature_variant", "coding_exon"));
+ assertEquals(-1, fc.compare("coding_exon", "feature_variant"));
+ assertEquals(1f, fc.getTransparency());
+ }
+
+ @Test(groups = "Network")
+ public void testGetGeneIds()
+ {
+ /*
+ * ENSG00000158828 gene id PINK1 human
+ * ENST00000321556 transcript for the same gene - should not be duplicated
+ * P30419 Uniprot identifier for ENSG00000136448
+ * ENST00000592782 transcript for Uniprot gene - should not be duplicated
+ * BRAF - gene name resolvabe (at time of writing) for 6 model species
+ */
+ String ids = "ENSG00000158828 ENST00000321556 P30419 ENST00000592782 BRAF";
+ EnsemblGene testee = new EnsemblGene();
+ List geneIds = testee.getGeneIds(ids);
+ assertEquals(8, geneIds.size());
+ assertTrue(geneIds.contains("ENSG00000158828"));
+ assertTrue(geneIds.contains("ENSG00000136448"));
+ assertTrue(geneIds.contains("ENSG00000157764")); // BRAF human
+ assertTrue(geneIds.contains("ENSMUSG00000002413")); // mouse
+ assertTrue(geneIds.contains("ENSRNOG00000010957")); // rat
+ assertTrue(geneIds.contains("ENSXETG00000004845")); // xenopus
+ assertTrue(geneIds.contains("ENSDARG00000017661")); // zebrafish
+ assertTrue(geneIds.contains("ENSGALG00000012865")); // chicken
}
}