X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fio%2FSequenceAnnotationReport.java;h=3a7ee65defabe116cf0a68a17f606a774e74fb85;hb=b8cd52fe7bed59130e5b080acfd42c3ef2effdbb;hp=9c42c9e31610a21ecac7de66d135b00e9e74429a;hpb=a8f483d04205bb8273ee311c12968b7e86d205fa;p=jalview.git
diff --git a/src/jalview/io/SequenceAnnotationReport.java b/src/jalview/io/SequenceAnnotationReport.java
index 9c42c9e..3a7ee65 100644
--- a/src/jalview/io/SequenceAnnotationReport.java
+++ b/src/jalview/io/SequenceAnnotationReport.java
@@ -1,32 +1,42 @@
/*
- * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
- * 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.datamodel.DBRefEntry;
+import jalview.datamodel.DBRefSource;
+import jalview.datamodel.DynamicData;
+import jalview.datamodel.PDBEntry;
import jalview.datamodel.SequenceFeature;
import jalview.datamodel.SequenceI;
+import jalview.io.gff.GffConstants;
+import jalview.util.MessageManager;
import jalview.util.UrlLink;
+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;
+ /*
+ * Comparator to order DBRefEntry by Source + accession id (case-insensitive)
+ */
+ private static Comparator comparator = new Comparator()
+ {
+
+ @Override
+ public int compare(DBRefEntry ref1, DBRefEntry ref2)
+ {
+ 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 linkImageURL)
{
this.linkImageURL = linkImageURL;
}
/**
- * 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, Map minmax)
{
- appendFeatures(tooltipText2, rpos, features, null);
+ if (features != null)
+ {
+ for (SequenceFeature feature : features)
+ {
+ appendFeature(sb, rpos, minmax, 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,
+ Map minmax, 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("
");
+ }
+ sb.append(feature.getType()).append(" ").append(feature.getBegin())
+ .append(":")
+ .append(feature.getEnd());
+ }
+ }
+ else
+ {
+ if (sb.length() > 6)
+ {
+ sb.append("
");
+ }
+ // TODO: remove this hack to display link only features
+ boolean linkOnly = feature.getValue("linkonly") != null;
+ if (!linkOnly)
+ {
+ sb.append(feature.getType()).append(" ");
+ if (rpos != 0)
+ {
+ // we are marking a positional feature
+ sb.append(feature.begin);
}
- else
+ if (feature.begin != feature.end)
+ {
+ sb.append(" ").append(feature.end);
+ }
+
+ if (feature.getDescription() != null
+ && !feature.description.equals(feature.getType()))
{
- if (tooltipText2.length() > 6)
+ String tmpString = feature.getDescription();
+ String tmp2up = tmpString.toUpperCase();
+ int startTag = tmp2up.indexOf("");
+ if (startTag > -1)
{
- tooltipText2.append("
");
+ tmpString = tmpString.substring(startTag + 6);
+ tmp2up = tmp2up.substring(startTag + 6);
}
- // TODO: remove this hack to display link only features
- boolean linkOnly = features[i].getValue("linkonly") != null;
- if (!linkOnly)
+ int endTag = tmp2up.indexOf("");
+ if (endTag > -1)
{
- 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);
- }
+ tmpString = tmpString.substring(0, endTag);
+ tmp2up = tmp2up.substring(0, endTag);
+ }
+ endTag = tmp2up.indexOf("