X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=inline;f=test%2Fjalview%2Fdatamodel%2FSequenceFeatureTest.java;h=390f24d9dc5cff199970e551b840e0895decad6d;hb=5eec392de3099482d771ab078f0db57f9c47e81c;hp=e87d7e56a96326fc8f8fb4c67f3382a28b7bb3c4;hpb=5f4e1e4c330b045e9c8bce28ee132a0fca3834d8;p=jalview.git
diff --git a/test/jalview/datamodel/SequenceFeatureTest.java b/test/jalview/datamodel/SequenceFeatureTest.java
index e87d7e5..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
{
@@ -42,13 +46,13 @@ public class SequenceFeatureTest
}
@Test(groups = { "Functional" })
- public void testCopyConstructor()
+ 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 = new Integer(7);
+ Integer count = Integer.valueOf(7);
sf1.setValue("Count", count);
SequenceFeature sf2 = new SequenceFeature(sf1);
@@ -56,10 +60,41 @@ public class SequenceFeatureTest
assertEquals("desc", sf2.getDescription());
assertEquals(22, sf2.getBegin());
assertEquals(33, sf2.getEnd());
+ assertEquals(12.5f, sf2.getScore());
assertEquals("+", sf2.getValue("STRAND"));
assertEquals("Testing", sf2.getValue("Note"));
// shallow clone of otherDetails map - contains the same object values!
assertSame(count, sf2.getValue("Count"));
+
+ /*
+ * copy constructor modifying begin/end/group/score
+ */
+ SequenceFeature sf3 = new SequenceFeature(sf1, 11, 14, "group2", 17.4f);
+ assertEquals("type", sf3.getType());
+ assertEquals("desc", sf3.getDescription());
+ assertEquals(11, sf3.getBegin());
+ assertEquals(14, sf3.getEnd());
+ assertEquals(17.4f, sf3.getScore());
+ assertEquals("+", sf3.getValue("STRAND"));
+ assertEquals("Testing", sf3.getValue("Note"));
+ // shallow clone of otherDetails map - contains the same object values!
+ assertSame(count, sf3.getValue("Count"));
+
+ /*
+ * copy constructor modifying type/begin/end/group/score
+ */
+ SequenceFeature sf4 = new SequenceFeature(sf1, "Disulfide bond", 12, 15,
+ "group3", -9.1f);
+ assertEquals("Disulfide bond", sf4.getType());
+ assertTrue(sf4.isContactFeature());
+ assertEquals("desc", sf4.getDescription());
+ assertEquals(12, sf4.getBegin());
+ assertEquals(15, sf4.getEnd());
+ assertEquals(-9.1f, sf4.getScore());
+ assertEquals("+", sf4.getValue("STRAND"));
+ assertEquals("Testing", sf4.getValue("Note"));
+ // shallow clone of otherDetails map - contains the same object values!
+ assertSame(count, sf4.getValue("Count"));
}
/**
@@ -69,13 +104,13 @@ 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
assertEquals(".", sf1.getValue("unknown", "."));
- Integer i = new Integer(27);
+ Integer i = Integer.valueOf(27);
assertSame(i, sf1.getValue("Unknown", i));
}
@@ -102,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");
@@ -123,51 +158,64 @@ public class SequenceFeatureTest
assertEquals(sf1.hashCode(), sf2.hashCode());
// changing type breaks equals:
- String restores = sf2.getType();
- sf2.setType("Type");
- assertFalse(sf1.equals(sf2));
- sf2.setType(restores);
+ 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:
- restores = sf2.getDescription();
+ String restores = sf2.getDescription();
sf2.setDescription("Desc");
assertFalse(sf1.equals(sf2));
sf2.setDescription(restores);
// changing score breaks equals:
float restoref = sf2.getScore();
- sf2.setScore(12.4f);
+ sf2 = new SequenceFeature(sf2, sf2.getBegin(), sf2.getEnd(),
+ sf2.getFeatureGroup(), 10f);
assertFalse(sf1.equals(sf2));
- sf2.setScore(restoref);
+ sf2 = new SequenceFeature(sf2, sf2.getBegin(), sf2.getEnd(),
+ sf2.getFeatureGroup(), restoref);
// NaN doesn't match a number
restoref = sf2.getScore();
- sf2.setScore(Float.NaN);
+ sf2 = new SequenceFeature(sf2, sf2.getBegin(), sf2.getEnd(),
+ sf2.getFeatureGroup(), Float.NaN);
assertFalse(sf1.equals(sf2));
// NaN matches NaN
- sf1.setScore(Float.NaN);
+ sf1 = new SequenceFeature(sf1, sf1.getBegin(), sf1.getEnd(),
+ sf1.getFeatureGroup(), Float.NaN);
assertTrue(sf1.equals(sf2));
- sf1.setScore(restoref);
- sf2.setScore(restoref);
+ sf1 = new SequenceFeature(sf1, sf1.getBegin(), sf1.getEnd(),
+ sf1.getFeatureGroup(), restoref);
+ sf2 = new SequenceFeature(sf2, sf2.getBegin(), sf2.getEnd(),
+ sf2.getFeatureGroup(), restoref);
// changing start position breaks equals:
int restorei = sf2.getBegin();
- sf2.setBegin(21);
+ sf2 = new SequenceFeature(sf2, 21, sf2.getEnd(), sf2.getFeatureGroup(),
+ sf2.getScore());
assertFalse(sf1.equals(sf2));
- sf2.setBegin(restorei);
+ sf2 = new SequenceFeature(sf2, restorei, sf2.getEnd(),
+ sf2.getFeatureGroup(), sf2.getScore());
// changing end position breaks equals:
restorei = sf2.getEnd();
- sf2.setEnd(32);
+ sf2 = new SequenceFeature(sf2, sf2.getBegin(), 32,
+ sf2.getFeatureGroup(), sf2.getScore());
assertFalse(sf1.equals(sf2));
- sf2.setEnd(restorei);
+ sf2 = new SequenceFeature(sf2, sf2.getBegin(), restorei,
+ sf2.getFeatureGroup(), sf2.getScore());
// changing feature group breaks equals:
restores = sf2.getFeatureGroup();
- sf2.setFeatureGroup("Group");
+ sf2 = new SequenceFeature(sf2, sf2.getBegin(), sf2.getEnd(), "Group",
+ sf2.getScore());
assertFalse(sf1.equals(sf2));
- sf2.setFeatureGroup(restores);
+ sf2 = new SequenceFeature(sf2, sf2.getBegin(), sf2.getEnd(), restores,
+ sf2.getScore());
// changing ID breaks equals:
restores = (String) sf2.getValue("ID");
@@ -208,4 +256,120 @@ public class SequenceFeatureTest
sf1.setStatus("new");
assertTrue(sf1.equals(sf2));
}
+
+ @Test(groups = { "Functional" })
+ public void testIsContactFeature()
+ {
+ SequenceFeature sf = new SequenceFeature("type", "desc", 22, 33, 12.5f,
+ "group");
+ assertFalse(sf.isContactFeature());
+ sf = new SequenceFeature("", "desc", 22, 33, 12.5f, "group");
+ assertFalse(sf.isContactFeature());
+ sf = new SequenceFeature(null, "desc", 22, 33, 12.5f, "group");
+ assertFalse(sf.isContactFeature());
+ sf = new SequenceFeature("Disulfide Bond", "desc", 22, 33, 12.5f,
+ "group");
+ assertTrue(sf.isContactFeature());
+ sf = new SequenceFeature("disulfide bond", "desc", 22, 33, 12.5f,
+ "group");
+ assertTrue(sf.isContactFeature());
+ sf = new SequenceFeature("Disulphide Bond", "desc", 22, 33, 12.5f,
+ "group");
+ assertTrue(sf.isContactFeature());
+ sf = new SequenceFeature("disulphide bond", "desc", 22, 33, 12.5f,
+ "group");
+ assertTrue(sf.isContactFeature());
+ }
+
+ @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 = "
Location | TestSeq | 22 |
"
+ + "Type | variant | |
"
+ + "Description | G,C | |
";
+ assertEquals(expected, sf.getDetailsReport(seqName, null));
+
+ // contact feature
+ sf = new SequenceFeature("Disulphide Bond", "a description", 28, 31,
+ null);
+ expected = "
Location | TestSeq | 28:31 |
"
+ + "Type | Disulphide Bond | |
"
+ + "Description | a description | |
";
+ assertEquals(expected, sf.getDetailsReport(seqName, null));
+
+ sf = new SequenceFeature("variant", "G,C", 22, 33, 12.5f, "group");
+ sf.setValue("Parent", "ENSG001");
+ sf.setValue("Child", "ENSP002");
+ expected = "
Location | TestSeq | 22-33 |
"
+ + "Type | variant | |
"
+ + "Description | G,C | |
"
+ + "Score | 12.5 | |
"
+ + "Group | group | |
"
+ + "Child | | ENSP002 |
"
+ + "Parent | | ENSG001 |
";
+ 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 = "
Location | TestSeq | 8-83 |
"
+ + "Type | Pfam | |
"
+ + "Description | Fer2 Status: True Positive Pfam 8_8 | |
"
+ + "Group | Uniprot | |
";
+ 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));
+ }
}