import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
return;
}
- int rsize = 0, gSize = sg.getSize();
- SequenceI[] rseqs, seqs = new SequenceI[gSize];
- SequenceFeature[] tfeatures, features = new SequenceFeature[gSize];
+ int gSize = sg.getSize();
+ List<SequenceI> seqs = new ArrayList<SequenceI>();
+ List<SequenceFeature> features = new ArrayList<SequenceFeature>();
for (int i = 0; i < gSize; i++)
{
int end = sg.findEndRes(sg.getSequenceAt(i));
if (start <= end)
{
- seqs[rsize] = sg.getSequenceAt(i);
- features[rsize] = new SequenceFeature(null, null, null, start,
- end, "Jalview");
- rsize++;
+ seqs.add(sg.getSequenceAt(i));
+ features.add(new SequenceFeature(null, null, null, start, end,
+ "Jalview"));
}
}
- rseqs = new SequenceI[rsize];
- tfeatures = new SequenceFeature[rsize];
- System.arraycopy(seqs, 0, rseqs, 0, rsize);
- System.arraycopy(features, 0, tfeatures, 0, rsize);
- features = tfeatures;
- seqs = rseqs;
if (ap.seqPanel.seqCanvas.getFeatureRenderer().amendFeatures(seqs,
features, true, ap))
{
ap.alignFrame.sequenceFeatures.setState(true);
ap.av.setShowSequenceFeatures(true);
- ;
ap.highlightSearchResults(null);
}
}
import java.awt.event.TextEvent;
import java.awt.event.TextListener;
import java.util.Hashtable;
+import java.util.List;
/**
* DOCUMENT ME!
* @param ap
* @return
*/
- boolean amendFeatures(final SequenceI[] sequences,
- final SequenceFeature[] features, boolean create,
+ boolean amendFeatures(final List<SequenceI> sequences,
+ final List<SequenceFeature> features, boolean create,
final AlignmentPanel ap)
{
final Panel bigPanel = new Panel(new BorderLayout());
// /////////////////////////////////////
// /MULTIPLE FEATURES AT SELECTED RESIDUE
- if (!create && features.length > 1)
+ if (!create && features.size() > 1)
{
panel = new Panel(new GridLayout(4, 1));
tmp = new Panel();
tmp.add(new Label("Select Feature: "));
overlaps = new Choice();
- for (int i = 0; i < features.length; i++)
+ for (SequenceFeature sf : features)
{
- String item = features[i].getType() + "/" + features[i].getBegin()
- + "-" + features[i].getEnd();
-
- if (features[i].getFeatureGroup() != null)
+ String item = sf.getType() + "/" + sf.getBegin() + "-"
+ + sf.getEnd();
+ if (sf.getFeatureGroup() != null)
{
- item += " (" + features[i].getFeatureGroup() + ")";
+ item += " (" + sf.getFeatureGroup() + ")";
}
-
overlaps.addItem(item);
}
if (index != -1)
{
featureIndex = index;
- name.setText(features[index].getType());
- description.setText(features[index].getDescription());
- group.setText(features[index].getFeatureGroup());
- start.setText(features[index].getBegin() + "");
- end.setText(features[index].getEnd() + "");
+ SequenceFeature sf = features.get(index);
+ name.setText(sf.getType());
+ description.setText(sf.getDescription());
+ group.setText(sf.getFeatureGroup());
+ start.setText(sf.getBegin() + "");
+ end.setText(sf.getEnd() + "");
SearchResultsI highlight = new SearchResults();
- highlight.addResult(sequences[0], features[index].getBegin(),
- features[index].getEnd());
+ highlight.addResult(sequences.get(0), sf.getBegin(),
+ sf.getEnd());
ap.seqPanel.seqCanvas.highlightSearchResults(highlight);
FeatureColourI col = getFeatureStyle(name.getText());
if (col == null)
{
- Color generatedColour = ColorUtils
- .createColourFromName(name.getText());
+ Color generatedColour = ColorUtils.createColourFromName(name
+ .getText());
col = new FeatureColour(generatedColour);
}
* if feature type has not been supplied by the caller
* (e.g. for Amend, or create features from Find)
*/
- boolean useLastDefaults = features[0].getType() == null;
- String featureType = useLastDefaults ? lastFeatureAdded : features[0]
+ SequenceFeature firstFeature = features.get(0);
+ boolean useLastDefaults = firstFeature.getType() == null;
+ String featureType = useLastDefaults ? lastFeatureAdded : firstFeature
.getType();
String featureGroup = useLastDefaults ? lastFeatureGroupAdded
- : features[0].getFeatureGroup();
+ : firstFeature.getFeatureGroup();
String title = create ? MessageManager
.getString("label.create_new_sequence_features")
: MessageManager.formatMessage("label.amend_delete_features",
- new String[] { sequences[0].getName() });
+ new String[] { sequences.get(0).getName() });
final JVDialog dialog = new JVDialog(ap.alignFrame, title, true, 385,
240);
});
}
- start.setText(features[0].getBegin() + "");
- end.setText(features[0].getEnd() + "");
- description.setText(features[0].getDescription());
+ start.setText(firstFeature.getBegin() + "");
+ end.setText(firstFeature.getEnd() + "");
+ description.setText(firstFeature.getDescription());
// lookup (or generate) the feature colour
FeatureColourI fcol = getFeatureStyle(name.getText());
// simply display the feature color in a box
if (!create)
{
- SequenceFeature sf = features[featureIndex];
+ SequenceFeature sf = features.get(featureIndex);
if (dialog.accept)
{
sf.type = enteredType;
}
if (deleteFeature)
{
- sequences[0].deleteFeature(sf);
+ sequences.get(0).deleteFeature(sf);
// ensure Feature Settings reflects removal of feature / group
featuresAdded();
}
*/
if (dialog.accept && name.getText().length() > 0)
{
- for (int i = 0; i < sequences.length; i++)
+ for (int i = 0; i < sequences.size(); i++)
{
- features[i].type = enteredType;
- features[i].featureGroup = group.getText().trim();
- features[i].description = description.getText()
+ features.get(i).type = enteredType;
+ features.get(i).featureGroup = group.getText().trim();
+ features.get(i).description = description.getText()
.replace('\n', ' ');
- sequences[i].addSequenceFeature(features[i]);
- ffile.parseDescriptionHTML(features[i], false);
+ sequences.get(i).addSequenceFeature(features.get(i));
+ ffile.parseDescriptionHTML(features.get(i), false);
}
Color newColour = colourPanel.getBackground();
import java.awt.event.KeyEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
+import java.util.ArrayList;
+import java.util.List;
import java.util.Vector;
public class Finder extends Panel implements ActionListener
public void createNewGroup_actionPerformed()
{
- SequenceI[] seqs = new SequenceI[searchResults.getSize()];
- SequenceFeature[] features = new SequenceFeature[searchResults
- .getSize()];
+ List<SequenceI> seqs = new ArrayList<SequenceI>();
+ List<SequenceFeature> features = new ArrayList<SequenceFeature>();
String searchString = textfield.getText().trim();
- int i = 0;
for (SearchResultMatchI match : searchResults.getResults())
{
- seqs[i] = match.getSequence().getDatasetSequence();
-
- features[i] = new SequenceFeature(searchString,
+ seqs.add(match.getSequence().getDatasetSequence());
+ features.add(new SequenceFeature(searchString,
"Search Results", null, match.getStart(), match.getEnd(),
- "Search Results");
- i++;
+ "Search Results"));
}
if (ap.seqPanel.seqCanvas.getFeatureRenderer().amendFeatures(seqs,
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.ListIterator;
import java.util.Vector;
public class SeqPanel extends Panel implements MouseMotionListener,
av.setSelectionGroup(null);
}
- SequenceFeature[] features = findFeaturesAtRes(sequence,
- sequence.findPosition(findRes(evt)));
+ int column = findRes(evt);
+ boolean isGapped = Comparison.isGap(sequence.getCharAt(column));
+ List<SequenceFeature> features = findFeaturesAtRes(sequence,
+ sequence.findPosition(column));
+ if (isGapped)
+ {
+ removeAdjacentFeatures(features, column + 1, sequence);
+ }
- 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);
+ Collections.singletonList(sequence), features, false, ap);
seqCanvas.highlightSearchResults(null);
}
}
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,
+ List<SequenceFeature> allFeatures = findFeaturesAtRes(sequence,
sequence.findPosition(column));
-
- int index = 0;
- while (index < allFeatures.length)
+ if (isGapped)
+ {
+ removeAdjacentFeatures(allFeatures, column + 1, sequence);
+ }
+ 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)
+ /**
+ * Removes from the list of features any that start after, or end before, the
+ * given column position. This allows us to retain only those features
+ * adjacent to a gapped position that straddle the position.
+ *
+ * @param features
+ * @param column
+ * alignment column (1..)
+ * @param sequence
+ */
+ protected void removeAdjacentFeatures(List<SequenceFeature> features,
+ int column, SequenceI sequence)
{
- Vector tmp = new Vector();
+ // TODO should this be an AlignViewController method (shared by gui)?
+ ListIterator<SequenceFeature> it = features.listIterator();
+ while (it.hasNext())
+ {
+ SequenceFeature sf = it.next();
+ if (sequence.findIndex(sf.getBegin()) > column
+ || sequence.findIndex(sf.getEnd()) < column)
+ {
+ it.remove();
+ }
+ }
+ }
+
+ List<SequenceFeature> findFeaturesAtRes(SequenceI sequence, int res)
+ {
+ List<SequenceFeature> result = new ArrayList<SequenceFeature>();
SequenceFeature[] features = sequence.getSequenceFeatures();
if (features != null)
{
if ((features[i].getBegin() <= res)
&& (features[i].getEnd() >= res))
{
- tmp.addElement(features[i]);
+ result.add(features[i]);
}
}
}
- features = new SequenceFeature[tmp.size()];
- tmp.copyInto(features);
-
- return features;
+ return result;
}
Tooltip tooltip;
// DETECT RIGHT MOUSE BUTTON IN AWT
if ((evt.getModifiers() & InputEvent.BUTTON3_MASK) == InputEvent.BUTTON3_MASK)
{
- SequenceFeature[] allFeatures = findFeaturesAtRes(sequence,
+ List<SequenceFeature> allFeatures = findFeaturesAtRes(sequence,
sequence.findPosition(res));
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>();
+ }
+ for (int j = 0; j < sf.links.size(); j++)
+ {
+ links.addElement(sf.links.elementAt(j));
}
}
}
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
+import java.util.ListIterator;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
/*
* set status bar message, returning residue position in sequence
*/
+ boolean isGapped = Comparison.isGap(sequence.getCharAt(column));
final int pos = setStatusMessage(sequence, column, seq);
- if (ssm != null && pos > -1)
+ if (ssm != null && !isGapped)
{
mouseOverSequence(sequence, column, pos);
}
}
}
- if (av.isShowSequenceFeatures() && pos != -1)
+ /*
+ * add any features at the position to the tooltip; if over a gap, only
+ * add features that straddle the gap (pos may be the residue before or
+ * after the gap)
+ */
+ if (av.isShowSequenceFeatures())
{
List<SequenceFeature> features = ap.getFeatureRenderer()
.findFeaturesAtRes(sequence.getDatasetSequence(), pos);
+ if (isGapped)
+ {
+ removeAdjacentFeatures(features, column + 1, sequence);
+ }
seqARep.appendFeatures(tooltipText, pos, features,
this.ap.getSeqPanel().seqCanvas.fr.getMinMax());
}
}
+ /**
+ * Removes from the list of features any that start after, or end before, the
+ * given column position. This allows us to retain only those features
+ * adjacent to a gapped position that straddle the position.
+ *
+ * @param features
+ * @param column
+ * alignment column (1..)
+ * @param sequence
+ */
+ protected void removeAdjacentFeatures(List<SequenceFeature> features,
+ final int column, SequenceI sequence)
+ {
+ // TODO should this be an AlignViewController method (and reused by applet)?
+ ListIterator<SequenceFeature> it = features.listIterator();
+ while (it.hasNext())
+ {
+ SequenceFeature sf = it.next();
+ if (sequence.findIndex(sf.getBegin()) > column
+ || sequence.findIndex(sf.getEnd()) < column)
+ {
+ it.remove();
+ }
+ }
+ }
+
private Point lastp = null;
/*
/**
* Sets the status message in alignment panel, showing the sequence number
- * (index) and id, residue and residue position for the given sequence and
- * column position. Returns the calculated residue position in the sequence,
- * or -1 for a gapped column position.
+ * (index) and id, and residue and residue position if not at a gap, for the
+ * given sequence and column position. Returns the residue position returned
+ * by Sequence.findPosition. Note this may be for the nearest adjacent residue
+ * if at a gapped position.
*
* @param sequence
* aligned sequence object
* alignment column
* @param seq
* index of sequence in alignment
- * @return position of column in sequence or -1 if at a gap
+ * @return sequence position of residue at column, or adjacent residue if at a
+ * gap
*/
int setStatusMessage(SequenceI sequence, final int column, int seq)
{
.append(sequence.getName());
String residue = null;
+
/*
* Try to translate the display character to residue name (null for gap).
*/
final String displayChar = String.valueOf(sequence.getCharAt(column));
- if (av.getAlignment().isNucleotide())
+ boolean isGapped = Comparison.isGap(sequence.getCharAt(column));
+ int pos = sequence.findPosition(column);
+
+ if (!isGapped)
{
- residue = ResidueProperties.nucleotideName.get(displayChar);
- if (residue != null)
+ boolean nucleotide = av.getAlignment().isNucleotide();
+ if (nucleotide)
{
- text.append(" Nucleotide: ").append(residue);
+ residue = ResidueProperties.nucleotideName.get(displayChar);
}
- }
- else
- {
- residue = "X".equalsIgnoreCase(displayChar) ? "X" : ("*"
- .equals(displayChar) ? "STOP" : ResidueProperties.aa2Triplet
- .get(displayChar));
- if (residue != null)
+ else
{
- text.append(" Residue: ").append(residue);
+ residue = "X".equalsIgnoreCase(displayChar) ? "X" : ("*"
+ .equals(displayChar) ? "STOP"
+ : ResidueProperties.aa2Triplet.get(displayChar));
}
- }
+ text.append(" ").append(nucleotide ? "Nucleotide" : "Residue")
+ .append(": ").append(residue == null ? displayChar : residue);
- int pos = -1;
- if (residue != null)
- {
- pos = sequence.findPosition(column);
text.append(" (").append(Integer.toString(pos)).append(")");
}
ap.alignFrame.statusBar.setText(text.toString());
+
return pos;
}
av.setSelectionGroup(null);
}
+ int column = findColumn(evt);
+ boolean isGapped = Comparison.isGap(sequence.getCharAt(column));
+
+ /*
+ * find features at the position (if not gapped), or straddling
+ * the position (if at a gap)
+ */
List<SequenceFeature> features = seqCanvas.getFeatureRenderer()
.findFeaturesAtRes(sequence.getDatasetSequence(),
- sequence.findPosition(findColumn(evt)));
+ sequence.findPosition(column));
+ if (isGapped)
+ {
+ removeAdjacentFeatures(features, column, sequence);
+ }
if (!features.isEmpty())
{