+ for (int v = 0; v < views.length; v++)
+ {
+ if (views[v].av.getViewId().equalsIgnoreCase(viewId))
+ {
+ // recover the existing alignpanel, alignframe, viewport
+ af = views[v].alignFrame;
+ av = views[v].av;
+ ap = views[v];
+ // TODO: could even skip resetting view settings if we don't want to
+ // change the local settings from other jalview processes
+ isnewview = false;
+ }
+ }
+ }
+ }
+
+ if (isnewview)
+ {
+ af = loadViewport(file, JSEQ, hiddenSeqs, al, jms, view,
+ uniqueSeqSetId, viewId, autoAlan);
+ av = af.viewport;
+ ap = af.alignPanel;
+ }
+ // LOAD TREES
+ // /////////////////////////////////////
+ if (loadTreesAndStructures && jms.getTreeCount() > 0)
+ {
+ try
+ {
+ for (int t = 0; t < jms.getTreeCount(); t++)
+ {
+
+ Tree tree = jms.getTree(t);
+
+ TreePanel tp = (TreePanel) retrieveExistingObj(tree.getId());
+ if (tp == null)
+ {
+ tp = af.ShowNewickTree(
+ new jalview.io.NewickFile(tree.getNewick()),
+ tree.getTitle(), tree.getWidth(), tree.getHeight(),
+ tree.getXpos(), tree.getYpos());
+ if (tree.getId() != null)
+ {
+ // perhaps bind the tree id to something ?
+ }
+ }
+ else
+ {
+ // update local tree attributes ?
+ // TODO: should check if tp has been manipulated by user - if so its
+ // settings shouldn't be modified
+ tp.setTitle(tree.getTitle());
+ tp.setBounds(new Rectangle(tree.getXpos(), tree.getYpos(), tree
+ .getWidth(), tree.getHeight()));
+ tp.av = av; // af.viewport; // TODO: verify 'associate with all
+ // views'
+ // works still
+ tp.treeCanvas.av = av; // af.viewport;
+ tp.treeCanvas.ap = ap; // af.alignPanel;
+
+ }
+ if (tp == null)
+ {
+ warn("There was a problem recovering stored Newick tree: \n"
+ + tree.getNewick());
+ continue;
+ }
+
+ tp.fitToWindow.setState(tree.getFitToWindow());
+ tp.fitToWindow_actionPerformed(null);
+
+ if (tree.getFontName() != null)
+ {
+ tp.setTreeFont(new java.awt.Font(tree.getFontName(), tree
+ .getFontStyle(), tree.getFontSize()));
+ }
+ else
+ {
+ tp.setTreeFont(new java.awt.Font(view.getFontName(), view
+ .getFontStyle(), tree.getFontSize()));
+ }
+
+ tp.showPlaceholders(tree.getMarkUnlinked());
+ tp.showBootstrap(tree.getShowBootstrap());
+ tp.showDistances(tree.getShowDistances());
+
+ tp.treeCanvas.threshold = tree.getThreshold();
+
+ if (tree.getCurrentTree())
+ {
+ af.viewport.setCurrentTree(tp.getTree());
+ }
+ }
+
+ } catch (Exception ex)
+ {
+ ex.printStackTrace();
+ }
+ }
+
+ // //LOAD STRUCTURES
+ if (loadTreesAndStructures)
+ {
+ // run through all PDB ids on the alignment, and collect mappings between
+ // jmol view ids and all sequences referring to it
+ Hashtable<String, Object[]> jmolViewIds = new Hashtable();
+
+ for (int i = 0; i < JSEQ.length; i++)
+ {
+ if (JSEQ[i].getPdbidsCount() > 0)
+ {
+ Pdbids[] ids = JSEQ[i].getPdbids();
+ for (int p = 0; p < ids.length; p++)
+ {
+ for (int s = 0; s < ids[p].getStructureStateCount(); s++)
+ {
+ // check to see if we haven't already created this structure view
+ String sviewid = (ids[p].getStructureState(s).getViewId() == null) ? null
+ : ids[p].getStructureState(s).getViewId()
+ + uniqueSetSuffix;
+ jalview.datamodel.PDBEntry jpdb = new jalview.datamodel.PDBEntry();
+ // Originally : ids[p].getFile()
+ // : TODO: verify external PDB file recovery still works in normal
+ // jalview project load
+ jpdb.setFile(loadPDBFile(jprovider, ids[p].getId()));
+ jpdb.setId(ids[p].getId());
+
+ int x = ids[p].getStructureState(s).getXpos();
+ int y = ids[p].getStructureState(s).getYpos();
+ int width = ids[p].getStructureState(s).getWidth();
+ int height = ids[p].getStructureState(s).getHeight();
+
+ // Probably don't need to do this anymore...
+ // Desktop.desktop.getComponentAt(x, y);
+ // TODO: NOW: check that this recovers the PDB file correctly.
+ String pdbFile = loadPDBFile(jprovider, ids[p].getId());
+ jalview.datamodel.SequenceI seq = (jalview.datamodel.SequenceI) seqRefIds
+ .get(JSEQ[i].getId() + "");
+ if (sviewid == null)
+ {
+ sviewid = "_jalview_pre2_4_" + x + "," + y + "," + width
+ + "," + height;
+ }
+ if (!jmolViewIds.containsKey(sviewid))
+ {
+ jmolViewIds.put(sviewid, new Object[]
+ { new int[]
+ { x, y, width, height }, "",
+ new Hashtable<String, Object[]>(), 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
+ }
+
+ // assemble String[] { pdb files }, String[] { id for each
+ // file }, orig_fileloc, SequenceI[][] {{ seqs_file 1 }, {
+ // seqs_file 2}, boolean[] {
+ // linkAlignPanel,superposeWithAlignpanel}} from hash
+ Object[] jmoldat = 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())
+ {
+ {
+ jmoldat[1] = ids[p].getStructureState(s).getContent();
+ }
+ }
+ if (ids[p].getFile() != null)
+ {
+ File mapkey = new File(ids[p].getFile());
+ Object[] seqstrmaps = (Object[]) ((Hashtable) jmoldat[2])
+ .get(mapkey);
+ if (seqstrmaps == null)
+ {
+ ((Hashtable) jmoldat[2]).put(mapkey,
+ 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
+ }
+ }
+ else
+ {
+ errorMessage = ("The Jmol views in this project were imported\nfrom an older version of Jalview.\nPlease review the sequence colour associations\nin the Colour by section of the Jmol View menu.\n\nIn the case of problems, see note at\nhttp://issues.jalview.org/browse/JAL-747");
+ warn(errorMessage);
+ }
+ }
+ }
+ }
+ }
+ {
+
+ // Instantiate the associated Jmol views
+ for (Entry<String, Object[]> entry : jmolViewIds.entrySet())
+ {
+ String sviewid = entry.getKey();
+ Object[] svattrib = entry.getValue();
+ int[] geom = (int[]) svattrib[0];
+ String state = (String) svattrib[1];
+ Hashtable<File, Object[]> oldFiles = (Hashtable<File, Object[]>) 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<String> pdbfilenames = new Vector<String>();
+ Vector<SequenceI[]> seqmaps = new Vector<SequenceI[]>();
+ Vector<String> pdbids = new Vector<String>();
+
+ // Search to see if we've already created this Jmol view
+ AppJmol comp = null;
+ JInternalFrame[] frames = null;
+ do
+ {
+ try
+ {
+ frames = Desktop.desktop.getAllFrames();
+ } catch (ArrayIndexOutOfBoundsException e)
+ {
+ // occasional No such child exceptions are thrown here...
+ frames = null;
+ try
+ {
+ Thread.sleep(10);
+ } catch (Exception f)
+ {
+ }
+ ;
+ }
+ } while (frames == null);
+ // search for any Jmol windows already open from other
+ // alignment views that exactly match the stored structure state
+ for (int f = 0; comp == null && f < frames.length; f++)
+ {
+ if (frames[f] instanceof AppJmol)
+ {
+ if (sviewid != null
+ && ((AppJmol) frames[f]).getViewId().equals(sviewid))
+ {
+ // post jalview 2.4 schema includes structure view id
+ comp = (AppJmol) frames[f];
+ }
+ else if (frames[f].getX() == x && frames[f].getY() == y
+ && frames[f].getHeight() == height
+ && frames[f].getWidth() == width)
+ {
+ comp = (AppJmol) frames[f];
+ }
+ }
+ }
+
+ if (comp == null)
+ {
+ // create a new Jmol window.
+ // First parse the Jmol state to translate filenames loaded into the
+ // view, and record the order in which files are shown in the Jmol
+ // view, so we can add the sequence mappings in same order.
+ StringBuffer newFileLoc = null;
+ int cp = 0, ncp, ecp;
+ while ((ncp = state.indexOf("load ", cp)) > -1)
+ {
+ if (newFileLoc == null)
+ {
+ newFileLoc = new StringBuffer();
+ }
+ do
+ {
+ // look for next filename in load statement
+ newFileLoc.append(state.substring(cp,
+ ncp = (state.indexOf("\"", ncp + 1) + 1)));
+ String oldfilenam = state.substring(ncp,
+ ecp = state.indexOf("\"", ncp));
+ // recover the new mapping data for this old filename
+ // have to normalize filename - since Jmol and jalview do
+ // filename
+ // translation differently.
+ Object[] filedat = oldFiles.get(new File(oldfilenam));
+ newFileLoc.append(Platform
+ .escapeString((String) filedat[0]));
+ pdbfilenames.addElement((String) filedat[0]);
+ pdbids.addElement((String) filedat[1]);
+ seqmaps.addElement(((Vector<SequenceI>) filedat[2])
+ .toArray(new SequenceI[0]));
+ newFileLoc.append("\"");
+ cp = ecp + 1; // advance beyond last \" and set cursor so we can
+ // look for next file statement.
+ } while ((ncp = state.indexOf("/*file*/", cp)) > -1);
+ }
+ if (cp > 0)
+ {
+ // just append rest of state
+ newFileLoc.append(state.substring(cp));
+ }
+ else
+ {
+ System.err
+ .print("Ignoring incomplete Jmol state for PDB ids: ");
+ newFileLoc = new StringBuffer(state);
+ newFileLoc.append("; load append ");
+ for (File id : oldFiles.keySet())
+ {
+ // add this and any other pdb files that should be present in
+ // the viewer
+ Object[] filedat = oldFiles.get(id);
+ String nfilename;
+ newFileLoc.append(((String) filedat[0]));
+ pdbfilenames.addElement((String) filedat[0]);
+ pdbids.addElement((String) filedat[1]);
+ seqmaps.addElement(((Vector<SequenceI>) filedat[2])
+ .toArray(new SequenceI[0]));
+ newFileLoc.append(" \"");
+ newFileLoc.append((String) filedat[0]);
+ newFileLoc.append("\"");
+
+ }
+ newFileLoc.append(";");
+ }
+
+ if (newFileLoc != null)
+ {
+ int histbug = newFileLoc.indexOf("history = ");
+ histbug += 10;
+ int diff = histbug == -1 ? -1 : newFileLoc.indexOf(";",
+ histbug);
+ String val = (diff == -1) ? null : newFileLoc.substring(
+ histbug, diff);
+ if (val != null && val.length() >= 4)
+ {
+ if (val.contains("e"))
+ {
+ if (val.trim().equals("true"))
+ {
+ val = "1";
+ }
+ else
+ {
+ val = "0";
+ }
+ newFileLoc.replace(histbug, diff, val);
+ }
+ }
+ // TODO: assemble String[] { pdb files }, String[] { id for each
+ // file }, orig_fileloc, SequenceI[][] {{ seqs_file 1 }, {
+ // seqs_file 2}} from hash
+ final String[] pdbf = pdbfilenames
+ .toArray(new String[pdbfilenames.size()]), id = pdbids
+ .toArray(new String[pdbids.size()]);
+ final SequenceI[][] sq = seqmaps
+ .toArray(new SequenceI[seqmaps.size()][]);
+ final String fileloc = newFileLoc.toString(), vid = sviewid;
+ final AlignFrame alf = af;
+ final java.awt.Rectangle rect = new java.awt.Rectangle(x, y,
+ width, height);
+ try
+ {
+ javax.swing.SwingUtilities.invokeAndWait(new Runnable()
+ {
+ @Override
+ public void run()
+ {
+ AppJmol sview = null;
+ try
+ {
+ sview = new AppJmol(pdbf, id, sq, alf.alignPanel,
+ useinJmolsuperpos, usetoColourbyseq,
+ jmolColouring, fileloc, rect, vid);
+ addNewStructureViewer(sview);
+ } catch (OutOfMemoryError ex)
+ {
+ new OOMWarning("restoring structure view for PDB id "
+ + id, (OutOfMemoryError) ex.getCause());
+ if (sview != null && sview.isVisible())
+ {
+ sview.closeViewer();
+ sview.setVisible(false);
+ sview.dispose();
+ }
+ }
+ }
+ });
+ } catch (InvocationTargetException ex)
+ {
+ warn("Unexpected error when opening Jmol view.", ex);
+
+ } catch (InterruptedException e)
+ {
+ // e.printStackTrace();
+ }
+ }
+
+ }
+ else
+ // if (comp != null)
+ {
+ // NOTE: if the jalview project is part of a shared session then
+ // view synchronization should/could be done here.
+
+ // add mapping for sequences in this view to an already open Jmol
+ // instance
+ for (File id : oldFiles.keySet())
+ {
+ // add this and any other pdb files that should be present in the
+ // viewer
+ Object[] filedat = oldFiles.get(id);
+ String pdbFile = (String) filedat[0];
+ SequenceI[] seq = ((Vector<SequenceI>) filedat[2])
+ .toArray(new SequenceI[0]);
+ comp.jmb.ssm.setMapping(seq, null, pdbFile,
+ jalview.io.AppletFormatAdapter.FILE);
+ comp.jmb.addSequenceForStructFile(pdbFile, seq);
+ }
+ // and add the AlignmentPanel's reference to the Jmol view
+ comp.addAlignmentPanel(ap);
+ if (useinJmolsuperpos)
+ {
+ comp.useAlignmentPanelForSuperposition(ap);
+ }
+ else
+ {
+ comp.excludeAlignmentPanelForSuperposition(ap);
+ }
+ if (usetoColourbyseq)
+ {
+ comp.useAlignmentPanelForColourbyseq(ap, !jmolColouring);
+ }
+ else
+ {
+ comp.excludeAlignmentPanelForColourbyseq(ap);
+ }
+ }
+ }
+ }
+ }
+ // and finally return.
+ return af;
+ }
+
+ /**
+ *
+ * @param supported
+ * - minimum version we are comparing against
+ * @param version
+ * - version of data being processsed.
+ * @return true if version is development/null or evaluates to the same or
+ * later X.Y.Z (where X,Y,Z are like [0-9]+b?[0-9]*)
+ */
+ private boolean isVersionStringLaterThan(String supported, String version)
+ {
+ if (version == null || version.equalsIgnoreCase("DEVELOPMENT BUILD")
+ || version.equalsIgnoreCase("Test")
+ || version.equalsIgnoreCase("AUTOMATED BUILD"))
+ {
+ System.err.println("Assuming project file with "
+ + (version == null ? "null" : version)
+ + " is compatible with Jalview version " + supported);
+ return true;
+ }
+ else
+ {
+ StringTokenizer currentV = new StringTokenizer(supported, "."), fileV = new StringTokenizer(
+ version, ".");
+ while (currentV.hasMoreTokens() && fileV.hasMoreTokens())
+ {
+ // convert b to decimal to catch bugfix releases within a series
+ String curT = currentV.nextToken().toLowerCase().replace('b', '.');
+ String fileT = fileV.nextToken().toLowerCase().replace('b', '.');
+ try
+ {
+ if (Float.valueOf(curT) > Float.valueOf(fileT))
+ {
+ // current version is newer than the version that wrote the file
+ return false;
+ }
+ } catch (NumberFormatException nfe)
+ {
+ System.err
+ .println("** WARNING: Version comparison failed for tokens ("
+ + curT
+ + ") and ("
+ + fileT
+ + ")\n** Current: '"
+ + supported + "' and Version: '" + version + "'");
+ }
+ }
+ if (currentV.hasMoreElements())
+ {
+ // fileV has no minor version but identical series to current
+ return false;
+ }
+ }
+ return true;
+ }
+
+ Vector<AppJmol> newStructureViewers = null;
+
+ protected void addNewStructureViewer(AppJmol sview)
+ {
+ if (newStructureViewers != null)
+ {
+ sview.jmb.setFinishedLoadingFromArchive(false);
+ newStructureViewers.add(sview);
+ }
+ }
+
+ protected void setLoadingFinishedForNewStructureViewers()
+ {
+ if (newStructureViewers != null)
+ {
+ for (AppJmol sview : newStructureViewers)
+ {
+ sview.jmb.setFinishedLoadingFromArchive(true);
+ }
+ newStructureViewers.clear();
+ newStructureViewers = null;
+ }
+ }
+
+ AlignFrame loadViewport(String file, JSeq[] JSEQ, Vector hiddenSeqs,
+ Alignment al, JalviewModelSequence jms, Viewport view,
+ String uniqueSeqSetId, String viewId,
+ ArrayList<JvAnnotRow> autoAlan)
+ {
+ AlignFrame af = null;
+ af = new AlignFrame(al, view.getWidth(), view.getHeight(),
+ uniqueSeqSetId, viewId);
+
+ af.setFileName(file, "Jalview");
+
+ for (int i = 0; i < JSEQ.length; i++)
+ {
+ af.viewport.setSequenceColour(af.viewport.getAlignment()
+ .getSequenceAt(i), new java.awt.Color(JSEQ[i].getColour()));
+ }
+
+ af.viewport.gatherViewsHere = view.getGatheredViews();
+
+ if (view.getSequenceSetId() != null)
+ {
+ jalview.gui.AlignViewport av = (jalview.gui.AlignViewport) viewportsAdded
+ .get(uniqueSeqSetId);
+
+ af.viewport.setSequenceSetId(uniqueSeqSetId);
+ if (av != null)
+ {
+ // propagate shared settings to this new view
+ af.viewport.historyList = av.historyList;
+ af.viewport.redoList = av.redoList;
+ }
+ else
+ {
+ viewportsAdded.put(uniqueSeqSetId, af.viewport);
+ }
+ // TODO: check if this method can be called repeatedly without
+ // side-effects if alignpanel already registered.
+ PaintRefresher.Register(af.alignPanel, uniqueSeqSetId);
+ }
+ // apply Hidden regions to view.
+ if (hiddenSeqs != null)
+ {
+ for (int s = 0; s < JSEQ.length; s++)
+ {
+ jalview.datamodel.SequenceGroup hidden = new jalview.datamodel.SequenceGroup();
+
+ for (int r = 0; r < JSEQ[s].getHiddenSequencesCount(); r++)
+ {
+ hidden.addSequence(
+ al.getSequenceAt(JSEQ[s].getHiddenSequences(r)), false);
+ }
+ af.viewport.hideRepSequences(al.getSequenceAt(s), hidden);
+ }
+
+ jalview.datamodel.SequenceI[] hseqs = new jalview.datamodel.SequenceI[hiddenSeqs
+ .size()];
+
+ for (int s = 0; s < hiddenSeqs.size(); s++)
+ {
+ hseqs[s] = (jalview.datamodel.SequenceI) hiddenSeqs.elementAt(s);
+ }
+
+ af.viewport.hideSequence(hseqs);
+
+ }
+ // 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());
+
+ af.viewport.setColourText(view.getShowColourText());
+
+ af.viewport.setConservationSelected(view.getConservationSelected());
+ af.viewport.setShowJVSuffix(view.getShowFullId());
+ af.viewport.rightAlignIds = view.getRightAlignIds();
+ af.viewport.setFont(new java.awt.Font(view.getFontName(), view
+ .getFontStyle(), view.getFontSize()));
+ af.alignPanel.fontChanged();
+ af.viewport.setRenderGaps(view.getRenderGaps());
+ af.viewport.setWrapAlignment(view.getWrapAlignment());
+ af.alignPanel.setWrapAlignment(view.getWrapAlignment());
+ af.viewport.setShowAnnotation(view.getShowAnnotation());
+ af.alignPanel.setAnnotationVisible(view.getShowAnnotation());
+
+ af.viewport.setShowBoxes(view.getShowBoxes());
+
+ af.viewport.setShowText(view.getShowText());
+
+ af.viewport.textColour = new java.awt.Color(view.getTextCol1());
+ af.viewport.textColour2 = new java.awt.Color(view.getTextCol2());
+ af.viewport.thresholdTextColour = view.getTextColThreshold();
+ af.viewport.setShowUnconserved(view.hasShowUnconserved() ? view
+ .isShowUnconserved() : false);
+ af.viewport.setStartRes(view.getStartRes());
+ af.viewport.setStartSeq(view.getStartSeq());
+
+ ColourSchemeI cs = null;
+ // apply colourschemes
+ if (view.getBgColour() != null)
+ {
+ if (view.getBgColour().startsWith("ucs"))
+ {
+ cs = GetUserColourScheme(jms, view.getBgColour());
+ }
+ else if (view.getBgColour().startsWith("Annotation"))
+ {
+ AnnotationColours viewAnnColour = view.getAnnotationColours();
+ cs = constructAnnotationColour(viewAnnColour, af, al, jms, true);
+
+ // annpos
+
+ }
+ else
+ {
+ cs = ColourSchemeProperty.getColour(al, view.getBgColour());
+ }
+
+ if (cs != null)
+ {
+ cs.setThreshold(view.getPidThreshold(), true);
+ cs.setConsensus(af.viewport.getSequenceConsensusHash());
+ }
+ }
+
+ af.viewport.setGlobalColourScheme(cs);
+ af.viewport.setColourAppliesToAllGroups(false);
+
+ if (view.getConservationSelected() && cs != null)
+ {
+ cs.setConservationInc(view.getConsThreshold());
+ }
+
+ af.changeColour(cs);
+
+ af.viewport.setColourAppliesToAllGroups(true);
+
+ if (view.getShowSequenceFeatures())
+ {
+ af.viewport.showSequenceFeatures = true;
+ }
+ if (view.hasCentreColumnLabels())
+ {
+ af.viewport.setCentreColumnLabels(view.getCentreColumnLabels());
+ }
+ if (view.hasIgnoreGapsinConsensus())
+ {
+ af.viewport.setIgnoreGapsConsensus(view.getIgnoreGapsinConsensus(),
+ null);
+ }
+ if (view.hasFollowHighlight())
+ {
+ af.viewport.followHighlight = view.getFollowHighlight();
+ }
+ if (view.hasFollowSelection())
+ {
+ af.viewport.followSelection = view.getFollowSelection();
+ }
+ if (view.hasShowConsensusHistogram())
+ {
+ af.viewport.setShowConsensusHistogram(view
+ .getShowConsensusHistogram());
+ }
+ else
+ {
+ af.viewport.setShowConsensusHistogram(true);
+ }
+ if (view.hasShowSequenceLogo())
+ {
+ af.viewport.setShowSequenceLogo(view.getShowSequenceLogo());
+ }
+ else
+ {
+ af.viewport.setShowSequenceLogo(false);
+ }
+ if (view.hasNormaliseSequenceLogo())
+ {
+ af.viewport.setNormaliseSequenceLogo(view.getNormaliseSequenceLogo());
+ }
+ if (view.hasShowDbRefTooltip())
+ {
+ af.viewport.setShowDbRefs(view.getShowDbRefTooltip());
+ }
+ if (view.hasShowNPfeatureTooltip())
+ {
+ af.viewport.setShowNpFeats(view.hasShowNPfeatureTooltip());
+ }
+ if (view.hasShowGroupConsensus())
+ {
+ af.viewport.setShowGroupConsensus(view.getShowGroupConsensus());
+ }
+ else
+ {
+ af.viewport.setShowGroupConsensus(false);
+ }
+ if (view.hasShowGroupConservation())
+ {
+ af.viewport.setShowGroupConservation(view.getShowGroupConservation());
+ }
+ else
+ {
+ af.viewport.setShowGroupConservation(false);
+ }
+
+ // recover featre settings
+ if (jms.getFeatureSettings() != null)
+ {
+ af.viewport.featuresDisplayed = new Hashtable();
+ String[] renderOrder = new String[jms.getFeatureSettings()
+ .getSettingCount()];
+ for (int fs = 0; fs < jms.getFeatureSettings().getSettingCount(); fs++)
+ {
+ Setting setting = jms.getFeatureSettings().getSetting(fs);
+ if (setting.hasMincolour())
+ {
+ GraduatedColor gc = setting.hasMin() ? new GraduatedColor(
+ new java.awt.Color(setting.getMincolour()),
+ new java.awt.Color(setting.getColour()),
+ setting.getMin(), setting.getMax()) : new GraduatedColor(
+ new java.awt.Color(setting.getMincolour()),
+ new java.awt.Color(setting.getColour()), 0, 1);
+ if (setting.hasThreshold())
+ {
+ gc.setThresh(setting.getThreshold());
+ gc.setThreshType(setting.getThreshstate());
+ }
+ gc.setAutoScaled(true); // default
+ if (setting.hasAutoScale())
+ {
+ gc.setAutoScaled(setting.getAutoScale());
+ }
+ if (setting.hasColourByLabel())
+ {
+ gc.setColourByLabel(setting.getColourByLabel());
+ }
+ // and put in the feature colour table.
+ af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer().setColour(
+ setting.getType(), gc);
+ }
+ else
+ {
+ af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer().setColour(
+ setting.getType(),
+ new java.awt.Color(setting.getColour()));
+ }
+ renderOrder[fs] = setting.getType();
+ if (setting.hasOrder())
+ af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer().setOrder(
+ setting.getType(), setting.getOrder());
+ else
+ af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer().setOrder(
+ setting.getType(),
+ fs / jms.getFeatureSettings().getSettingCount());
+ if (setting.getDisplay())
+ {
+ af.viewport.featuresDisplayed.put(setting.getType(), new Integer(
+ setting.getColour()));
+ }
+ }
+ af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer().renderOrder = renderOrder;
+ Hashtable fgtable;
+ af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer().featureGroups = fgtable = new Hashtable();
+ for (int gs = 0; gs < jms.getFeatureSettings().getGroupCount(); gs++)
+ {
+ Group grp = jms.getFeatureSettings().getGroup(gs);
+ fgtable.put(grp.getName(), new Boolean(grp.getDisplay()));
+ }
+ }
+
+ if (view.getHiddenColumnsCount() > 0)
+ {
+ for (int c = 0; c < view.getHiddenColumnsCount(); c++)
+ {
+ af.viewport.hideColumns(view.getHiddenColumns(c).getStart(), view
+ .getHiddenColumns(c).getEnd() // +1
+ );
+ }
+ }
+ if (view.getCalcIdParam() != null)
+ {
+ for (CalcIdParam calcIdParam : view.getCalcIdParam())
+ {
+ if (calcIdParam != null)
+ {
+ if (recoverCalcIdParam(calcIdParam, af.viewport))
+ {
+ }
+ else
+ {
+ warn("Couldn't recover parameters for "
+ + calcIdParam.getCalcId());
+ }
+ }
+ }
+ }
+ af.setMenusFromViewport(af.viewport);
+ // TODO: we don't need to do this if the viewport is aready visible.
+ Desktop.addInternalFrame(af, view.getTitle(), view.getWidth(),
+ view.getHeight());
+ af.alignPanel.updateAnnotation(false, true); // recompute any autoannotation
+ reorderAutoannotation(af, al, autoAlan);
+ af.alignPanel.alignmentChanged();
+ return af;
+ }
+
+ private ColourSchemeI constructAnnotationColour(
+ AnnotationColours viewAnnColour, AlignFrame af, Alignment 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)
+ {
+ // pre 2.8.1 behaviour
+ // check to see if we should transfer annotation colours
+ propagateAnnColour = true;
+ for (jalview.datamodel.SequenceGroup sg : al.getGroups())
+ {
+ if (sg.cs instanceof AnnotationColourGradient)
+ {
+ propagateAnnColour = false;
+ }
+ }
+ }
+ // int find annotation
+ if (annAlignment.getAlignmentAnnotation() != null)
+ {
+ for (int i = 0; i < annAlignment.getAlignmentAnnotation().length; i++)
+ {
+ if (annAlignment.getAlignmentAnnotation()[i].label
+ .equals(viewAnnColour.getAnnotation()))
+ {
+ 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("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.getColour(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;
+ }
+
+ /*
+ * if (viewAnnColour.getColourScheme().equals("None" )) { sg.cs =
+ * new AnnotationColourGradient(
+ * annAlignment.getAlignmentAnnotation()[i], new
+ * java.awt.Color(viewAnnColour. getMinColour()), new
+ * java.awt.Color(viewAnnColour. getMaxColour()),
+ * viewAnnColour.getAboveThreshold()); } else
+ */
+ {
+ sg.cs = new AnnotationColourGradient(
+ annAlignment.getAlignmentAnnotation()[i], sg.cs,
+ viewAnnColour.getAboveThreshold());
+ if (cs instanceof AnnotationColourGradient)
+ {
+ if (viewAnnColour.hasPerSequence())
+ {
+ ((AnnotationColourGradient) cs)
+ .setSeqAssociated(viewAnnColour.isPerSequence());
+ }
+ if (viewAnnColour.hasPredefinedColours())
+ {
+ ((AnnotationColourGradient) cs)
+ .setPredefinedColours(viewAnnColour
+ .isPredefinedColours());
+ }
+ }
+ }
+
+ }
+ }
+
+ break;
+ }
+
+ }
+ }
+ return cs;
+ }
+
+ private void reorderAutoannotation(AlignFrame af, Alignment al,
+ ArrayList<JvAnnotRow> 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<String, JvAnnotRow> visan = new Hashtable<String, JvAnnotRow>();
+ 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;
+ ArrayList<JvAnnotRow> reorder = new ArrayList<JvAnnotRow>();
+ // 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<String> 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;
+
+ /**
+ * TODO remove this method
+ *
+ * @param view
+ * @return AlignFrame bound to sequenceSetId from view, if one exists. private
+ * AlignFrame getSkippedFrame(Viewport view) { if (skipList==null) {
+ * throw new Error("Implementation Error. No skipList defined for this
+ * Jalview2XML instance."); } return (AlignFrame)
+ * skipList.get(view.getSequenceSetId()); }
+ */
+
+ /**
+ * Check if the Jalview view contained in object should be skipped or not.
+ *
+ * @param object
+ * @return true if view's sequenceSetId is a key in skipList
+ */
+ private boolean skipViewport(JalviewModel object)
+ {
+ if (skipList == null)
+ {
+ return false;
+ }
+ String id;
+ if (skipList.containsKey(id = object.getJalviewModelSequence()
+ .getViewport()[0].getSequenceSetId()))
+ {
+ if (Cache.log != null && Cache.log.isDebugEnabled())
+ {
+ Cache.log.debug("Skipping seuqence set id " + id);
+ }
+ return true;
+ }
+ return false;
+ }
+
+ public void AddToSkipList(AlignFrame af)
+ {
+ if (skipList == null)
+ {
+ skipList = new Hashtable();
+ }
+ skipList.put(af.getViewport().getSequenceSetId(), af);
+ }
+
+ public void clearSkipList()
+ {
+ if (skipList != null)
+ {
+ skipList.clear();
+ skipList = null;
+ }
+ }
+
+ private void recoverDatasetFor(SequenceSet vamsasSet, Alignment al)
+ {
+ jalview.datamodel.Alignment ds = getDatasetFor(vamsasSet.getDatasetId());
+ Vector dseqs = null;
+ if (ds == null)
+ {
+ // create a list of new dataset sequences
+ dseqs = new Vector();
+ }
+ for (int i = 0, iSize = vamsasSet.getSequenceCount(); i < iSize; i++)
+ {
+ Sequence vamsasSeq = vamsasSet.getSequence(i);
+ ensureJalviewDatasetSequence(vamsasSeq, ds, dseqs);
+ }
+ // create a new dataset
+ if (ds == null)
+ {
+ SequenceI[] dsseqs = new SequenceI[dseqs.size()];
+ dseqs.copyInto(dsseqs);
+ ds = new jalview.datamodel.Alignment(dsseqs);
+ debug("Created new dataset " + vamsasSet.getDatasetId()
+ + " for alignment " + System.identityHashCode(al));
+ addDatasetRef(vamsasSet.getDatasetId(), ds);
+ }
+ // set the dataset for the newly imported alignment.
+ if (al.getDataset() == null)
+ {
+ al.setDataset(ds);
+ }
+ }
+
+ /**
+ *
+ * @param vamsasSeq
+ * sequence definition to create/merge dataset sequence for
+ * @param ds
+ * dataset alignment
+ * @param dseqs
+ * vector to add new dataset sequence to
+ */
+ private void ensureJalviewDatasetSequence(Sequence vamsasSeq,
+ AlignmentI ds, Vector dseqs)
+ {
+ // JBP TODO: Check this is called for AlCodonFrames to support recovery of
+ // xRef Codon Maps
+ jalview.datamodel.Sequence sq = (jalview.datamodel.Sequence) seqRefIds
+ .get(vamsasSeq.getId());
+ jalview.datamodel.SequenceI dsq = null;
+ if (sq != null && sq.getDatasetSequence() != null)
+ {
+ dsq = sq.getDatasetSequence();
+ }
+
+ String sqid = vamsasSeq.getDsseqid();
+ if (dsq == null)
+ {
+ // need to create or add a new dataset sequence reference to this sequence
+ if (sqid != null)
+ {
+ dsq = (jalview.datamodel.SequenceI) seqRefIds.get(sqid);
+ }
+ // check again
+ if (dsq == null)
+ {
+ // make a new dataset sequence
+ dsq = sq.createDatasetSequence();
+ if (sqid == null)
+ {
+ // make up a new dataset reference for this sequence
+ sqid = seqHash(dsq);
+ }
+ dsq.setVamsasId(uniqueSetSuffix + sqid);
+ seqRefIds.put(sqid, dsq);
+ if (ds == null)
+ {
+ if (dseqs != null)
+ {
+ dseqs.addElement(dsq);
+ }
+ }
+ else
+ {
+ ds.addSequence(dsq);
+ }