+ else
+ {
+ // defer to later
+ frefedSequence.add(new Object[]
+ { maps[m].getDnasq(), cf, mapping });
+ }
+ }
+ }
+ al.addCodonFrame(cf);
+ }
+
+ }
+
+ // ////////////////////////////////
+ // LOAD ANNOTATIONS
+ boolean hideQuality = true, hideConservation = true, hideConsensus = true;
+ /**
+ * store any annotations which forward reference a group's ID
+ */
+ Hashtable groupAnnotRefs = new Hashtable();
+
+ if (vamsasSet.getAnnotationCount() > 0)
+ {
+ Annotation[] an = vamsasSet.getAnnotation();
+
+ 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;
+ }
+ else if (an[i].getLabel().equals("Consensus"))
+ {
+ hideConsensus = false;
+ continue;
+ }
+ // set visiblity for other annotation in this view
+ if (an[i].getId() != null
+ && annotationIds.containsKey(an[i].getId()))
+ {
+ jalview.datamodel.AlignmentAnnotation jda = (jalview.datamodel.AlignmentAnnotation) annotationIds
+ .get(an[i].getId());
+ // in principle Visible should always be true for annotation displayed
+ // in multiple views
+ if (an[i].hasVisible())
+ jda.visible = an[i].getVisible();
+
+ al.addAnnotation(jda);
+
+ continue;
+ }
+ // Construct new annotation from model.
+ AnnotationElement[] ae = an[i].getAnnotationElement();
+ jalview.datamodel.Annotation[] anot = null;
+
+ 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)
+ continue;
+
+ anot[ae[aa].getPosition()] = new jalview.datamodel.Annotation(
+
+ ae[aa].getDisplayCharacter(), ae[aa].getDescription(),
+ (ae[aa].getSecondaryStructure() == null || ae[aa]
+ .getSecondaryStructure().length() == 0) ? ' '
+ : ae[aa].getSecondaryStructure().charAt(0),
+ ae[aa].getValue()
+
+ );
+ // JBPNote: Consider verifying dataflow for IO of secondary
+ // structure annotation read from Stockholm files
+ // this was added to try to ensure that
+ // if (anot[ae[aa].getPosition()].secondaryStructure>' ')
+ // {
+ // anot[ae[aa].getPosition()].displayCharacter = "";
+ // }
+ anot[ae[aa].getPosition()].colour = new java.awt.Color(
+ ae[aa].getColour());
+ }
+ }
+ jalview.datamodel.AlignmentAnnotation jaa = null;
+
+ if (an[i].getGraph())
+ {
+ jaa = new jalview.datamodel.AlignmentAnnotation(an[i].getLabel(),
+ an[i].getDescription(), anot, 0, 0, an[i].getGraphType());
+
+ jaa.graphGroup = an[i].getGraphGroup();
+
+ if (an[i].getThresholdLine() != null)
+ {
+ jaa.setThreshold(new jalview.datamodel.GraphLine(an[i]
+ .getThresholdLine().getValue(), an[i]
+ .getThresholdLine().getLabel(), new java.awt.Color(
+ an[i].getThresholdLine().getColour())));
+
+ }
+
+ }
+ else
+ {
+ jaa = new jalview.datamodel.AlignmentAnnotation(an[i].getLabel(),
+ an[i].getDescription(), anot);
+ }
+ // register new annotation
+ if (an[i].getId() != null)
+ {
+ 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);
+ }
+
+ if (an[i].hasScore())
+ {
+ jaa.setScore(an[i].getScore());
+ }
+ if (an[i].hasVisible())
+ jaa.visible = an[i].getVisible();
+
+ if (an[i].hasCentreColLabels())
+ jaa.centreColLabels = an[i].getCentreColLabels();
+
+ if (an[i].hasScaleColLabels())
+ {
+ jaa.scaleColLabel = an[i].getScaleColLabels();
+ }
+ if (an[i].hasAutoCalculated() && an[i].isAutoCalculated())
+ {
+ // newer files have an 'autoCalculated' flag and store calculation
+ // state in viewport properties
+ jaa.autoCalculated = true; // means annotation will be marked for
+ // update at end of load.
+ }
+ al.addAnnotation(jaa);
+ }
+ }
+
+ // ///////////////////////
+ // LOAD GROUPS
+ // Create alignment markup and styles for this view
+ if (jms.getJGroupCount() > 0)
+ {
+ JGroup[] groups = jms.getJGroup();
+
+ for (int i = 0; i < groups.length; i++)
+ {
+ ColourSchemeI cs = null;
+
+ if (groups[i].getColour() != null)
+ {
+ if (groups[i].getColour().startsWith("ucs"))
+ {
+ cs = GetUserColourScheme(jms, groups[i].getColour());
+ }
+ else
+ {
+ cs = ColourSchemeProperty.getColour(al, groups[i].getColour());
+ }
+
+ if (cs != null)
+ {
+ cs.setThreshold(groups[i].getPidThreshold(), true);
+ }
+ }
+
+ Vector seqs = new Vector();
+
+ for (int s = 0; s < groups[i].getSeqCount(); s++)
+ {
+ String seqId = groups[i].getSeq(s) + "";
+ jalview.datamodel.SequenceI ts = (jalview.datamodel.SequenceI) seqRefIds
+ .get(seqId);
+
+ if (ts != null)
+ {
+ seqs.addElement(ts);
+ }
+ }
+
+ if (seqs.size() < 1)
+ {
+ continue;
+ }
+
+ jalview.datamodel.SequenceGroup sg = new jalview.datamodel.SequenceGroup(
+ seqs, groups[i].getName(), cs, groups[i].getDisplayBoxes(),
+ groups[i].getDisplayText(), groups[i].getColourText(),
+ groups[i].getStart(), groups[i].getEnd());
+
+ sg.setOutlineColour(new java.awt.Color(groups[i].getOutlineColour()));
+
+ sg.textColour = new java.awt.Color(groups[i].getTextCol1());
+ sg.textColour2 = new java.awt.Color(groups[i].getTextCol2());
+ sg.setShowNonconserved(groups[i].hasShowUnconserved() ? groups[i]
+ .isShowUnconserved() : false);
+ sg.thresholdTextColour = groups[i].getTextColThreshold();
+ if (groups[i].hasShowConsensusHistogram())
+ {
+ sg.setShowConsensusHistogram(groups[i].isShowConsensusHistogram());
+ }
+ ;
+ if (groups[i].hasShowSequenceLogo())
+ {
+ sg.setshowSequenceLogo(groups[i].isShowSequenceLogo());
+ }
+ if (groups[i].hasIgnoreGapsinConsensus())
+ {
+ sg.setIgnoreGapsConsensus(groups[i].getIgnoreGapsinConsensus());
+ }
+ if (groups[i].getConsThreshold() != 0)
+ {
+ jalview.analysis.Conservation c = new jalview.analysis.Conservation(
+ "All", ResidueProperties.propHash, 3,
+ sg.getSequences(null), 0, sg.getWidth() - 1);
+ c.calculate();
+ c.verdict(false, 25);
+ sg.cs.setConservation(c);
+ }
+
+ if (groups[i].getId() != null && groupAnnotRefs.size() > 0)
+ {
+ // re-instate unique group/annotation row reference
+ jalview.datamodel.AlignmentAnnotation jaa = (jalview.datamodel.AlignmentAnnotation) groupAnnotRefs
+ .get(groups[i].getId());
+ if (jaa != null)
+ {
+ jaa.groupRef = sg;
+ }
+ }
+ al.addGroup(sg);
+
+ }
+ }
+
+ // ///////////////////////////////
+ // LOAD VIEWPORT
+
+ // If we just load in the same jar file again, the sequenceSetId
+ // will be the same, and we end up with multiple references
+ // to the same sequenceSet. We must modify this id on load
+ // so that each load of the file gives a unique id
+ String uniqueSeqSetId = view.getSequenceSetId() + uniqueSetSuffix;
+ String viewId = (view.getId() == null ? null : view.getId()
+ + uniqueSetSuffix);
+ AlignFrame af = null;
+ AlignViewport av = null;
+ // now check to see if we really need to create a new viewport.
+ if (multipleView && viewportsAdded.size() == 0)
+ {
+ // We recovered an alignment for which a viewport already exists.
+ // TODO: fix up any settings necessary for overlaying stored state onto
+ // state recovered from another document. (may not be necessary).
+ // we may need a binding from a viewport in memory to one recovered from
+ // XML.
+ // and then recover its containing af to allow the settings to be applied.
+ // TODO: fix for vamsas demo
+ System.err
+ .println("About to recover a viewport for existing alignment: Sequence set ID is "
+ + uniqueSeqSetId);
+ Object seqsetobj = retrieveExistingObj(uniqueSeqSetId);
+ if (seqsetobj != null)
+ {
+ if (seqsetobj instanceof String)
+ {
+ uniqueSeqSetId = (String) seqsetobj;
+ System.err
+ .println("Recovered extant sequence set ID mapping for ID : New Sequence set ID is "
+ + uniqueSeqSetId);
+ }
+ else
+ {
+ System.err
+ .println("Warning : Collision between sequence set ID string and existing jalview object mapping.");
+ }
+
+ }
+ }
+ AlignmentPanel ap = null;
+ boolean isnewview = true;
+ if (viewId != null)
+ {
+ // Check to see if this alignment already has a view id == viewId
+ jalview.gui.AlignmentPanel views[] = Desktop
+ .getAlignmentPanels(uniqueSeqSetId);
+ if (views != null && views.length > 0)
+ {
+ 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, hideConsensus,
+ hideQuality, hideConservation, jms, view, uniqueSeqSetId,
+ viewId);
+ 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[]>() });
+ }
+ // TODO: assemble String[] { pdb files }, String[] { id for each
+ // file }, orig_fileloc, SequenceI[][] {{ seqs_file 1 }, {
+ // seqs_file 2}} from hash
+ Object[] jmoldat = (Object[]) jmolViewIds.get(sviewid);
+ if (((String) jmoldat[1]).length() < ids[p]
+ .getStructureState(s).getContent().length())
+ {
+ {
+ jmoldat[1] = ids[p].getStructureState(s).getContent();
+ }
+ }
+ 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
+ }
+ }
+ }
+ }
+ }
+ {
+
+ // 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<String, Object[]> oldFiles = (Hashtable<String, Object[]>) svattrib[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();
+ }
+ 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)
+ .toString());
+ newFileLoc.append(((String) filedat[0]));
+ pdbfilenames.addElement((String) filedat[0]);
+ pdbids.addElement((String) filedat[1]);
+ seqmaps.addElement((SequenceI[]) ((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.
+ }
+ 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 (String 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((SequenceI[]) ((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 = (String[]) pdbfilenames
+ .toArray(new String[pdbfilenames.size()]), id = (String[]) pdbids
+ .toArray(new String[pdbids.size()]);
+ final SequenceI[][] sq = (SequenceI[][]) 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()
+ {
+ public void run()
+ {
+ AppJmol sview=null;
+ try {
+ sview=new AppJmol(pdbf, id, sq, alf.alignPanel, fileloc,
+
+ rect, vid);
+ }
+ 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 (String 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 = (SequenceI[]) ((Vector<SequenceI>) filedat[2])
+ .toArray(new SequenceI[0]);
+ StructureSelectionManager.getStructureSelectionManager()
+ .setMapping(seq, null, pdbFile,
+ jalview.io.AppletFormatAdapter.FILE);
+ ((AppJmol) comp).jmb.addSequenceForStructFile(pdbFile, seq);
+ }
+ }
+ }
+ }
+ }
+ // and finally return.
+ return af;
+ }
+
+ AlignFrame loadViewport(String file, JSeq[] JSEQ, Vector hiddenSeqs,
+ Alignment al, boolean hideConsensus, boolean hideQuality,
+ boolean hideConservation, JalviewModelSequence jms,
+ Viewport view, String uniqueSeqSetId, String viewId)
+ {
+ 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.alignment.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.sequenceSetID = 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);
+
+ }
+ // 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)
+ {
+ 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"))
+ {
+ // int find annotation
+ if (af.viewport.alignment.getAlignmentAnnotation() != null)
+ {
+ for (int i = 0; i < af.viewport.alignment
+ .getAlignmentAnnotation().length; i++)
+ {
+ if (af.viewport.alignment.getAlignmentAnnotation()[i].label
+ .equals(view.getAnnotationColours().getAnnotation()))
+ {
+ if (af.viewport.alignment.getAlignmentAnnotation()[i]
+ .getThreshold() == null)
+ {
+ af.viewport.alignment.getAlignmentAnnotation()[i]
+ .setThreshold(new jalview.datamodel.GraphLine(view
+ .getAnnotationColours().getThreshold(),
+ "Threshold", java.awt.Color.black)
+
+ );
+ }
+
+ if (view.getAnnotationColours().getColourScheme()
+ .equals("None"))
+ {
+ cs = new AnnotationColourGradient(
+ af.viewport.alignment.getAlignmentAnnotation()[i],
+ new java.awt.Color(view.getAnnotationColours()
+ .getMinColour()), new java.awt.Color(view
+ .getAnnotationColours().getMaxColour()),
+ view.getAnnotationColours().getAboveThreshold());
+ }
+ else if (view.getAnnotationColours().getColourScheme()
+ .startsWith("ucs"))
+ {
+ cs = new AnnotationColourGradient(
+ af.viewport.alignment.getAlignmentAnnotation()[i],
+ GetUserColourScheme(jms, view
+ .getAnnotationColours().getColourScheme()),
+ view.getAnnotationColours().getAboveThreshold());
+ }
+ else
+ {
+ cs = new AnnotationColourGradient(
+ af.viewport.alignment.getAlignmentAnnotation()[i],
+ ColourSchemeProperty.getColour(al, view
+ .getAnnotationColours().getColourScheme()),
+ view.getAnnotationColours().getAboveThreshold());
+ }
+
+ // Also use these settings for all the groups
+ if (al.getGroups() != null)
+ {
+ for (int g = 0; g < al.getGroups().size(); g++)
+ {
+ jalview.datamodel.SequenceGroup sg = (jalview.datamodel.SequenceGroup) al
+ .getGroups().elementAt(g);
+
+ if (sg.cs == null)
+ {
+ continue;
+ }
+
+ /*
+ * if
+ * (view.getAnnotationColours().getColourScheme().equals("None"
+ * )) { sg.cs = new AnnotationColourGradient(
+ * af.viewport.alignment.getAlignmentAnnotation()[i], new
+ * java.awt.Color(view.getAnnotationColours().
+ * getMinColour()), new
+ * java.awt.Color(view.getAnnotationColours().
+ * getMaxColour()),
+ * view.getAnnotationColours().getAboveThreshold()); } else
+ */
+ {
+ sg.cs = new AnnotationColourGradient(
+ af.viewport.alignment.getAlignmentAnnotation()[i],
+ sg.cs, view.getAnnotationColours()
+ .getAboveThreshold());
+ }
+
+ }
+ }
+
+ break;
+ }
+
+ }