From: tcofoegbu Date: Thu, 1 Oct 2015 13:50:52 +0000 (+0100) Subject: JAL-1912 refactor annotation refsequence assignemnt mechanism X-Git-Tag: Release_2_10_0~365^2~8 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=384e43c561fbc2446923dd2ed227e2931a8ac406;p=jalview.git JAL-1912 refactor annotation refsequence assignemnt mechanism --- diff --git a/src/jalview/io/JSONFile.java b/src/jalview/io/JSONFile.java index 3a08409..4e293db 100644 --- a/src/jalview/io/JSONFile.java +++ b/src/jalview/io/JSONFile.java @@ -211,12 +211,14 @@ public class JSONFile extends AlignFile implements ComplexAlignFile if (exportSettings.isExportAnnotations()) { jsonAlignmentPojo -.setAlignAnnotation(annotationToJsonPojo( - annotations, seqs)); + .setAlignAnnotation(annotationToJsonPojo(annotations)); } else { - if (globalColourScheme.equalsIgnoreCase("RNA Helices")) + // These color schemes require annotation, disable them if annotations + // are not exported + if (globalColourScheme.equalsIgnoreCase("RNA Helices") + || globalColourScheme.equalsIgnoreCase("T-COFFEE SCORES")) { jsonAlignmentPojo.setGlobalColorScheme("None"); } @@ -360,7 +362,7 @@ public class JSONFile extends AlignFile implements ComplexAlignFile } public static List annotationToJsonPojo( - Vector annotations, Vector seqs) + Vector annotations) { List jsonAnnotations = new ArrayList(); if (annotations == null) @@ -369,24 +371,25 @@ public class JSONFile extends AlignFile implements ComplexAlignFile } for (AlignmentAnnotation annot : annotations) { + AlignmentAnnotationPojo alignAnnotPojo = new AlignmentAnnotationPojo(); + alignAnnotPojo.setDescription(annot.description); + alignAnnotPojo.setLabel(annot.label); + alignAnnotPojo.setScore(annot.score); + alignAnnotPojo.setCalcId(annot.getCalcId()); + alignAnnotPojo.setGraphType(annot.graph); + AnnotationDisplaySettingPojo annotSetting = new AnnotationDisplaySettingPojo(); annotSetting.setBelowAlignment(annot.belowAlignment); annotSetting.setCentreColLabels(annot.centreColLabels); annotSetting.setScaleColLabel(annot.centreColLabels); annotSetting.setShowAllColLabels(annot.showAllColLabels); annotSetting.setVisible(annot.visible); - - - AlignmentAnnotationPojo alignAnnotPojo = new AlignmentAnnotationPojo(); - alignAnnotPojo.setScore(annot.score); - alignAnnotPojo.setCalcId(annot.getCalcId()); - alignAnnotPojo.setDescription(annot.description); - alignAnnotPojo.setLabel(annot.label); - alignAnnotPojo.setGraphType(annot.graph); alignAnnotPojo.setAnnotationSettings(annotSetting); - int seqHash = setAnnotationRefSeq(annot, seqs); - alignAnnotPojo.setSequenceRef(seqHash == 0 ? null : String - .valueOf(seqHash)); + SequenceI refSeq = annot.sequenceRef; + if (refSeq != null) + { + alignAnnotPojo.setSequenceRef(String.valueOf(refSeq.hashCode())); + } for (Annotation annotation : annot.annotations) { AnnotationPojo annotationPojo = new AnnotationPojo(); @@ -413,7 +416,7 @@ public class JSONFile extends AlignFile implements ComplexAlignFile } else { - alignAnnotPojo.getAnnotations().add(null); + alignAnnotPojo.getAnnotations().add(annotationPojo); } } } @@ -422,29 +425,6 @@ public class JSONFile extends AlignFile implements ComplexAlignFile return jsonAnnotations; } - private static int setAnnotationRefSeq(AlignmentAnnotation annot, - Vector seqs) - { - if (annot == null || seqs == null || seqs.size() == 0) - { - return 0; - } - for (SequenceI seq : seqs) - { - if (seq == null || seq.getAnnotation() == null) - { - continue; - } - for (AlignmentAnnotation seqAnnot : seq.getAnnotation()) - { - if (seqAnnot == annot) - { - return seq.hashCode(); - } - } - } - return 0; - } @SuppressWarnings("unchecked") public JSONFile parse(Reader jsonAlignmentString) { @@ -552,14 +532,10 @@ public class JSONFile extends AlignFile implements ComplexAlignFile { continue; } - JSONObject diplaySettings = (JSONObject) alAnnot - .get("annotationSettings"); JSONArray annotJsonArray = (JSONArray) alAnnot.get("annotations"); Annotation[] annotations = new Annotation[annotJsonArray.size()]; int count = 0; - String calcId = alAnnot.get("calcId") == null ? "" : alAnnot.get( - "calcId").toString(); for (Iterator annotIter = annotJsonArray.iterator(); annotIter .hasNext();) { @@ -595,24 +571,39 @@ public class JSONFile extends AlignFile implements ComplexAlignFile alignAnnot.graph = (alAnnot.get("graphType") == null) ? 0 : Integer .valueOf(alAnnot.get("graphType") .toString()); - alignAnnot.scaleColLabel = (diplaySettings.get("scaleColLabel") == null) ? false - : Boolean.valueOf(diplaySettings.get("scaleColLabel") - .toString()); - alignAnnot.showAllColLabels = (diplaySettings - .get("showAllColLabels") == null) ? true : Boolean - .valueOf(diplaySettings.get("showAllColLabels").toString()); - alignAnnot.centreColLabels = (diplaySettings.get("centreColLabels") == null) ? true - : Boolean.valueOf(diplaySettings.get("centreColLabels") - .toString()); - alignAnnot.belowAlignment = (diplaySettings.get("belowAlignment") == null) ? false - : Boolean.valueOf(diplaySettings.get("belowAlignment") - .toString()); - alignAnnot.visible = (diplaySettings.get("visible") == null) ? true - : Boolean.valueOf(diplaySettings.get("visible").toString()); + JSONObject diplaySettings = (JSONObject) alAnnot + .get("annotationSettings"); + if (diplaySettings != null) + { + + alignAnnot.scaleColLabel = (diplaySettings.get("scaleColLabel") == null) ? false + : Boolean.valueOf(diplaySettings.get("scaleColLabel") + .toString()); + alignAnnot.showAllColLabels = (diplaySettings + .get("showAllColLabels") == null) ? true : Boolean + .valueOf(diplaySettings.get("showAllColLabels") + .toString()); + alignAnnot.centreColLabels = (diplaySettings + .get("centreColLabels") == null) ? true + : Boolean.valueOf(diplaySettings.get("centreColLabels") + .toString()); + alignAnnot.belowAlignment = (diplaySettings.get("belowAlignment") == null) ? false + : Boolean.valueOf(diplaySettings.get("belowAlignment") + .toString()); + alignAnnot.visible = (diplaySettings.get("visible") == null) ? true + : Boolean.valueOf(diplaySettings.get("visible") + .toString()); - alignAnnot.score = alAnnot.get("score") == null ? null : Double - .valueOf(alAnnot.get("score").toString()); + } + if (alAnnot.get("score") != null) + { + alignAnnot.score = Double + .valueOf(alAnnot.get("score").toString()); + } + + String calcId = (alAnnot.get("calcId") == null) ? "" : alAnnot.get( + "calcId").toString(); alignAnnot.setCalcId(calcId); String seqHash = (alAnnot.get("sequenceRef") != null) ? alAnnot .get("sequenceRef").toString() : null; @@ -631,7 +622,6 @@ public class JSONFile extends AlignFile implements ComplexAlignFile } } this.annotations.add(alignAnnot); - alignAnnot.validateRangeAndDisplay(); } } catch (Exception e) { diff --git a/src/jalview/jbgui/GAlignFrame.java b/src/jalview/jbgui/GAlignFrame.java index e629932..73d34c2 100755 --- a/src/jalview/jbgui/GAlignFrame.java +++ b/src/jalview/jbgui/GAlignFrame.java @@ -3110,9 +3110,4 @@ public class GAlignFrame extends JInternalFrame protected void showComplement_actionPerformed(boolean state) { } - - public JRadioButtonMenuItem getTcoffeColour() - { - return tcoffeeColour; - } } diff --git a/test/jalview/io/JSONFileTest.java b/test/jalview/io/JSONFileTest.java index 4c2757f..d327134 100644 --- a/test/jalview/io/JSONFileTest.java +++ b/test/jalview/io/JSONFileTest.java @@ -324,9 +324,6 @@ public class JSONFileTest "Colourscheme is null, parsing failed!"); Assert.assertEquals(testJsonFile.getGlobalColourScheme(), "Zappo", "Zappo colour scheme expected!"); - // Assert.assertTrue( - // testJsonFile.getGlobalColourScheme() instanceof ZappoColourScheme, - // "Zappo colour scheme expected!"); } @Test(groups = { "Functional" })