X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FJalview2XML.java;h=1a9bc033fd659bddd02994af1bf2c047db143630;hb=e74c1be398cd4ebe5f420c13be6143464100bb52;hp=a93e84cb430f26b1e52e444551c5f9265b2a62f5;hpb=8a6fa9ea9900d0f106529c3f6283e7f9d76dd2cb;p=jalview.git diff --git a/src/jalview/gui/Jalview2XML.java b/src/jalview/gui/Jalview2XML.java old mode 100755 new mode 100644 index a93e84c..1a9bc03 --- a/src/jalview/gui/Jalview2XML.java +++ b/src/jalview/gui/Jalview2XML.java @@ -32,6 +32,7 @@ import org.exolab.castor.xml.*; import uk.ac.vamsas.objects.utils.MapList; import jalview.bin.Cache; import jalview.datamodel.Alignment; +import jalview.datamodel.AlignmentAnnotation; import jalview.datamodel.AlignmentI; import jalview.datamodel.SequenceI; import jalview.schemabinding.version2.*; @@ -47,7 +48,7 @@ import jalview.util.jarInputStreamProvider; * will be :) * * @author $author$ - * @version $Revision$ + * @version $Revision: 1.134 $ */ public class Jalview2XML { @@ -580,7 +581,6 @@ public class Jalview2XML { if (frames[f] instanceof AppJmol) { - // TODO: revise schema to allow many:one PDB id binding to viewer jmol = (AppJmol) frames[f]; for (int peid = 0; peid < jmol.jmb.pdbentry.length; peid++) { @@ -621,6 +621,10 @@ public class Jalview2XML state.setWidth(jmol.getWidth()); state.setHeight(jmol.getHeight()); state.setViewId(jmol.getViewId()); + state.setAlignwithAlignPanel(jmol.isUsedforaligment(ap)); + state.setColourwithAlignPanel(jmol + .isUsedforcolourby(ap)); + state.setColourByJmol(jmol.isColouredByJmol()); if (!jmolViewIds.contains(state.getViewId())) { // Make sure we only store a Jmol state once in each XML @@ -832,19 +836,13 @@ public class Jalview2XML } an.setGroupRef(groupIdr.toString()); } - if (aa[i] == av.quality || aa[i] == av.conservation - || aa[i] == av.consensus || aa[i].autoCalculated) - { - // new way of indicating autocalculated annotation - - an.setAutoCalculated(aa[i].autoCalculated); - // write a stub for this annotation - indicate presence of autocalc - // rows - an.setLabel(aa[i].label); - an.setGraph(true); - vamsasSet.addAnnotation(an); - continue; - } + // store all visualization attributes for annotation + an.setGraphHeight(aa[i].graphHeight); + an.setCentreColLabels(aa[i].centreColLabels); + an.setScaleColLabels(aa[i].scaleColLabel); + an.setShowAllColLabels(aa[i].showAllColLabels); + if (aa[i].graph > 0) { an.setGraph(true); @@ -865,6 +863,13 @@ public class Jalview2XML } an.setLabel(aa[i].label); + + if (aa[i] == av.quality || aa[i] == av.conservation + || aa[i] == av.consensus || aa[i].autoCalculated) + { + // new way of indicating autocalculated annotation - + an.setAutoCalculated(aa[i].autoCalculated); + } if (aa[i].hasScore()) { an.setScore(aa[i].getScore()); @@ -902,6 +907,11 @@ public class Jalview2XML } an.addAnnotationElement(ae); + if (aa[i].autoCalculated) + { + // only write one non-null entry into the annotation row - sufficient to get the visualization attributes necessary to display data + continue; + } } } else @@ -1823,6 +1833,25 @@ public class Jalview2XML return null; } + private class JvAnnotRow + { + public JvAnnotRow(int i, AlignmentAnnotation jaa) + { + order = i; + template = jaa; + } + + /** + * persisted version of annotation row from which to take vis properties + */ + public jalview.datamodel.AlignmentAnnotation template; + + /** + * original position of the annotation row in the alignment + */ + public int order; + } + /** * Load alignment frame from jalview XML DOM object * @@ -2055,11 +2084,11 @@ public class Jalview2XML // //////////////////////////////// // LOAD ANNOTATIONS - boolean hideQuality = true, hideConservation = true, hideConsensus = true; + ArrayList autoAlan = new ArrayList(); /** * store any annotations which forward reference a group's ID */ - Hashtable groupAnnotRefs = new Hashtable(); + Hashtable> groupAnnotRefs = new Hashtable>(); if (vamsasSet.getAnnotationCount() > 0) { @@ -2067,22 +2096,27 @@ public class Jalview2XML for (int i = 0; i < an.length; i++) { - // set visibility for automatic annotation for this view - if (an[i].getLabel().equals("Quality")) - { - hideQuality = false; - continue; - } - else if (an[i].getLabel().equals("Conservation")) - { - hideConservation = false; - continue; + /** + * test if annotation is automatically calculated for this view only + */ + boolean autoForView = false; + if (an[i].getLabel().equals("Quality") + || an[i].getLabel().equals("Conservation") + || an[i].getLabel().equals("Consensus")) + { + // Kludge for pre 2.5 projects which lacked the autocalculated flag + autoForView = true; + if (!an[i].hasAutoCalculated()) + { + an[i].setAutoCalculated(true); + } } - else if (an[i].getLabel().equals("Consensus")) - { - hideConsensus = false; - continue; + if (autoForView || (an[i].hasAutoCalculated() && an[i].isAutoCalculated())) { + // remove ID - we don't recover annotation from other views for + // view-specific annotation + an[i].setId(null); } + // set visiblity for other annotation in this view if (an[i].getId() != null && annotationIds.containsKey(an[i].getId())) @@ -2105,7 +2139,6 @@ public class Jalview2XML if (!an[i].getScoreOnly()) { anot = new jalview.datamodel.Annotation[al.getWidth()]; - for (int aa = 0; aa < ae.length && aa < anot.length; aa++) { if (ae[aa].getPosition() >= anot.length) @@ -2135,8 +2168,12 @@ public class Jalview2XML if (an[i].getGraph()) { + float llim=0,hlim=0; + // if (autoForView || an[i].isAutoCalculated()) { + // hlim=11f; + // } jaa = new jalview.datamodel.AlignmentAnnotation(an[i].getLabel(), - an[i].getDescription(), anot, 0, 0, an[i].getGraphType()); + an[i].getDescription(), anot, llim, hlim, an[i].getGraphType()); jaa.graphGroup = an[i].getGraphGroup(); @@ -2148,33 +2185,45 @@ public class Jalview2XML an[i].getThresholdLine().getColour()))); } - + if (autoForView || an[i].isAutoCalculated()) { + // Hardwire the symbol display line to ensure that labels for histograms are displayed + jaa.hasText=true; + } } else { jaa = new jalview.datamodel.AlignmentAnnotation(an[i].getLabel(), an[i].getDescription(), anot); } - // register new annotation - if (an[i].getId() != null) + if (autoForView) { - annotationIds.put(an[i].getId(), jaa); - jaa.annotationId = an[i].getId(); - } - // recover sequence association - if (an[i].getSequenceRef() != null) - { - if (al.findName(an[i].getSequenceRef()) != null) + // register new annotation + if (an[i].getId() != null) { - jaa.createSequenceMapping(al.findName(an[i].getSequenceRef()), - 1, true); - al.findName(an[i].getSequenceRef()).addAlignmentAnnotation(jaa); + annotationIds.put(an[i].getId(), jaa); + jaa.annotationId = an[i].getId(); + } + // recover sequence association + if (an[i].getSequenceRef() != null) + { + if (al.findName(an[i].getSequenceRef()) != null) + { + jaa.createSequenceMapping( + al.findName(an[i].getSequenceRef()), 1, true); + al.findName(an[i].getSequenceRef()).addAlignmentAnnotation( + jaa); + } } } // and make a note of any group association if (an[i].getGroupRef() != null && an[i].getGroupRef().length() > 0) { - groupAnnotRefs.put(an[i].getGroupRef(), jaa); + ArrayList aal=groupAnnotRefs.get(an[i].getGroupRef()); + if (aal==null) { + aal = new ArrayList(); + groupAnnotRefs.put(an[i].getGroupRef(),aal); + } + aal.add(jaa); } if (an[i].hasScore()) @@ -2198,7 +2247,19 @@ public class Jalview2XML jaa.autoCalculated = true; // means annotation will be marked for // update at end of load. } - al.addAnnotation(jaa); + if (an[i].hasGraphHeight()) + { + jaa.graphHeight = an[i].getGraphHeight(); + } + if (jaa.autoCalculated) + { + autoAlan.add(new JvAnnotRow(i, jaa)); + } else + // if (!autoForView) + { + // add autocalculated group annotation and any user created annotation for the view + al.addAnnotation(jaa); + } } } @@ -2287,11 +2348,24 @@ public class Jalview2XML if (groups[i].getId() != null && groupAnnotRefs.size() > 0) { // re-instate unique group/annotation row reference - jalview.datamodel.AlignmentAnnotation jaa = (jalview.datamodel.AlignmentAnnotation) groupAnnotRefs + ArrayList jaal = groupAnnotRefs .get(groups[i].getId()); - if (jaa != null) + if (jaal != null) { - jaa.groupRef = sg; + for (jalview.datamodel.AlignmentAnnotation jaa:jaal) { + jaa.groupRef = sg; + if (jaa.autoCalculated) + { + // match up and try to set group autocalc alignment row for this annotation + if (jaa.label.startsWith("Consensus for ")) { + sg.setConsensus(jaa); + } + // match up and try to set group autocalc alignment row for this annotation + if (jaa.label.startsWith("Conservation for ")) { + sg.setConservationRow(jaa); + } + } + } } } al.addGroup(sg); @@ -2369,9 +2443,8 @@ public class Jalview2XML if (isnewview) { - af = loadViewport(file, JSEQ, hiddenSeqs, al, hideConsensus, - hideQuality, hideConservation, jms, view, uniqueSeqSetId, - viewId); + af = loadViewport(file, JSEQ, hiddenSeqs, al, jms, view, + uniqueSeqSetId, viewId, autoAlan); av = af.viewport; ap = af.alignPanel; } @@ -2500,12 +2573,28 @@ public class Jalview2XML jmolViewIds.put(sviewid, new Object[] { new int[] { x, y, width, height }, "", - new Hashtable() }); + new Hashtable(), new boolean[] + { false, false, true } }); + // Legacy pre-2.7 conversion JAL-823 : + // do not assume any view has to be linked for colour by sequence } - // TODO: assemble String[] { pdb files }, String[] { id for each + + // assemble String[] { pdb files }, String[] { id for each // file }, orig_fileloc, SequenceI[][] {{ seqs_file 1 }, { - // seqs_file 2}} from hash + // seqs_file 2}, boolean[] { + // linkAlignPanel,superposeWithAlignpanel}} from hash Object[] jmoldat = (Object[]) jmolViewIds.get(sviewid); + ((boolean[]) jmoldat[3])[0] |= ids[p].getStructureState(s) + .hasAlignwithAlignPanel() ? ids[p].getStructureState( + s).getAlignwithAlignPanel() : false; + // never colour by linked panel if not specified + ((boolean[]) jmoldat[3])[1] |= ids[p].getStructureState(s) + .hasColourwithAlignPanel() ? ids[p] + .getStructureState(s).getColourwithAlignPanel() + : false; + // default for pre-2.7 projects is that Jmol colouring is enabled + ((boolean[])jmoldat[3])[2] &=ids[p].getStructureState(s).hasColourByJmol() ? ids[p].getStructureState(s).getColourByJmol() : true; + if (((String) jmoldat[1]).length() < ids[p] .getStructureState(s).getContent().length()) { @@ -2513,22 +2602,32 @@ public class Jalview2XML jmoldat[1] = ids[p].getStructureState(s).getContent(); } } - Object[] seqstrmaps = (Object[]) ((Hashtable) jmoldat[2]) - .get(ids[p].getFile()); - if (seqstrmaps == null) + if (ids[p].getFile() != null) { - ((Hashtable) jmoldat[2]).put( - new File(ids[p].getFile()).toString(), - seqstrmaps = new Object[] - { pdbFile, ids[p].getId(), new Vector(), - new Vector() }); + Object[] seqstrmaps = (Object[]) ((Hashtable) jmoldat[2]) + .get(ids[p].getFile()); + if (seqstrmaps == null) + { + ((Hashtable) jmoldat[2]).put( + new File(ids[p].getFile()).toString(), + seqstrmaps = new Object[] + { pdbFile, ids[p].getId(), new Vector(), + new Vector() }); + } + if (!((Vector) seqstrmaps[2]).contains(seq)) + { + ((Vector) seqstrmaps[2]).addElement(seq); + // ((Vector)seqstrmaps[3]).addElement(n) : + // in principle, chains + // should be stored here : do we need to + // TODO: store and recover seq/pdb_id : + // chain mappings + } } - if (!((Vector) seqstrmaps[2]).contains(seq)) + else { - ((Vector) seqstrmaps[2]).addElement(seq); - // ((Vector)seqstrmaps[3]).addElement(n) : in principle, chains - // should be stored here : do we need to - // TODO: store and recover seq/pdb_id : chain mappings + errorMessage=("The Jmol views in the Jalview 2 project may\nnot be correctly bound to sequences in the alignment.\nIn the case of problems, see note at\nhttp://issues.jalview.org/browse/JAL-747"); + warn(errorMessage); } } } @@ -2544,7 +2643,7 @@ public class Jalview2XML int[] geom = (int[]) svattrib[0]; String state = (String) svattrib[1]; Hashtable oldFiles = (Hashtable) svattrib[2]; - + final boolean useinJmolsuperpos = ((boolean[]) svattrib[3])[0], usetoColourbyseq = ((boolean[]) svattrib[3])[1], jmolColouring=((boolean[])svattrib[3])[2]; int x = geom[0], y = geom[1], width = geom[2], height = geom[3]; // collate the pdbfile -> sequence mappings from this view Vector pdbfilenames = new Vector(); @@ -2700,8 +2799,7 @@ public class Jalview2XML try { sview = new AppJmol(pdbf, id, sq, alf.alignPanel, - fileloc, - + useinJmolsuperpos, usetoColourbyseq, jmolColouring, fileloc, rect, vid); } catch (OutOfMemoryError ex) { @@ -2743,11 +2841,28 @@ public class Jalview2XML String pdbFile = (String) filedat[0]; SequenceI[] seq = (SequenceI[]) ((Vector) filedat[2]) .toArray(new SequenceI[0]); - StructureSelectionManager.getStructureSelectionManager() - .setMapping(seq, null, pdbFile, + ((AppJmol) comp).jmb.ssm.setMapping(seq, null, pdbFile, jalview.io.AppletFormatAdapter.FILE); ((AppJmol) comp).jmb.addSequenceForStructFile(pdbFile, seq); } + // and add the AlignmentPanel's reference to the Jmol view + ((AppJmol) comp).addAlignmentPanel(ap); + if (useinJmolsuperpos) + { + ((AppJmol) comp).useAlignmentPanelForSuperposition(ap); + } + else + { + ((AppJmol) comp).excludeAlignmentPanelForSuperposition(ap); + } + if (usetoColourbyseq) + { + ((AppJmol) comp).useAlignmentPanelForColourbyseq(ap, !jmolColouring); + } + else + { + ((AppJmol) comp).excludeAlignmentPanelForColourbyseq(ap); + } } } } @@ -2757,9 +2872,9 @@ public class Jalview2XML } AlignFrame loadViewport(String file, JSeq[] JSEQ, Vector hiddenSeqs, - Alignment al, boolean hideConsensus, boolean hideQuality, - boolean hideConservation, JalviewModelSequence jms, - Viewport view, String uniqueSeqSetId, String viewId) + Alignment al, JalviewModelSequence jms, Viewport view, + String uniqueSeqSetId, String viewId, + ArrayList autoAlan) { AlignFrame af = null; af = new AlignFrame(al, view.getWidth(), view.getHeight(), @@ -2821,27 +2936,6 @@ public class Jalview2XML af.viewport.hideSequence(hseqs); } - // set visibility of annotation in view - if ((hideConsensus || hideQuality || hideConservation) - && al.getAlignmentAnnotation() != null) - { - int hSize = al.getAlignmentAnnotation().length; - for (int h = 0; h < hSize; h++) - { - if ((hideConsensus && al.getAlignmentAnnotation()[h].label - .equals("Consensus")) - || (hideQuality && al.getAlignmentAnnotation()[h].label - .equals("Quality")) - || (hideConservation && al.getAlignmentAnnotation()[h].label - .equals("Conservation"))) - { - al.deleteAnnotation(al.getAlignmentAnnotation()[h]); - hSize--; - h--; - } - } - af.alignPanel.adjustAnnotationHeight(); - } // recover view properties and display parameters if (view.getViewName() != null) { @@ -3145,9 +3239,82 @@ public class Jalview2XML Desktop.addInternalFrame(af, view.getTitle(), view.getWidth(), view.getHeight()); af.alignPanel.updateAnnotation(false); // recompute any autoannotation + reorderAutoannotation(af,al,autoAlan); return af; } + private void reorderAutoannotation(AlignFrame af, Alignment al, + ArrayList 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); + } + int hSize = al.getAlignmentAnnotation().length; + ArrayList reorder = new ArrayList(); + for (int h = 0; h < hSize; h++) + { + jalview.datamodel.AlignmentAnnotation jalan = al + .getAlignmentAnnotation()[h]; + if (jalan.autoCalculated) + { + JvAnnotRow valan = visan.get(jalan.label); + if (valan != null) + { + // delete the auto calculated row from the alignment + al.deleteAnnotation(al.getAlignmentAnnotation()[h],false); + 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)); + } + } + } + } + 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; /**