From 7ae76399fefb94ffa0bd7c5e890bc5a17e457f66 Mon Sep 17 00:00:00 2001 From: gmungoc Date: Thu, 14 Apr 2016 14:36:34 +0100 Subject: [PATCH] JAL-2041 add ID,clinical_significance to feature attributes (for export) --- src/jalview/analysis/AlignmentUtils.java | 13 +++++++++++-- src/jalview/datamodel/SequenceFeature.java | 4 ++++ src/jalview/io/SequenceAnnotationReport.java | 4 +++- src/jalview/io/gff/GffConstants.java | 23 +++++++++++++++++++++++ test/jalview/analysis/AlignmentUtilsTests.java | 5 +++++ 5 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 src/jalview/io/gff/GffConstants.java diff --git a/src/jalview/analysis/AlignmentUtils.java b/src/jalview/analysis/AlignmentUtils.java index fa135f8..42a1201 100644 --- a/src/jalview/analysis/AlignmentUtils.java +++ b/src/jalview/analysis/AlignmentUtils.java @@ -20,6 +20,8 @@ */ package jalview.analysis; +import static jalview.io.gff.GffConstants.CLINICAL_SIGNIFICANCE; + import jalview.datamodel.AlignedCodon; import jalview.datamodel.AlignedCodonFrame; import jalview.datamodel.Alignment; @@ -69,7 +71,6 @@ public class AlignmentUtils private static final String SEQUENCE_VARIANT = "sequence_variant:"; private static final String ID = "ID"; - private static final String CLINICAL_SIGNIFICANCE = "clinical_significance"; /** * A data model to hold the 'normal' base value at a position, and an optional @@ -1927,10 +1928,11 @@ public class AlignmentUtils if (trans != null && !trans.equals(residue)) { String desc = residue + "->" + trans; - // set score to 0f so 'graduated colour' option is offered! + // set score to 0f so 'graduated colour' option is offered! JAL-2060 SequenceFeature sf = new SequenceFeature( SequenceOntologyI.SEQUENCE_VARIANT, desc, peptidePos, peptidePos, 0f, null); + StringBuilder attributes = new StringBuilder(32); String id = (String) var.variant.getValue(ID); if (id != null) { @@ -1939,6 +1941,7 @@ public class AlignmentUtils id = id.substring(SEQUENCE_VARIANT.length()); } sf.setValue(ID, id); + attributes.append(ID).append("=").append(id); // TODO handle other species variants StringBuilder link = new StringBuilder(32); try @@ -1957,8 +1960,14 @@ public class AlignmentUtils if (clinSig != null) { sf.setValue(CLINICAL_SIGNIFICANCE, clinSig); + attributes.append(";").append(CLINICAL_SIGNIFICANCE).append("=") + .append(clinSig); } peptide.addSequenceFeature(sf); + if (attributes.length() > 0) + { + sf.setAttributes(attributes.toString()); + } return true; } return false; diff --git a/src/jalview/datamodel/SequenceFeature.java b/src/jalview/datamodel/SequenceFeature.java index 4c9aa05..f2eb8ac 100755 --- a/src/jalview/datamodel/SequenceFeature.java +++ b/src/jalview/datamodel/SequenceFeature.java @@ -39,6 +39,10 @@ public class SequenceFeature // private key for Phase designed not to conflict with real GFF data private static final String PHASE = "!Phase"; + /* + * ATTRIBUTES is reserved for the GFF 'column 9' data, formatted as + * name1=value1;name2=value2,value3;...etc + */ private static final String ATTRIBUTES = "ATTRIBUTES"; public int begin; diff --git a/src/jalview/io/SequenceAnnotationReport.java b/src/jalview/io/SequenceAnnotationReport.java index 8469355..2d76d6b 100644 --- a/src/jalview/io/SequenceAnnotationReport.java +++ b/src/jalview/io/SequenceAnnotationReport.java @@ -23,6 +23,7 @@ package jalview.io; import jalview.datamodel.DBRefEntry; import jalview.datamodel.SequenceFeature; import jalview.datamodel.SequenceI; +import jalview.io.gff.GffConstants; import jalview.util.DBRefUtils; import jalview.util.UrlLink; @@ -175,7 +176,8 @@ public class SequenceAnnotationReport { sb.append("; (").append(status).append(")"); } - String clinSig = (String) feature.getValue("clinical_significance"); + String clinSig = (String) feature + .getValue(GffConstants.CLINICAL_SIGNIFICANCE); if (clinSig != null) { sb.append("; ").append(clinSig); diff --git a/src/jalview/io/gff/GffConstants.java b/src/jalview/io/gff/GffConstants.java new file mode 100644 index 0000000..545c6e3 --- /dev/null +++ b/src/jalview/io/gff/GffConstants.java @@ -0,0 +1,23 @@ +package jalview.io.gff; + +/** + * A class to hold constants shared by creators and consumers of GFF or feature + * data + */ +public class GffConstants +{ + // SequenceOntology terms are to be found in SequenceOntologyI + + /* + * clinical_significance may be an attribute of + * sequence_variant data from Ensembl + */ + public static final String CLINICAL_SIGNIFICANCE = "clinical_significance"; + + /* + * not instantiable + */ + private GffConstants() + { + } +} diff --git a/test/jalview/analysis/AlignmentUtilsTests.java b/test/jalview/analysis/AlignmentUtilsTests.java index d811bef..860d979 100644 --- a/test/jalview/analysis/AlignmentUtilsTests.java +++ b/test/jalview/analysis/AlignmentUtilsTests.java @@ -1971,6 +1971,7 @@ public class AlignmentUtilsTests assertEquals("K->E", sf.getDescription()); assertEquals("var1.125A>G", sf.getValue("ID")); assertNull(sf.getValue("clinical_significance")); + assertEquals("ID=var1.125A>G", sf.getAttributes()); assertEquals(1, sf.links.size()); // link to variation is urlencoded assertEquals( @@ -1982,6 +1983,7 @@ public class AlignmentUtilsTests assertEquals("K->Q", sf.getDescription()); assertEquals("var2", sf.getValue("ID")); assertEquals("Dodgy", sf.getValue("clinical_significance")); + assertEquals("ID=var2;clinical_significance=Dodgy", sf.getAttributes()); assertEquals(1, sf.links.size()); assertEquals( "K->Q var2|http://www.ensembl.org/Homo_sapiens/Variation/Summary?v=var2", @@ -1992,6 +1994,7 @@ public class AlignmentUtilsTests assertEquals("K->N", sf.getDescription()); assertEquals("var4", sf.getValue("ID")); assertEquals("Benign", sf.getValue("clinical_significance")); + assertEquals("ID=var4;clinical_significance=Benign", sf.getAttributes()); assertEquals(1, sf.links.size()); assertEquals( "K->N var4|http://www.ensembl.org/Homo_sapiens/Variation/Summary?v=var4", @@ -2002,6 +2005,7 @@ public class AlignmentUtilsTests assertEquals("P->H", sf.getDescription()); assertEquals("var6", sf.getValue("ID")); assertEquals("Good", sf.getValue("clinical_significance")); + assertEquals("ID=var6;clinical_significance=Good", sf.getAttributes()); assertEquals(1, sf.links.size()); assertEquals( "P->H var6|http://www.ensembl.org/Homo_sapiens/Variation/Summary?v=var6", @@ -2013,6 +2017,7 @@ public class AlignmentUtilsTests assertEquals("P->R", sf.getDescription()); assertEquals("var6", sf.getValue("ID")); assertEquals("Good", sf.getValue("clinical_significance")); + assertEquals("ID=var6;clinical_significance=Good", sf.getAttributes()); assertEquals(1, sf.links.size()); assertEquals( "P->R var6|http://www.ensembl.org/Homo_sapiens/Variation/Summary?v=var6", -- 1.7.10.2