X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FJalview2XML.java;h=d472ef81f7f6b4a2c44d68ea07c2e84aefda9a59;hb=62d2ca926e73609acc4c2a50676f2010c6e3e343;hp=68184e9d06bc2b1dfba3d66adc05db9d83992e79;hpb=e2e2b85d7a8e3d7ed6926ef1bf55eb2328e744d1;p=jalview.git diff --git a/src/jalview/gui/Jalview2XML.java b/src/jalview/gui/Jalview2XML.java index 68184e9..d472ef8 100644 --- a/src/jalview/gui/Jalview2XML.java +++ b/src/jalview/gui/Jalview2XML.java @@ -29,6 +29,7 @@ import jalview.datamodel.AlignedCodonFrame; import jalview.datamodel.Alignment; import jalview.datamodel.AlignmentAnnotation; import jalview.datamodel.AlignmentI; +import jalview.datamodel.GraphLine; import jalview.datamodel.PDBEntry; import jalview.datamodel.RnaViewerModel; import jalview.datamodel.SequenceGroup; @@ -77,7 +78,6 @@ import jalview.schemes.AnnotationColourGradient; import jalview.schemes.ColourSchemeI; import jalview.schemes.ColourSchemeProperty; import jalview.schemes.FeatureColour; -import jalview.schemes.ResidueColourScheme; import jalview.schemes.ResidueProperties; import jalview.schemes.UserColourScheme; import jalview.structure.StructureSelectionManager; @@ -87,6 +87,7 @@ import jalview.util.Platform; import jalview.util.StringUtils; import jalview.util.jarInputStreamProvider; import jalview.viewmodel.AlignmentViewport; +import jalview.viewmodel.ViewportRanges; import jalview.viewmodel.seqfeatures.FeatureRendererSettings; import jalview.viewmodel.seqfeatures.FeaturesDisplayed; import jalview.ws.jws2.Jws2Discoverer; @@ -179,13 +180,13 @@ public class Jalview2XML * Map of reconstructed AlignFrame objects that appear to have come from * SplitFrame objects (have a dna/protein complement view). */ - private Map splitFrameCandidates = new HashMap(); + private Map splitFrameCandidates = new HashMap<>(); /* * Map from displayed rna structure models to their saved session state jar * entry names */ - private Map rnaSessions = new HashMap(); + private Map rnaSessions = new HashMap<>(); /** * create/return unique hash string for sq @@ -246,19 +247,19 @@ public class Jalview2XML { if (seqsToIds == null) { - seqsToIds = new IdentityHashMap(); + seqsToIds = new IdentityHashMap<>(); } if (seqRefIds == null) { - seqRefIds = new HashMap(); + seqRefIds = new HashMap<>(); } if (incompleteSeqs == null) { - incompleteSeqs = new HashMap(); + incompleteSeqs = new HashMap<>(); } if (frefedSequence == null) { - frefedSequence = new ArrayList(); + frefedSequence = new ArrayList<>(); } } @@ -457,9 +458,9 @@ public class Jalview2XML * This maintains a map of viewports, the key being the seqSetId. Important to * set historyItem and redoList for multiple views */ - Map viewportsAdded = new HashMap(); + Map viewportsAdded = new HashMap<>(); - Map annotationIds = new HashMap(); + Map annotationIds = new HashMap<>(); String uniqueSetSuffix = ""; @@ -535,7 +536,7 @@ public class Jalview2XML */ private void saveAllFrames(List frames, JarOutputStream jout) { - Hashtable dsses = new Hashtable(); + Hashtable dsses = new Hashtable<>(); /* * ensure cached data is clear before starting @@ -550,8 +551,8 @@ public class Jalview2XML // NOTE UTF-8 MUST BE USED FOR WRITING UNICODE CHARS // ////////////////////////////////////////////////// - List shortNames = new ArrayList(); - List viewIds = new ArrayList(); + List shortNames = new ArrayList<>(); + List viewIds = new ArrayList<>(); // REVERSE ORDER for (int i = frames.size() - 1; i > -1; i--) @@ -661,7 +662,7 @@ public class Jalview2XML { FileOutputStream fos = new FileOutputStream(jarFile); JarOutputStream jout = new JarOutputStream(fos); - List frames = new ArrayList(); + List frames = new ArrayList<>(); // resolve splitframes if (af.getViewport().getCodingComplement() != null) @@ -747,14 +748,15 @@ public class Jalview2XML { if (viewIds == null) { - viewIds = new ArrayList(); + viewIds = new ArrayList<>(); } initSeqRefs(); - List userColours = new ArrayList(); + List userColours = new ArrayList<>(); AlignViewport av = ap.av; + ViewportRanges vpRanges = av.getRanges(); JalviewModel object = new JalviewModel(); object.setVamsasModel(new jalview.schemabinding.version2.VamsasModel()); @@ -805,9 +807,9 @@ public class Jalview2XML } JSeq jseq; - Set calcIdSet = new HashSet(); + Set calcIdSet = new HashSet<>(); // record the set of vamsas sequence XML POJO we create. - HashMap vamsasSetIds = new HashMap(); + HashMap vamsasSetIds = new HashMap<>(); // SAVE SEQUENCES for (final SequenceI jds : rjal.getSequences()) { @@ -984,7 +986,7 @@ public class Jalview2XML pdb.setFile(matchedFile); // entry.getFile()); if (pdbfiles == null) { - pdbfiles = new ArrayList(); + pdbfiles = new ArrayList<>(); } if (!pdbfiles.contains(pdbId)) @@ -1105,7 +1107,7 @@ public class Jalview2XML Tree tree = new Tree(); tree.setTitle(tp.getTitle()); tree.setCurrentTree((av.currentTree == tp.getTree())); - tree.setNewick(tp.getTree().toString()); + tree.setNewick(tp.getTree().print()); tree.setThreshold(tp.treeCanvas.threshold); tree.setFitToWindow(tp.fitToWindow.getState()); @@ -1133,7 +1135,7 @@ public class Jalview2XML /** * store forward refs from an annotationRow to any groups */ - IdentityHashMap groupRefs = new IdentityHashMap(); + IdentityHashMap groupRefs = new IdentityHashMap<>(); if (storeDS) { for (SequenceI sq : jal.getSequences()) @@ -1270,8 +1272,8 @@ public class Jalview2XML view.setWidth(size.width); view.setHeight(size.height); - view.setStartRes(av.startRes); - view.setStartSeq(av.startSeq); + view.setStartRes(vpRanges.getStartRes()); + view.setStartSeq(vpRanges.getStartSeq()); if (av.getGlobalColourScheme() instanceof jalview.schemes.UserColourScheme) { @@ -1347,7 +1349,7 @@ public class Jalview2XML .getFeatureRenderer().getRenderOrder() .toArray(new String[0]); - Vector settingsAdded = new Vector(); + Vector settingsAdded = new Vector<>(); if (renderOrder != null) { for (String featureType : renderOrder) @@ -1390,7 +1392,7 @@ public class Jalview2XML // is groups actually supposed to be a map here ? Iterator en = ap.getSeqPanel().seqCanvas .getFeatureRenderer().getFeatureGroups().iterator(); - Vector groupsAdded = new Vector(); + Vector groupsAdded = new Vector<>(); while (en.hasNext()) { String grp = en.next(); @@ -1411,18 +1413,18 @@ public class Jalview2XML if (av.hasHiddenColumns()) { - if (av.getColumnSelection() == null - || av.getColumnSelection().getHiddenColumns() == null) + jalview.datamodel.HiddenColumns hidden = av.getAlignment() + .getHiddenColumns(); + if (hidden == null) { warn("REPORT BUG: avoided null columnselection bug (DMAM reported). Please contact Jim about this."); } else { - for (int c = 0; c < av.getColumnSelection().getHiddenColumns() - .size(); c++) + ArrayList hiddenRegions = hidden + .getHiddenColumnsCopy(); + for (int[] region : hiddenRegions) { - int[] region = av.getColumnSelection().getHiddenColumns() - .get(c); HiddenColumns hc = new HiddenColumns(); hc.setStart(region[0]); hc.setEnd(region[1]); @@ -1711,6 +1713,15 @@ public class Jalview2XML return matchedFile; } + /** + * Populates the AnnotationColours xml for save. This captures the settings of + * the options in the 'Colour by Annotation' dialog. + * + * @param acg + * @param userColours + * @param jms + * @return + */ private AnnotationColours constructAnnotationColours( AnnotationColourGradient acg, List userColours, JalviewModelSequence jms) @@ -1718,8 +1729,9 @@ public class Jalview2XML AnnotationColours ac = new AnnotationColours(); ac.setAboveThreshold(acg.getAboveThreshold()); ac.setThreshold(acg.getAnnotationThreshold()); - ac.setAnnotation(acg.getAnnotation()); - if (acg.getBaseColour() instanceof jalview.schemes.UserColourScheme) + // 2.10.2 save annotationId (unique) not annotation label + ac.setAnnotation(acg.getAnnotation().annotationId); + if (acg.getBaseColour() instanceof UserColourScheme) { ac.setColourScheme(setUserColourScheme(acg.getBaseColour(), userColours, jms)); @@ -2277,7 +2289,7 @@ public class Jalview2XML try { // create list to store references for any new Jmol viewers created - newStructureViewers = new Vector(); + newStructureViewers = new Vector<>(); // UNMARSHALLER SEEMS TO CLOSE JARINPUTSTREAM, MOST ANNOYING // Workaround is to make sure caller implements the JarInputStreamProvider // interface @@ -2370,8 +2382,8 @@ public class Jalview2XML initSeqRefs(); } AlignFrame af = null, _af = null; - IdentityHashMap importedDatasets = new IdentityHashMap(); - Map gatherToThisFrame = new HashMap(); + IdentityHashMap importedDatasets = new IdentityHashMap<>(); + Map gatherToThisFrame = new HashMap<>(); final String file = jprovider.getFilename(); try { @@ -2512,9 +2524,9 @@ public class Jalview2XML */ protected void restoreSplitFrames() { - List gatherTo = new ArrayList(); - List addedToSplitFrames = new ArrayList(); - Map dna = new HashMap(); + List gatherTo = new ArrayList<>(); + List addedToSplitFrames = new ArrayList<>(); + Map dna = new HashMap<>(); /* * Identify the DNA alignments @@ -2639,10 +2651,12 @@ public class Jalview2XML @Override public void run() { - JvOptionPane.showInternalMessageDialog(Desktop.desktop, - finalErrorMessage, "Error " - + (saving ? "saving" : "loading") - + " Jalview file", JvOptionPane.WARNING_MESSAGE); + JvOptionPane + .showInternalMessageDialog(Desktop.desktop, + finalErrorMessage, "Error " + + (saving ? "saving" : "loading") + + " Jalview file", + JvOptionPane.WARNING_MESSAGE); } }); } @@ -2654,7 +2668,7 @@ public class Jalview2XML errorMessage = null; } - Map alreadyLoadedPDB = new HashMap(); + Map alreadyLoadedPDB = new HashMap<>(); /** * when set, local views will be updated from view stored in JalviewXML @@ -2825,7 +2839,7 @@ public class Jalview2XML List hiddenSeqs = null; - List tmpseqs = new ArrayList(); + List tmpseqs = new ArrayList<>(); boolean multipleView = false; SequenceI referenceseqForView = null; @@ -2893,7 +2907,7 @@ public class Jalview2XML { if (hiddenSeqs == null) { - hiddenSeqs = new ArrayList(); + hiddenSeqs = new ArrayList<>(); } hiddenSeqs.add(tmpSeq); @@ -3101,12 +3115,12 @@ public class Jalview2XML // //////////////////////////////// // LOAD ANNOTATIONS - List autoAlan = new ArrayList(); + List autoAlan = new ArrayList<>(); /* * store any annotations which forward reference a group's ID */ - Map> groupAnnotRefs = new Hashtable>(); + Map> groupAnnotRefs = new Hashtable<>(); if (vamsasSet.getAnnotationCount() > 0) { @@ -3261,7 +3275,7 @@ public class Jalview2XML .get(an[i].getGroupRef()); if (aal == null) { - aal = new ArrayList(); + aal = new ArrayList<>(); groupAnnotRefs.put(an[i].getGroupRef(), aal); } aal.add(jaa); @@ -3351,7 +3365,7 @@ public class Jalview2XML } int pidThreshold = jGroup.getPidThreshold(); - Vector seqs = new Vector(); + Vector seqs = new Vector<>(); for (int s = 0; s < jGroup.getSeqCount(); s++) { @@ -3744,7 +3758,7 @@ public class Jalview2XML * Run through all PDB ids on the alignment, and collect mappings between * distinct view ids and all sequences referring to that view. */ - Map structureViewers = new LinkedHashMap(); + Map structureViewers = new LinkedHashMap<>(); for (int i = 0; i < jseqs.length; i++) { @@ -3942,8 +3956,8 @@ public class Jalview2XML Set> fileData = data.getFileData() .entrySet(); - List pdbs = new ArrayList(); - List allseqs = new ArrayList(); + List pdbs = new ArrayList<>(); + List allseqs = new ArrayList<>(); for (Entry pdb : fileData) { String filePath = pdb.getValue().getFilePath(); @@ -3999,9 +4013,9 @@ public class Jalview2XML getViewerJarEntryName(svattrib.getViewId())); } - List pdbfilenames = new ArrayList(); - List seqmaps = new ArrayList(); - List pdbids = new ArrayList(); + List pdbfilenames = new ArrayList<>(); + List seqmaps = new ArrayList<>(); + List pdbids = new ArrayList<>(); StringBuilder newFileLoc = new StringBuilder(64); int cp = 0, ncp, ecp; Map oldFiles = svattrib.getFileData(); @@ -4409,13 +4423,6 @@ public class Jalview2XML } // recover view properties and display parameters - if (view.getViewName() != null) - { - af.viewport.viewName = view.getViewName(); - af.setInitialTabVisible(); - } - af.setBounds(view.getXpos(), view.getYpos(), view.getWidth(), - view.getHeight()); af.viewport.setShowAnnotation(view.getShowAnnotation()); af.viewport.setAbovePIDThreshold(view.getPidSelected()); @@ -4448,8 +4455,16 @@ public class Jalview2XML af.viewport.setThresholdTextColour(view.getTextColThreshold()); af.viewport.setShowUnconserved(view.hasShowUnconserved() ? view .isShowUnconserved() : false); - af.viewport.setStartRes(view.getStartRes()); - af.viewport.setStartSeq(view.getStartSeq()); + af.viewport.getRanges().setStartRes(view.getStartRes()); + + if (view.getViewName() != null) + { + af.viewport.viewName = view.getViewName(); + af.setInitialTabVisible(); + } + af.setBounds(view.getXpos(), view.getYpos(), view.getWidth(), + view.getHeight()); + // startSeq set in af.alignPanel.updateLayout below af.alignPanel.updateLayout(); ColourSchemeI cs = null; // apply colourschemes @@ -4562,8 +4577,8 @@ public class Jalview2XML af.viewport.setFeaturesDisplayed(fdi = new FeaturesDisplayed()); String[] renderOrder = new String[jms.getFeatureSettings() .getSettingCount()]; - Map featureColours = new Hashtable(); - Map featureOrder = new Hashtable(); + Map featureColours = new Hashtable<>(); + Map featureOrder = new Hashtable<>(); for (int fs = 0; fs < jms.getFeatureSettings().getSettingCount(); fs++) { @@ -4622,7 +4637,7 @@ public class Jalview2XML fdi.setVisible(setting.getType()); } } - Map fgtable = new Hashtable(); + Map fgtable = new Hashtable<>(); for (int gs = 0; gs < jms.getFeatureSettings().getGroupCount(); gs++) { Group grp = jms.getFeatureSettings().getGroup(gs); @@ -4689,12 +4704,21 @@ public class Jalview2XML return af; } + /** + * Reads saved data to restore Colour by Annotation settings + * + * @param viewAnnColour + * @param af + * @param al + * @param jms + * @param checkGroupAnnColour + * @return + */ private ColourSchemeI constructAnnotationColour( AnnotationColours viewAnnColour, AlignFrame af, AlignmentI al, JalviewModelSequence jms, boolean checkGroupAnnColour) { boolean propagateAnnColour = false; - ColourSchemeI cs = null; AlignmentI annAlignment = af != null ? af.viewport.getAlignment() : al; if (checkGroupAnnColour && al.getGroups() != null && al.getGroups().size() > 0) @@ -4702,7 +4726,7 @@ public class Jalview2XML // pre 2.8.1 behaviour // check to see if we should transfer annotation colours propagateAnnColour = true; - for (jalview.datamodel.SequenceGroup sg : al.getGroups()) + for (SequenceGroup sg : al.getGroups()) { if (sg.getColourScheme() instanceof AnnotationColourGradient) { @@ -4710,107 +4734,84 @@ public class Jalview2XML } } } - // int find annotation - if (annAlignment.getAlignmentAnnotation() != null) + + /* + * 2.10.2- : saved annotationId is AlignmentAnnotation.annotationId + */ + String annotationId = viewAnnColour.getAnnotation(); + AlignmentAnnotation matchedAnnotation = annotationIds.get(annotationId); + + /* + * pre 2.10.2: saved annotationId is AlignmentAnnotation.label + */ + if (matchedAnnotation == null && annAlignment.getAlignmentAnnotation() != null) { for (int i = 0; i < annAlignment.getAlignmentAnnotation().length; i++) { - if (annAlignment.getAlignmentAnnotation()[i].label - .equals(viewAnnColour.getAnnotation())) + if (annotationId + .equals(annAlignment.getAlignmentAnnotation()[i].label)) { - if (annAlignment.getAlignmentAnnotation()[i].getThreshold() == null) - { - annAlignment.getAlignmentAnnotation()[i] - .setThreshold(new jalview.datamodel.GraphLine( - viewAnnColour.getThreshold(), "Threshold", - java.awt.Color.black) - - ); - } - - if (viewAnnColour.getColourScheme().equals( - ResidueColourScheme.NONE)) - { - cs = new AnnotationColourGradient( - annAlignment.getAlignmentAnnotation()[i], - new java.awt.Color(viewAnnColour.getMinColour()), - new java.awt.Color(viewAnnColour.getMaxColour()), - viewAnnColour.getAboveThreshold()); - } - else if (viewAnnColour.getColourScheme().startsWith("ucs")) - { - cs = new AnnotationColourGradient( - annAlignment.getAlignmentAnnotation()[i], - getUserColourScheme(jms, - viewAnnColour.getColourScheme()), - viewAnnColour.getAboveThreshold()); - } - else - { - cs = new AnnotationColourGradient( - annAlignment.getAlignmentAnnotation()[i], - ColourSchemeProperty.getColourScheme(al, - viewAnnColour.getColourScheme()), - viewAnnColour.getAboveThreshold()); - } - if (viewAnnColour.hasPerSequence()) - { - ((AnnotationColourGradient) cs).setSeqAssociated(viewAnnColour - .isPerSequence()); - } - if (viewAnnColour.hasPredefinedColours()) - { - ((AnnotationColourGradient) cs) - .setPredefinedColours(viewAnnColour - .isPredefinedColours()); - } - if (propagateAnnColour && al.getGroups() != null) - { - // Also use these settings for all the groups - for (int g = 0; g < al.getGroups().size(); g++) - { - jalview.datamodel.SequenceGroup sg = al.getGroups().get(g); - - if (sg.cs == null) - { - continue; - } + matchedAnnotation = annAlignment.getAlignmentAnnotation()[i]; + break; + } + } + } + if (matchedAnnotation == null) + { + System.err.println("Failed to match annotation colour scheme for " + + annotationId); + return null; + } + if (matchedAnnotation.getThreshold() == null) + { + matchedAnnotation.setThreshold(new GraphLine(viewAnnColour.getThreshold(), + "Threshold", Color.black)); + } - /* - * if (viewAnnColour.getColourScheme().equals(ResidueColourScheme.NONE)) { sg.cs = - * new AnnotationColourGradient( - * annAlignment.getAlignmentAnnotation()[i], new - * java.awt.Color(viewAnnColour. getMinColour()), new - * java.awt.Color(viewAnnColour. getMaxColour()), - * viewAnnColour.getAboveThreshold()); } else - */ - { - sg.setColourScheme(new AnnotationColourGradient( - annAlignment.getAlignmentAnnotation()[i], sg - .getColourScheme(), viewAnnColour - .getAboveThreshold())); - if (cs instanceof AnnotationColourGradient) - { - if (viewAnnColour.hasPerSequence()) - { - ((AnnotationColourGradient) cs) - .setSeqAssociated(viewAnnColour.isPerSequence()); - } - if (viewAnnColour.hasPredefinedColours()) - { - ((AnnotationColourGradient) cs) - .setPredefinedColours(viewAnnColour - .isPredefinedColours()); - } - } - } + AnnotationColourGradient cs = null; + if (viewAnnColour.getColourScheme().equals("None")) + { + cs = new AnnotationColourGradient(matchedAnnotation, new Color( + viewAnnColour.getMinColour()), new Color( + viewAnnColour.getMaxColour()), + viewAnnColour.getAboveThreshold()); + } + else if (viewAnnColour.getColourScheme().startsWith("ucs")) + { + cs = new AnnotationColourGradient(matchedAnnotation, getUserColourScheme( + jms, viewAnnColour.getColourScheme()), + viewAnnColour.getAboveThreshold()); + } + else + { + cs = new AnnotationColourGradient(matchedAnnotation, + ColourSchemeProperty.getColourScheme(al, + viewAnnColour.getColourScheme()), + viewAnnColour.getAboveThreshold()); + } - } - } + boolean perSequenceOnly = viewAnnColour.isPerSequence(); + boolean useOriginalColours = viewAnnColour.isPredefinedColours(); + cs.setSeqAssociated(perSequenceOnly); + cs.setPredefinedColours(useOriginalColours); - break; + if (propagateAnnColour && al.getGroups() != null) + { + // Also use these settings for all the groups + for (int g = 0; g < al.getGroups().size(); g++) + { + SequenceGroup sg = al.getGroups().get(g); + if (sg.getGroupColourScheme() == null) + { + continue; } + AnnotationColourGradient groupScheme = new AnnotationColourGradient( + matchedAnnotation, sg.getColourScheme(), + viewAnnColour.getAboveThreshold()); + sg.setColourScheme(groupScheme); + groupScheme.setSeqAssociated(perSequenceOnly); + groupScheme.setPredefinedColours(useOriginalColours); } } return cs; @@ -4829,7 +4830,7 @@ public class Jalview2XML String[] magicNames = new String[] { "Consensus", "Quality", "Conservation" }; JvAnnotRow nullAnnot = new JvAnnotRow(-1, null); - Hashtable visan = new Hashtable(); + Hashtable visan = new Hashtable<>(); for (String nm : magicNames) { visan.put(nm, nullAnnot); @@ -4841,11 +4842,11 @@ public class Jalview2XML + auan.template.getCalcId()), auan); } int hSize = al.getAlignmentAnnotation().length; - List reorder = new ArrayList(); + List reorder = new ArrayList<>(); // work through any autoCalculated annotation already on the view // removing it if it should be placed in a different location on the // annotation panel. - List remains = new ArrayList(visan.keySet()); + List remains = new ArrayList<>(visan.keySet()); for (int h = 0; h < hSize; h++) { jalview.datamodel.AlignmentAnnotation jalan = al @@ -5173,7 +5174,7 @@ public class Jalview2XML { if (datasetIds == null) { - datasetIds = new Hashtable(); + datasetIds = new Hashtable<>(); return null; } if (datasetIds.containsKey(datasetId)) @@ -5187,7 +5188,7 @@ public class Jalview2XML { if (datasetIds == null) { - datasetIds = new Hashtable(); + datasetIds = new Hashtable<>(); } datasetIds.put(datasetId, dataset); } @@ -5210,7 +5211,7 @@ public class Jalview2XML // make a new datasetId and record it if (dataset2Ids == null) { - dataset2Ids = new IdentityHashMap(); + dataset2Ids = new IdentityHashMap<>(); } else { @@ -5489,11 +5490,11 @@ public class Jalview2XML // register sequence object so the XML parser can recover it. if (seqRefIds == null) { - seqRefIds = new HashMap(); + seqRefIds = new HashMap<>(); } if (seqsToIds == null) { - seqsToIds = new IdentityHashMap(); + seqsToIds = new IdentityHashMap<>(); } seqRefIds.put(jv2vobj.get(jvobj).toString(), (SequenceI) jvobj); seqsToIds.put((SequenceI) jvobj, id);