*/
package jalview.io;
-import java.util.Arrays;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.Comparator;
import java.util.LinkedHashMap;
import java.util.List;
+import java.util.Locale;
import java.util.Map;
import jalview.api.FeatureColourI;
private static final int MAX_REFS_PER_SOURCE = 4;
- private static final int MAX_SOURCES = 40;
+ private static final int MAX_SOURCES = 5;
private static String linkImageURL;
- private static final String[][] PRIMARY_SOURCES = new String[][] {
- DBRefSource.CODINGDBS, DBRefSource.DNACODINGDBS,
- DBRefSource.PROTEINDBS };
+ // public static final String[][] PRIMARY_SOURCES moved to DBRefSource.java
/*
* Comparator to order DBRefEntry by Source + accession id (case-insensitive),
{
return 1;
}
+
String s1 = ref1.getSource();
String s2 = ref2.getSource();
- boolean s1Primary = isPrimarySource(s1);
- boolean s2Primary = isPrimarySource(s2);
+ boolean s1Primary = DBRefSource.isPrimarySource(s1);
+ boolean s2Primary = DBRefSource.isPrimarySource(s2);
+ if (ref1.isCanonical() && !ref2.isCanonical())
+ {
+ return -1;
+ }
+ if (!ref1.isCanonical() && ref2.isCanonical())
+ {
+ return 1;
+ }
if (s1Primary && !s2Primary)
{
return -1;
{
return 1;
}
- int comp = s1 == null ? -1 : (s2 == null ? 1 : s1
- .compareToIgnoreCase(s2));
+ 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));
+ 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;
- }
+ // private boolean isPrimarySource(String source)
+ // {
+ // for (String[] primary : DBRefSource.PRIMARY_SOURCES)
+ // {
+ // for (String s : primary)
+ // {
+ // if (source.equals(s))
+ // {
+ // return true;
+ // }
+ // }
+ // }
+ // return false;
+ // }
};
private boolean forTooltip;
* @param minmax
* @param maxlength
*/
- public int appendFeatures(final StringBuilder sb,
- int residuePos, List<SequenceFeature> features,
- FeatureRendererModel fr, int maxlength)
+ public int appendFeatures(final StringBuilder sb, int residuePos,
+ List<SequenceFeature> features, FeatureRendererModel fr,
+ int maxlength)
{
for (int i = 0; i < features.size(); i++)
{
* 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;
+ int[] beginRange = null; // feature start in local coordinates
+ int[] endRange = null; // feature end in local coordinates
if (mf != null)
{
- beginRange = mf.getMappedPositions(begin, begin);
- endRange = mf.getMappedPositions(end, end);
+ if (feature.isContactFeature())
+ {
+ /*
+ * map start and end points individually
+ */
+ beginRange = mf.getMappedPositions(begin, begin);
+ endRange = begin == end ? beginRange
+ : mf.getMappedPositions(end, end);
+ }
+ else
+ {
+ /*
+ * map the feature extent
+ */
+ beginRange = mf.getMappedPositions(begin, end);
+ endRange = beginRange;
+ }
+ if (beginRange == null || endRange == null)
+ {
+ // something went wrong
+ return false;
+ }
begin = beginRange[0];
end = endRange[endRange.length - 1];
}
* truncate overlong descriptions unless they contain an href
* before the truncation point (as truncation could leave corrupted html)
*/
- int linkindex = description.toLowerCase().indexOf("<a ");
+ int linkindex = description.toLowerCase(Locale.ROOT).indexOf("<a ");
boolean hasLink = linkindex > -1
&& linkindex < MAX_DESCRIPTION_LENGTH;
if (description.length() > MAX_DESCRIPTION_LENGTH && !hasLink)
{
for (List<String> urllink : createLinksFrom(null, urlstring))
{
- sb.append("<br/> <a href=\""
- + urllink.get(3)
- + "\" target=\""
- + urllink.get(0)
- + "\">"
- + (urllink.get(0).toLowerCase()
- .equals(urllink.get(1).toLowerCase()) ? urllink
- .get(0) : (urllink.get(0) + ":" + urllink
- .get(1)))
+ sb.append("<br/> <a href=\"" + urllink.get(3) + "\" target=\""
+ + urllink.get(0) + "\">"
+ + (urllink.get(0).toLowerCase(Locale.ROOT).equals(
+ urllink.get(1).toLowerCase(Locale.ROOT))
+ ? urllink.get(0)
+ : (urllink.get(0) + ":"
+ + urllink.get(1)))
+ "</a><br/>");
}
} catch (Exception x)
{
- System.err.println("problem when creating links from "
- + urlstring);
+ jalview.bin.Console.errPrintln(
+ "problem when creating links from " + urlstring);
x.printStackTrace();
}
}
UrlLink urlLink = new UrlLink(link);
if (!urlLink.isValid())
{
- System.err.println(urlLink.getInvalidMessage());
+ jalview.bin.Console.errPrintln(urlLink.getInvalidMessage());
return null;
}
sb.append(tmp);
maxWidth = Math.max(maxWidth, tmp.length());
}
+ sb.append("\n");
SequenceI ds = sequence;
while (ds.getDatasetSequence() != null)
{
{
maxWidth = Math.max(maxWidth, appendDbRefs(sb, ds, summary));
}
+ sb.append("\n");
/*
* add non-positional features if wanted
protected int appendDbRefs(final StringBuilder sb, SequenceI ds,
boolean summary)
{
- DBRefEntry[] dbrefs = ds.getDBRefs();
- if (dbrefs == null)
+ List<DBRefEntry> dbrefs, dbrefset = ds.getDBRefs();
+
+ if (dbrefset == null)
{
return 0;
}
+ // PATCH for JAL-3980 defensive copy
+
+ dbrefs = new ArrayList<DBRefEntry>();
+
+ dbrefs.addAll(dbrefset);
+
// note this sorts the refs held on the sequence!
- Arrays.sort(dbrefs, comparator);
+ dbrefs.sort(comparator);
boolean ellipsis = false;
String source = null;
String lastSource = null;
countForSource++;
if (countForSource == 1 || !summary)
{
- sb.append("<br/>");
+ sb.append("<br/>\n");
}
if (countForSource <= MAX_REFS_PER_SOURCE || !summary)
{
lineLength += accessionId.length() + 1;
if (countForSource > 1 && summary)
{
- sb.append(", ").append(accessionId);
+ sb.append(",\n ").append(accessionId);
lineLength++;
}
else
}
if (moreSources)
{
- sb.append("<br/>").append(source).append(COMMA).append(ELLIPSIS);
+ sb.append("<br/>\n").append(source).append(COMMA).append(ELLIPSIS);
}
if (ellipsis)
{
- sb.append("<br/>(");
+ sb.append("<br/>\n(");
sb.append(MessageManager.getString("label.output_seq_details"));
sb.append(")");
}
SequenceI sequence, boolean showDbRefs, boolean showNpFeats,
FeatureRendererModel fr)
{
- int maxWidth = createSequenceAnnotationReport(tip, sequence,
- showDbRefs, showNpFeats, fr, true);
+ int maxWidth = createSequenceAnnotationReport(tip, sequence, showDbRefs,
+ showNpFeats, fr, true);
if (maxWidth > 60)
{