2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.viewmodel.seqfeatures;
23 import jalview.api.AlignViewportI;
24 import jalview.api.FeatureColourI;
25 import jalview.api.FeaturesDisplayedI;
26 import jalview.datamodel.AlignedCodonFrame;
27 import jalview.datamodel.AlignmentI;
28 import jalview.datamodel.MappedFeatures;
29 import jalview.datamodel.Mapping;
30 import jalview.datamodel.SearchResultMatchI;
31 import jalview.datamodel.SearchResults;
32 import jalview.datamodel.SearchResultsI;
33 import jalview.datamodel.SequenceFeature;
34 import jalview.datamodel.SequenceI;
35 import jalview.datamodel.features.FeatureMatcherSetI;
36 import jalview.datamodel.features.SequenceFeatures;
37 import jalview.renderer.seqfeatures.FeatureRenderer;
38 import jalview.schemes.FeatureColour;
39 import jalview.util.ColorUtils;
41 import java.awt.Color;
42 import java.beans.PropertyChangeListener;
43 import java.beans.PropertyChangeSupport;
44 import java.util.ArrayList;
45 import java.util.Arrays;
46 import java.util.Comparator;
47 import java.util.HashMap;
48 import java.util.HashSet;
49 import java.util.Hashtable;
50 import java.util.Iterator;
51 import java.util.List;
54 import java.util.concurrent.ConcurrentHashMap;
56 public abstract class FeatureRendererModel
57 implements jalview.api.FeatureRenderer
60 * a data bean to hold one row of feature settings from the gui
62 public static class FeatureSettingsBean
64 public final String featureType;
66 public final FeatureColourI featureColour;
68 public final FeatureMatcherSetI filter;
70 public final Boolean show;
72 public FeatureSettingsBean(String type, FeatureColourI colour,
73 FeatureMatcherSetI theFilter, Boolean isShown)
76 featureColour = colour;
83 * global transparency for feature
85 protected float transparency = 1.0f;
88 * colour scheme for each feature type
90 protected Map<String, FeatureColourI> featureColours = new ConcurrentHashMap<>();
93 * visibility flag for each feature group
95 protected Map<String, Boolean> featureGroups = new ConcurrentHashMap<>();
98 * filters for each feature type
100 protected Map<String, FeatureMatcherSetI> featureFilters = new HashMap<>();
102 protected String[] renderOrder;
104 Map<String, Float> featureOrder = null;
106 protected PropertyChangeSupport changeSupport = new PropertyChangeSupport(
109 protected AlignViewportI av;
112 public AlignViewportI getViewport()
117 public FeatureRendererSettings getSettings()
119 return new FeatureRendererSettings(this);
122 public void transferSettings(FeatureRendererSettings fr)
124 this.renderOrder = fr.renderOrder;
125 this.featureGroups = fr.featureGroups;
126 this.featureColours = fr.featureColours;
127 this.transparency = fr.transparency;
128 this.featureOrder = fr.featureOrder;
132 * update from another feature renderer
137 public void transferSettings(jalview.api.FeatureRenderer _fr)
139 FeatureRenderer fr = (FeatureRenderer) _fr;
140 FeatureRendererSettings frs = new FeatureRendererSettings(fr);
141 this.renderOrder = frs.renderOrder;
142 this.featureGroups = frs.featureGroups;
143 this.featureColours = frs.featureColours;
144 this.featureFilters = frs.featureFilters;
145 this.transparency = frs.transparency;
146 this.featureOrder = frs.featureOrder;
147 if (av != null && av != fr.getViewport())
149 // copy over the displayed feature settings
150 if (_fr.getFeaturesDisplayed() != null)
152 FeaturesDisplayedI fd = getFeaturesDisplayed();
155 setFeaturesDisplayedFrom(_fr.getFeaturesDisplayed());
162 for (String type : _fr.getFeaturesDisplayed()
163 .getVisibleFeatures())
173 public void setFeaturesDisplayedFrom(FeaturesDisplayedI featuresDisplayed)
175 av.setFeaturesDisplayed(new FeaturesDisplayed(featuresDisplayed));
179 public void setVisible(String featureType)
181 FeaturesDisplayedI fdi = av.getFeaturesDisplayed();
184 av.setFeaturesDisplayed(fdi = new FeaturesDisplayed());
186 if (!fdi.isRegistered(featureType))
188 pushFeatureType(Arrays.asList(new String[] { featureType }));
190 fdi.setVisible(featureType);
194 public void setAllVisible(List<String> featureTypes)
196 FeaturesDisplayedI fdi = av.getFeaturesDisplayed();
199 av.setFeaturesDisplayed(fdi = new FeaturesDisplayed());
201 List<String> nft = new ArrayList<>();
202 for (String featureType : featureTypes)
204 if (!fdi.isRegistered(featureType))
206 nft.add(featureType);
211 pushFeatureType(nft);
213 fdi.setAllVisible(featureTypes);
217 * push a set of new types onto the render order stack. Note - this is a
218 * direct mechanism rather than the one employed in updateRenderOrder
222 private void pushFeatureType(List<String> types)
225 int ts = types.size();
226 String neworder[] = new String[(renderOrder == null ? 0
227 : renderOrder.length) + ts];
228 types.toArray(neworder);
229 if (renderOrder != null)
231 System.arraycopy(neworder, 0, neworder, renderOrder.length, ts);
232 System.arraycopy(renderOrder, 0, neworder, 0, renderOrder.length);
234 renderOrder = neworder;
237 protected Map<String, float[][]> minmax = new Hashtable<>();
239 public Map<String, float[][]> getMinMax()
245 * normalise a score against the max/min bounds for the feature type.
247 * @param sequenceFeature
248 * @return byte[] { signed, normalised signed (-127 to 127) or unsigned
251 protected final byte[] normaliseScore(SequenceFeature sequenceFeature)
253 float[] mm = minmax.get(sequenceFeature.type)[0];
254 final byte[] r = new byte[] { 0, (byte) 255 };
257 if (r[0] != 0 || mm[0] < 0.0)
260 r[1] = (byte) ((int) 128.0
261 + 127.0 * (sequenceFeature.score / mm[1]));
265 r[1] = (byte) ((int) 255.0 * (sequenceFeature.score / mm[1]));
271 boolean newFeatureAdded = false;
273 boolean findingFeatures = false;
275 protected boolean updateFeatures()
277 if (av.getFeaturesDisplayed() == null || renderOrder == null
281 if (av.getFeaturesDisplayed().getVisibleFeatureCount() < 1)
286 // TODO: decide if we should check for the visible feature count first
291 * search the alignment for all new features, give them a colour and display
292 * them. Then fires a PropertyChangeEvent on the changeSupport object.
295 protected void findAllFeatures()
297 synchronized (firing)
299 if (firing.equals(Boolean.FALSE))
301 firing = Boolean.TRUE;
302 findAllFeatures(true); // add all new features as visible
303 changeSupport.firePropertyChange("changeSupport", null, null);
304 firing = Boolean.FALSE;
310 public List<SequenceFeature> findFeaturesAtColumn(SequenceI sequence, int column)
313 * include features at the position provided their feature type is
314 * displayed, and feature group is null or marked for display
316 List<SequenceFeature> result = new ArrayList<>();
317 if (!av.areFeaturesDisplayed() || getFeaturesDisplayed() == null)
322 Set<String> visibleFeatures = getFeaturesDisplayed()
323 .getVisibleFeatures();
324 String[] visibleTypes = visibleFeatures
325 .toArray(new String[visibleFeatures.size()]);
326 List<SequenceFeature> features = sequence.findFeatures(column, column,
330 * include features unless they are hidden (have no colour), based on
331 * feature group visibility, or a filter or colour threshold
333 for (SequenceFeature sf : features)
335 if (getColour(sf) != null)
344 * Searches alignment for all features and updates colours
346 * @param newMadeVisible
347 * if true newly added feature types will be rendered immediately
348 * TODO: check to see if this method should actually be proxied so
349 * repaint events can be propagated by the renderer code
352 public synchronized void findAllFeatures(boolean newMadeVisible)
354 newFeatureAdded = false;
358 newFeatureAdded = true;
362 findingFeatures = true;
363 if (av.getFeaturesDisplayed() == null)
365 av.setFeaturesDisplayed(new FeaturesDisplayed());
367 FeaturesDisplayedI featuresDisplayed = av.getFeaturesDisplayed();
369 Set<String> oldfeatures = new HashSet<>();
370 if (renderOrder != null)
372 for (int i = 0; i < renderOrder.length; i++)
374 if (renderOrder[i] != null)
376 oldfeatures.add(renderOrder[i]);
381 AlignmentI alignment = av.getAlignment();
382 List<String> allfeatures = new ArrayList<>();
384 for (int i = 0; i < alignment.getHeight(); i++)
386 SequenceI asq = alignment.getSequenceAt(i);
387 for (String group : asq.getFeatures().getFeatureGroups(true))
389 boolean groupDisplayed = true;
392 if (featureGroups.containsKey(group))
394 groupDisplayed = featureGroups.get(group);
398 groupDisplayed = newMadeVisible;
399 featureGroups.put(group, groupDisplayed);
404 Set<String> types = asq.getFeatures().getFeatureTypesForGroups(
406 for (String type : types)
408 if (!allfeatures.contains(type)) // or use HashSet and no test?
410 allfeatures.add(type);
412 updateMinMax(asq, type, true); // todo: for all features?
418 // uncomment to add new features in alphebetical order (but JAL-2575)
419 // Collections.sort(allfeatures, String.CASE_INSENSITIVE_ORDER);
422 for (String type : allfeatures)
424 if (!oldfeatures.contains(type))
426 featuresDisplayed.setVisible(type);
432 updateRenderOrder(allfeatures);
433 findingFeatures = false;
437 * Updates the global (alignment) min and max values for a feature type from
438 * the score for a sequence, if the score is not NaN. Values are stored
439 * separately for positional and non-positional features.
445 protected void updateMinMax(SequenceI seq, String featureType,
448 float min = seq.getFeatures().getMinimumScore(featureType, positional);
449 if (Float.isNaN(min))
454 float max = seq.getFeatures().getMaximumScore(featureType, positional);
458 * { {positionalMin, positionalMax}, {nonPositionalMin, nonPositionalMax} }
462 minmax = new Hashtable<>();
464 synchronized (minmax)
466 float[][] mm = minmax.get(featureType);
467 int index = positional ? 0 : 1;
470 mm = new float[][] { null, null };
471 minmax.put(featureType, mm);
473 if (mm[index] == null)
475 mm[index] = new float[] { min, max };
479 mm[index][0] = Math.min(mm[index][0], min);
480 mm[index][1] = Math.max(mm[index][1], max);
484 protected Boolean firing = Boolean.FALSE;
487 * replaces the current renderOrder with the unordered features in
488 * allfeatures. The ordering of any types in both renderOrder and allfeatures
489 * is preserved, and all new feature types are rendered on top of the existing
490 * types, in the order given by getOrder or the order given in allFeatures.
491 * Note. this operates directly on the featureOrder hash for efficiency. TODO:
492 * eliminate the float storage for computing/recalling the persistent ordering
493 * New Cability: updates min/max for colourscheme range if its dynamic
497 private void updateRenderOrder(List<String> allFeatures)
499 List<String> allfeatures = new ArrayList<>(allFeatures);
500 String[] oldRender = renderOrder;
501 renderOrder = new String[allfeatures.size()];
502 boolean initOrders = (featureOrder == null);
504 if (oldRender != null && oldRender.length > 0)
506 for (int j = 0; j < oldRender.length; j++)
508 if (oldRender[j] != null)
512 setOrder(oldRender[j],
513 (1 - (1 + (float) j) / oldRender.length));
515 if (allfeatures.contains(oldRender[j]))
517 renderOrder[opos++] = oldRender[j]; // existing features always
518 // appear below new features
519 allfeatures.remove(oldRender[j]);
522 float[][] mmrange = minmax.get(oldRender[j]);
525 FeatureColourI fc = featureColours.get(oldRender[j]);
526 if (fc != null && !fc.isSimpleColour() && fc.isAutoScaled()
527 && !fc.isColourByAttribute())
529 fc.updateBounds(mmrange[0][0], mmrange[0][1]);
537 if (allfeatures.size() == 0)
539 // no new features - leave order unchanged.
542 int i = allfeatures.size() - 1;
544 boolean sort = false;
545 String[] newf = new String[allfeatures.size()];
546 float[] sortOrder = new float[allfeatures.size()];
547 for (String newfeat : allfeatures)
552 // update from new features minmax if necessary
553 float[][] mmrange = minmax.get(newf[i]);
556 FeatureColourI fc = featureColours.get(newf[i]);
557 if (fc != null && !fc.isSimpleColour() && fc.isAutoScaled()
558 && !fc.isColourByAttribute())
560 fc.updateBounds(mmrange[0][0], mmrange[0][1]);
564 if (initOrders || !featureOrder.containsKey(newf[i]))
566 int denom = initOrders ? allfeatures.size() : featureOrder.size();
567 // new unordered feature - compute persistent ordering at head of
568 // existing features.
569 setOrder(newf[i], i / (float) denom);
571 // set order from newly found feature from persisted ordering.
572 sortOrder[i] = 2 - featureOrder.get(newf[i]).floatValue();
575 // only sort if we need to
576 sort = sort || sortOrder[i] > sortOrder[i + 1];
580 if (iSize > 1 && sort)
582 jalview.util.QuickSort.sort(sortOrder, newf);
585 System.arraycopy(newf, 0, renderOrder, opos, newf.length);
589 * get a feature style object for the given type string. Creates a
590 * java.awt.Color for a featureType with no existing colourscheme.
596 public FeatureColourI getFeatureStyle(String featureType)
598 FeatureColourI fc = featureColours.get(featureType);
601 Color col = ColorUtils.createColourFromName(featureType);
602 fc = new FeatureColour(col);
603 featureColours.put(featureType, fc);
609 public Color getColour(SequenceFeature feature)
611 FeatureColourI fc = getFeatureStyle(feature.getType());
612 return getColor(feature, fc);
616 * Answers true if the feature type is currently selected to be displayed,
622 public boolean showFeatureOfType(String type)
624 return type == null ? false : (av.getFeaturesDisplayed() == null ? true
625 : av.getFeaturesDisplayed().isVisible(type));
629 public void setColour(String featureType, FeatureColourI col)
631 featureColours.put(featureType, col);
635 public void setTransparency(float value)
637 transparency = value;
641 public float getTransparency()
647 * analogous to colour - store a normalized ordering for all feature types in
648 * this rendering context.
651 * Feature type string
653 * normalized priority - 0 means always appears on top, 1 means
656 public float setOrder(String type, float position)
658 if (featureOrder == null)
660 featureOrder = new Hashtable<>();
662 featureOrder.put(type, Float.valueOf(position));
667 * get the global priority (0 (top) to 1 (bottom))
670 * @return [0,1] or -1 for a type without a priority
672 public float getOrder(String type)
674 if (featureOrder != null)
676 if (featureOrder.containsKey(type))
678 return featureOrder.get(type).floatValue();
685 public Map<String, FeatureColourI> getFeatureColours()
687 return featureColours;
691 * Replace current ordering with new ordering
694 * an array of { Type, Colour, Filter, Boolean }
695 * @return true if any visible features have been reordered, else false
697 public boolean setFeaturePriority(FeatureSettingsBean[] data)
699 return setFeaturePriority(data, true);
703 * Sets the priority order for features, with the highest priority (displayed on
704 * top) at the start of the data array
707 * an array of { Type, Colour, Filter, Boolean }
709 * when true current featureDisplay list will be cleared
710 * @return true if any visible features have been reordered or recoloured, else
711 * false (i.e. no need to repaint)
713 public boolean setFeaturePriority(FeatureSettingsBean[] data,
717 * note visible feature ordering and colours before update
719 List<String> visibleFeatures = getDisplayedFeatureTypes();
720 Map<String, FeatureColourI> visibleColours = new HashMap<>(
721 getFeatureColours());
723 FeaturesDisplayedI av_featuresdisplayed = null;
726 if ((av_featuresdisplayed = av.getFeaturesDisplayed()) != null)
728 av.getFeaturesDisplayed().clear();
732 av.setFeaturesDisplayed(
733 av_featuresdisplayed = new FeaturesDisplayed());
738 av_featuresdisplayed = av.getFeaturesDisplayed();
744 // The feature table will display high priority
745 // features at the top, but these are the ones
746 // we need to render last, so invert the data
747 renderOrder = new String[data.length];
751 for (int i = 0; i < data.length; i++)
753 String type = data[i].featureType;
754 setColour(type, data[i].featureColour);
757 av_featuresdisplayed.setVisible(type);
760 renderOrder[data.length - i - 1] = type;
765 * get the new visible ordering and return true if it has changed
766 * order or any colour has changed
768 List<String> reorderedVisibleFeatures = getDisplayedFeatureTypes();
769 if (!visibleFeatures.equals(reorderedVisibleFeatures))
772 * the list of ordered visible features has changed
778 * return true if any feature colour has changed
780 for (String feature : visibleFeatures)
782 if (visibleColours.get(feature) != getFeatureStyle(feature))
792 * @see java.beans.PropertyChangeSupport#addPropertyChangeListener(java.beans.PropertyChangeListener)
794 public void addPropertyChangeListener(PropertyChangeListener listener)
796 changeSupport.addPropertyChangeListener(listener);
801 * @see java.beans.PropertyChangeSupport#removePropertyChangeListener(java.beans.PropertyChangeListener)
803 public void removePropertyChangeListener(PropertyChangeListener listener)
805 changeSupport.removePropertyChangeListener(listener);
808 public Set<String> getAllFeatureColours()
810 return featureColours.keySet();
813 public void clearRenderOrder()
818 public boolean hasRenderOrder()
820 return renderOrder != null;
824 * Returns feature types in ordering of rendering, where last means on top
826 public List<String> getRenderOrder()
828 if (renderOrder == null)
830 return Arrays.asList(new String[] {});
832 return Arrays.asList(renderOrder);
835 public int getFeatureGroupsSize()
837 return featureGroups != null ? 0 : featureGroups.size();
841 public List<String> getFeatureGroups()
843 // conflict between applet and desktop - featureGroups returns the map in
844 // the desktop featureRenderer
845 return (featureGroups == null) ? Arrays.asList(new String[0])
846 : Arrays.asList(featureGroups.keySet().toArray(new String[0]));
849 public boolean checkGroupVisibility(String group,
850 boolean newGroupsVisible)
852 if (featureGroups == null)
854 // then an exception happens next..
856 if (featureGroups.containsKey(group))
858 return featureGroups.get(group).booleanValue();
860 if (newGroupsVisible)
862 featureGroups.put(group, Boolean.valueOf(true));
869 * get visible or invisible groups
872 * true to return visible groups, false to return hidden ones.
873 * @return list of groups
876 public List<String> getGroups(boolean visible)
878 if (featureGroups != null)
880 List<String> gp = new ArrayList<>();
882 for (String grp : featureGroups.keySet())
884 Boolean state = featureGroups.get(grp);
885 if (state.booleanValue() == visible)
896 public void setGroupVisibility(String group, boolean visible)
898 featureGroups.put(group, Boolean.valueOf(visible));
902 public void setGroupVisibility(List<String> toset, boolean visible)
904 if (toset != null && toset.size() > 0 && featureGroups != null)
906 boolean rdrw = false;
907 for (String gst : toset)
909 Boolean st = featureGroups.get(gst);
910 featureGroups.put(gst, Boolean.valueOf(visible));
913 rdrw = rdrw || (visible != st.booleanValue());
918 // set local flag indicating redraw needed ?
924 public Map<String, FeatureColourI> getDisplayedFeatureCols()
926 Map<String, FeatureColourI> fcols = new Hashtable<>();
927 if (getViewport().getFeaturesDisplayed() == null)
931 Set<String> features = getViewport().getFeaturesDisplayed()
932 .getVisibleFeatures();
933 for (String feature : features)
935 fcols.put(feature, getFeatureStyle(feature));
941 public FeaturesDisplayedI getFeaturesDisplayed()
943 return av.getFeaturesDisplayed();
947 * Returns a (possibly empty) list of visible feature types, in render order
951 public List<String> getDisplayedFeatureTypes()
953 List<String> typ = getRenderOrder();
954 List<String> displayed = new ArrayList<>();
955 FeaturesDisplayedI feature_disp = av.getFeaturesDisplayed();
956 if (feature_disp != null)
958 synchronized (feature_disp)
960 for (String type : typ)
962 if (feature_disp.isVisible(type))
973 public List<String> getDisplayedFeatureGroups()
975 List<String> _gps = new ArrayList<>();
976 for (String gp : getFeatureGroups())
978 if (checkGroupVisibility(gp, false))
987 * Answers true if the feature belongs to a feature group which is not
988 * currently displayed, else false
990 * @param sequenceFeature
993 public boolean featureGroupNotShown(final SequenceFeature sequenceFeature)
995 return featureGroups != null
996 && sequenceFeature.featureGroup != null
997 && sequenceFeature.featureGroup.length() != 0
998 && featureGroups.containsKey(sequenceFeature.featureGroup)
999 && !featureGroups.get(sequenceFeature.featureGroup)
1007 public List<SequenceFeature> findFeaturesAtResidue(SequenceI sequence,
1008 int fromResNo, int toResNo)
1010 List<SequenceFeature> result = new ArrayList<>();
1011 if (!av.areFeaturesDisplayed() || getFeaturesDisplayed() == null)
1017 * include features at the position provided their feature type is
1018 * displayed, and feature group is null or the empty string
1019 * or marked for display
1021 List<String> visibleFeatures = getDisplayedFeatureTypes();
1022 String[] visibleTypes = visibleFeatures
1023 .toArray(new String[visibleFeatures.size()]);
1024 List<SequenceFeature> features = sequence.getFeatures().findFeatures(
1025 fromResNo, toResNo, visibleTypes);
1027 for (SequenceFeature sf : features)
1029 if (!featureGroupNotShown(sf) && getColour(sf) != null)
1038 * Removes from the list of features any whose group is not shown, or that are
1039 * visible and duplicate the location of a visible feature of the same type.
1040 * Should be used only for features of the same, simple, feature colour (which
1041 * normally implies the same feature type). No filtering is done if
1042 * transparency, or any feature filters, are in force.
1046 public void filterFeaturesForDisplay(List<SequenceFeature> features)
1049 * don't remove 'redundant' features if
1050 * - transparency is applied (feature count affects depth of feature colour)
1051 * - filters are applied (not all features may be displayable)
1053 if (features.isEmpty() || transparency != 1f
1054 || !featureFilters.isEmpty())
1059 SequenceFeatures.sortFeatures(features, true);
1060 SequenceFeature lastFeature = null;
1062 Iterator<SequenceFeature> it = features.iterator();
1063 while (it.hasNext())
1065 SequenceFeature sf = it.next();
1066 if (featureGroupNotShown(sf))
1073 * a feature is redundant for rendering purposes if it has the
1074 * same extent as another (so would just redraw the same colour);
1075 * (checking type and isContactFeature as a fail-safe here, although
1076 * currently they are guaranteed to match in this context)
1078 if (lastFeature != null
1079 && sf.getBegin() == lastFeature.getBegin()
1080 && sf.getEnd() == lastFeature.getEnd()
1081 && sf.isContactFeature() == lastFeature.isContactFeature()
1082 && sf.getType().equals(lastFeature.getType()))
1091 public Map<String, FeatureMatcherSetI> getFeatureFilters()
1093 return featureFilters;
1097 public void setFeatureFilters(Map<String, FeatureMatcherSetI> filters)
1099 featureFilters = filters;
1103 public FeatureMatcherSetI getFeatureFilter(String featureType)
1105 return featureFilters.get(featureType);
1109 public void setFeatureFilter(String featureType, FeatureMatcherSetI filter)
1111 if (filter == null || filter.isEmpty())
1113 featureFilters.remove(featureType);
1117 featureFilters.put(featureType, filter);
1122 * Answers the colour for the feature, or null if the feature is excluded by
1123 * feature group visibility, by filters, or by colour threshold settings. This
1124 * method does not take feature visibility into account.
1130 public Color getColor(SequenceFeature sf, FeatureColourI fc)
1133 * is the feature group displayed?
1135 if (featureGroupNotShown(sf))
1141 * does the feature pass filters?
1143 if (!featureMatchesFilters(sf))
1148 return fc.getColor(sf);
1152 * Answers true if there no are filters defined for the feature type, or this
1153 * feature matches the filters. Answers false if the feature fails to match
1159 protected boolean featureMatchesFilters(SequenceFeature sf)
1161 FeatureMatcherSetI filter = featureFilters.get(sf.getType());
1162 return filter == null ? true : filter.matches(sf);
1166 * Answers true unless the specified group is set to hidden. Defaults to true
1167 * if group visibility is not set.
1172 public boolean isGroupVisible(String group)
1174 if (!featureGroups.containsKey(group))
1178 return featureGroups.get(group);
1182 * Orders features in render precedence (last in order is last to render, so
1183 * displayed on top of other features)
1187 public void orderFeatures(Comparator<String> order)
1189 Arrays.sort(renderOrder, order);
1193 public MappedFeatures findComplementFeaturesAtResidue(SequenceI sequence,
1196 SequenceI ds = sequence.getDatasetSequence();
1201 final char residue = ds.getCharAt(pos - ds.getStart());
1203 List<SequenceFeature> found = new ArrayList<>();
1204 List<AlignedCodonFrame> mappings = this.av.getAlignment()
1205 .getCodonFrame(sequence);
1208 * fudge: if no mapping found, check the complementary alignment
1209 * todo: only store in one place? StructureSelectionManager?
1211 if (mappings.isEmpty())
1213 mappings = this.av.getCodingComplement().getAlignment()
1214 .getCodonFrame(sequence);
1218 * todo: direct lookup of CDS for peptide and vice-versa; for now,
1219 * have to search through an unordered list of mappings for a candidate
1221 Mapping mapping = null;
1222 SequenceI mapFrom = null;
1224 for (AlignedCodonFrame acf : mappings)
1226 mapping = acf.getMappingForSequence(sequence);
1227 if (mapping == null || !mapping.getMap().isTripletMap())
1229 continue; // we are only looking for 3:1 or 1:3 mappings
1231 SearchResultsI sr = new SearchResults();
1232 acf.markMappedRegion(ds, pos, sr);
1233 for (SearchResultMatchI match : sr.getResults())
1235 int fromRes = match.getStart();
1236 int toRes = match.getEnd();
1237 mapFrom = match.getSequence();
1238 List<SequenceFeature> fs = findFeaturesAtResidue(
1239 match.getSequence(), fromRes, toRes);
1240 for (SequenceFeature sf : fs)
1242 if (!found.contains(sf))
1250 * just take the first mapped features we find
1252 if (!found.isEmpty())
1257 if (found.isEmpty())
1263 * sort by renderorder, inefficiently
1265 List<SequenceFeature> result = new ArrayList<>();
1266 for (String type : renderOrder)
1268 for (SequenceFeature sf : found)
1270 if (type.equals(sf.getType()))
1273 if (result.size() == found.size())
1275 return new MappedFeatures(mapping, mapFrom, pos, residue,
1282 return new MappedFeatures(mapping, mapFrom, pos, residue, result);
1286 public boolean isVisible(SequenceFeature feature)
1288 if (feature == null)
1292 if (getFeaturesDisplayed() == null
1293 || !getFeaturesDisplayed().isVisible(feature.getType()))
1297 if (featureGroupNotShown(feature))
1301 FeatureColourI fc = featureColours.get(feature.getType());
1302 if (fc != null && fc.isOutwithThreshold(feature))
1306 if (!featureMatchesFilters(feature))