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 java.awt.Color;
24 import java.beans.PropertyChangeListener;
25 import java.beans.PropertyChangeSupport;
26 import java.util.ArrayList;
27 import java.util.Arrays;
28 import java.util.HashMap;
29 import java.util.HashSet;
30 import java.util.Hashtable;
31 import java.util.Iterator;
32 import java.util.List;
35 import java.util.concurrent.ConcurrentHashMap;
37 import jalview.api.AlignViewportI;
38 import jalview.api.FeatureColourI;
39 import jalview.api.FeaturesDisplayedI;
40 import jalview.datamodel.AlignedCodonFrame;
41 import jalview.datamodel.AlignedCodonFrame.SequenceToSequenceMapping;
42 import jalview.datamodel.AlignmentI;
43 import jalview.datamodel.MappedFeatures;
44 import jalview.datamodel.SearchResultMatchI;
45 import jalview.datamodel.SearchResults;
46 import jalview.datamodel.SearchResultsI;
47 import jalview.datamodel.SequenceFeature;
48 import jalview.datamodel.SequenceI;
49 import jalview.datamodel.features.FeatureMatcherSetI;
50 import jalview.datamodel.features.SequenceFeatures;
51 import jalview.renderer.seqfeatures.FeatureRenderer;
52 import jalview.schemes.FeatureColour;
53 import jalview.util.ColorUtils;
55 public abstract class FeatureRendererModel
56 implements jalview.api.FeatureRenderer
59 * a data bean to hold one row of feature settings from the gui
61 public static class FeatureSettingsBean
63 public final String featureType;
65 public final FeatureColourI featureColour;
67 public final FeatureMatcherSetI filter;
69 public final Boolean show;
71 public FeatureSettingsBean(String type, FeatureColourI colour,
72 FeatureMatcherSetI theFilter, Boolean isShown)
75 featureColour = colour;
82 * global transparency for feature
84 protected float transparency = 1.0f;
87 * colour scheme for each feature type
89 protected Map<String, FeatureColourI> featureColours = new ConcurrentHashMap<>();
92 * visibility flag for each feature group
94 protected Map<String, Boolean> featureGroups = new ConcurrentHashMap<>();
97 * filters for each feature type
99 protected Map<String, FeatureMatcherSetI> featureFilters = new HashMap<>();
101 protected String[] renderOrder;
103 Map<String, Float> featureOrder = null;
105 protected AlignViewportI av;
107 private PropertyChangeSupport changeSupport = new PropertyChangeSupport(
111 public AlignViewportI getViewport()
116 public FeatureRendererSettings getSettings()
118 return new FeatureRendererSettings(this);
121 public void transferSettings(FeatureRendererSettings fr)
123 this.renderOrder = fr.renderOrder;
124 this.featureGroups = fr.featureGroups;
125 this.featureColours = fr.featureColours;
126 this.transparency = fr.transparency;
127 this.featureOrder = fr.featureOrder;
131 * update from another feature renderer
136 public void transferSettings(jalview.api.FeatureRenderer _fr)
138 FeatureRenderer fr = (FeatureRenderer) _fr;
139 FeatureRendererSettings frs = new FeatureRendererSettings(fr);
140 this.renderOrder = frs.renderOrder;
141 this.featureGroups = frs.featureGroups;
142 this.featureColours = frs.featureColours;
143 this.featureFilters = frs.featureFilters;
144 this.transparency = frs.transparency;
145 this.featureOrder = frs.featureOrder;
146 if (av != null && av != fr.getViewport())
148 // copy over the displayed feature settings
149 if (_fr.getFeaturesDisplayed() != null)
151 FeaturesDisplayedI fd = getFeaturesDisplayed();
154 setFeaturesDisplayedFrom(_fr.getFeaturesDisplayed());
161 for (String type : _fr.getFeaturesDisplayed()
162 .getVisibleFeatures())
172 public void setFeaturesDisplayedFrom(FeaturesDisplayedI featuresDisplayed)
174 av.setFeaturesDisplayed(new FeaturesDisplayed(featuresDisplayed));
178 public void setVisible(String featureType)
180 FeaturesDisplayedI fdi = av.getFeaturesDisplayed();
183 av.setFeaturesDisplayed(fdi = new FeaturesDisplayed());
185 if (!fdi.isRegistered(featureType))
187 pushFeatureType(Arrays.asList(new String[] { featureType }));
189 fdi.setVisible(featureType);
193 public void setAllVisible(List<String> featureTypes)
195 FeaturesDisplayedI fdi = av.getFeaturesDisplayed();
198 av.setFeaturesDisplayed(fdi = new FeaturesDisplayed());
200 List<String> nft = new ArrayList<>();
201 for (String featureType : featureTypes)
203 if (!fdi.isRegistered(featureType))
205 nft.add(featureType);
210 pushFeatureType(nft);
212 fdi.setAllVisible(featureTypes);
216 * push a set of new types onto the render order stack. Note - this is a
217 * direct mechanism rather than the one employed in updateRenderOrder
221 private void pushFeatureType(List<String> types)
224 int ts = types.size();
225 String neworder[] = new String[(renderOrder == null ? 0
226 : renderOrder.length) + ts];
227 types.toArray(neworder);
228 if (renderOrder != null)
230 System.arraycopy(neworder, 0, neworder, renderOrder.length, ts);
231 System.arraycopy(renderOrder, 0, neworder, 0, renderOrder.length);
233 renderOrder = neworder;
236 protected Map<String, float[][]> minmax = new Hashtable<>();
238 public Map<String, float[][]> getMinMax()
244 * normalise a score against the max/min bounds for the feature type.
246 * @param sequenceFeature
247 * @return byte[] { signed, normalised signed (-127 to 127) or unsigned
250 protected final byte[] normaliseScore(SequenceFeature sequenceFeature)
252 float[] mm = minmax.get(sequenceFeature.type)[0];
253 final byte[] r = new byte[] { 0, (byte) 255 };
256 if (r[0] != 0 || mm[0] < 0.0)
259 r[1] = (byte) ((int) 128.0
260 + 127.0 * (sequenceFeature.score / mm[1]));
264 r[1] = (byte) ((int) 255.0 * (sequenceFeature.score / mm[1]));
270 boolean newFeatureAdded = false;
272 boolean findingFeatures = false;
274 protected boolean updateFeatures()
276 if (av.getFeaturesDisplayed() == null || renderOrder == null
280 if (av.getFeaturesDisplayed().getVisibleFeatureCount() < 1)
285 // TODO: decide if we should check for the visible feature count first
290 * search the alignment for all new features, give them a colour and display
291 * them. Then fires a PropertyChangeEvent on the changeSupport object.
294 protected void findAllFeatures()
296 synchronized (firing)
298 if (firing.equals(Boolean.FALSE))
300 firing = Boolean.TRUE;
301 findAllFeatures(true); // add all new features as visible
302 notifyFeaturesChanged();
303 firing = Boolean.FALSE;
309 public void notifyFeaturesChanged()
311 changeSupport.firePropertyChange("changeSupport", null, null);
315 public List<SequenceFeature> findFeaturesAtColumn(SequenceI sequence, int column)
318 * include features at the position provided their feature type is
319 * displayed, and feature group is null or marked for display
321 List<SequenceFeature> result = new ArrayList<>();
322 if (!av.areFeaturesDisplayed() || getFeaturesDisplayed() == null)
327 Set<String> visibleFeatures = getFeaturesDisplayed()
328 .getVisibleFeatures();
329 String[] visibleTypes = visibleFeatures
330 .toArray(new String[visibleFeatures.size()]);
331 List<SequenceFeature> features = sequence.findFeatures(column, column,
335 * include features unless they are hidden (have no colour), based on
336 * feature group visibility, or a filter or colour threshold
338 for (SequenceFeature sf : features)
340 if (getColour(sf) != null)
349 * Searches alignment for all features and updates colours
351 * @param newMadeVisible
352 * if true newly added feature types will be rendered immediately
353 * TODO: check to see if this method should actually be proxied so
354 * repaint events can be propagated by the renderer code
357 public synchronized void findAllFeatures(boolean newMadeVisible)
359 newFeatureAdded = false;
363 newFeatureAdded = true;
367 findingFeatures = true;
368 if (av.getFeaturesDisplayed() == null)
370 av.setFeaturesDisplayed(new FeaturesDisplayed());
372 FeaturesDisplayedI featuresDisplayed = av.getFeaturesDisplayed();
374 Set<String> oldfeatures = new HashSet<>();
375 if (renderOrder != null)
377 for (int i = 0; i < renderOrder.length; i++)
379 if (renderOrder[i] != null)
381 oldfeatures.add(renderOrder[i]);
386 AlignmentI alignment = av.getAlignment();
387 List<String> allfeatures = new ArrayList<>();
389 for (int i = 0; i < alignment.getHeight(); i++)
391 SequenceI asq = alignment.getSequenceAt(i);
392 for (String group : asq.getFeatures().getFeatureGroups(true))
394 boolean groupDisplayed = true;
397 if (featureGroups.containsKey(group))
399 groupDisplayed = featureGroups.get(group);
403 groupDisplayed = newMadeVisible;
404 featureGroups.put(group, groupDisplayed);
409 Set<String> types = asq.getFeatures().getFeatureTypesForGroups(
411 for (String type : types)
413 if (!allfeatures.contains(type)) // or use HashSet and no test?
415 allfeatures.add(type);
417 updateMinMax(asq, type, true); // todo: for all features?
423 // uncomment to add new features in alphebetical order (but JAL-2575)
424 // Collections.sort(allfeatures, String.CASE_INSENSITIVE_ORDER);
427 for (String type : allfeatures)
429 if (!oldfeatures.contains(type))
431 featuresDisplayed.setVisible(type);
437 updateRenderOrder(allfeatures);
438 findingFeatures = false;
442 * Updates the global (alignment) min and max values for a feature type from
443 * the score for a sequence, if the score is not NaN. Values are stored
444 * separately for positional and non-positional features.
450 protected void updateMinMax(SequenceI seq, String featureType,
453 float min = seq.getFeatures().getMinimumScore(featureType, positional);
454 if (Float.isNaN(min))
459 float max = seq.getFeatures().getMaximumScore(featureType, positional);
463 * { {positionalMin, positionalMax}, {nonPositionalMin, nonPositionalMax} }
467 minmax = new Hashtable<>();
469 synchronized (minmax)
471 float[][] mm = minmax.get(featureType);
472 int index = positional ? 0 : 1;
475 mm = new float[][] { null, null };
476 minmax.put(featureType, mm);
478 if (mm[index] == null)
480 mm[index] = new float[] { min, max };
484 mm[index][0] = Math.min(mm[index][0], min);
485 mm[index][1] = Math.max(mm[index][1], max);
489 protected Boolean firing = Boolean.FALSE;
492 * replaces the current renderOrder with the unordered features in
493 * allfeatures. The ordering of any types in both renderOrder and allfeatures
494 * is preserved, and all new feature types are rendered on top of the existing
495 * types, in the order given by getOrder or the order given in allFeatures.
496 * Note. this operates directly on the featureOrder hash for efficiency. TODO:
497 * eliminate the float storage for computing/recalling the persistent ordering
498 * New Cability: updates min/max for colourscheme range if its dynamic
502 private void updateRenderOrder(List<String> allFeatures)
504 List<String> allfeatures = new ArrayList<>(allFeatures);
505 String[] oldRender = renderOrder;
506 renderOrder = new String[allfeatures.size()];
507 boolean initOrders = (featureOrder == null);
509 if (oldRender != null && oldRender.length > 0)
511 for (int j = 0; j < oldRender.length; j++)
513 if (oldRender[j] != null)
517 setOrder(oldRender[j],
518 (1 - (1 + (float) j) / oldRender.length));
520 if (allfeatures.contains(oldRender[j]))
522 renderOrder[opos++] = oldRender[j]; // existing features always
523 // appear below new features
524 allfeatures.remove(oldRender[j]);
527 float[][] mmrange = minmax.get(oldRender[j]);
530 FeatureColourI fc = featureColours.get(oldRender[j]);
531 if (fc != null && !fc.isSimpleColour() && fc.isAutoScaled()
532 && !fc.isColourByAttribute())
534 fc.updateBounds(mmrange[0][0], mmrange[0][1]);
542 if (allfeatures.size() == 0)
544 // no new features - leave order unchanged.
547 int i = allfeatures.size() - 1;
549 boolean sort = false;
550 String[] newf = new String[allfeatures.size()];
551 float[] sortOrder = new float[allfeatures.size()];
552 for (String newfeat : allfeatures)
557 // update from new features minmax if necessary
558 float[][] mmrange = minmax.get(newf[i]);
561 FeatureColourI fc = featureColours.get(newf[i]);
562 if (fc != null && !fc.isSimpleColour() && fc.isAutoScaled()
563 && !fc.isColourByAttribute())
565 fc.updateBounds(mmrange[0][0], mmrange[0][1]);
569 if (initOrders || !featureOrder.containsKey(newf[i]))
571 int denom = initOrders ? allfeatures.size() : featureOrder.size();
572 // new unordered feature - compute persistent ordering at head of
573 // existing features.
574 setOrder(newf[i], i / (float) denom);
576 // set order from newly found feature from persisted ordering.
577 sortOrder[i] = 2 - featureOrder.get(newf[i]).floatValue();
580 // only sort if we need to
581 sort = sort || sortOrder[i] > sortOrder[i + 1];
585 if (iSize > 1 && sort)
587 jalview.util.QuickSort.sort(sortOrder, newf);
590 System.arraycopy(newf, 0, renderOrder, opos, newf.length);
594 * get a feature style object for the given type string. Creates a
595 * java.awt.Color for a featureType with no existing colourscheme.
601 public FeatureColourI getFeatureStyle(String featureType)
603 FeatureColourI fc = featureColours.get(featureType);
606 Color col = ColorUtils.createColourFromName(featureType);
607 fc = new FeatureColour(col);
608 featureColours.put(featureType, fc);
614 public Color getColour(SequenceFeature feature)
616 FeatureColourI fc = getFeatureStyle(feature.getType());
617 return getColor(feature, fc);
621 * Answers true if the feature type is currently selected to be displayed,
627 protected boolean showFeatureOfType(String type)
629 return type == null ? false : (av.getFeaturesDisplayed() == null ? true
630 : av.getFeaturesDisplayed().isVisible(type));
634 public void setColour(String featureType, FeatureColourI col)
636 featureColours.put(featureType, col);
640 public void setTransparency(float value)
642 transparency = value;
646 public float getTransparency()
652 * analogous to colour - store a normalized ordering for all feature types in
653 * this rendering context.
656 * Feature type string
658 * normalized priority - 0 means always appears on top, 1 means
661 public float setOrder(String type, float position)
663 if (featureOrder == null)
665 featureOrder = new Hashtable<>();
667 featureOrder.put(type, Float.valueOf(position));
672 * get the global priority (0 (top) to 1 (bottom))
675 * @return [0,1] or -1 for a type without a priority
677 public float getOrder(String type)
679 if (featureOrder != null)
681 if (featureOrder.containsKey(type))
683 return featureOrder.get(type).floatValue();
690 public Map<String, FeatureColourI> getFeatureColours()
692 return featureColours;
696 * Replace current ordering with new ordering
699 * an array of { Type, Colour, Filter, Boolean }
700 * @return true if any visible features have been reordered, else false
702 public boolean setFeaturePriority(FeatureSettingsBean[] data)
704 return setFeaturePriority(data, true);
708 * Sets the priority order for features, with the highest priority (displayed on
709 * top) at the start of the data array
712 * an array of { Type, Colour, Filter, Boolean }
714 * when true current featureDisplay list will be cleared
715 * @return true if any visible features have been reordered or recoloured, else
716 * false (i.e. no need to repaint)
718 public boolean setFeaturePriority(FeatureSettingsBean[] data,
722 * note visible feature ordering and colours before update
724 List<String> visibleFeatures = getDisplayedFeatureTypes();
725 Map<String, FeatureColourI> visibleColours = new HashMap<>(
726 getFeatureColours());
728 FeaturesDisplayedI av_featuresdisplayed = null;
731 if ((av_featuresdisplayed = av.getFeaturesDisplayed()) != null)
733 av.getFeaturesDisplayed().clear();
737 av.setFeaturesDisplayed(
738 av_featuresdisplayed = new FeaturesDisplayed());
743 av_featuresdisplayed = av.getFeaturesDisplayed();
749 // The feature table will display high priority
750 // features at the top, but these are the ones
751 // we need to render last, so invert the data
752 renderOrder = new String[data.length];
756 for (int i = 0; i < data.length; i++)
758 String type = data[i].featureType;
759 setColour(type, data[i].featureColour);
762 av_featuresdisplayed.setVisible(type);
765 renderOrder[data.length - i - 1] = type;
770 * get the new visible ordering and return true if it has changed
771 * order or any colour has changed
773 List<String> reorderedVisibleFeatures = getDisplayedFeatureTypes();
774 if (!visibleFeatures.equals(reorderedVisibleFeatures))
777 * the list of ordered visible features has changed
783 * return true if any feature colour has changed
785 for (String feature : visibleFeatures)
787 if (visibleColours.get(feature) != getFeatureStyle(feature))
797 * @see java.beans.PropertyChangeSupport#addPropertyChangeListener(java.beans.PropertyChangeListener)
799 public void addPropertyChangeListener(PropertyChangeListener listener)
801 changeSupport.addPropertyChangeListener(listener);
806 * @see java.beans.PropertyChangeSupport#removePropertyChangeListener(java.beans.PropertyChangeListener)
808 public void removePropertyChangeListener(PropertyChangeListener listener)
810 changeSupport.removePropertyChangeListener(listener);
813 public Set<String> getAllFeatureColours()
815 return featureColours.keySet();
818 public void clearRenderOrder()
823 public boolean hasRenderOrder()
825 return renderOrder != null;
829 * Returns feature types in ordering of rendering, where last means on top
831 public List<String> getRenderOrder()
833 if (renderOrder == null)
835 return Arrays.asList(new String[] {});
837 return Arrays.asList(renderOrder);
840 public int getFeatureGroupsSize()
842 return featureGroups != null ? 0 : featureGroups.size();
846 public List<String> getFeatureGroups()
848 // conflict between applet and desktop - featureGroups returns the map in
849 // the desktop featureRenderer
850 return (featureGroups == null) ? Arrays.asList(new String[0])
851 : Arrays.asList(featureGroups.keySet().toArray(new String[0]));
854 public boolean checkGroupVisibility(String group,
855 boolean newGroupsVisible)
857 if (featureGroups == null)
859 // then an exception happens next..
861 if (featureGroups.containsKey(group))
863 return featureGroups.get(group).booleanValue();
865 if (newGroupsVisible)
867 featureGroups.put(group, Boolean.valueOf(true));
874 * get visible or invisible groups
877 * true to return visible groups, false to return hidden ones.
878 * @return list of groups
881 public List<String> getGroups(boolean visible)
883 if (featureGroups != null)
885 List<String> gp = new ArrayList<>();
887 for (String grp : featureGroups.keySet())
889 Boolean state = featureGroups.get(grp);
890 if (state.booleanValue() == visible)
901 public void setGroupVisibility(String group, boolean visible)
903 featureGroups.put(group, Boolean.valueOf(visible));
907 public void setGroupVisibility(List<String> toset, boolean visible)
909 if (toset != null && toset.size() > 0 && featureGroups != null)
911 boolean rdrw = false;
912 for (String gst : toset)
914 Boolean st = featureGroups.get(gst);
915 featureGroups.put(gst, Boolean.valueOf(visible));
918 rdrw = rdrw || (visible != st.booleanValue());
923 // set local flag indicating redraw needed ?
929 public Map<String, FeatureColourI> getDisplayedFeatureCols()
931 Map<String, FeatureColourI> fcols = new Hashtable<>();
932 if (getViewport().getFeaturesDisplayed() == null)
936 Set<String> features = getViewport().getFeaturesDisplayed()
937 .getVisibleFeatures();
938 for (String feature : features)
940 fcols.put(feature, getFeatureStyle(feature));
946 public FeaturesDisplayedI getFeaturesDisplayed()
948 return av.getFeaturesDisplayed();
952 * Returns a (possibly empty) list of visible feature types, in render order
956 public List<String> getDisplayedFeatureTypes()
958 List<String> typ = getRenderOrder();
959 List<String> displayed = new ArrayList<>();
960 FeaturesDisplayedI feature_disp = av.getFeaturesDisplayed();
961 if (feature_disp != null)
963 synchronized (feature_disp)
965 for (String type : typ)
967 if (feature_disp.isVisible(type))
978 public List<String> getDisplayedFeatureGroups()
980 List<String> _gps = new ArrayList<>();
981 for (String gp : getFeatureGroups())
983 if (checkGroupVisibility(gp, false))
992 * Answers true if the feature belongs to a feature group which is not
993 * currently displayed, else false
995 * @param sequenceFeature
998 public boolean featureGroupNotShown(final SequenceFeature sequenceFeature)
1000 return featureGroups != null
1001 && sequenceFeature.featureGroup != null
1002 && sequenceFeature.featureGroup.length() != 0
1003 && featureGroups.containsKey(sequenceFeature.featureGroup)
1004 && !featureGroups.get(sequenceFeature.featureGroup)
1012 public List<SequenceFeature> findFeaturesAtResidue(SequenceI sequence,
1013 int fromResNo, int toResNo)
1015 List<SequenceFeature> result = new ArrayList<>();
1016 if (!av.areFeaturesDisplayed() || getFeaturesDisplayed() == null)
1022 * include features at the position provided their feature type is
1023 * displayed, and feature group is null or the empty string
1024 * or marked for display
1026 List<String> visibleFeatures = getDisplayedFeatureTypes();
1027 String[] visibleTypes = visibleFeatures
1028 .toArray(new String[visibleFeatures.size()]);
1029 List<SequenceFeature> features = sequence.getFeatures().findFeatures(
1030 fromResNo, toResNo, visibleTypes);
1032 for (SequenceFeature sf : features)
1034 if (!featureGroupNotShown(sf) && getColour(sf) != null)
1043 * Removes from the list of features any whose group is not shown, or that are
1044 * visible and duplicate the location of a visible feature of the same type.
1045 * Should be used only for features of the same, simple, feature colour (which
1046 * normally implies the same feature type). No filtering is done if
1047 * transparency, or any feature filters, are in force.
1051 public void filterFeaturesForDisplay(List<SequenceFeature> features)
1054 * don't remove 'redundant' features if
1055 * - transparency is applied (feature count affects depth of feature colour)
1056 * - filters are applied (not all features may be displayable)
1058 if (features.isEmpty() || transparency != 1f
1059 || !featureFilters.isEmpty())
1064 SequenceFeatures.sortFeatures(features, true);
1065 SequenceFeature lastFeature = null;
1067 Iterator<SequenceFeature> it = features.iterator();
1068 while (it.hasNext())
1070 SequenceFeature sf = it.next();
1071 if (featureGroupNotShown(sf))
1078 * a feature is redundant for rendering purposes if it has the
1079 * same extent as another (so would just redraw the same colour);
1080 * (checking type and isContactFeature as a fail-safe here, although
1081 * currently they are guaranteed to match in this context)
1083 if (lastFeature != null
1084 && sf.getBegin() == lastFeature.getBegin()
1085 && sf.getEnd() == lastFeature.getEnd()
1086 && sf.isContactFeature() == lastFeature.isContactFeature()
1087 && sf.getType().equals(lastFeature.getType()))
1096 public Map<String, FeatureMatcherSetI> getFeatureFilters()
1098 return featureFilters;
1102 public void setFeatureFilters(Map<String, FeatureMatcherSetI> filters)
1104 featureFilters = filters;
1108 public FeatureMatcherSetI getFeatureFilter(String featureType)
1110 return featureFilters.get(featureType);
1114 public void setFeatureFilter(String featureType, FeatureMatcherSetI filter)
1116 if (filter == null || filter.isEmpty())
1118 featureFilters.remove(featureType);
1122 featureFilters.put(featureType, filter);
1127 * Answers the colour for the feature, or null if the feature is excluded by
1128 * feature group visibility, by filters, or by colour threshold settings. This
1129 * method does not take feature visibility into account.
1135 public Color getColor(SequenceFeature sf, FeatureColourI fc)
1138 * is the feature group displayed?
1140 if (featureGroupNotShown(sf))
1146 * does the feature pass filters?
1148 if (!featureMatchesFilters(sf))
1153 return fc.getColor(sf);
1157 * Answers true if there no are filters defined for the feature type, or this
1158 * feature matches the filters. Answers false if the feature fails to match
1164 protected boolean featureMatchesFilters(SequenceFeature sf)
1166 FeatureMatcherSetI filter = featureFilters.get(sf.getType());
1167 return filter == null ? true : filter.matches(sf);
1171 public MappedFeatures findComplementFeaturesAtResidue(
1172 final SequenceI sequence, final int pos)
1174 SequenceI ds = sequence.getDatasetSequence();
1179 final char residue = ds.getCharAt(pos - ds.getStart());
1181 List<SequenceFeature> found = new ArrayList<>();
1182 List<AlignedCodonFrame> mappings = this.av.getAlignment()
1183 .getCodonFrame(sequence);
1186 * fudge: if no mapping found, check the complementary alignment
1187 * todo: only store in one place? StructureSelectionManager?
1189 if (mappings.isEmpty())
1191 mappings = this.av.getCodingComplement().getAlignment()
1192 .getCodonFrame(sequence);
1196 * todo: direct lookup of CDS for peptide and vice-versa; for now,
1197 * have to search through an unordered list of mappings for a candidate
1199 SequenceToSequenceMapping mapping = null;
1200 SequenceI mapFrom = null;
1202 for (AlignedCodonFrame acf : mappings)
1204 mapping = acf.getCoveringCodonMapping(ds);
1205 if (mapping == null)
1209 SearchResultsI sr = new SearchResults();
1210 mapping.markMappedRegion(ds, pos, sr);
1211 for (SearchResultMatchI match : sr.getResults())
1213 int fromRes = match.getStart();
1214 int toRes = match.getEnd();
1215 mapFrom = match.getSequence();
1216 List<SequenceFeature> fs = findFeaturesAtResidue(
1217 mapFrom, fromRes, toRes);
1218 for (SequenceFeature sf : fs)
1220 if (!found.contains(sf))
1228 * just take the first mapped features we find
1230 if (!found.isEmpty())
1235 if (found.isEmpty())
1241 * sort by renderorder (inefficiently but ok for small scale);
1242 * NB this sorts 'on top' feature to end, for rendering
1244 List<SequenceFeature> result = new ArrayList<>();
1245 final int toAdd = found.size();
1247 for (String type : renderOrder)
1249 for (SequenceFeature sf : found)
1251 if (type.equals(sf.getType()))
1263 return new MappedFeatures(mapping.getMapping(), mapFrom, pos, residue, result);
1267 public boolean isVisible(SequenceFeature feature)
1269 if (feature == null)
1273 if (getFeaturesDisplayed() == null
1274 || !getFeaturesDisplayed().isVisible(feature.getType()))
1278 if (featureGroupNotShown(feature))
1282 FeatureColourI fc = featureColours.get(feature.getType());
1283 if (fc != null && fc.isOutwithThreshold(feature))
1287 if (!featureMatchesFilters(feature))