/*
* 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.
*
* 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 .
* The Jalview Authors are detailed in the 'AUTHORS' file.
*/
package jalview.io;
import jalview.datamodel.DBRefEntry;
import jalview.datamodel.SequenceFeature;
import jalview.datamodel.SequenceI;
import jalview.util.UrlLink;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Hashtable;
import java.util.List;
/**
* generate HTML reports for a sequence
*
* @author jimp
*/
public class SequenceAnnotationReport
{
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();
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;
}
};
public SequenceAnnotationReport(String linkImageURL)
{
this.linkImageURL = linkImageURL;
}
/**
* appends the features at rpos to the given stringbuffer ready for display in
* a tooltip
*
* @param tooltipText
* @param linkImageURL
* @param rpos
* @param features
* @param minmax
* TODO refactor to Jalview 'utilities' somehow.
*/
public void appendFeatures(final StringBuilder tooltipText, int rpos,
List features, Hashtable minmax)
{
String tmpString;
if (features != null)
{
for (SequenceFeature feature : features)
{
if (feature.getType().equals("disulfide bond"))
{
if (feature.getBegin() == rpos || feature.getEnd() == rpos)
{
if (tooltipText.length() > 6)
{
tooltipText.append("
");
}
tooltipText.append("disulfide bond " + feature.getBegin()
+ ":" + feature.getEnd());
}
}
else
{
if (tooltipText.length() > 6)
{
tooltipText.append("
");
}
// TODO: remove this hack to display link only features
boolean linkOnly = feature.getValue("linkonly") != null;
if (!linkOnly)
{
tooltipText.append(feature.getType() + " ");
if (rpos != 0)
{
// we are marking a positional feature
tooltipText.append(feature.begin);
}
if (feature.begin != feature.end)
{
tooltipText.append(" " + feature.end);
}
if (feature.getDescription() != null
&& !feature.description.equals(feature.getType()))
{
tmpString = feature.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("