*/
private Map<String, float[][]> minmax = new Hashtable<String, float[][]>();
+ /*
+ * List of feature types where getFeatureNumber() > 0 is found
+ * - a heuristic for 'features have an explicit ordering'
+ */
+ private List<String> ordinalFeatures = new ArrayList<String>();
+
@Override
public AlignViewportI getViewport()
{
* Searches alignment for all features and updates colours
*
* @param newMadeVisible
- * if true newly added feature types will be rendered immediatly
+ * if true newly added feature types will be rendered immediately
* TODO: check to see if this method should actually be proxied so
* repaint events can be propagated by the renderer code
*/
}
findingFeatures = true;
+ ordinalFeatures.clear();
if (av.getFeaturesDisplayed() == null)
{
av.setFeaturesDisplayed(new FeaturesDisplayed());
}
FeaturesDisplayedI featuresDisplayed = av.getFeaturesDisplayed();
- ArrayList<String> allfeatures = new ArrayList<String>();
- ArrayList<String> oldfeatures = new ArrayList<String>();
+ List<String> allfeatures = new ArrayList<String>();
+ List<String> oldfeatures = new ArrayList<String>();
if (renderOrder != null)
{
for (int i = 0; i < renderOrder.length; i++)
minmax = new Hashtable<String, float[][]>();
}
AlignmentI alignment = av.getAlignment();
- for (int i = 0; i < alignment.getHeight(); i++)
+ for (SequenceI asq : alignment.getSequences())
{
- SequenceI asq = alignment.getSequenceAt(i);
SequenceFeature[] features = asq.getSequenceFeatures();
if (features == null)
continue;
}
- int index = 0;
- while (index < features.length)
+ for (SequenceFeature feature : features)
{
- if (!featuresDisplayed.isRegistered(features[index].getType()))
+ String type = feature.getType();
+ if (!featuresDisplayed.isRegistered(type))
{
- String fgrp = features[index].getFeatureGroup();
+ String fgrp = feature.getFeatureGroup();
if (fgrp != null)
{
Boolean groupDisplayed = featureGroups.get(fgrp);
}
if (!groupDisplayed.booleanValue())
{
- index++;
continue;
}
}
- if (!(features[index].begin == 0 && features[index].end == 0))
+ if (!(feature.begin == 0 && feature.end == 0))
{
// If beginning and end are 0, the feature is for the whole sequence
// and we don't want to render the feature in the normal way
if (newMadeVisible
- && !oldfeatures.contains(features[index].getType()))
+ && !oldfeatures.contains(type))
{
// this is a new feature type on the alignment. Mark it for
// display.
- featuresDisplayed.setVisible(features[index].getType());
- setOrder(features[index].getType(), 0);
+ featuresDisplayed.setVisible(type);
+ setOrder(type, 0);
}
}
}
- if (!allfeatures.contains(features[index].getType()))
+ if (!allfeatures.contains(type))
{
- allfeatures.add(features[index].getType());
+ allfeatures.add(type);
}
- if (!Float.isNaN(features[index].score))
+ float score = feature.score;
+ if (!Float.isNaN(score))
{
- int nonpos = features[index].getBegin() >= 1 ? 0 : 1;
- float[][] mm = minmax.get(features[index].getType());
+ int nonpos = feature.getBegin() >= 1 ? 0 : 1;
+ float[][] mm = minmax.get(type);
if (mm == null)
{
mm = new float[][] { null, null };
- minmax.put(features[index].getType(), mm);
+ minmax.put(type, mm);
}
if (mm[nonpos] == null)
{
- mm[nonpos] = new float[] { features[index].score,
- features[index].score };
+ mm[nonpos] = new float[] { score, score };
}
else
{
- if (mm[nonpos][0] > features[index].score)
- {
- mm[nonpos][0] = features[index].score;
- }
- if (mm[nonpos][1] < features[index].score)
- {
- mm[nonpos][1] = features[index].score;
- }
+ mm[nonpos][0] = Math.min(mm[nonpos][0], score);
+ mm[nonpos][1] = Math.max(mm[nonpos][1], score);
+ }
+ }
+
+ /*
+ * add to 'ordinal feature types' if it has featureNumber > 0
+ */
+ if (!ordinalFeatures.contains(type))
+ {
+ if (feature.getFeatureNumber() > 0)
+ {
+ ordinalFeatures.add(type);
}
}
- index++;
}
}
updateRenderOrder(allfeatures);
List<String> allfeatures = new ArrayList<String>(allFeatures);
String[] oldRender = renderOrder;
renderOrder = new String[allfeatures.size()];
- Object mmrange, fc = null;
+ float[][] mmrange;
+ Object fc;
boolean initOrders = (featureOrder == null);
int opos = 0;
if (oldRender != null && oldRender.length > 0)
}
if (allfeatures.contains(oldRender[j]))
{
- renderOrder[opos++] = oldRender[j]; // existing features always
- // appear below new features
+ renderOrder[opos++] = oldRender[j];
+ // existing features always appear below new features
allfeatures.remove(oldRender[j]);
if (minmax != null)
{
&& ((GraduatedColor) fc).isAutoScale())
{
((GraduatedColor) fc).updateBounds(
- ((float[][]) mmrange)[0][0],
- ((float[][]) mmrange)[0][1]);
+ mmrange[0][0],
+ mmrange[0][1]);
}
}
}
if (fc != null && fc instanceof GraduatedColor
&& ((GraduatedColor) fc).isAutoScale())
{
- ((GraduatedColor) fc).updateBounds(((float[][]) mmrange)[0][0],
- ((float[][]) mmrange)[0][1]);
+ ((GraduatedColor) fc).updateBounds(mmrange[0][0],
+ mmrange[0][1]);
}
}
}
return _gps;
}
+ @Override
+ public boolean isOrdinal(String featureType)
+ {
+ return ordinalFeatures.contains(featureType);
+ }
}