import jalview.commands.EditCommand.Action;
import jalview.datamodel.ColumnSelection;
import jalview.datamodel.SearchResults;
+import jalview.datamodel.SearchResults.Match;
import jalview.datamodel.Sequence;
import jalview.datamodel.SequenceFeature;
import jalview.datamodel.SequenceGroup;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
+import java.util.List;
import java.util.Vector;
public class SeqPanel extends Panel implements MouseMotionListener,
return 1;
}
+ /**
+ * Set status message in alignment panel
+ *
+ * @param sequence
+ * aligned sequence object
+ * @param res
+ * alignment column
+ * @param seq
+ * index of sequence in alignment
+ * @return position of res in sequence
+ */
void setStatusMessage(SequenceI sequence, int res, int seq)
{
- StringBuffer text = new StringBuffer("Sequence " + (seq + 1) + " ID: "
- + sequence.getName());
+ // TODO remove duplication of identical gui method
+ StringBuilder text = new StringBuilder(32);
+ String seqno = seq == -1 ? "" : " " + (seq + 1);
+ text.append("Sequence" + seqno + " ID: " + sequence.getName());
- Object obj = null;
+ String residue = null;
+ /*
+ * Try to translate the display character to residue name (null for gap).
+ */
+ final String displayChar = String.valueOf(sequence.getCharAt(res));
if (av.getAlignment().isNucleotide())
{
- obj = ResidueProperties.nucleotideName.get(sequence.getCharAt(res)
- + "");
- if (obj != null)
+ residue = ResidueProperties.nucleotideName.get(displayChar);
+ if (residue != null)
{
- text.append(" Nucleotide: ");
+ text.append(" Nucleotide: ").append(residue);
}
}
else
{
- obj = ResidueProperties.aa2Triplet.get(sequence.getCharAt(res) + "");
- if (obj != null)
- {
- text.append(" Residue: ");
- }
- }
+ residue = "X".equalsIgnoreCase(displayChar) ? "X"
+ : ResidueProperties.aa2Triplet.get(displayChar);
+ if (residue != null)
+ {
+ text.append(" Residue: ").append(residue);
+ }
+ }
+
+ int pos = -1;
+ if (residue != null)
+ {
+ pos = sequence.findPosition(res);
+ text.append(" (").append(Integer.toString(pos)).append(")");
+ }
+ // Object obj = null;
+ // if (av.getAlignment().isNucleotide())
+ // {
+ // obj = ResidueProperties.nucleotideName.get(sequence.getCharAt(res)
+ // + "");
+ // if (obj != null)
+ // {
+ // text.append(" Nucleotide: ");
+ // }
+ // }
+ // else
+ // {
+ // obj = ResidueProperties.aa2Triplet.get(sequence.getCharAt(res) + "");
+ // if (obj != null)
+ // {
+ // text.append(" Residue: ");
+ // }
+ // }
+ //
+ // if (obj != null)
+ // {
+ //
+ // if (obj != "")
+ // {
+ // text.append(obj + " (" + sequence.findPosition(res) + ")");
+ // }
+ // }
- if (obj != null)
- {
+ ap.alignFrame.statusBar.setText(text.toString());
- if (obj != "")
- {
- text.append(obj + " (" + sequence.findPosition(res) + ")");
- }
- }
+ }
- ap.alignFrame.statusBar.setText(text.toString());
+ /**
+ * Set the status bar message to highlight the first matched position in
+ * search results.
+ *
+ * @param results
+ */
+ private void setStatusMessage(SearchResults results)
+ {
+ List<Match> matches = results.getResults();
+ if (!matches.isEmpty())
+ {
+ Match m = matches.get(0);
+ SequenceI seq = m.getSequence();
+ int sequenceIndex = this.av.getAlignment().findIndex(seq);
+ /*
+ * Convert position in sequence (base 1) to sequence character array index
+ * (base 0)
+ */
+ int start = m.getStart() - 1;
+ setStatusMessage(seq, start, sequenceIndex);
+ }
}
public void mousePressed(MouseEvent evt)
ap.alignFrame.repaint();
}
}
+ setStatusMessage(results);
seqCanvas.highlightSearchResults(results);
}
}
else
{
- obj = "X".equalsIgnoreCase(ch) ? "STOP"
+ obj = "X".equalsIgnoreCase(ch) ? "X"
: ResidueProperties.aa2Triplet.get(ch);
if (obj != null)
{
import jalview.commands.EditCommand.Edit;
import jalview.datamodel.ColumnSelection;
import jalview.datamodel.SearchResults;
+import jalview.datamodel.SearchResults.Match;
import jalview.datamodel.Sequence;
import jalview.datamodel.SequenceFeature;
import jalview.datamodel.SequenceGroup;
seqCanvas.revalidate();
}
}
+ setStatusMessage(results);
seqCanvas.highlightSearchResults(results);
}
*/
int setStatusMessage(SequenceI sequence, int res, int seq)
{
- int pos = -1;
StringBuilder text = new StringBuilder(32);
- text.append("Sequence " + (seq + 1) + " ID: " + sequence.getName());
+
+ /*
+ * Sequence number (if known), and sequence name.
+ */
+ String seqno = seq == -1 ? "" : " " + (seq + 1);
+ text.append("Sequence" + seqno + " ID: " + sequence.getName());
String residue = null;
/*
}
else
{
- residue = "X".equalsIgnoreCase(displayChar) ? "STOP"
+ residue = "X".equalsIgnoreCase(displayChar) ? "X"
: ResidueProperties.aa2Triplet.get(displayChar);
if (residue != null)
{
}
}
+ int pos = -1;
if (residue != null)
{
pos = sequence.findPosition(res);
}
/**
+ * Set the status bar message to highlight the first matched position in
+ * search results.
+ *
+ * @param results
+ */
+ private void setStatusMessage(SearchResults results)
+ {
+ List<Match> matches = results.getResults();
+ if (!matches.isEmpty())
+ {
+ Match m = matches.get(0);
+ SequenceI seq = m.getSequence();
+ int sequenceIndex = this.av.getAlignment().findIndex(seq);
+
+ /*
+ * Convert position in sequence (base 1) to sequence character array index
+ * (base 0)
+ */
+ int start = m.getStart() - 1;
+ setStatusMessage(seq, start, sequenceIndex);
+ }
+ }
+
+ /**
* DOCUMENT ME!
*
* @param evt