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.HashMap;
47 import java.util.HashSet;
48 import java.util.Hashtable;
49 import java.util.Iterator;
50 import java.util.List;
53 import java.util.concurrent.ConcurrentHashMap;
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 PropertyChangeSupport changeSupport = new PropertyChangeSupport(
108 protected AlignViewportI av;
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 changeSupport.firePropertyChange("changeSupport", null, null);
303 firing = Boolean.FALSE;
309 public List<SequenceFeature> findFeaturesAtColumn(SequenceI sequence, int column)
312 * include features at the position provided their feature type is
313 * displayed, and feature group is null or marked for display
315 List<SequenceFeature> result = new ArrayList<>();
316 if (!av.areFeaturesDisplayed() || getFeaturesDisplayed() == null)
321 Set<String> visibleFeatures = getFeaturesDisplayed()
322 .getVisibleFeatures();
323 String[] visibleTypes = visibleFeatures
324 .toArray(new String[visibleFeatures.size()]);
325 List<SequenceFeature> features = sequence.findFeatures(column, column,
329 * include features unless they are hidden (have no colour), based on
330 * feature group visibility, or a filter or colour threshold
332 for (SequenceFeature sf : features)
334 if (getColour(sf) != null)
343 * Searches alignment for all features and updates colours
345 * @param newMadeVisible
346 * if true newly added feature types will be rendered immediately
347 * TODO: check to see if this method should actually be proxied so
348 * repaint events can be propagated by the renderer code
351 public synchronized void findAllFeatures(boolean newMadeVisible)
353 newFeatureAdded = false;
357 newFeatureAdded = true;
361 findingFeatures = true;
362 if (av.getFeaturesDisplayed() == null)
364 av.setFeaturesDisplayed(new FeaturesDisplayed());
366 FeaturesDisplayedI featuresDisplayed = av.getFeaturesDisplayed();
368 Set<String> oldfeatures = new HashSet<>();
369 if (renderOrder != null)
371 for (int i = 0; i < renderOrder.length; i++)
373 if (renderOrder[i] != null)
375 oldfeatures.add(renderOrder[i]);
380 AlignmentI alignment = av.getAlignment();
381 List<String> allfeatures = new ArrayList<>();
383 for (int i = 0; i < alignment.getHeight(); i++)
385 SequenceI asq = alignment.getSequenceAt(i);
386 for (String group : asq.getFeatures().getFeatureGroups(true))
388 boolean groupDisplayed = true;
391 if (featureGroups.containsKey(group))
393 groupDisplayed = featureGroups.get(group);
397 groupDisplayed = newMadeVisible;
398 featureGroups.put(group, groupDisplayed);
403 Set<String> types = asq.getFeatures().getFeatureTypesForGroups(
405 for (String type : types)
407 if (!allfeatures.contains(type)) // or use HashSet and no test?
409 allfeatures.add(type);
411 updateMinMax(asq, type, true); // todo: for all features?
417 // uncomment to add new features in alphebetical order (but JAL-2575)
418 // Collections.sort(allfeatures, String.CASE_INSENSITIVE_ORDER);
421 for (String type : allfeatures)
423 if (!oldfeatures.contains(type))
425 featuresDisplayed.setVisible(type);
431 updateRenderOrder(allfeatures);
432 findingFeatures = false;
436 * Updates the global (alignment) min and max values for a feature type from
437 * the score for a sequence, if the score is not NaN. Values are stored
438 * separately for positional and non-positional features.
444 protected void updateMinMax(SequenceI seq, String featureType,
447 float min = seq.getFeatures().getMinimumScore(featureType, positional);
448 if (Float.isNaN(min))
453 float max = seq.getFeatures().getMaximumScore(featureType, positional);
457 * { {positionalMin, positionalMax}, {nonPositionalMin, nonPositionalMax} }
461 minmax = new Hashtable<>();
463 synchronized (minmax)
465 float[][] mm = minmax.get(featureType);
466 int index = positional ? 0 : 1;
469 mm = new float[][] { null, null };
470 minmax.put(featureType, mm);
472 if (mm[index] == null)
474 mm[index] = new float[] { min, max };
478 mm[index][0] = Math.min(mm[index][0], min);
479 mm[index][1] = Math.max(mm[index][1], max);
483 protected Boolean firing = Boolean.FALSE;
486 * replaces the current renderOrder with the unordered features in
487 * allfeatures. The ordering of any types in both renderOrder and allfeatures
488 * is preserved, and all new feature types are rendered on top of the existing
489 * types, in the order given by getOrder or the order given in allFeatures.
490 * Note. this operates directly on the featureOrder hash for efficiency. TODO:
491 * eliminate the float storage for computing/recalling the persistent ordering
492 * New Cability: updates min/max for colourscheme range if its dynamic
496 private void updateRenderOrder(List<String> allFeatures)
498 List<String> allfeatures = new ArrayList<>(allFeatures);
499 String[] oldRender = renderOrder;
500 renderOrder = new String[allfeatures.size()];
501 boolean initOrders = (featureOrder == null);
503 if (oldRender != null && oldRender.length > 0)
505 for (int j = 0; j < oldRender.length; j++)
507 if (oldRender[j] != null)
511 setOrder(oldRender[j],
512 (1 - (1 + (float) j) / oldRender.length));
514 if (allfeatures.contains(oldRender[j]))
516 renderOrder[opos++] = oldRender[j]; // existing features always
517 // appear below new features
518 allfeatures.remove(oldRender[j]);
521 float[][] mmrange = minmax.get(oldRender[j]);
524 FeatureColourI fc = featureColours.get(oldRender[j]);
525 if (fc != null && !fc.isSimpleColour() && fc.isAutoScaled()
526 && !fc.isColourByAttribute())
528 fc.updateBounds(mmrange[0][0], mmrange[0][1]);
536 if (allfeatures.size() == 0)
538 // no new features - leave order unchanged.
541 int i = allfeatures.size() - 1;
543 boolean sort = false;
544 String[] newf = new String[allfeatures.size()];
545 float[] sortOrder = new float[allfeatures.size()];
546 for (String newfeat : allfeatures)
551 // update from new features minmax if necessary
552 float[][] mmrange = minmax.get(newf[i]);
555 FeatureColourI fc = featureColours.get(newf[i]);
556 if (fc != null && !fc.isSimpleColour() && fc.isAutoScaled()
557 && !fc.isColourByAttribute())
559 fc.updateBounds(mmrange[0][0], mmrange[0][1]);
563 if (initOrders || !featureOrder.containsKey(newf[i]))
565 int denom = initOrders ? allfeatures.size() : featureOrder.size();
566 // new unordered feature - compute persistent ordering at head of
567 // existing features.
568 setOrder(newf[i], i / (float) denom);
570 // set order from newly found feature from persisted ordering.
571 sortOrder[i] = 2 - featureOrder.get(newf[i]).floatValue();
574 // only sort if we need to
575 sort = sort || sortOrder[i] > sortOrder[i + 1];
579 if (iSize > 1 && sort)
581 jalview.util.QuickSort.sort(sortOrder, newf);
584 System.arraycopy(newf, 0, renderOrder, opos, newf.length);
588 * get a feature style object for the given type string. Creates a
589 * java.awt.Color for a featureType with no existing colourscheme.
595 public FeatureColourI getFeatureStyle(String featureType)
597 FeatureColourI fc = featureColours.get(featureType);
600 Color col = ColorUtils.createColourFromName(featureType);
601 fc = new FeatureColour(col);
602 featureColours.put(featureType, fc);
608 public Color getColour(SequenceFeature feature)
610 FeatureColourI fc = getFeatureStyle(feature.getType());
611 return getColor(feature, fc);
615 * Answers true if the feature type is currently selected to be displayed,
621 protected boolean showFeatureOfType(String type)
623 return type == null ? false : (av.getFeaturesDisplayed() == null ? true
624 : av.getFeaturesDisplayed().isVisible(type));
628 public void setColour(String featureType, FeatureColourI col)
630 featureColours.put(featureType, col);
634 public void setTransparency(float value)
636 transparency = value;
640 public float getTransparency()
646 * analogous to colour - store a normalized ordering for all feature types in
647 * this rendering context.
650 * Feature type string
652 * normalized priority - 0 means always appears on top, 1 means
655 public float setOrder(String type, float position)
657 if (featureOrder == null)
659 featureOrder = new Hashtable<>();
661 featureOrder.put(type, Float.valueOf(position));
666 * get the global priority (0 (top) to 1 (bottom))
669 * @return [0,1] or -1 for a type without a priority
671 public float getOrder(String type)
673 if (featureOrder != null)
675 if (featureOrder.containsKey(type))
677 return featureOrder.get(type).floatValue();
684 public Map<String, FeatureColourI> getFeatureColours()
686 return featureColours;
690 * Replace current ordering with new ordering
693 * an array of { Type, Colour, Filter, Boolean }
694 * @return true if any visible features have been reordered, else false
696 public boolean setFeaturePriority(FeatureSettingsBean[] data)
698 return setFeaturePriority(data, true);
702 * Sets the priority order for features, with the highest priority (displayed on
703 * top) at the start of the data array
706 * an array of { Type, Colour, Filter, Boolean }
708 * when true current featureDisplay list will be cleared
709 * @return true if any visible features have been reordered or recoloured, else
710 * false (i.e. no need to repaint)
712 public boolean setFeaturePriority(FeatureSettingsBean[] data,
716 * note visible feature ordering and colours before update
718 List<String> visibleFeatures = getDisplayedFeatureTypes();
719 Map<String, FeatureColourI> visibleColours = new HashMap<>(
720 getFeatureColours());
722 FeaturesDisplayedI av_featuresdisplayed = null;
725 if ((av_featuresdisplayed = av.getFeaturesDisplayed()) != null)
727 av.getFeaturesDisplayed().clear();
731 av.setFeaturesDisplayed(
732 av_featuresdisplayed = new FeaturesDisplayed());
737 av_featuresdisplayed = av.getFeaturesDisplayed();
743 // The feature table will display high priority
744 // features at the top, but these are the ones
745 // we need to render last, so invert the data
746 renderOrder = new String[data.length];
750 for (int i = 0; i < data.length; i++)
752 String type = data[i].featureType;
753 setColour(type, data[i].featureColour);
756 av_featuresdisplayed.setVisible(type);
759 renderOrder[data.length - i - 1] = type;
764 * get the new visible ordering and return true if it has changed
765 * order or any colour has changed
767 List<String> reorderedVisibleFeatures = getDisplayedFeatureTypes();
768 if (!visibleFeatures.equals(reorderedVisibleFeatures))
771 * the list of ordered visible features has changed
777 * return true if any feature colour has changed
779 for (String feature : visibleFeatures)
781 if (visibleColours.get(feature) != getFeatureStyle(feature))
791 * @see java.beans.PropertyChangeSupport#addPropertyChangeListener(java.beans.PropertyChangeListener)
793 public void addPropertyChangeListener(PropertyChangeListener listener)
795 changeSupport.addPropertyChangeListener(listener);
800 * @see java.beans.PropertyChangeSupport#removePropertyChangeListener(java.beans.PropertyChangeListener)
802 public void removePropertyChangeListener(PropertyChangeListener listener)
804 changeSupport.removePropertyChangeListener(listener);
807 public Set<String> getAllFeatureColours()
809 return featureColours.keySet();
812 public void clearRenderOrder()
817 public boolean hasRenderOrder()
819 return renderOrder != null;
823 * Returns feature types in ordering of rendering, where last means on top
825 public List<String> getRenderOrder()
827 if (renderOrder == null)
829 return Arrays.asList(new String[] {});
831 return Arrays.asList(renderOrder);
834 public int getFeatureGroupsSize()
836 return featureGroups != null ? 0 : featureGroups.size();
840 public List<String> getFeatureGroups()
842 // conflict between applet and desktop - featureGroups returns the map in
843 // the desktop featureRenderer
844 return (featureGroups == null) ? Arrays.asList(new String[0])
845 : Arrays.asList(featureGroups.keySet().toArray(new String[0]));
848 public boolean checkGroupVisibility(String group,
849 boolean newGroupsVisible)
851 if (featureGroups == null)
853 // then an exception happens next..
855 if (featureGroups.containsKey(group))
857 return featureGroups.get(group).booleanValue();
859 if (newGroupsVisible)
861 featureGroups.put(group, Boolean.valueOf(true));
868 * get visible or invisible groups
871 * true to return visible groups, false to return hidden ones.
872 * @return list of groups
875 public List<String> getGroups(boolean visible)
877 if (featureGroups != null)
879 List<String> gp = new ArrayList<>();
881 for (String grp : featureGroups.keySet())
883 Boolean state = featureGroups.get(grp);
884 if (state.booleanValue() == visible)
895 public void setGroupVisibility(String group, boolean visible)
897 featureGroups.put(group, Boolean.valueOf(visible));
901 public void setGroupVisibility(List<String> toset, boolean visible)
903 if (toset != null && toset.size() > 0 && featureGroups != null)
905 boolean rdrw = false;
906 for (String gst : toset)
908 Boolean st = featureGroups.get(gst);
909 featureGroups.put(gst, Boolean.valueOf(visible));
912 rdrw = rdrw || (visible != st.booleanValue());
917 // set local flag indicating redraw needed ?
923 public Map<String, FeatureColourI> getDisplayedFeatureCols()
925 Map<String, FeatureColourI> fcols = new Hashtable<>();
926 if (getViewport().getFeaturesDisplayed() == null)
930 Set<String> features = getViewport().getFeaturesDisplayed()
931 .getVisibleFeatures();
932 for (String feature : features)
934 fcols.put(feature, getFeatureStyle(feature));
940 public FeaturesDisplayedI getFeaturesDisplayed()
942 return av.getFeaturesDisplayed();
946 * Returns a (possibly empty) list of visible feature types, in render order
950 public List<String> getDisplayedFeatureTypes()
952 List<String> typ = getRenderOrder();
953 List<String> displayed = new ArrayList<>();
954 FeaturesDisplayedI feature_disp = av.getFeaturesDisplayed();
955 if (feature_disp != null)
957 synchronized (feature_disp)
959 for (String type : typ)
961 if (feature_disp.isVisible(type))
972 public List<String> getDisplayedFeatureGroups()
974 List<String> _gps = new ArrayList<>();
975 for (String gp : getFeatureGroups())
977 if (checkGroupVisibility(gp, false))
986 * Answers true if the feature belongs to a feature group which is not
987 * currently displayed, else false
989 * @param sequenceFeature
992 public boolean featureGroupNotShown(final SequenceFeature sequenceFeature)
994 return featureGroups != null
995 && sequenceFeature.featureGroup != null
996 && sequenceFeature.featureGroup.length() != 0
997 && featureGroups.containsKey(sequenceFeature.featureGroup)
998 && !featureGroups.get(sequenceFeature.featureGroup)
1006 public List<SequenceFeature> findFeaturesAtResidue(SequenceI sequence,
1007 int fromResNo, int toResNo)
1009 List<SequenceFeature> result = new ArrayList<>();
1010 if (!av.areFeaturesDisplayed() || getFeaturesDisplayed() == null)
1016 * include features at the position provided their feature type is
1017 * displayed, and feature group is null or the empty string
1018 * or marked for display
1020 List<String> visibleFeatures = getDisplayedFeatureTypes();
1021 String[] visibleTypes = visibleFeatures
1022 .toArray(new String[visibleFeatures.size()]);
1023 List<SequenceFeature> features = sequence.getFeatures().findFeatures(
1024 fromResNo, toResNo, visibleTypes);
1026 for (SequenceFeature sf : features)
1028 if (!featureGroupNotShown(sf) && getColour(sf) != null)
1037 * Removes from the list of features any whose group is not shown, or that are
1038 * visible and duplicate the location of a visible feature of the same type.
1039 * Should be used only for features of the same, simple, feature colour (which
1040 * normally implies the same feature type). No filtering is done if
1041 * transparency, or any feature filters, are in force.
1045 public void filterFeaturesForDisplay(List<SequenceFeature> features)
1048 * don't remove 'redundant' features if
1049 * - transparency is applied (feature count affects depth of feature colour)
1050 * - filters are applied (not all features may be displayable)
1052 if (features.isEmpty() || transparency != 1f
1053 || !featureFilters.isEmpty())
1058 SequenceFeatures.sortFeatures(features, true);
1059 SequenceFeature lastFeature = null;
1061 Iterator<SequenceFeature> it = features.iterator();
1062 while (it.hasNext())
1064 SequenceFeature sf = it.next();
1065 if (featureGroupNotShown(sf))
1072 * a feature is redundant for rendering purposes if it has the
1073 * same extent as another (so would just redraw the same colour);
1074 * (checking type and isContactFeature as a fail-safe here, although
1075 * currently they are guaranteed to match in this context)
1077 if (lastFeature != null
1078 && sf.getBegin() == lastFeature.getBegin()
1079 && sf.getEnd() == lastFeature.getEnd()
1080 && sf.isContactFeature() == lastFeature.isContactFeature()
1081 && sf.getType().equals(lastFeature.getType()))
1090 public Map<String, FeatureMatcherSetI> getFeatureFilters()
1092 return featureFilters;
1096 public void setFeatureFilters(Map<String, FeatureMatcherSetI> filters)
1098 featureFilters = filters;
1102 public FeatureMatcherSetI getFeatureFilter(String featureType)
1104 return featureFilters.get(featureType);
1108 public void setFeatureFilter(String featureType, FeatureMatcherSetI filter)
1110 if (filter == null || filter.isEmpty())
1112 featureFilters.remove(featureType);
1116 featureFilters.put(featureType, filter);
1121 * Answers the colour for the feature, or null if the feature is excluded by
1122 * feature group visibility, by filters, or by colour threshold settings. This
1123 * method does not take feature visibility into account.
1129 public Color getColor(SequenceFeature sf, FeatureColourI fc)
1132 * is the feature group displayed?
1134 if (featureGroupNotShown(sf))
1140 * does the feature pass filters?
1142 if (!featureMatchesFilters(sf))
1147 return fc.getColor(sf);
1151 * Answers true if there no are filters defined for the feature type, or this
1152 * feature matches the filters. Answers false if the feature fails to match
1158 protected boolean featureMatchesFilters(SequenceFeature sf)
1160 FeatureMatcherSetI filter = featureFilters.get(sf.getType());
1161 return filter == null ? true : filter.matches(sf);
1165 public MappedFeatures findComplementFeaturesAtResidue(SequenceI sequence,
1168 SequenceI ds = sequence.getDatasetSequence();
1173 final char residue = ds.getCharAt(pos - ds.getStart());
1175 List<SequenceFeature> found = new ArrayList<>();
1176 List<AlignedCodonFrame> mappings = this.av.getAlignment()
1177 .getCodonFrame(sequence);
1180 * fudge: if no mapping found, check the complementary alignment
1181 * todo: only store in one place? StructureSelectionManager?
1183 if (mappings.isEmpty())
1185 mappings = this.av.getCodingComplement().getAlignment()
1186 .getCodonFrame(sequence);
1190 * todo: direct lookup of CDS for peptide and vice-versa; for now,
1191 * have to search through an unordered list of mappings for a candidate
1193 Mapping mapping = null;
1194 SequenceI mapFrom = null;
1196 for (AlignedCodonFrame acf : mappings)
1198 mapping = acf.getMappingForSequence(sequence);
1199 if (mapping == null || !mapping.getMap().isTripletMap())
1201 continue; // we are only looking for 3:1 or 1:3 mappings
1203 SearchResultsI sr = new SearchResults();
1204 acf.markMappedRegion(ds, pos, sr);
1205 for (SearchResultMatchI match : sr.getResults())
1207 int fromRes = match.getStart();
1208 int toRes = match.getEnd();
1209 mapFrom = match.getSequence();
1210 List<SequenceFeature> fs = findFeaturesAtResidue(
1211 match.getSequence(), fromRes, toRes);
1212 for (SequenceFeature sf : fs)
1214 if (!found.contains(sf))
1222 * just take the first mapped features we find
1224 if (!found.isEmpty())
1229 if (found.isEmpty())
1235 * sort by renderorder, inefficiently
1237 List<SequenceFeature> result = new ArrayList<>();
1238 for (String type : renderOrder)
1240 for (SequenceFeature sf : found)
1242 if (type.equals(sf.getType()))
1245 if (result.size() == found.size())
1247 return new MappedFeatures(mapping, mapFrom, pos, residue,
1254 return new MappedFeatures(mapping, mapFrom, pos, residue, result);
1258 public boolean isVisible(SequenceFeature feature)
1260 if (feature == null)
1264 if (getFeaturesDisplayed() == null
1265 || !getFeaturesDisplayed().isVisible(feature.getType()))
1269 if (featureGroupNotShown(feature))
1273 FeatureColourI fc = featureColours.get(feature.getType());
1274 if (fc != null && fc.isOutwithThreshold(feature))
1278 if (!featureMatchesFilters(feature))