From de96de2488774840f2f6298d757369f9e43acaee Mon Sep 17 00:00:00 2001 From: gmungoc Date: Thu, 16 Apr 2020 18:43:21 +0100 Subject: [PATCH] JAL-3567 adjust layout of linked feature report, unit test --- src/jalview/datamodel/MappedFeatures.java | 9 ++++-- src/jalview/datamodel/SequenceFeature.java | 11 +++++-- test/jalview/datamodel/SequenceFeatureTest.java | 37 +++++++++++++++++++++++ 3 files changed, 52 insertions(+), 5 deletions(-) diff --git a/src/jalview/datamodel/MappedFeatures.java b/src/jalview/datamodel/MappedFeatures.java index a42f34a..520ff92 100644 --- a/src/jalview/datamodel/MappedFeatures.java +++ b/src/jalview/datamodel/MappedFeatures.java @@ -119,11 +119,14 @@ public class MappedFeatures /** * Computes and returns comma-delimited HGVS notation peptide variants derived * from codon allele variants. If no variants are found, answers an empty - * string. + * string. The peptide variant is either simply read from the "CSQ:HGVSp" + * attribute if present, else computed based on the "alleles" attribute if + * present. If neither attribute is found, no variant (empty string) is + * returned. * * @param sf - * a sequence feature (which must be one of those held in this - * object) + * a sequence feature (which must be one of those held in this + * object) * @return */ public String findProteinVariants(SequenceFeature sf) diff --git a/src/jalview/datamodel/SequenceFeature.java b/src/jalview/datamodel/SequenceFeature.java index 7a539d0..01574e1 100755 --- a/src/jalview/datamodel/SequenceFeature.java +++ b/src/jalview/datamodel/SequenceFeature.java @@ -608,6 +608,8 @@ public class SequenceFeature implements FeatureLocationI sb.append(String.format(ROW_DATA, "Location", name, begin == end ? begin : begin + (isContactFeature() ? ":" : "-") + end)); + + String consequence = ""; if (mf != null) { int[] beginRange = mf.getMappedPositions(begin, begin); @@ -619,8 +621,7 @@ public class SequenceFeature implements FeatureLocationI : from + (isContactFeature() ? ":" : "-") + to)); if (mf.isFromCds()) { - sb.append(String.format(ROW_DATA, "Consequence", - mf.findProteinVariants(this), "imputed by Jalview")); + consequence = mf.findProteinVariants(this); } } sb.append(String.format(ROW_DATA, "Type", type, "")); @@ -635,6 +636,12 @@ public class SequenceFeature implements FeatureLocationI sb.append(String.format(ROW_DATA, "Group", featureGroup, "")); } + if (!consequence.isEmpty()) + { + sb.append(String.format(ROW_DATA, "Consequence", + "Imputed by Jalview", consequence)); + } + if (otherDetails != null) { TreeMap ordered = new TreeMap<>( diff --git a/test/jalview/datamodel/SequenceFeatureTest.java b/test/jalview/datamodel/SequenceFeatureTest.java index 673ea29..e105659 100644 --- a/test/jalview/datamodel/SequenceFeatureTest.java +++ b/test/jalview/datamodel/SequenceFeatureTest.java @@ -26,10 +26,14 @@ import static org.testng.AssertJUnit.assertNull; import static org.testng.AssertJUnit.assertSame; import static org.testng.AssertJUnit.assertTrue; +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 { @@ -319,4 +323,37 @@ public class SequenceFeatureTest + "GroupUniprot"; 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.getDatasetSequence(), 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 = "
" + + "" + + "" + + "" + + "" + + "" + + "
LocationCds106
Peptide LocationTestSeq9
Typevariant
DescriptionG,C
ConsequenceImputed by Jalviewp.Leu9Phe
allelesG,C
"; + + assertEquals(expected, sf.getDetailsReport(seq.getName(), mf)); + } } -- 1.7.10.2