import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
+import java.util.Collections;
+import java.util.List;
import java.util.Vector;
public class SeqPanel extends Panel implements MouseMotionListener,
}
int seq = findSeq(evt);
- int res = findRes(evt);
+ int res = findColumn(evt);
if (seq < 0 || res < 0)
{
av.setSelectionGroup(null);
}
- SequenceFeature[] features = findFeaturesAtRes(sequence,
- sequence.findPosition(findRes(evt)));
+ int column = findColumn(evt);
+ List<SequenceFeature> features = findFeaturesAtColumn(sequence,
+ column + 1);
- if (features != null && features.length > 0)
+ if (!features.isEmpty())
{
SearchResultsI highlight = new SearchResults();
- highlight.addResult(sequence, features[0].getBegin(),
- features[0].getEnd());
+ highlight.addResult(sequence, features.get(0).getBegin(), features
+ .get(0).getEnd());
seqCanvas.highlightSearchResults(highlight);
- }
- if (features != null && features.length > 0)
- {
seqCanvas.getFeatureRenderer().amendFeatures(
- new SequenceI[] { sequence }, features, false, ap);
-
- seqCanvas.highlightSearchResults(null);
+ Collections.singletonList(sequence), features, false, ap);
+ av.setSearchResults(null); // clear highlighting
+ seqCanvas.repaint(); // draw new/amended features
}
}
}
int wrappedBlock = -1;
- int findRes(MouseEvent evt)
+ /**
+ * Returns the aligned sequence position (base 0) at the mouse position, or
+ * the closest visible one
+ *
+ * @param evt
+ * @return
+ */
+ int findColumn(MouseEvent evt)
{
int res = 0;
int x = evt.getX();
+ int startRes = av.getRanges().getStartRes();
if (av.getWrapAlignment())
{
int y = evt.getY();
y -= hgap;
- x -= seqCanvas.LABEL_WEST;
+ x = Math.max(0, x - seqCanvas.LABEL_WEST);
int cwidth = seqCanvas.getWrappedCanvasWidth(getSize().width);
if (cwidth < 1)
}
wrappedBlock = y / cHeight;
- wrappedBlock += av.getRanges().getStartRes() / cwidth;
-
- res = wrappedBlock * cwidth + x / av.getCharWidth();
-
+ wrappedBlock += startRes / cwidth;
+ int startOffset = startRes % cwidth; // in case start is scrolled right
+ // from 0
+ res = wrappedBlock * cwidth + startOffset
+ + +Math.min(cwidth - 1, x / av.getCharWidth());
}
else
{
- res = (x / av.getCharWidth()) + av.getRanges().getStartRes();
+ res = (x / av.getCharWidth()) + startRes;
}
if (av.hasHiddenColumns())
{
int seq = findSeq(evt);
- int res = findRes(evt);
+ int res = findColumn(evt);
if (seq < av.getAlignment().getHeight()
&& res < av.getAlignment().getSequenceAt(seq).getLength())
@Override
public void mouseMoved(MouseEvent evt)
{
- final int column = findRes(evt);
+ final int column = findColumn(evt);
int seq = findSeq(evt);
if (seq >= av.getAlignment().getHeight() || seq < 0 || column < 0)
}
final char ch = sequence.getCharAt(column);
- int respos = Comparison.isGap(ch) ? -1 : sequence.findPosition(column);
+ boolean isGapped = Comparison.isGap(ch);
+ // find residue at column (or nearest if at a gap)
+ int respos = sequence.findPosition(column);
- if (ssm != null && respos != -1)
+ if (ssm != null && !isGapped)
{
mouseOverSequence(sequence, column, respos);
}
text.append("Sequence ").append(Integer.toString(seq + 1))
.append(" ID: ").append(sequence.getName());
- String obj = null;
- if (respos != -1)
+ if (!isGapped)
{
if (av.getAlignment().isNucleotide())
{
- obj = ResidueProperties.nucleotideName.get(ch);
- if (obj != null)
- {
- text.append(" Nucleotide: ").append(obj);
- }
+ String base = ResidueProperties.nucleotideName.get(ch);
+ text.append(" Nucleotide: ").append(base == null ? ch : base);
}
else
{
- obj = (ch == 'x' || ch == 'X') ? "X" : ResidueProperties.aa2Triplet
+ String residue = (ch == 'x' || ch == 'X') ? "X"
+ : ResidueProperties.aa2Triplet
.get(String.valueOf(ch));
- if (obj != null)
- {
- text.append(" Residue: ").append(obj);
- }
- }
- if (obj != null)
- {
- text.append(" (").append(Integer.toString(respos)).append(")");
+ text.append(" Residue: ").append(residue == null ? ch : residue);
}
+ text.append(" (").append(Integer.toString(respos)).append(")");
}
ap.alignFrame.statusBar.setText(text.toString());
}
/*
- * add feature details to tooltip if over one or more features
+ * add feature details to tooltip, including any that straddle
+ * a gapped position
*/
- if (respos != -1)
+ if (av.isShowSequenceFeatures())
{
- SequenceFeature[] allFeatures = findFeaturesAtRes(sequence,
- sequence.findPosition(column));
-
- int index = 0;
- while (index < allFeatures.length)
+ List<SequenceFeature> allFeatures = findFeaturesAtColumn(sequence,
+ column + 1);
+ for (SequenceFeature sf : allFeatures)
{
- SequenceFeature sf = allFeatures[index];
-
tooltipText.append(sf.getType() + " " + sf.begin + ":" + sf.end);
if (sf.getDescription() != null)
}
}
tooltipText.append("\n");
-
- index++;
}
}
}
}
- SequenceFeature[] findFeaturesAtRes(SequenceI sequence, int res)
+ /**
+ * Returns features at the specified aligned column on the given sequence.
+ * Non-positional features are not included. If the column has a gap, then
+ * enclosing features are included (but not contact features).
+ *
+ * @param sequence
+ * @param column
+ * (1..)
+ * @return
+ */
+ List<SequenceFeature> findFeaturesAtColumn(SequenceI sequence, int column)
{
- Vector tmp = new Vector();
- SequenceFeature[] features = sequence.getSequenceFeatures();
- if (features != null)
- {
- for (int i = 0; i < features.length; i++)
- {
- if (av.getFeaturesDisplayed() == null
- || !av.getFeaturesDisplayed().isVisible(
- features[i].getType()))
- {
- continue;
- }
-
- if (features[i].featureGroup != null
- && !seqCanvas.fr.checkGroupVisibility(
- features[i].featureGroup, false))
- {
- continue;
- }
-
- if ((features[i].getBegin() <= res)
- && (features[i].getEnd() >= res))
- {
- tmp.addElement(features[i]);
- }
- }
- }
-
- features = new SequenceFeature[tmp.size()];
- tmp.copyInto(features);
-
- return features;
+ return seqCanvas.getFeatureRenderer().findFeaturesAtColumn(sequence, column);
}
Tooltip tooltip;
return;
}
- int res = findRes(evt);
+ int res = findColumn(evt);
if (res < 0)
{
// Find the next gap before the end
// of the visible region boundary
boolean blank = false;
- for (fixedRight = fixedRight; fixedRight > lastres; fixedRight--)
+ for (; fixedRight > lastres; fixedRight--)
{
blank = true;
scrollThread = null;
}
- int res = findRes(evt);
+ int column = findColumn(evt);
int seq = findSeq(evt);
oldSeq = seq;
startWrapBlock = wrappedBlock;
SequenceI sequence = av.getAlignment().getSequenceAt(seq);
- if (sequence == null || res > sequence.getLength())
+ if (sequence == null || column > sequence.getLength())
{
return;
}
stretchGroup = av.getSelectionGroup();
- if (stretchGroup == null || !stretchGroup.contains(sequence, res))
+ if (stretchGroup == null || !stretchGroup.contains(sequence, column))
{
- stretchGroup = av.getAlignment().findGroup(sequence, res);
+ stretchGroup = av.getAlignment().findGroup(sequence, column);
if (stretchGroup != null)
{
// only update the current selection if the popup menu has a group to
// DETECT RIGHT MOUSE BUTTON IN AWT
if ((evt.getModifiers() & InputEvent.BUTTON3_MASK) == InputEvent.BUTTON3_MASK)
{
- SequenceFeature[] allFeatures = findFeaturesAtRes(sequence,
- sequence.findPosition(res));
+ List<SequenceFeature> allFeatures = findFeaturesAtColumn(sequence,
+ sequence.findPosition(column + 1));
Vector<String> links = null;
- if (allFeatures != null)
+ for (SequenceFeature sf : allFeatures)
{
- for (int i = 0; i < allFeatures.length; i++)
+ if (sf.links != null)
{
- if (allFeatures[i].links != null)
+ if (links == null)
{
- if (links == null)
- {
- links = new Vector<>();
- }
- for (int j = 0; j < allFeatures[i].links.size(); j++)
- {
- links.addElement(allFeatures[i].links.elementAt(j));
- }
+ links = new Vector<String>();
}
+ links.addAll(sf.links);
}
}
APopupMenu popup = new APopupMenu(ap, null, links);
if (av.cursorMode)
{
- seqCanvas.cursorX = findRes(evt);
+ seqCanvas.cursorX = findColumn(evt);
seqCanvas.cursorY = findSeq(evt);
seqCanvas.repaint();
return;
{
// define a new group here
SequenceGroup sg = new SequenceGroup();
- sg.setStartRes(res);
- sg.setEndRes(res);
+ sg.setStartRes(column);
+ sg.setEndRes(column);
sg.addSequence(sequence, false);
av.setSelectionGroup(sg);
stretchGroup = sg;
public void doMouseDraggedDefineMode(MouseEvent evt)
{
- int res = findRes(evt);
+ int res = findColumn(evt);
int y = findSeq(evt);
if (wrappedBlock != startWrapBlock)
}
if (copycolsel
&& av.hasHiddenColumns()
- && (av.getColumnSelection() == null || av.getAlignment()
- .getHiddenColumns().getHiddenRegions() == null))
+ && (av.getColumnSelection() == null))
{
System.err.println("Bad things");
}