*/
public class AnnotationSorter
{
-
/**
* enum for annotation sort options. The text description is used in the
* Preferences drop-down options. The enum name is saved in the preferences
// working map of sequence index in alignment
private final Map<SequenceI, Integer> sequenceIndices = new HashMap<>();
+ // if true, sort only repositions auto-calculated annotation (to top or
+ // bottom)
+ private final boolean autocalcOnly;
+
/**
* Constructor given an alignment and the location (top or bottom) of
* Consensus and similar.
*
* @param alignmentI
* @param showAutocalculatedAbove
+ * @param autoCalcOnly
*/
public AnnotationSorter(AlignmentI alignmentI,
- boolean showAutocalculatedAbove)
+ boolean showAutocalculatedAbove, boolean autoCalcOnly)
{
this.alignment = alignmentI;
this.showAutocalcAbove = showAutocalculatedAbove;
+ this.autocalcOnly = autoCalcOnly;
}
/**
{
return showAutocalcAbove ? 1 : -1;
}
+ if (autocalcOnly)
+ {
+ return 0; // don't reorder other annotations
+ }
int sequenceOrder = compareSequences(o1, o2);
return sequenceOrder == 0 ? compareLabels(o1, o2) : sequenceOrder;
}
{
return showAutocalcAbove ? 1 : -1;
}
+ if (autocalcOnly)
+ {
+ return 0; // don't reorder other annotations
+ }
int labelOrder = compareLabels(o1, o2);
return labelOrder == 0 ? compareSequences(o1, o2) : labelOrder;
}
* Sorts annotations according to currently selected preferences. Does nothing
* if currently set to 'Custom' (manual) ordering, so as not to trash user
* customised annotation ordering.
+ *
+ * @param autoCalcOnly
+ * if true, only automatically calculated annotations are reordered
*/
- void sortAnnotations();
+ void sortAnnotations(boolean autoCalcOnly);
}
*/
package jalview.appletgui;
-import jalview.analysis.AnnotationSorter;
import jalview.api.AlignViewportI;
import jalview.api.AlignmentViewPanel;
import jalview.bin.JalviewLite;
public void paintAlignment(boolean updateOverview,
boolean updateStructures)
{
- final AnnotationSorter sorter = new AnnotationSorter(getAlignment(),
- av.isShowAutocalculatedAbove());
- sorter.sort(getAlignment().getAlignmentAnnotation(),
- av.getSortAnnotationsBy());
repaint();
if (updateStructures)
}
@Override
- public void sortAnnotations()
+ public void sortAnnotations(boolean autocalcOnly)
{
}
}
});
- alignPanel.sortAnnotations();
+ alignPanel.sortAnnotations(false);
}
/**
}
if (isAnnotation)
{
- alignPanel.sortAnnotations();
+ alignPanel.sortAnnotations(false);
alignPanel.adjustAnnotationHeight();
viewport.updateSequenceIdColours();
buildSortByAnnotationScoresMenu();
* Sorts annotations and repaints the alignment
*/
@Override
- public void sortAnnotations()
+ public void sortAnnotations(boolean autoCalcOnly)
{
- alignPanel.sortAnnotations();
+ alignPanel.sortAnnotations(autoCalcOnly);
alignPanel.paintAlignment(false, false);
}
* if currently set to 'Custom' (manual) ordering.
*/
@Override
- public void sortAnnotations()
+ public void sortAnnotations(boolean autoCalcOnly)
{
SequenceAnnotationOrder sortBy = av.getSortAnnotationsBy();
if (sortBy != SequenceAnnotationOrder.CUSTOM)
{
final AnnotationSorter sorter = new AnnotationSorter(getAlignment(),
- av.isShowAutocalculatedAbove());
+ av.isShowAutocalculatedAbove(), autoCalcOnly);
sorter.sort(getAlignment().getAlignmentAnnotation(), sortBy);
}
}
hideAllAnnotations_actionPerformed(true, false);
}
});
- SequenceAnnotationOrder sortAnnotationsBy = SequenceAnnotationOrder
- .valueOf(Cache.getDefault(Preferences.SORT_ANNOTATIONS,
- SequenceAnnotationOrder.NONE.name()));
sortAnnBySequence = new JCheckBoxMenuItem(
MessageManager.getString("label.sort_annotations_by_sequence"));
sortAnnByLabel = new JCheckBoxMenuItem(
public void actionPerformed(ActionEvent e)
{
setAnnotationSortOrder(SequenceAnnotationOrder.SEQUENCE_AND_LABEL);
- sortAnnotations();
+ sortAnnotations(false);
}
});
sortAnnByLabel.addActionListener(new ActionListener()
public void actionPerformed(ActionEvent e)
{
setAnnotationSortOrder(SequenceAnnotationOrder.LABEL_AND_SEQUENCE);
- sortAnnotations();
+ sortAnnotations(false);
}
});
colourTextMenuItem = new JCheckBoxMenuItem(
{
if (setShowAutoCalculatedAbove(showAutoFirst.isSelected()))
{
- sortAnnotations();
+ sortAnnotations(true);
}
}
});
{
if (setShowAutoCalculatedAbove(!showAutoLast.isSelected()))
{
- sortAnnotations();
+ sortAnnotations(true);
}
}
});
}
/**
- * Action on clicking sort annotations by type.
+ * Action on clicking sort annotations by type, or change position of
+ * autocalculated annotation
*
- * @param sortOrder
+ * @param autoCalcOnly
*/
- protected void sortAnnotations()
+ protected void sortAnnotations(boolean autoCalcOnly)
{
}
{
af = loadViewport(file, jseqs, hiddenSeqs, al, jalviewModel, view,
uniqueSeqSetId, viewId, autoAlan);
+ // TODO resort annotations here to their order in the project?
av = af.getViewport();
ap = af.alignPanel;
}
// recompute any autoannotation
af.alignPanel.updateAnnotation(false, true);
reorderAutoannotation(af, al, autoAlan);
- af.sortAnnotations();
+ af.sortAnnotations(false);
af.alignPanel.alignmentChanged();
}
else
jalview.bin.Cache.log.debug("Updating result annotation from Job "
+ rslt + " at " + service.getUri());
updateResultAnnotation(true);
- ap.sortAnnotations();
+ ap.sortAnnotations(false);
ap.adjustAnnotationHeight();
}
}
*/
protected AlignmentAnnotation[] buildAnnotations(int numAnns)
{
- List<AlignmentAnnotation> annlist = new ArrayList<AlignmentAnnotation>();
+ List<AlignmentAnnotation> annlist = new ArrayList<>();
for (int i = 0; i < numAnns; i++)
{
AlignmentAnnotation ann = new AlignmentAnnotation(SS + i, "", 0);
* </ul>
*/
@Test(groups = { "Functional" })
- public void testSortBySequenceAndType_autocalcLast()
+ public void testSortBySequenceAndLabel_autocalcLast()
{
// @formatter:off
anns[0].sequenceRef = al.getSequenceAt(1); anns[0].label = "label0";
anns[6].sequenceRef = al.getSequenceAt(3); anns[6].label = "IRP";
// @formatter:on
- AnnotationSorter testee = new AnnotationSorter(al, false);
+ AnnotationSorter testee = new AnnotationSorter(al, false, false);
testee.sort(anns, SequenceAnnotationOrder.SEQUENCE_AND_LABEL);
assertEquals("label5", anns[0].label); // for sequence 0
assertEquals("label0", anns[1].label); // for sequence 1
* Variant with autocalculated annotations sorting to front
*/
@Test(groups = { "Functional" })
- public void testSortBySequenceAndType_autocalcFirst()
+ public void testSortBySequenceAndLabel_autocalcFirst()
{
// @formatter:off
anns[0].sequenceRef = al.getSequenceAt(1); anns[0].label = "label0";
anns[6].sequenceRef = al.getSequenceAt(3); anns[6].label = "IRP";
// @formatter:on
- AnnotationSorter testee = new AnnotationSorter(al, true);
+ AnnotationSorter testee = new AnnotationSorter(al, true, false);
testee.sort(anns, SequenceAnnotationOrder.SEQUENCE_AND_LABEL);
assertEquals("Quality", anns[0].label); // autocalc annotations
assertEquals("Consensus", anns[1].label); // retain ordering
* </ul>
*/
@Test(groups = { "Functional" })
- public void testSortByTypeAndSequence_autocalcLast()
+ public void testSortByLabelAndSequence_autocalcLast()
{
// @formatter:off
anns[0].sequenceRef = al.getSequenceAt(1); anns[0].label = "label0";
anns[6].sequenceRef = al.getSequenceAt(2); anns[6].label = "Structure";
// @formatter:on
- AnnotationSorter testee = new AnnotationSorter(al, false);
+ AnnotationSorter testee = new AnnotationSorter(al, false, false);
testee.sort(anns, SequenceAnnotationOrder.LABEL_AND_SEQUENCE);
assertEquals("IRON", anns[0].label); // IRON / sequence 0
assertEquals("iron", anns[1].label); // iron / sequence 3
* Variant of test with autocalculated annotations sorted to front
*/
@Test(groups = { "Functional" })
- public void testSortByTypeAndSequence_autocalcFirst()
+ public void testSortByLabelAndSequence_autocalcFirst()
{
// @formatter:off
anns[0].sequenceRef = al.getSequenceAt(1); anns[0].label = "label0";
anns[6].sequenceRef = al.getSequenceAt(2); anns[6].label = "Structure";
// @formatter:on
- AnnotationSorter testee = new AnnotationSorter(al, true);
+ AnnotationSorter testee = new AnnotationSorter(al, true, false);
testee.sort(anns, SequenceAnnotationOrder.LABEL_AND_SEQUENCE);
assertEquals("Quality", anns[0].label); // autocalc annotations
assertEquals("Consensus", anns[1].label); // retain ordering
anns[6].sequenceRef = al.getSequenceAt(2); anns[6].label = "Structure";
// @formatter:on
- AnnotationSorter testee = new AnnotationSorter(al, true);
+ AnnotationSorter testee = new AnnotationSorter(al, true, false);
testee.sort(anns, SequenceAnnotationOrder.NONE);
assertEquals("Quality", anns[0].label); // autocalc annotations
assertEquals("Consensus", anns[1].label); // retain ordering
annotations[i].label = "label" + i;
}
long startTime = System.currentTimeMillis();
- AnnotationSorter testee = new AnnotationSorter(alignment, false);
+ AnnotationSorter testee = new AnnotationSorter(alignment, false, false);
testee.sort(annotations, SequenceAnnotationOrder.LABEL_AND_SEQUENCE);
long endTime = System.currentTimeMillis();
final long elapsed = endTime - startTime;
annotations[i].label = "label" + i;
}
long startTime = System.currentTimeMillis();
- AnnotationSorter testee = new AnnotationSorter(alignment, false);
+ AnnotationSorter testee = new AnnotationSorter(alignment, false, false);
testee.sort(annotations, SequenceAnnotationOrder.SEQUENCE_AND_LABEL);
long endTime = System.currentTimeMillis();
final long elapsed = endTime - startTime;
annotations[i].label = labels[r.nextInt(labels.length)];
}
long startTime = System.currentTimeMillis();
- AnnotationSorter testee = new AnnotationSorter(alignment, false);
+ AnnotationSorter testee = new AnnotationSorter(alignment, false, false);
testee.sort(annotations, SequenceAnnotationOrder.LABEL_AND_SEQUENCE);
long endTime = System.currentTimeMillis();
long elapsed = endTime - startTime;