From: gmungoc Date: Tue, 29 Jan 2019 11:33:12 +0000 (+0000) Subject: Merge branch 'Jalview-BH/JAL-3026-JAL-3063-JAXB' of https://source.jalview.org/git... X-Git-Tag: Develop-2_11_2_0-d20201215~24^2~68^2~273^2 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=1cb2d001bec9aac0da55fe770b40f034c4b071ff;hp=b0038bd579e099546c767d98a8006f29f5f71905;p=jalview.git Merge branch 'Jalview-BH/JAL-3026-JAL-3063-JAXB' of https://source.jalview.org/git/jalview.git into Jalview-BH/JAL-3026-JAL-3063-JAXB --- diff --git a/src/jalview/analysis/AlignmentUtils.java b/src/jalview/analysis/AlignmentUtils.java index 8fd961e..2946ba2 100644 --- a/src/jalview/analysis/AlignmentUtils.java +++ b/src/jalview/analysis/AlignmentUtils.java @@ -74,12 +74,15 @@ import java.util.TreeMap; */ public class AlignmentUtils { - private static final int CODON_LENGTH = 3; private static final String SEQUENCE_VARIANT = "sequence_variant:"; - private static final String ID = "ID"; + /* + * the 'id' attribute is provided for variant features fetched from + * Ensembl using its REST service with JSON format + */ + public static final String VARIANT_ID = "id"; /** * A data model to hold the 'normal' base value at a position, and an optional @@ -2583,15 +2586,15 @@ public class AlignmentUtils peptidePos, var.getSource()); StringBuilder attributes = new StringBuilder(32); - String id = (String) var.variant.getValue(ID); + String id = (String) var.variant.getValue(VARIANT_ID); if (id != null) { if (id.startsWith(SEQUENCE_VARIANT)) { id = id.substring(SEQUENCE_VARIANT.length()); } - sf.setValue(ID, id); - attributes.append(ID).append("=").append(id); + sf.setValue(VARIANT_ID, id); + attributes.append(VARIANT_ID).append("=").append(id); // TODO handle other species variants JAL-2064 StringBuilder link = new StringBuilder(32); try diff --git a/src/jalview/ext/ensembl/EnsemblFeatures.java b/src/jalview/ext/ensembl/EnsemblFeatures.java index 2772498..2dd6ebb 100644 --- a/src/jalview/ext/ensembl/EnsemblFeatures.java +++ b/src/jalview/ext/ensembl/EnsemblFeatures.java @@ -109,18 +109,16 @@ class EnsemblFeatures extends EnsemblRestClient * @return */ @SuppressWarnings("unchecked") -private SequenceI parseFeaturesJson(List queries) + private SequenceI parseFeaturesJson(List queries) { - - SequenceI seq = new Sequence("Dummy", ""); - try { - Iterator rvals = (Iterator) getJSON(null, queries, -1, MODE_ITERATOR, null); if (rvals == null) + { return null; + } while (rvals.hasNext()) { try @@ -178,31 +176,33 @@ private SequenceI parseFeaturesJson(List queries) return seq; } - -/** - * Returns the first non-null attribute found (if any) as a string + /** + * Returns the first non-null attribute found (if any) as a string, formatted + * suitably for display as feature description or tooltip. Answers null if + * none of the attribute keys is present. * * @param obj * @param keys * @return */ + @SuppressWarnings("unchecked") protected String getFirstNotNull(Map obj, String... keys) { - String desc = null; - for (String key : keys) { Object val = obj.get(key); if (val != null) { - String s = val.toString(); + String s = val instanceof List + ? JSONUtils.arrayToStringList((List) val) + : val.toString(); if (!s.isEmpty()) { return s; } } } - return desc; + return null; } /** diff --git a/src/jalview/ext/ensembl/EnsemblSequenceFetcher.java b/src/jalview/ext/ensembl/EnsemblSequenceFetcher.java index 9e3fef4..4da0e3c 100644 --- a/src/jalview/ext/ensembl/EnsemblSequenceFetcher.java +++ b/src/jalview/ext/ensembl/EnsemblSequenceFetcher.java @@ -20,6 +20,7 @@ */ package jalview.ext.ensembl; +import jalview.analysis.AlignmentUtils; import jalview.bin.Cache; import jalview.datamodel.DBRefSource; import jalview.ws.seqfetcher.DbSourceProxyImpl; @@ -64,7 +65,7 @@ abstract class EnsemblSequenceFetcher extends DbSourceProxyImpl protected static final String PARENT = "Parent"; - protected static final String JSON_ID = "id"; + protected static final String JSON_ID = AlignmentUtils.VARIANT_ID; // "id"; protected static final String OBJECT_TYPE = "object_type";