X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fio%2FSequenceAnnotationReport.java;h=6b826712db05ff9503209a7999a09128cf6a6cf2;hb=7047b076a62df177047ceb16c3611efe020bdd76;hp=fbcc436d5fabee96df0172ade97ac324d056dde9;hpb=865a855a4ca87eadb3e5ff284ed32ed307d9c34b;p=jalview.git
diff --git a/src/jalview/io/SequenceAnnotationReport.java b/src/jalview/io/SequenceAnnotationReport.java
index fbcc436..6b82671 100644
--- a/src/jalview/io/SequenceAnnotationReport.java
+++ b/src/jalview/io/SequenceAnnotationReport.java
@@ -1,31 +1,41 @@
/*
- * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.0b1)
- * Copyright (C) 2014 The Jalview Authors
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
*
* This file is part of Jalview.
*
* Jalview is free software: you can redistribute it and/or
* modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
*
* Jalview is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
- * You should have received a copy of the GNU General Public License along with Jalview. If not, see .
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview. If not, see .
* The Jalview Authors are detailed in the 'AUTHORS' file.
*/
package jalview.io;
-import java.util.ArrayList;
-import java.util.Hashtable;
-import java.util.Vector;
-
+import jalview.api.FeatureColourI;
import jalview.datamodel.DBRefEntry;
+import jalview.datamodel.DBRefSource;
import jalview.datamodel.SequenceFeature;
import jalview.datamodel.SequenceI;
+import jalview.util.MessageManager;
+import jalview.util.StringUtils;
import jalview.util.UrlLink;
+import jalview.viewmodel.seqfeatures.FeatureRendererModel;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Comparator;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
/**
* generate HTML reports for a sequence
@@ -34,313 +44,313 @@ import jalview.util.UrlLink;
*/
public class SequenceAnnotationReport
{
+ private static final String COMMA = ",";
+
+ private static final String ELLIPSIS = "...";
+
+ private static final int MAX_REFS_PER_SOURCE = 4;
+
+ private static final int MAX_SOURCES = 40;
+
+ private static final String[][] PRIMARY_SOURCES = new String[][] {
+ DBRefSource.CODINGDBS, DBRefSource.DNACODINGDBS,
+ DBRefSource.PROTEINDBS };
+
final String linkImageURL;
- public SequenceAnnotationReport(String linkImageURL)
+ /*
+ * Comparator to order DBRefEntry by Source + accession id (case-insensitive),
+ * with 'Primary' sources placed before others, and 'chromosome' first of all
+ */
+ private static Comparator comparator = new Comparator()
+ {
+
+ @Override
+ public int compare(DBRefEntry ref1, DBRefEntry ref2)
+ {
+ if (ref1.isChromosome())
+ {
+ return -1;
+ }
+ if (ref2.isChromosome())
+ {
+ return 1;
+ }
+ String s1 = ref1.getSource();
+ String s2 = ref2.getSource();
+ boolean s1Primary = isPrimarySource(s1);
+ boolean s2Primary = isPrimarySource(s2);
+ if (s1Primary && !s2Primary)
+ {
+ return -1;
+ }
+ if (!s1Primary && s2Primary)
+ {
+ return 1;
+ }
+ int comp = s1 == null ? -1 : (s2 == null ? 1 : s1
+ .compareToIgnoreCase(s2));
+ if (comp == 0)
+ {
+ String a1 = ref1.getAccessionId();
+ String a2 = ref2.getAccessionId();
+ comp = a1 == null ? -1 : (a2 == null ? 1 : a1
+ .compareToIgnoreCase(a2));
+ }
+ return comp;
+ }
+
+ private boolean isPrimarySource(String source)
+ {
+ for (String[] primary : PRIMARY_SOURCES)
+ {
+ for (String s : primary)
+ {
+ if (source.equals(s))
+ {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+ };
+
+ public SequenceAnnotationReport(String linkURL)
{
- this.linkImageURL = linkImageURL;
+ this.linkImageURL = linkURL;
}
/**
- * appends the features at rpos to the given stringbuffer ready for display in
- * a tooltip
+ * Append text for the list of features to the tooltip
*
- * @param tooltipText2
- * @param linkImageURL
+ * @param sb
* @param rpos
* @param features
- * TODO refactor to Jalview 'utilities' somehow.
+ * @param minmax
*/
- public void appendFeatures(final StringBuffer tooltipText2, int rpos,
- SequenceFeature[] features)
+ public void appendFeatures(final StringBuilder sb, int rpos,
+ List features, FeatureRendererModel fr)
{
- appendFeatures(tooltipText2, rpos, features, null);
+ if (features != null)
+ {
+ for (SequenceFeature feature : features)
+ {
+ appendFeature(sb, rpos, fr, feature);
+ }
+ }
}
- public void appendFeatures(final StringBuffer tooltipText2, int rpos,
- SequenceFeature[] features, Hashtable minmax)
+ /**
+ * Appends the feature at rpos to the given buffer
+ *
+ * @param sb
+ * @param rpos
+ * @param minmax
+ * @param feature
+ */
+ void appendFeature(final StringBuilder sb, int rpos,
+ FeatureRendererModel fr, SequenceFeature feature)
{
- String tmpString;
- if (features != null)
+ if (feature.isContactFeature())
{
- for (int i = 0; i < features.length; i++)
+ if (feature.getBegin() == rpos || feature.getEnd() == rpos)
{
- if (features[i].getType().equals("disulfide bond"))
+ if (sb.length() > 6)
{
- if (features[i].getBegin() == rpos
- || features[i].getEnd() == rpos)
- {
- if (tooltipText2.length() > 6)
- {
- tooltipText2.append("
");
- }
- tooltipText2.append("disulfide bond " + features[i].getBegin()
- + ":" + features[i].getEnd());
- }
+ sb.append("
");
}
- else
- {
- if (tooltipText2.length() > 6)
- {
- tooltipText2.append("
");
- }
- // TODO: remove this hack to display link only features
- boolean linkOnly = features[i].getValue("linkonly") != null;
- if (!linkOnly)
- {
- tooltipText2.append(features[i].getType() + " ");
- if (rpos != 0)
- {
- // we are marking a positional feature
- tooltipText2.append(features[i].begin);
- }
- if (features[i].begin != features[i].end)
- {
- tooltipText2.append(" " + features[i].end);
- }
+ sb.append(feature.getType()).append(" ").append(feature.getBegin())
+ .append(":").append(feature.getEnd());
+ }
+ return;
+ }
- if (features[i].getDescription() != null
- && !features[i].description.equals(features[i]
- .getType()))
- {
- tmpString = features[i].getDescription();
- String tmp2up = tmpString.toUpperCase();
- int startTag = tmp2up.indexOf("");
- if (startTag > -1)
- {
- tmpString = tmpString.substring(startTag + 6);
- tmp2up = tmp2up.substring(startTag + 6);
- }
- int endTag = tmp2up.indexOf("");
- if (endTag > -1)
- {
- tmpString = tmpString.substring(0, endTag);
- tmp2up = tmp2up.substring(0, endTag);
- }
- endTag = tmp2up.indexOf("