*/
package jalview.io;
+import java.util.Collection;
+import java.util.Comparator;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
import jalview.api.FeatureColourI;
import jalview.datamodel.DBRefEntry;
import jalview.datamodel.DBRefSource;
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
*
private static final int MAX_SOURCES = 40;
- // public static final String[][] PRIMARY_SOURCES moved to DBRefSource.java
+ private static String linkImageURL;
- final String linkImageURL;
+ // public static final String[][] PRIMARY_SOURCES moved to DBRefSource.java
/*
* Comparator to order DBRefEntry by Source + accession id (case-insensitive),
// }
};
- public SequenceAnnotationReport(String linkURL)
+ private boolean forTooltip;
+
+ /**
+ * Constructor given a flag which affects behaviour
+ * <ul>
+ * <li>if true, generates feature details suitable to show in a tooltip</li>
+ * <li>if false, generates feature details in a form suitable for the sequence
+ * details report</li>
+ * </ul>
+ *
+ * @param isForTooltip
+ */
+ public SequenceAnnotationReport(boolean isForTooltip)
{
- this.linkImageURL = linkURL;
+ this.forTooltip = isForTooltip;
+ if (linkImageURL == null)
+ {
+ linkImageURL = getClass().getResource("/images/link.gif").toString();
+ }
}
/**
- * Append text for the list of features to the tooltip Returns number of
- * features left if maxlength limit is (or would have been) reached
+ * Append text for the list of features to the tooltip. Returns the number of
+ * features not added if maxlength limit is (or would have been) reached.
*
* @param sb
* @param residuePos
* @param minmax
* @param maxlength
*/
- public int appendFeaturesLengthLimit(final StringBuilder sb,
+ public int appendFeatures(final StringBuilder sb,
int residuePos, List<SequenceFeature> features,
FeatureRendererModel fr, int maxlength)
{
return 0;
}
- public void appendFeatures(final StringBuilder sb, int residuePos,
- List<SequenceFeature> features, FeatureRendererModel fr)
- {
- appendFeaturesLengthLimit(sb, residuePos, features, fr, 0);
- }
-
/**
- * Appends text for mapped features (e.g. CDS feature for peptide or vice versa)
- * Returns number of features left if maxlength limit is (or would have been)
- * reached
+ * Appends text for mapped features (e.g. CDS feature for peptide or vice
+ * versa) Returns number of features left if maxlength limit is (or would have
+ * been) reached.
*
* @param sb
* @param residuePos
* @param fr
* @param maxlength
*/
- public int appendFeaturesLengthLimit(StringBuilder sb, int residuePos,
+ public int appendFeatures(StringBuilder sb, int residuePos,
MappedFeatures mf, FeatureRendererModel fr, int maxlength)
{
for (int i = 0; i < mf.features.size(); i++)
return 0;
}
- public void appendFeatures(StringBuilder sb, int residuePos,
- MappedFeatures mf, FeatureRendererModel fr)
- {
- appendFeaturesLengthLimit(sb, residuePos, mf, fr, 0);
- }
-
/**
* Appends the feature at rpos to the given buffer
*
FeatureRendererModel fr, SequenceFeature feature,
MappedFeatures mf, int maxlength)
{
+ int begin = feature.getBegin();
+ int end = feature.getEnd();
+
+ /*
+ * if this is a virtual features, convert begin/end to the
+ * coordinates of the sequence it is mapped to
+ */
+ int[] beginRange = null;
+ int[] endRange = null;
+ if (mf != null)
+ {
+ beginRange = mf.getMappedPositions(begin, begin);
+ endRange = mf.getMappedPositions(end, end);
+ if (beginRange == null || endRange == null)
+ {
+ // something went wrong
+ return false;
+ }
+ begin = beginRange[0];
+ end = endRange[endRange.length - 1];
+ }
+
StringBuilder sb = new StringBuilder();
if (feature.isContactFeature())
{
- if (feature.getBegin() == rpos || feature.getEnd() == rpos)
+ /*
+ * include if rpos is at start or end position of [mapped] feature
+ */
+ boolean showContact = (mf == null) && (rpos == begin || rpos == end);
+ boolean showMappedContact = (mf != null) && ((rpos >= beginRange[0]
+ && rpos <= beginRange[beginRange.length - 1])
+ || (rpos >= endRange[0]
+ && rpos <= endRange[endRange.length - 1]));
+ if (showContact || showMappedContact)
{
if (sb0.length() > 6)
{
sb.append("<br/>");
}
- sb.append(feature.getType()).append(" ").append(feature.getBegin())
- .append(":").append(feature.getEnd());
+ sb.append(feature.getType()).append(" ").append(begin).append(":")
+ .append(end);
}
- return appendTextMaxLengthReached(sb0, sb, maxlength);
+ return appendText(sb0, sb, maxlength);
}
if (sb0.length() > 6)
if (rpos != 0)
{
// we are marking a positional feature
- sb.append(feature.begin);
- }
- if (feature.begin != feature.end)
- {
- sb.append(" ").append(feature.end);
+ sb.append(begin);
+ if (begin != end)
+ {
+ sb.append(" ").append(end);
+ }
}
String description = feature.getDescription();
}
}
}
- return appendTextMaxLengthReached(sb0, sb, maxlength);
+ return appendText(sb0, sb, maxlength);
}
- void appendFeature(final StringBuilder sb, int rpos,
- FeatureRendererModel fr, SequenceFeature feature,
- MappedFeatures mf)
- {
- appendFeature(sb, rpos, fr, feature, mf, 0);
- }
-
- private static boolean appendTextMaxLengthReached(StringBuilder sb0,
- StringBuilder sb, int maxlength)
+ /**
+ * Appends sb to sb0, and returns false, unless maxlength is not zero and
+ * appending would make the result longer than or equal to maxlength, in which
+ * case the append is not done and returns true
+ *
+ * @param sb0
+ * @param sb
+ * @param maxlength
+ * @return
+ */
+ private static boolean appendText(StringBuilder sb0, StringBuilder sb,
+ int maxlength)
{
- boolean ret = false;
if (maxlength == 0 || sb0.length() + sb.length() < maxlength)
{
sb0.append(sb);
return false;
- } else {
- return true;
}
+ return true;
}
/**
.getNonPositionalFeatures())
{
int sz = -sb.length();
- appendFeature(sb, 0, fr, sf, null);
+ appendFeature(sb, 0, fr, sf, null, 0);
sz += sb.length();
maxWidth = Math.max(maxWidth, sz);
}