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);
}
@Override
public void mouseReleased(MouseEvent evt)
{
+ boolean didDrag = mouseDragging; // did we come here after a drag
mouseDragging = false;
mouseWheelPressed = false;
- ap.paintAlignment(true);
if (!editingSeqs)
{
- doMouseReleasedDefineMode(evt);
+ doMouseReleasedDefineMode(evt, didDrag);
return;
}
}
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. Contact features
+ * that 'straddle' the position are also removed, since they are not 'at' 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 (sf.isContactFeature()
+ || 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<String>();
- }
- 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));
}
}
}
}
}
- public void doMouseReleasedDefineMode(MouseEvent evt)
+ public void doMouseReleasedDefineMode(MouseEvent evt, boolean afterDrag)
{
if (stretchGroup == null)
{
// but defer colourscheme update until hidden sequences are passed in
boolean vischange = stretchGroup.recalcConservation(true);
// here we rely on stretchGroup == av.getSelection()
- needOverviewUpdate |= vischange && av.isSelectionDefinedGroup();
+ needOverviewUpdate |= vischange && av.isSelectionDefinedGroup()
+ && afterDrag;
if (stretchGroup.cs != null)
{
stretchGroup.cs.alignmentChanged(stretchGroup,
groups = Collections.synchronizedList(new ArrayList<SequenceGroup>());
hiddenSequences = new HiddenSequences(this);
hiddenCols = new HiddenColumns();
- codonFrameList = new ArrayList<AlignedCodonFrame>();
+ codonFrameList = new ArrayList<>();
nucleotide = Comparison.isNucleotide(seqs);
@Override
public SequenceGroup[] findAllGroups(SequenceI s)
{
- ArrayList<SequenceGroup> temp = new ArrayList<SequenceGroup>();
+ ArrayList<SequenceGroup> temp = new ArrayList<>();
synchronized (groups)
{
return;
}
}
- sg.setContext(this);
+ sg.setContext(this, true);
groups.add(sg);
}
}
}
for (SequenceGroup sg : groups)
{
- sg.setContext(null);
+ sg.setContext(null, false);
}
groups.clear();
}
{
removeAnnotationForGroup(g);
groups.remove(g);
- g.setContext(null);
+ g.setContext(null, false);
}
}
}
{
return;
}
- List<SequenceI> toProcess = new ArrayList<SequenceI>();
+ List<SequenceI> toProcess = new ArrayList<>();
toProcess.add(currentSeq);
while (toProcess.size() > 0)
{
return;
}
// try to avoid using SequenceI.equals at this stage, it will be expensive
- Set<SequenceI> seqs = new LinkedIdentityHashSet<SequenceI>();
+ Set<SequenceI> seqs = new LinkedIdentityHashSet<>();
for (int i = 0; i < getHeight(); i++)
{
{
return null;
}
- List<AlignedCodonFrame> cframes = new ArrayList<AlignedCodonFrame>();
+ List<AlignedCodonFrame> cframes = new ArrayList<>();
for (AlignedCodonFrame acf : getCodonFrames())
{
if (acf.involvesSequence(seq))
if (sqs != null)
{
// avoid self append deadlock by
- List<SequenceI> toappendsq = new ArrayList<SequenceI>();
+ List<SequenceI> toappendsq = new ArrayList<>();
synchronized (sqs)
{
for (SequenceI addedsq : sqs)
@Override
public Iterable<AlignmentAnnotation> findAnnotation(String calcId)
{
- List<AlignmentAnnotation> aa = new ArrayList<AlignmentAnnotation>();
+ List<AlignmentAnnotation> aa = new ArrayList<>();
AlignmentAnnotation[] alignmentAnnotation = getAlignmentAnnotation();
if (alignmentAnnotation != null)
{
public Iterable<AlignmentAnnotation> findAnnotations(SequenceI seq,
String calcId, String label)
{
- ArrayList<AlignmentAnnotation> aa = new ArrayList<AlignmentAnnotation>();
+ ArrayList<AlignmentAnnotation> aa = new ArrayList<>();
for (AlignmentAnnotation ann : getAlignmentAnnotation())
{
if ((calcId == null || (ann.getCalcId() != null && ann.getCalcId()
@Override
public Set<String> getSequenceNames()
{
- Set<String> names = new HashSet<String>();
+ Set<String> names = new HashSet<>();
for (SequenceI seq : getSequences())
{
names.add(seq.getName());
boolean colourText = false;
/**
+ * True if the group is defined as a group on the alignment, false if it is
+ * just a selection.
+ */
+ boolean isDefined = false;
+
+ /**
* after Olivier's non-conserved only character display
*/
boolean showNonconserved = false;
/**
* group members
*/
- private List<SequenceI> sequences = new ArrayList<SequenceI>();
+ private List<SequenceI> sequences = new ArrayList<>();
/**
* representative sequence for this group (if any)
*/
private boolean normaliseSequenceLogo;
- /**
- * @return the includeAllConsSymbols
+ /*
+ * visibility of rows or represented rows covered by group
*/
- public boolean isShowSequenceLogo()
- {
- return showSequenceLogo;
- }
+ private boolean hidereps = false;
+
+ /*
+ * visibility of columns intersecting this group
+ */
+ private boolean hidecols = false;
+
+ AlignmentAnnotation consensus = null;
+
+ AlignmentAnnotation conservation = null;
+
+ private boolean showConsensusHistogram;
+
+ private AnnotatedCollectionI context;
/**
* Creates a new SequenceGroup object.
this();
if (seqsel != null)
{
- sequences = new ArrayList<SequenceI>();
+ sequences = new ArrayList<>();
sequences.addAll(seqsel.sequences);
if (seqsel.groupName != null)
{
colourText = seqsel.colourText;
startRes = seqsel.startRes;
endRes = seqsel.endRes;
- cs = seqsel.cs;
+ cs = new ResidueShader(seqsel.getColourScheme());
if (seqsel.description != null)
{
description = new String(seqsel.description);
}
hidecols = seqsel.hidecols;
hidereps = seqsel.hidereps;
+ showNonconserved = seqsel.showNonconserved;
+ showSequenceLogo = seqsel.showSequenceLogo;
+ normaliseSequenceLogo = seqsel.normaliseSequenceLogo;
+ showConsensusHistogram = seqsel.showConsensusHistogram;
idColour = seqsel.idColour;
outlineColour = seqsel.outlineColour;
seqrep = seqsel.seqrep;
}
}
+ public boolean isShowSequenceLogo()
+ {
+ return showSequenceLogo;
+ }
+
public SequenceI[] getSelectionAsNewSequences(AlignmentI align)
{
int iSize = sequences.size();
}
else
{
- List<SequenceI> allSequences = new ArrayList<SequenceI>();
+ List<SequenceI> allSequences = new ArrayList<>();
for (SequenceI seq : sequences)
{
allSequences.add(seq);
}
/**
- * visibility of rows or represented rows covered by group
- */
- private boolean hidereps = false;
-
- /**
* set visibility of sequences covered by (if no sequence representative is
* defined) or represented by this group.
*
}
/**
- * visibility of columns intersecting this group
- */
- private boolean hidecols = false;
-
- /**
* set intended visibility of columns covered by this group
*
* @param visibility
{
SequenceGroup sgroup = new SequenceGroup(this);
SequenceI[] insect = getSequencesInOrder(alignment);
- sgroup.sequences = new ArrayList<SequenceI>();
+ sgroup.sequences = new ArrayList<>();
for (int s = 0; insect != null && s < insect.length; s++)
{
if (map == null || map.containsKey(insect[s]))
this.showNonconserved = displayNonconserved;
}
- AlignmentAnnotation consensus = null, conservation = null;
-
- /**
- * flag indicating if consensus histogram should be rendered
- */
- private boolean showConsensusHistogram;
-
/**
* set this alignmentAnnotation object as the one used to render consensus
* annotation
{
// TODO add in other methods like 'getAlignmentAnnotation(String label),
// etc'
- ArrayList<AlignmentAnnotation> annot = new ArrayList<AlignmentAnnotation>();
+ ArrayList<AlignmentAnnotation> annot = new ArrayList<>();
synchronized (sequences)
{
for (SequenceI seq : sequences)
@Override
public Iterable<AlignmentAnnotation> findAnnotation(String calcId)
{
- List<AlignmentAnnotation> aa = new ArrayList<AlignmentAnnotation>();
+ List<AlignmentAnnotation> aa = new ArrayList<>();
if (calcId == null)
{
return aa;
public Iterable<AlignmentAnnotation> findAnnotations(SequenceI seq,
String calcId, String label)
{
- ArrayList<AlignmentAnnotation> aa = new ArrayList<AlignmentAnnotation>();
+ ArrayList<AlignmentAnnotation> aa = new ArrayList<>();
for (AlignmentAnnotation ann : getAlignmentAnnotation())
{
if ((calcId == null || (ann.getCalcId() != null && ann.getCalcId()
}
}
- private AnnotatedCollectionI context;
+ /**
+ * Sets the alignment or group context for this group, and whether it is
+ * defined as a group
+ *
+ * @param ctx
+ * the context for the group
+ * @param defined
+ * whether the group is defined on the alignment or is just a
+ * selection
+ * @throws IllegalArgumentException
+ * if setting the context would result in a circular reference chain
+ */
+ public void setContext(AnnotatedCollectionI ctx, boolean defined)
+ {
+ setContext(ctx);
+ this.isDefined = defined;
+ }
/**
* Sets the alignment or group context for this group
*
* @param ctx
+ * the context for the group
* @throws IllegalArgumentException
* if setting the context would result in a circular reference chain
*/
return context;
}
+ public boolean isDefined()
+ {
+ return isDefined;
+ }
+
public void setColourScheme(ColourSchemeI scheme)
{
if (cs == null)
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
+import java.util.ListIterator;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
@Override
public void mouseReleased(MouseEvent evt)
{
+ boolean didDrag = mouseDragging; // did we come here after a drag
mouseDragging = false;
mouseWheelPressed = false;
if (!editingSeqs)
{
- doMouseReleasedDefineMode(evt);
+ doMouseReleasedDefineMode(evt, didDrag);
return;
}
/*
* 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. Contact features
+ * that 'straddle' the position are also removed, since they are not 'at' 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 (sf.isContactFeature()
+ || 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())
{
List<SequenceFeature> allFeatures = ap.getFeatureRenderer()
.findFeaturesAtRes(sequence.getDatasetSequence(),
sequence.findPosition(res));
- List<String> links = new ArrayList<String>();
+ List<String> links = new ArrayList<>();
for (SequenceFeature sf : allFeatures)
{
if (sf.links != null)
}
/**
- * DOCUMENT ME!
+ * Update the display after mouse up on a selection or group
*
* @param evt
- * DOCUMENT ME!
+ * mouse released event details
+ * @param afterDrag
+ * true if this event is happening after a mouse drag (rather than a
+ * mouse down)
*/
- public void doMouseReleasedDefineMode(MouseEvent evt)
+ public void doMouseReleasedDefineMode(MouseEvent evt, boolean afterDrag)
{
if (stretchGroup == null)
{
// always do this - annotation has own state
// but defer colourscheme update until hidden sequences are passed in
boolean vischange = stretchGroup.recalcConservation(true);
- needOverviewUpdate |= vischange && av.isSelectionDefinedGroup();
+ needOverviewUpdate |= vischange && av.isSelectionDefinedGroup()
+ && afterDrag;
if (stretchGroup.cs != null)
{
stretchGroup.cs.alignmentChanged(stretchGroup,
ap.getCalculationDialog().validateCalcTypes();
}
- // process further ?
- if (!av.followSelection)
- {
- return;
- }
+ return;
+ }
+
+ // process further ?
+ if (!av.followSelection)
+ {
+ return;
}
/*
return null;
}
- public static DataSourceType checkProtocol(String file)
+ /**
+ * Determines the protocol (i.e DataSourceType.{FILE|PASTE|URL}) for the input
+ * data
+ *
+ * @param data
+ * @return the protocol for the input data
+ */
+ public static DataSourceType checkProtocol(String data)
{
- DataSourceType protocol = DataSourceType.FILE;
- String ft = file.toLowerCase().trim();
+ DataSourceType protocol = DataSourceType.PASTE;
+ String ft = data.toLowerCase().trim();
if (ft.indexOf("http:") == 0 || ft.indexOf("https:") == 0
|| ft.indexOf("file:") == 0)
{
protocol = DataSourceType.URL;
}
+ else if (new File(data).exists())
+ {
+ protocol = DataSourceType.FILE;
+ }
return protocol;
}
FeaturesDisplayedI featuresDisplayed = null;
- protected Deque<CommandI> historyList = new ArrayDeque<CommandI>();
+ protected Deque<CommandI> historyList = new ArrayDeque<>();
- protected Deque<CommandI> redoList = new ArrayDeque<CommandI>();
+ protected Deque<CommandI> redoList = new ArrayDeque<>();
/**
* alignment displayed in the viewport. Please use get/setter
public void setHiddenColumns(HiddenColumns hidden)
{
this.alignment.setHiddenColumns(hidden);
- // this.colSel = colsel;
}
@Override
protected boolean showOccupancy = true;
- private Map<SequenceI, Color> sequenceColours = new HashMap<SequenceI, Color>();
+ private Map<SequenceI, Color> sequenceColours = new HashMap<>();
protected SequenceAnnotationOrder sortAnnotationsBy = null;
if (hiddenRepSequences == null)
{
- hiddenRepSequences = new Hashtable<SequenceI, SequenceCollectionI>();
+ hiddenRepSequences = new Hashtable<>();
}
hiddenRepSequences.put(repSequence, sg);
@Override
public List<int[]> getVisibleRegionBoundaries(int min, int max)
{
- ArrayList<int[]> regions = new ArrayList<int[]>();
+ ArrayList<int[]> regions = new ArrayList<>();
int start = min;
int end = max;
public List<AlignmentAnnotation> getVisibleAlignmentAnnotation(
boolean selectedOnly)
{
- ArrayList<AlignmentAnnotation> ala = new ArrayList<AlignmentAnnotation>();
+ ArrayList<AlignmentAnnotation> ala = new ArrayList<>();
AlignmentAnnotation[] aa;
if ((aa = alignment.getAlignmentAnnotation()) != null)
{
// intersect alignment annotation with alignment groups
AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
- List<SequenceGroup> oldrfs = new ArrayList<SequenceGroup>();
+ List<SequenceGroup> oldrfs = new ArrayList<>();
if (aan != null)
{
for (int an = 0; an < aan.length; an++)
selectionIsDefinedGroup = gps.contains(selectionGroup);
}
}
- return selectionGroup.getContext() == alignment
- || selectionIsDefinedGroup;
+ return selectionGroup.isDefined() || selectionIsDefinedGroup;
}
/**
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertNotSame;
import static org.testng.Assert.assertNull;
import static org.testng.Assert.assertSame;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.fail;
import jalview.schemes.NucleotideColourScheme;
+import jalview.schemes.PIDColourScheme;
+
+import java.awt.Color;
import junit.extensions.PA;
PA.setValue(sg2, "context", sg2);
try
{
- sg3.setContext(sg2); // circular reference in sg2
+ sg3.setContext(sg2, false); // circular reference in sg2
fail("Expected exception");
} catch (IllegalArgumentException e)
{
// expected
assertNull(sg3.getContext());
}
+
+ // test isDefined setting behaviour
+ sg2 = new SequenceGroup();
+ sg1.setContext(null, false);
+ assertFalse(sg1.isDefined());
+
+ sg1.setContext(sg2, false);
+ assertFalse(sg1.isDefined());
+
+ sg1.setContext(sg2, true);
+ assertTrue(sg1.isDefined());
+
+ // setContext without defined parameter does not change isDefined
+ sg1.setContext(null);
+ assertTrue(sg1.isDefined());
+
+ sg1.setContext(null, false);
+ sg1.setContext(sg2);
+ assertFalse(sg1.isDefined());
}
@Test(groups = { "Functional" })
assertTrue(sg2.contains(seq2, 8));
sg2.deleteSequence(seq2, false);
assertFalse(sg2.contains(seq2));
+ }
+
+ @Test(groups = { "Functional" })
+ public void testCopyConstructor()
+ {
+ SequenceI seq = new Sequence("seq", "ABC");
+ SequenceGroup sg = new SequenceGroup();
+ sg.addSequence(seq, false);
+ sg.setName("g1");
+ sg.setDescription("desc");
+ sg.setColourScheme(new PIDColourScheme());
+ sg.setDisplayBoxes(false);
+ sg.setDisplayText(false);
+ sg.setColourText(true);
+ sg.isDefined = true;
+ sg.setShowNonconserved(true);
+ sg.setOutlineColour(Color.red);
+ sg.setIdColour(Color.blue);
+ sg.thresholdTextColour = 1;
+ sg.textColour = Color.orange;
+ sg.textColour2 = Color.yellow;
+ sg.setIgnoreGapsConsensus(false);
+ sg.setshowSequenceLogo(true);
+ sg.setNormaliseSequenceLogo(true);
+ sg.setHidereps(true);
+ sg.setHideCols(true);
+ sg.setShowConsensusHistogram(true);
+ sg.setContext(new SequenceGroup());
+
+ SequenceGroup sg2 = new SequenceGroup(sg);
+ assertEquals(sg2.getName(), sg.getName());
+ assertEquals(sg2.getDescription(), sg.getDescription());
+ assertNotSame(sg2.getGroupColourScheme(), sg.getGroupColourScheme());
+ assertSame(sg2.getColourScheme(), sg.getColourScheme());
+ assertEquals(sg2.getDisplayBoxes(), sg.getDisplayBoxes());
+ assertEquals(sg2.getDisplayText(), sg.getDisplayText());
+ assertEquals(sg2.getColourText(), sg.getColourText());
+ assertEquals(sg2.getShowNonconserved(), sg.getShowNonconserved());
+ assertEquals(sg2.getOutlineColour(), sg.getOutlineColour());
+ assertEquals(sg2.getIdColour(), sg.getIdColour());
+ assertEquals(sg2.thresholdTextColour, sg.thresholdTextColour);
+ assertEquals(sg2.textColour, sg.textColour);
+ assertEquals(sg2.textColour2, sg.textColour2);
+ assertEquals(sg2.getIgnoreGapsConsensus(), sg.getIgnoreGapsConsensus());
+ assertEquals(sg2.isShowSequenceLogo(), sg.isShowSequenceLogo());
+ assertEquals(sg2.isNormaliseSequenceLogo(),
+ sg.isNormaliseSequenceLogo());
+ assertEquals(sg2.isHidereps(), sg.isHidereps());
+ assertEquals(sg2.isHideCols(), sg.isHideCols());
+ assertEquals(sg2.isShowConsensusHistogram(),
+ sg.isShowConsensusHistogram());
+
+ /*
+ * copy of sequences
+ */
+ assertNotSame(sg2.getSequences(), sg.getSequences());
+ assertEquals(sg2.getSequences(), sg.getSequences());
+ /*
+ * isDefined should only be set true when a new group is added to
+ * an alignment, not in the copy constructor
+ */
+ assertFalse(sg2.isDefined());
+
+ /*
+ * context should be set explicitly, not by copy
+ */
+ assertNull(sg2.getContext());
}
}
* local structure files should yield a false ID based on the filename
*/
assertNotNull(structureData.getId());
- assertEquals(structureData.getId(), "localstruct.pdb");
+ assertEquals(structureData.getId(), "localstruct");
assertNotNull(structureData.getSeqs());
/*
* the ID is also the group for features derived from structure data
assertNotNull(structureData.getSeqs().get(0).getSequenceFeatures()[0].featureGroup);
assertEquals(
structureData.getSeqs().get(0).getSequenceFeatures()[0].featureGroup,
- "localstruct.pdb");
+ "localstruct");
}
}
import jalview.gui.StructureViewer.ViewerType;
import jalview.io.DataSourceType;
-import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
}
}
- @Test(groups = { "Functional", "Network" })
- public void testStructureLoadingViaURL()
- {
- Cache.setProperty(Preferences.STRUCTURE_DISPLAY, ViewerType.JMOL.name());
- String inFile = "http://www.jalview.org/builds/develop/examples/3W5V.pdb";
- AlignFrame af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(
- inFile, DataSourceType.URL);
- assertTrue("Didn't read input file " + inFile, af != null);
- for (SequenceI sq : af.getViewport().getAlignment().getSequences())
- {
- SequenceI dsq = sq.getDatasetSequence();
- while (dsq.getDatasetSequence() != null)
- {
- dsq = dsq.getDatasetSequence();
- }
- if (dsq.getAllPDBEntries() != null
- && dsq.getAllPDBEntries().size() > 0)
- {
- for (int q = 0; q < dsq.getAllPDBEntries().size(); q++)
- {
- final StructureViewer structureViewer = new StructureViewer(af
- .getViewport().getStructureSelectionManager());
- structureViewer.setViewerType(ViewerType.JMOL);
- JalviewStructureDisplayI jmolViewer = structureViewer
- .viewStructures(dsq.getAllPDBEntries().elementAt(q),
- new SequenceI[] { sq }, af.getCurrentView()
- .getAlignPanel());
- /*
- * Wait for viewer load thread to complete
- */
- try
- {
- while (!jmolViewer.getBinding().isFinishedInit())
- {
- Thread.sleep(500);
- }
- } catch (InterruptedException e)
- {
- }
- // System.out.println(">>>>>>>>>>>>>>>>> "
- // + jmolViewer.getBinding().getPdbFile());
- String[] expectedModelFiles = new String[] { "http://www.jalview.org/builds/develop/examples/3W5V.pdb" };
- String[] actualModelFiles = jmolViewer.getBinding().getStructureFiles();
- Assert.assertEqualsNoOrder(actualModelFiles, expectedModelFiles);
- jmolViewer.closeViewer(true);
- // todo: break here means only once through this loop?
- break;
- }
- break;
- }
- }
- }
+
}
acf2.addMap(s1, s1, new MapList(new int[] { 1, 4 }, new int[] { 4, 1 },
1, 1));
- List<AlignedCodonFrame> mappings = new ArrayList<AlignedCodonFrame>();
+ List<AlignedCodonFrame> mappings = new ArrayList<>();
mappings.add(acf1);
mappings.add(acf2);
af1.getViewport().getAlignment().setCodonFrames(mappings);
acf3.addMap(cs2, cs2, new MapList(new int[] { 1, 12 }, new int[] { 1,
12 }, 1, 1));
- List<AlignedCodonFrame> mappings1 = new ArrayList<AlignedCodonFrame>();
+ List<AlignedCodonFrame> mappings1 = new ArrayList<>();
mappings1.add(acf1);
af1.getViewport().getAlignment().setCodonFrames(mappings1);
- List<AlignedCodonFrame> mappings2 = new ArrayList<AlignedCodonFrame>();
+ List<AlignedCodonFrame> mappings2 = new ArrayList<>();
mappings2.add(acf2);
mappings2.add(acf3);
af2.getViewport().getAlignment().setCodonFrames(mappings2);
acf3.addMap(cs2, cs2, new MapList(new int[] { 1, 12 }, new int[] { 1,
12 }, 1, 1));
- List<AlignedCodonFrame> mappings1 = new ArrayList<AlignedCodonFrame>();
+ List<AlignedCodonFrame> mappings1 = new ArrayList<>();
mappings1.add(acf1);
mappings1.add(acf2);
af1.getViewport().getAlignment().setCodonFrames(mappings1);
- List<AlignedCodonFrame> mappings2 = new ArrayList<AlignedCodonFrame>();
+ List<AlignedCodonFrame> mappings2 = new ArrayList<>();
mappings2.add(acf2);
mappings2.add(acf3);
af2.getViewport().getAlignment().setCodonFrames(mappings2);
/**
* Verify that setting the selection group has the side-effect of setting the
- * context on the group, unless it already has one
+ * context on the group, unless it already has one, but does not change
+ * whether the group is defined or not.
*/
@Test(groups = { "Functional" })
public void testSetSelectionGroup()
AlignViewport av = af.getViewport();
SequenceGroup sg1 = new SequenceGroup();
SequenceGroup sg2 = new SequenceGroup();
+ SequenceGroup sg3 = new SequenceGroup();
av.setSelectionGroup(sg1);
assertSame(sg1.getContext(), av.getAlignment()); // context set
+ assertFalse(sg1.isDefined()); // group not defined
- sg2.setContext(sg1);
+ sg2.setContext(sg1, false);
av.setSelectionGroup(sg2);
+ assertFalse(sg2.isDefined()); // unchanged
assertSame(sg2.getContext(), sg1); // unchanged
+
+ // create a defined group
+ sg3.setContext(av.getAlignment(), true);
+ av.setSelectionGroup(sg3);
+ assertTrue(sg3.isDefined()); // unchanged
}
/**
* Verify that setting/clearing SHOW_OCCUPANCY preference adds or omits occupancy row from viewport
StructureChooser sc = new StructureChooser(selectedSeqs, seq, null);
sc.populateFilterComboBox(false, false);
int optionsSize = sc.getCmbFilterOption().getItemCount();
- assertEquals(3, optionsSize); // if structures are not discovered then don't
+ assertEquals(2, optionsSize); // if structures are not discovered then don't
// populate filter options
sc.populateFilterComboBox(true, false);
fileLoader.LoadFileWaitTillLoaded(urlFile, DataSourceType.URL,
FileFormat.PDB);
Assert.assertNotNull(fileLoader.file);
- // The FileLoader's file is expected to a temporary file different from the
- // original URL.
- Assert.assertNotEquals(urlFile, fileLoader.file);
- // Data source type expected to be updated from DataSourceType.URL to
- // DataSourceType.FILE
- Assert.assertEquals(DataSourceType.FILE, fileLoader.protocol);
+ // The FileLoader's file is expected to be same as the original URL.
+ Assert.assertEquals(urlFile, fileLoader.file);
+ // Data source type expected to be DataSourceType.URL
+ Assert.assertEquals(DataSourceType.URL, fileLoader.protocol);
}
}