From: gmungoc Date: Mon, 7 Sep 2015 13:32:04 +0000 (+0100) Subject: JAL-1152 check 'autocalculated' not 'null sequenceRef'; sort by sequence X-Git-Tag: Release_2_10_0~478 X-Git-Url: http://source.jalview.org/gitweb/?p=jalview.git;a=commitdiff_plain;h=6b106f39c410cbb2b1714b905948d68b91a341dd JAL-1152 check 'autocalculated' not 'null sequenceRef'; sort by sequence respects autocalc above/below --- diff --git a/src/jalview/analysis/AnnotationSorter.java b/src/jalview/analysis/AnnotationSorter.java index 81398eb..0873f89 100644 --- a/src/jalview/analysis/AnnotationSorter.java +++ b/src/jalview/analysis/AnnotationSorter.java @@ -109,17 +109,38 @@ public class AnnotationSorter return 1; } + // TODO how to treat sequence-related autocalculated annotation + boolean o1auto = o1.autoCalculated && o1.sequenceRef == null; + boolean o2auto = o2.autoCalculated && o2.sequenceRef == null; /* * Ignore label (keep existing ordering) for * Conservation/Quality/Consensus etc */ - if (o1.sequenceRef == null && o2.sequenceRef == null) + if (o1auto && o2auto) { return 0; } + + /* + * Sort autocalculated before or after sequence-related. + */ + if (o1auto) + { + return showAutocalcAbove ? -1 : 1; + } + if (o2auto) + { + return showAutocalcAbove ? 1 : -1; + } int sequenceOrder = compareSequences(o1, o2); return sequenceOrder == 0 ? compareLabels(o1, o2) : sequenceOrder; } + + @Override + public String toString() + { + return "Sort by sequence and label"; + } }; /** @@ -149,55 +170,75 @@ public class AnnotationSorter return 1; } + // TODO how to treat sequence-related autocalculated annotation + boolean o1auto = o1.autoCalculated && o1.sequenceRef == null; + boolean o2auto = o2.autoCalculated && o2.sequenceRef == null; /* * Ignore label (keep existing ordering) for * Conservation/Quality/Consensus etc */ - if (o1.sequenceRef == null && o2.sequenceRef == null) + if (o1auto && o2auto) { return 0; } /* - * Sort non-sequence-related before or after sequence-related. + * Sort autocalculated before or after sequence-related. */ - if (o1.sequenceRef == null) + if (o1auto) { return showAutocalcAbove ? -1 : 1; } - if (o2.sequenceRef == null) + if (o2auto) { return showAutocalcAbove ? 1 : -1; } int labelOrder = compareLabels(o1, o2); return labelOrder == 0 ? compareSequences(o1, o2) : labelOrder; } + + @Override + public String toString() + { + return "Sort by label and sequence"; + } }; /** - * noSort leaves sort order unchanged, within sequence- and - * non-sequence-related annotations, but may switch the ordering of these - * groups. Note this is guaranteed (at least in Java 7) as Arrays.sort() is - * guaranteed to be 'stable' (not change ordering of equal items). + * noSort leaves sort order unchanged, within sequence- and autocalculated + * annotations, but may switch the ordering of these groups. Note this is + * guaranteed (at least in Java 7) as Arrays.sort() is guaranteed to be + * 'stable' (not change ordering of equal items). */ private Comparator noSort = new Comparator() { @Override public int compare(AlignmentAnnotation o1, AlignmentAnnotation o2) { + // TODO how to treat sequence-related autocalculated annotation + boolean o1auto = o1.autoCalculated && o1.sequenceRef == null; + boolean o2auto = o2.autoCalculated && o2.sequenceRef == null; + // TODO skip this test to allow customised ordering of all annotations + // - needs a third option: place autocalculated first / last / none if (o1 != null && o2 != null) { - if (o1.sequenceRef == null && o2.sequenceRef != null) + if (o1auto && !o2auto) { return showAutocalcAbove ? -1 : 1; } - if (o1.sequenceRef != null && o2.sequenceRef == null) + if (!o1auto && o2auto) { return showAutocalcAbove ? 1 : -1; } } return 0; } + + @Override + public String toString() + { + return "No sort"; + } }; /** diff --git a/test/jalview/analysis/AnnotationSorterTest.java b/test/jalview/analysis/AnnotationSorterTest.java index 1731302..47271e5 100644 --- a/test/jalview/analysis/AnnotationSorterTest.java +++ b/test/jalview/analysis/AnnotationSorterTest.java @@ -91,8 +91,8 @@ public class AnnotationSorterTest anns[0].sequenceRef = al.getSequenceAt(1); anns[0].label = "label0"; anns[1].sequenceRef = al.getSequenceAt(3); anns[1].label = "structure"; anns[2].sequenceRef = al.getSequenceAt(3); anns[2].label = "iron"; - anns[3].sequenceRef = null; anns[3].label = "Quality"; - anns[4].sequenceRef = null; anns[4].label = "Consensus"; + anns[3].autoCalculated = true; anns[3].label = "Quality"; + anns[4].autoCalculated = true; anns[4].label = "Consensus"; anns[5].sequenceRef = al.getSequenceAt(0); anns[5].label = "label5"; anns[6].sequenceRef = al.getSequenceAt(3); anns[6].label = "IRP"; // @formatter:on @@ -104,7 +104,7 @@ public class AnnotationSorterTest assertEquals("iron", anns[2].label); // sequence 3 /iron assertEquals("IRP", anns[3].label); // sequence 3/IRP assertEquals("structure", anns[4].label); // sequence 3/structure - assertEquals("Quality", anns[5].label); // non-sequence annotations + assertEquals("Quality", anns[5].label); // autocalc annotations assertEquals("Consensus", anns[6].label); // retain ordering } @@ -118,15 +118,15 @@ public class AnnotationSorterTest anns[0].sequenceRef = al.getSequenceAt(1); anns[0].label = "label0"; anns[1].sequenceRef = al.getSequenceAt(3); anns[1].label = "structure"; anns[2].sequenceRef = al.getSequenceAt(3); anns[2].label = "iron"; - anns[3].sequenceRef = null; anns[3].label = "Quality"; - anns[4].sequenceRef = null; anns[4].label = "Consensus"; + anns[3].autoCalculated = true; anns[3].label = "Quality"; + anns[4].autoCalculated = true; anns[4].label = "Consensus"; anns[5].sequenceRef = al.getSequenceAt(0); anns[5].label = "label5"; anns[6].sequenceRef = al.getSequenceAt(3); anns[6].label = "IRP"; // @formatter:on AnnotationSorter testee = new AnnotationSorter(al, true); testee.sort(anns, SequenceAnnotationOrder.SEQUENCE_AND_LABEL); - assertEquals("Quality", anns[0].label); // non-sequence annotations + assertEquals("Quality", anns[0].label); // autocalc annotations assertEquals("Consensus", anns[1].label); // retain ordering assertEquals("label5", anns[2].label); // for sequence 0 assertEquals("label0", anns[3].label); // for sequence 1 @@ -154,8 +154,8 @@ public class AnnotationSorterTest anns[0].sequenceRef = al.getSequenceAt(1); anns[0].label = "label0"; anns[1].sequenceRef = al.getSequenceAt(3); anns[1].label = "structure"; anns[2].sequenceRef = al.getSequenceAt(3); anns[2].label = "iron"; - anns[3].sequenceRef = null; anns[3].label = "Quality"; - anns[4].sequenceRef = null; anns[4].label = "Consensus"; + anns[3].autoCalculated = true; anns[3].label = "Quality"; + anns[4].autoCalculated = true; anns[4].label = "Consensus"; anns[5].sequenceRef = al.getSequenceAt(0); anns[5].label = "IRON"; anns[6].sequenceRef = al.getSequenceAt(2); anns[6].label = "Structure"; // @formatter:on @@ -167,7 +167,7 @@ public class AnnotationSorterTest assertEquals("label0", anns[2].label); // label0 / sequence 1 assertEquals("Structure", anns[3].label); // Structure / sequence 2 assertEquals("structure", anns[4].label); // structure / sequence 3 - assertEquals("Quality", anns[5].label); // non-sequence annotations + assertEquals("Quality", anns[5].label); // autocalc annotations assertEquals("Consensus", anns[6].label); // retain ordering } @@ -181,15 +181,15 @@ public class AnnotationSorterTest anns[0].sequenceRef = al.getSequenceAt(1); anns[0].label = "label0"; anns[1].sequenceRef = al.getSequenceAt(3); anns[1].label = "structure"; anns[2].sequenceRef = al.getSequenceAt(3); anns[2].label = "iron"; - anns[3].sequenceRef = null; anns[3].label = "Quality"; - anns[4].sequenceRef = null; anns[4].label = "Consensus"; + anns[3].autoCalculated = true; anns[3].label = "Quality"; + anns[4].autoCalculated = true; anns[4].label = "Consensus"; anns[5].sequenceRef = al.getSequenceAt(0); anns[5].label = "IRON"; anns[6].sequenceRef = al.getSequenceAt(2); anns[6].label = "Structure"; // @formatter:on AnnotationSorter testee = new AnnotationSorter(al, true); testee.sort(anns, SequenceAnnotationOrder.LABEL_AND_SEQUENCE); - assertEquals("Quality", anns[0].label); // non-sequence annotations + assertEquals("Quality", anns[0].label); // autocalc annotations assertEquals("Consensus", anns[1].label); // retain ordering assertEquals("IRON", anns[2].label); // IRON / sequence 0 assertEquals("iron", anns[3].label); // iron / sequence 3 @@ -209,15 +209,15 @@ public class AnnotationSorterTest anns[0].sequenceRef = al.getSequenceAt(1); anns[0].label = "label0"; anns[1].sequenceRef = al.getSequenceAt(3); anns[1].label = "structure"; anns[2].sequenceRef = al.getSequenceAt(3); anns[2].label = "iron"; - anns[3].sequenceRef = null; anns[3].label = "Quality"; - anns[4].sequenceRef = null; anns[4].label = "Consensus"; + anns[3].autoCalculated = true; anns[3].label = "Quality"; + anns[4].autoCalculated = true; anns[4].label = "Consensus"; anns[5].sequenceRef = al.getSequenceAt(0); anns[5].label = "IRON"; anns[6].sequenceRef = al.getSequenceAt(2); anns[6].label = "Structure"; // @formatter:on AnnotationSorter testee = new AnnotationSorter(al, true); testee.sort(anns, SequenceAnnotationOrder.NONE); - assertEquals("Quality", anns[0].label); // non-sequence annotations + assertEquals("Quality", anns[0].label); // autocalc annotations assertEquals("Consensus", anns[1].label); // retain ordering assertEquals("label0", anns[2].label); assertEquals("structure", anns[3].label);