+ @Override
+ public MappedFeatures findComplementFeaturesAtResidue(SequenceI sequence,
+ int pos)
+ {
+ SequenceI ds = sequence.getDatasetSequence();
+ if (ds == null)
+ {
+ ds = sequence;
+ }
+ final char residue = ds.getCharAt(pos - ds.getStart());
+
+ List<SequenceFeature> found = new ArrayList<>();
+ List<AlignedCodonFrame> mappings = this.av.getAlignment()
+ .getCodonFrame(sequence);
+
+ /*
+ * fudge: if no mapping found, check the complementary alignment
+ * todo: only store in one place? StructureSelectionManager?
+ */
+ if (mappings.isEmpty())
+ {
+ mappings = this.av.getCodingComplement().getAlignment()
+ .getCodonFrame(sequence);
+ }
+
+ /*
+ * todo: direct lookup of CDS for peptide and vice-versa; for now,
+ * have to search through an unordered list of mappings for a candidate
+ */
+ Mapping mapping = null;
+ SequenceI mapFrom = null;
+
+ for (AlignedCodonFrame acf : mappings)
+ {
+ mapping = acf.getMappingForSequence(sequence);
+ if (mapping == null || !mapping.getMap().isTripletMap())
+ {
+ continue; // we are only looking for 3:1 or 1:3 mappings
+ }
+ SearchResultsI sr = new SearchResults();
+ acf.markMappedRegion(ds, pos, sr);
+ for (SearchResultMatchI match : sr.getResults())
+ {
+ int fromRes = match.getStart();
+ int toRes = match.getEnd();
+ mapFrom = match.getSequence();
+ List<SequenceFeature> fs = findFeaturesAtResidue(
+ match.getSequence(), fromRes, toRes);
+ for (SequenceFeature sf : fs)
+ {
+ if (!found.contains(sf))
+ {
+ found.add(sf);
+ }
+ }
+ }
+
+ /*
+ * just take the first mapped features we find
+ */
+ if (!found.isEmpty())
+ {
+ break;
+ }
+ }
+ if (found.isEmpty())
+ {
+ return null;
+ }
+
+ /*
+ * sort by renderorder, inefficiently
+ */
+ List<SequenceFeature> result = new ArrayList<>();
+ for (String type : renderOrder)
+ {
+ for (SequenceFeature sf : found)
+ {
+ if (type.equals(sf.getType()))
+ {
+ result.add(sf);
+ if (result.size() == found.size())
+ {
+ return new MappedFeatures(mapping, mapFrom, pos, residue,
+ result);
+ }
+ }
+ }
+ }
+
+ return new MappedFeatures(mapping, mapFrom, pos, residue, result);
+ }
+
+ @Override
+ public boolean isVisible(SequenceFeature feature)
+ {
+ if (feature == null)
+ {
+ return false;
+ }
+ if (getFeaturesDisplayed() == null
+ || !getFeaturesDisplayed().isVisible(feature.getType()))
+ {
+ return false;
+ }
+ if (featureGroupNotShown(feature))
+ {
+ return false;
+ }
+ FeatureColourI fc = featureColours.get(feature.getType());
+ if (fc != null && fc.isOutwithThreshold(feature))
+ {
+ return false;
+ }
+ if (!featureMatchesFilters(feature))
+ {
+ return false;
+ }
+ return true;
+ }
+