X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fjalview%2Fext%2Fensembl%2FEnsemblFeatures.java;h=56498590928b507ac15f510d9b18fd68d875b4a6;hb=fdde9a078d7bdb46ed9fb7fe115ea83c84a19c81;hp=2772498cd49039120292bfa651203c68a01a3e35;hpb=26b115b0a77d521da92a06572d9b7819c2d0d49a;p=jalview.git diff --git a/src/jalview/ext/ensembl/EnsemblFeatures.java b/src/jalview/ext/ensembl/EnsemblFeatures.java index 2772498..5649859 100644 --- a/src/jalview/ext/ensembl/EnsemblFeatures.java +++ b/src/jalview/ext/ensembl/EnsemblFeatures.java @@ -91,12 +91,12 @@ class EnsemblFeatures extends EnsemblRestClient public AlignmentI getSequenceRecords(String query) throws IOException { // TODO: use a vararg String... for getSequenceRecords instead? - + List queries = new ArrayList<>(); queries.add(query); SequenceI seq = parseFeaturesJson(queries); if (seq == null) - return null; + return null; return new Alignment(new SequenceI[] { seq }); } @@ -109,20 +109,19 @@ 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); + Iterator rvals = (Iterator) getJSON(null, queries, -1, + MODE_ITERATOR, null); if (rvals == null) - return null; + { + return null; + } while (rvals.hasNext()) - { + { try { Map obj = (Map) rvals.next(); @@ -131,11 +130,11 @@ private SequenceI parseFeaturesJson(List queries) int end = Integer.parseInt(obj.get("end").toString()); String source = obj.get("source").toString(); String strand = obj.get("strand").toString(); + Object phase = obj.get("phase"); String alleles = JSONUtils .arrayToStringList((List) obj.get("alleles")); - String clinSig = JSONUtils - .arrayToStringList( - (List) obj.get("clinical_significance")); + String clinSig = JSONUtils.arrayToStringList( + (List) obj.get("clinical_significance")); /* * convert 'variation' to 'sequence_variant', and 'cds' to 'CDS' @@ -156,6 +155,10 @@ private SequenceI parseFeaturesJson(List queries) SequenceFeature sf = new SequenceFeature(type, desc, start, end, source); sf.setStrand("1".equals(strand) ? "+" : "-"); + if (phase != null) + { + sf.setPhase(phase.toString()); + } setFeatureAttribute(sf, obj, "id"); setFeatureAttribute(sf, obj, "Parent"); setFeatureAttribute(sf, obj, "consequence_type"); @@ -163,7 +166,7 @@ private SequenceI parseFeaturesJson(List queries) sf.setValue("clinical_significance", clinSig); seq.addSequenceFeature(sf); - + } catch (Throwable t) { // ignore - keep trying other features @@ -171,38 +174,40 @@ private SequenceI parseFeaturesJson(List queries) } } catch (ParseException | IOException e) { - e.printStackTrace(); + e.printStackTrace(); // ignore } 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; } /** @@ -213,8 +218,8 @@ private SequenceI parseFeaturesJson(List queries) * @param obj * @param key */ - protected void setFeatureAttribute(SequenceFeature sf, Map obj, - String key) + protected void setFeatureAttribute(SequenceFeature sf, + Map obj, String key) { Object object = obj.get(key); if (object != null)