X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=test%2Fjalview%2Fdatamodel%2FSequenceFeatureTest.java;h=390f24d9dc5cff199970e551b840e0895decad6d;hb=3659ecfe7bb17dd25a0a6b5c94a7d9dab4525136;hp=9111e5ac2720320bbf39e594216e665a3c6d0957;hpb=3027bfb4b1b13af8686abcd419888e03141bd672;p=jalview.git
diff --git a/test/jalview/datamodel/SequenceFeatureTest.java b/test/jalview/datamodel/SequenceFeatureTest.java
index 9111e5a..390f24d 100644
--- a/test/jalview/datamodel/SequenceFeatureTest.java
+++ b/test/jalview/datamodel/SequenceFeatureTest.java
@@ -26,11 +26,15 @@ import static org.testng.AssertJUnit.assertNull;
import static org.testng.AssertJUnit.assertSame;
import static org.testng.AssertJUnit.assertTrue;
-import jalview.gui.JvOptionPane;
+import java.util.ArrayList;
+import java.util.List;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
+import jalview.gui.JvOptionPane;
+import jalview.util.MapList;
+
public class SequenceFeatureTest
{
@@ -44,8 +48,8 @@ public class SequenceFeatureTest
@Test(groups = { "Functional" })
public void testCopyConstructors()
{
- SequenceFeature sf1 = new SequenceFeature("type", "desc", 22, 33,
- 12.5f, "group");
+ SequenceFeature sf1 = new SequenceFeature("type", "desc", 22, 33, 12.5f,
+ "group");
sf1.setValue("STRAND", "+");
sf1.setValue("Note", "Testing");
Integer count = Integer.valueOf(7);
@@ -79,8 +83,8 @@ public class SequenceFeatureTest
/*
* copy constructor modifying type/begin/end/group/score
*/
- SequenceFeature sf4 = new SequenceFeature(sf1, "Disulfide bond", 12,
- 15, "group3", -9.1f);
+ SequenceFeature sf4 = new SequenceFeature(sf1, "Disulfide bond", 12, 15,
+ "group3", -9.1f);
assertEquals("Disulfide bond", sf4.getType());
assertTrue(sf4.isContactFeature());
assertEquals("desc", sf4.getDescription());
@@ -100,8 +104,8 @@ public class SequenceFeatureTest
@Test(groups = { "Functional" })
public void testGetValue()
{
- SequenceFeature sf1 = new SequenceFeature("type", "desc", 22, 33,
- 12.5f, "group");
+ SequenceFeature sf1 = new SequenceFeature("type", "desc", 22, 33, 12.5f,
+ "group");
sf1.setValue("STRAND", "+");
assertEquals("+", sf1.getValue("STRAND"));
assertNull(sf1.getValue("strand")); // case-sensitive
@@ -133,15 +137,15 @@ public class SequenceFeatureTest
@Test(groups = { "Functional" })
public void testEqualsAndHashCode()
{
- SequenceFeature sf1 = new SequenceFeature("type", "desc", 22, 33,
- 12.5f, "group");
+ SequenceFeature sf1 = new SequenceFeature("type", "desc", 22, 33, 12.5f,
+ "group");
sf1.setValue("ID", "id");
sf1.setValue("Name", "name");
sf1.setValue("Parent", "parent");
sf1.setStrand("+");
sf1.setPhase("1");
- SequenceFeature sf2 = new SequenceFeature("type", "desc", 22, 33,
- 12.5f, "group");
+ SequenceFeature sf2 = new SequenceFeature("type", "desc", 22, 33, 12.5f,
+ "group");
sf2.setValue("ID", "id");
sf2.setValue("Name", "name");
sf2.setValue("Parent", "parent");
@@ -154,10 +158,10 @@ public class SequenceFeatureTest
assertEquals(sf1.hashCode(), sf2.hashCode());
// changing type breaks equals:
- SequenceFeature sf3 = new SequenceFeature("type", "desc", 22, 33,
- 12.5f, "group");
- SequenceFeature sf4 = new SequenceFeature("Type", "desc", 22, 33,
- 12.5f, "group");
+ SequenceFeature sf3 = new SequenceFeature("type", "desc", 22, 33, 12.5f,
+ "group");
+ SequenceFeature sf4 = new SequenceFeature("Type", "desc", 22, 33, 12.5f,
+ "group");
assertFalse(sf3.equals(sf4));
// changing description breaks equals:
@@ -191,7 +195,8 @@ public class SequenceFeatureTest
// changing start position breaks equals:
int restorei = sf2.getBegin();
- sf2 = new SequenceFeature(sf2, 21, sf2.getEnd(), sf2.getFeatureGroup(), sf2.getScore());
+ sf2 = new SequenceFeature(sf2, 21, sf2.getEnd(), sf2.getFeatureGroup(),
+ sf2.getScore());
assertFalse(sf1.equals(sf2));
sf2 = new SequenceFeature(sf2, restorei, sf2.getEnd(),
sf2.getFeatureGroup(), sf2.getScore());
@@ -206,9 +211,11 @@ public class SequenceFeatureTest
// changing feature group breaks equals:
restores = sf2.getFeatureGroup();
- sf2 = new SequenceFeature(sf2, sf2.getBegin(), sf2.getEnd(), "Group", sf2.getScore());
+ sf2 = new SequenceFeature(sf2, sf2.getBegin(), sf2.getEnd(), "Group",
+ sf2.getScore());
assertFalse(sf1.equals(sf2));
- sf2 = new SequenceFeature(sf2, sf2.getBegin(), sf2.getEnd(), restores, sf2.getScore());
+ sf2 = new SequenceFeature(sf2, sf2.getBegin(), sf2.getEnd(), restores,
+ sf2.getScore());
// changing ID breaks equals:
restores = (String) sf2.getValue("ID");
@@ -277,43 +284,92 @@ public class SequenceFeatureTest
@Test(groups = { "Functional" })
public void testGetDetailsReport()
{
+ SequenceI seq = new Sequence("TestSeq", "PLRFQMD");
+ String seqName = seq.getName();
+
// single locus, no group, no score
- SequenceFeature sf = new SequenceFeature("variant", "G,C", 22, 22, null);
- String expected = "
Type | variant | |
"
- + "Start/end | 22 | |
"
+ SequenceFeature sf = new SequenceFeature("variant", "G,C", 22, 22,
+ null);
+ String expected = "
Location | TestSeq | 22 |
"
+ + "Type | variant | |
"
+ "Description | G,C | |
";
- assertEquals(expected, sf.getDetailsReport());
+ assertEquals(expected, sf.getDetailsReport(seqName, null));
// contact feature
sf = new SequenceFeature("Disulphide Bond", "a description", 28, 31,
null);
- expected = "
Type | Disulphide Bond | |
"
- + "Start/end | 28:31 | |
"
+ expected = "
Location | TestSeq | 28:31 |
"
+ + "Type | Disulphide Bond | |
"
+ "Description | a description | |
";
- assertEquals(expected, sf.getDetailsReport());
+ assertEquals(expected, sf.getDetailsReport(seqName, null));
- sf = new SequenceFeature("variant", "G,C", 22, 33,
- 12.5f, "group");
+ sf = new SequenceFeature("variant", "G,C", 22, 33, 12.5f, "group");
sf.setValue("Parent", "ENSG001");
sf.setValue("Child", "ENSP002");
- expected = "
Type | variant | |
"
- + "Start/end | 22-33 | |
"
+ expected = "
Location | TestSeq | 22-33 |
"
+ + "Type | variant | |
"
+ "Description | G,C | |
"
+ "Score | 12.5 | |
"
+ "Group | group | |
"
+ "Child | | ENSP002 |
"
+ "Parent | | ENSG001 |
";
- assertEquals(expected, sf.getDetailsReport());
+ assertEquals(expected, sf.getDetailsReport(seqName, null));
/*
* feature with embedded html link in description
*/
String desc = "Fer2 Status: True Positive Pfam 8_8";
sf = new SequenceFeature("Pfam", desc, 8, 83, "Uniprot");
- expected = "
Type | Pfam | |
"
- + "Start/end | 8-83 | |
"
+ expected = "
Location | TestSeq | 8-83 |
"
+ + "Type | Pfam | |
"
+ "Description | Fer2 Status: True Positive Pfam 8_8 | |
"
+ "Group | Uniprot | |
";
- assertEquals(expected, sf.getDetailsReport());
+ assertEquals(expected, sf.getDetailsReport(seqName, null));
+ }
+
+ /**
+ * Feature details report for a virtual feature should include original and
+ * mapped locations, and also derived peptide consequence if it can be
+ * determined
+ */
+ @Test(groups = { "Functional" })
+ public void testGetDetailsReport_virtualFeature()
+ {
+ SequenceI cds = new Sequence("Cds/101-121", "CCTttgAGAtttCAAatgGAT");
+ SequenceI seq = new Sequence("TestSeq/8-14", "PLRFQMD");
+ MapList map = new MapList(new int[] { 101, 118 }, new int[] { 8, 13 },
+ 3, 1);
+ Mapping mapping = new Mapping(seq, map);
+ List features = new ArrayList<>();
+ // vary ttg (Leu) to ttc (Phe)
+ SequenceFeature sf = new SequenceFeature("variant", "G,C", 106, 106,
+ null);
+ sf.setValue("alleles", "G,C"); // needed to compute peptide consequence!
+ features.add(sf);
+
+ MappedFeatures mf = new MappedFeatures(mapping, cds, 9, 'L', features);
+
+ String expected = "
Location | Cds | 106 |
"
+ + "Peptide Location | TestSeq | 9 |
"
+ + "Type | variant | |
"
+ + "Description | G,C | |
"
+ + "Consequence | Translated by Jalview | p.Leu9Phe |
"
+ + "alleles | | G,C |
" + "
";
+
+ assertEquals(expected, sf.getDetailsReport(seq.getName(), mf));
+
+ /*
+ * exon feature extending beyond mapped range; mapped location should be
+ * restricted to peptide mapped range limit i.e. 10-13
+ */
+ SequenceFeature sf2 = new SequenceFeature("exon", "exon 1", 109, 230,
+ null);
+ features.add(sf2);
+ expected = "
Location | Cds | 109-230 |
"
+ + "Peptide Location | TestSeq | 10-13 |
"
+ + "Type | exon | |
"
+ + "Description | exon 1 | |
"
+ + "
";
+ assertEquals(expected, sf2.getDetailsReport(seq.getName(), mf));
}
}