X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fproject%2FJalview2XML.java;h=eaabd474b0f430ed7037f217483f1a808e5425c2;hb=9962480f980106936de9350235509116746a79a2;hp=74b6bf060b6995b16083618e075e7bc2108f398f;hpb=41d39ae9fa7cea070094d6e0230bca8c0cfba23a;p=jalview.git diff --git a/src/jalview/project/Jalview2XML.java b/src/jalview/project/Jalview2XML.java index 74b6bf0..eaabd47 100644 --- a/src/jalview/project/Jalview2XML.java +++ b/src/jalview/project/Jalview2XML.java @@ -24,6 +24,8 @@ import static jalview.math.RotatableMatrix.Axis.X; import static jalview.math.RotatableMatrix.Axis.Y; import static jalview.math.RotatableMatrix.Axis.Z; +import jalview.analysis.AnnotationSorter; +import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder; import jalview.analysis.Conservation; import jalview.analysis.PCA; import jalview.analysis.scoremodels.ScoreModels; @@ -59,7 +61,6 @@ import jalview.gui.AppVarna; import jalview.gui.ChimeraViewFrame; import jalview.gui.Desktop; import jalview.gui.FeatureRenderer; -import jalview.gui.Jalview2XML_V1; import jalview.gui.JvOptionPane; import jalview.gui.OOMWarning; import jalview.gui.PCAPanel; @@ -69,6 +70,7 @@ import jalview.gui.StructureViewer; import jalview.gui.StructureViewer.ViewerType; import jalview.gui.StructureViewerBase; import jalview.gui.TreePanel; +import jalview.io.BackupFiles; import jalview.io.DataSourceType; import jalview.io.FileFormat; import jalview.io.NewickFile; @@ -551,24 +553,30 @@ public class Jalview2XML public void saveState(File statefile) { FileOutputStream fos = null; + try { + fos = new FileOutputStream(statefile); + JarOutputStream jout = new JarOutputStream(fos); saveState(jout); + fos.close(); } catch (Exception e) { + Cache.log.error("Couln't write Jalview state to " + statefile, e); // TODO: inform user of the problem - they need to know if their data was // not saved ! if (errorMessage == null) { - errorMessage = "Couldn't write Jalview Archive to output file '" + errorMessage = "Did't write Jalview Archive to output file '" + statefile + "' - See console error log for details"; } else { - errorMessage += "(output file was '" + statefile + "')"; + errorMessage += "(Didn't write Jalview Archive to output file '" + + statefile + ")"; } e.printStackTrace(); } finally @@ -738,7 +746,11 @@ public class Jalview2XML { try { - FileOutputStream fos = new FileOutputStream(jarFile); + // create backupfiles object and get new temp filename destination + BackupFiles backupfiles = new BackupFiles(jarFile); + FileOutputStream fos = new FileOutputStream( + backupfiles.getTempFilePath()); + JarOutputStream jout = new JarOutputStream(fos); List frames = new ArrayList<>(); @@ -760,7 +772,12 @@ public class Jalview2XML } ; jout.close(); - return true; + boolean success = true; + + backupfiles.setWriteSuccess(success); + success = backupfiles.rollBackupsAndRenameTempFile(); + + return success; } catch (Exception ex) { errorMessage = "Couldn't Write alignment view to Jalview Archive - see error output for details"; @@ -1464,6 +1481,8 @@ public class Jalview2XML view.setRenderGaps(av.isRenderGaps()); view.setShowAnnotation(av.isShowAnnotation()); view.setShowBoxes(av.getShowBoxes()); + view.setShowAutocalcAbove(av.isShowAutocalculatedAbove()); + view.setSortAnnotationsBy(av.getSortAnnotationsBy().name()); view.setShowColourText(av.getColourText()); view.setShowFullId(av.getShowJVSuffix()); view.setRightAlignIds(av.isRightAlignIds()); @@ -2882,16 +2901,7 @@ public class Jalview2XML ex.printStackTrace(System.err); if (attemptversion1parse) { - // Is Version 1 Jar file? - try - { - af = new Jalview2XML_V1(raiseGUI).LoadJalviewAlign(jprovider); - } catch (Exception ex2) - { - System.err.println("Exception whilst loading as jalviewXMLV1:"); - ex2.printStackTrace(); - af = null; - } + // used to attempt to parse as V1 castor-generated xml } if (Desktop.instance != null) { @@ -3613,7 +3623,7 @@ public class Jalview2XML // //////////////////////////////// // LOAD ANNOTATIONS - List autoAlan = new ArrayList<>(); + List addedAnnotation = new ArrayList<>(); /* * store any annotations which forward reference a group's ID @@ -3704,7 +3714,11 @@ public class Jalview2XML } } } - jalview.datamodel.AlignmentAnnotation jaa = null; + + /* + * construct the Jalview AlignmentAnnotation, add to alignment + */ + AlignmentAnnotation jaa = null; if (annotation.isGraph()) { @@ -3802,9 +3816,10 @@ public class Jalview2XML jaa.autoCalculated = true; // means annotation will be marked for // update at end of load. } - if (annotation.getGraphHeight() != null) + Integer graphHeight = annotation.getGraphHeight(); + if (graphHeight != null) { - jaa.graphHeight = annotation.getGraphHeight().intValue(); + jaa.graphHeight = graphHeight.intValue(); } jaa.belowAlignment = annotation.isBelowAlignment(); jaa.setCalcId(annotation.getCalcId()); @@ -3816,17 +3831,16 @@ public class Jalview2XML jaa.setProperty(prop.getName(), prop.getValue()); } } - if (jaa.autoCalculated) + if (!jaa.autoCalculated) { - autoAlan.add(new JvAnnotRow(i, jaa)); - } - else - // if (!autoForView) - { - // add autocalculated group annotation and any user created annotation - // for the view + // TODO ensure Consensus etc is enabled if found in project? + /* + * add autocalculated group annotation and any user created annotation + * for the view + */ al.addAnnotation(jaa); } + addedAnnotation.add(jaa); } } // /////////////////////// @@ -3853,7 +3867,7 @@ public class Jalview2XML } else { - cs = ColourSchemeProperty.getColourScheme(al, + cs = ColourSchemeProperty.getColourScheme(null, al, jGroup.getColour()); } } @@ -4019,9 +4033,16 @@ public class Jalview2XML if (isnewview) { af = loadViewport(file, jseqs, hiddenSeqs, al, jalviewModel, view, - uniqueSeqSetId, viewId, autoAlan); + uniqueSeqSetId, viewId); + // TODO restore autocalc preferences if overridden earlier? + /* + * resort annotations to their order in the project + * (also sets height and visibility for autocalc'd annotation) + */ av = af.getViewport(); + new AnnotationSorter(av).sort(addedAnnotation); ap = af.alignPanel; + ap.adjustAnnotationHeight(); } /* @@ -4181,10 +4202,8 @@ public class Jalview2XML // TODO: verify 'associate with all views' works still tp.getTreeCanvas().setViewport(av); // af.viewport; tp.getTreeCanvas().setAssociatedPanel(ap); // af.alignPanel; - // FIXME: should we use safeBoolean here ? - tp.getTreeCanvas().setApplyToAllViews(tree.isLinkToAllViews()); - } + tp.getTreeCanvas().setApplyToAllViews(tree.isLinkToAllViews()); if (tp == null) { warn("There was a problem recovering stored Newick tree: \n" @@ -4831,7 +4850,7 @@ public class Jalview2XML AlignFrame loadViewport(String file, List JSEQ, List hiddenSeqs, AlignmentI al, JalviewModel jm, Viewport view, String uniqueSeqSetId, - String viewId, List autoAlan) + String viewId) { AlignFrame af = null; af = new AlignFrame(al, safeInt(view.getWidth()), @@ -4912,9 +4931,8 @@ public class Jalview2XML viewport.setColourText(safeBoolean(view.isShowColourText())); - viewport - .setConservationSelected( - safeBoolean(view.isConservationSelected())); + viewport.setConservationSelected( + safeBoolean(view.isConservationSelected())); viewport.setIncrement(safeInt(view.getConsThreshold())); viewport.setShowJVSuffix(safeBoolean(view.isShowFullId())); viewport.setRightAlignIds(safeBoolean(view.isRightAlignIds())); @@ -4930,10 +4948,27 @@ public class Jalview2XML viewport.setWrapAlignment(safeBoolean(view.isWrapAlignment())); viewport.setShowAnnotation(safeBoolean(view.isShowAnnotation())); - viewport.setShowBoxes(safeBoolean(view.isShowBoxes())); + Boolean autocalcFirst = view.isShowAutocalcAbove(); + if (autocalcFirst != null) + { + af.setShowAutoCalculatedAbove(autocalcFirst.booleanValue()); + } + String sortBy = view.getSortAnnotationsBy(); + if (sortBy != null) + { + try + { + viewport.setSortAnnotationsBy( + SequenceAnnotationOrder.valueOf(sortBy)); + } catch (IllegalArgumentException e) + { + Cache.log.error( + "Invalid annotation sort specifier in project: " + sortBy); + } + } + viewport.setShowBoxes(safeBoolean(view.isShowBoxes())); viewport.setShowText(safeBoolean(view.isShowText())); - viewport.setTextColour(new Color(safeInt(view.getTextCol1()))); viewport.setTextColour2(new Color(safeInt(view.getTextCol2()))); viewport.setThresholdTextColour(safeInt(view.getTextColThreshold())); @@ -4967,25 +5002,27 @@ public class Jalview2XML } else { - cs = ColourSchemeProperty.getColourScheme(al, view.getBgColour()); + cs = ColourSchemeProperty.getColourScheme(af.getViewport(), al, + view.getBgColour()); } } + /* + * turn off 'alignment colour applies to all groups' + * while restoring global colour scheme + */ + viewport.setColourAppliesToAllGroups(false); viewport.setGlobalColourScheme(cs); viewport.getResidueShading().setThreshold(pidThreshold, view.isIgnoreGapsinConsensus()); viewport.getResidueShading() .setConsensus(viewport.getSequenceConsensusHash()); - viewport.setColourAppliesToAllGroups(false); - if (safeBoolean(view.isConservationSelected()) && cs != null) { viewport.getResidueShading() .setConservationInc(safeInt(view.getConsThreshold())); } - af.changeColour(cs); - viewport.setColourAppliesToAllGroups(true); viewport @@ -5061,7 +5098,8 @@ public class Jalview2XML float min = safeFloat(safeFloat(setting.getMin())); float max = setting.getMax() == null ? 1f : setting.getMax().floatValue(); - FeatureColourI gc = new FeatureColour(minColour, maxColour, + FeatureColourI gc = new FeatureColour(maxColour, minColour, + maxColour, noValueColour, min, max); if (setting.getAttributeName().size() > 0) { @@ -5169,7 +5207,6 @@ public class Jalview2XML safeInt(view.getWidth()), safeInt(view.getHeight())); // recompute any autoannotation af.alignPanel.updateAnnotation(false, true); - reorderAutoannotation(af, al, autoAlan); af.alignPanel.alignmentChanged(); } else @@ -5263,7 +5300,7 @@ public class Jalview2XML else { cs = new AnnotationColourGradient(matchedAnnotation, - ColourSchemeProperty.getColourScheme(al, + ColourSchemeProperty.getColourScheme(af.getViewport(), al, viewAnnColour.getColourScheme()), safeInt(viewAnnColour.getAboveThreshold())); } @@ -5296,106 +5333,6 @@ public class Jalview2XML return cs; } - private void reorderAutoannotation(AlignFrame af, AlignmentI al, - List autoAlan) - { - // copy over visualization settings for autocalculated annotation in the - // view - if (al.getAlignmentAnnotation() != null) - { - /** - * Kludge for magic autoannotation names (see JAL-811) - */ - String[] magicNames = new String[] { "Consensus", "Quality", - "Conservation" }; - JvAnnotRow nullAnnot = new JvAnnotRow(-1, null); - Hashtable visan = new Hashtable<>(); - for (String nm : magicNames) - { - visan.put(nm, nullAnnot); - } - for (JvAnnotRow auan : autoAlan) - { - visan.put(auan.template.label - + (auan.template.getCalcId() == null ? "" - : "\t" + auan.template.getCalcId()), - auan); - } - int hSize = al.getAlignmentAnnotation().length; - 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()); - for (int h = 0; h < hSize; h++) - { - jalview.datamodel.AlignmentAnnotation jalan = al - .getAlignmentAnnotation()[h]; - if (jalan.autoCalculated) - { - String k; - JvAnnotRow valan = visan.get(k = jalan.label); - if (jalan.getCalcId() != null) - { - valan = visan.get(k = jalan.label + "\t" + jalan.getCalcId()); - } - - if (valan != null) - { - // delete the auto calculated row from the alignment - al.deleteAnnotation(jalan, false); - remains.remove(k); - hSize--; - h--; - if (valan != nullAnnot) - { - if (jalan != valan.template) - { - // newly created autoannotation row instance - // so keep a reference to the visible annotation row - // and copy over all relevant attributes - if (valan.template.graphHeight >= 0) - - { - jalan.graphHeight = valan.template.graphHeight; - } - jalan.visible = valan.template.visible; - } - reorder.add(new JvAnnotRow(valan.order, jalan)); - } - } - } - } - // Add any (possibly stale) autocalculated rows that were not appended to - // the view during construction - for (String other : remains) - { - JvAnnotRow othera = visan.get(other); - if (othera != nullAnnot && othera.template.getCalcId() != null - && othera.template.getCalcId().length() > 0) - { - reorder.add(othera); - } - } - // now put the automatic annotation in its correct place - int s = 0, srt[] = new int[reorder.size()]; - JvAnnotRow[] rws = new JvAnnotRow[reorder.size()]; - for (JvAnnotRow jvar : reorder) - { - rws[s] = jvar; - srt[s++] = jvar.order; - } - reorder.clear(); - jalview.util.QuickSort.sort(srt, rws); - // and re-insert the annotation at its correct position - for (JvAnnotRow jvar : rws) - { - al.addAnnotation(jvar.template, jvar.order); - } - af.alignPanel.adjustAnnotationHeight(); - } - } - Hashtable skipList = null; /** @@ -5829,15 +5766,16 @@ public class Jalview2XML jalview.datamodel.Mapping jmap = new jalview.datamodel.Mapping(dsto, fr, fto, m.getMapFromUnit().intValue(), m.getMapToUnit().intValue()); - // if (m.getMappingChoice() != null) - // { - // MappingChoice mc = m.getMappingChoice(); + + /* + * (optional) choice of dseqFor or Sequence + */ if (m.getDseqFor() != null) { String dsfor = m.getDseqFor(); if (seqRefIds.containsKey(dsfor)) { - /** + /* * recover from hash */ jmap.setTo(seqRefIds.get(dsfor)); @@ -5847,9 +5785,9 @@ public class Jalview2XML frefedSequence.add(newMappingRef(dsfor, jmap)); } } - else + else if (m.getSequence() != null) { - /** + /* * local sequence definition */ Sequence ms = m.getSequence(); @@ -6555,7 +6493,7 @@ public class Jalview2XML noValueColour = maxcol; } - colour = new FeatureColour(mincol, maxcol, noValueColour, + colour = new FeatureColour(maxcol, mincol, maxcol, noValueColour, safeFloat(colourModel.getMin()), safeFloat(colourModel.getMax())); final List attributeName = colourModel.getAttributeName();