import jalview.datamodel.AlignmentI;
import jalview.datamodel.PDBEntry;
import jalview.datamodel.SequenceI;
-import jalview.jbgui.GStructureViewer;
import jalview.schemabinding.version2.AlcodMap;
import jalview.schemabinding.version2.Alcodon;
import jalview.schemabinding.version2.AlcodonFrame;
import java.net.URL;
import java.util.ArrayList;
import java.util.Enumeration;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.IdentityHashMap;
import java.util.Iterator;
import java.util.List;
+import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.StringTokenizer;
*/
public class Jalview2XML
{
+
+ private class ViewerData
+ {
+
+ private int x;
+
+ private int y;
+
+ private int width;
+
+ private int height;
+
+ private boolean alignWithPanel;
+
+ private boolean colourWithAlignPanel;
+
+ private boolean colourByViewer;
+
+ private String stateData = "";
+
+ // todo: java bean in place of Object []
+ private Map<File, Object[]> fileData = new HashMap<File, Object[]>();
+
+ public ViewerData(int x, int y, int width, int height,
+ boolean alignWithPanel, boolean colourWithAlignPanel,
+ boolean colourByViewer)
+ {
+ this.x = x;
+ this.y = y;
+ this.width = width;
+ this.height = height;
+ this.alignWithPanel = alignWithPanel;
+ this.colourWithAlignPanel = colourWithAlignPanel;
+ this.colourByViewer = colourByViewer;
+ }
+
+ }
+
+ /*
+ * SequenceI reference -> XML ID string in jalview XML. Populated as XML reps
+ * of sequence objects are created.
+ */
+ IdentityHashMap<SequenceI, String> seqsToIds = null;
+
+ /**
+ * jalview XML Sequence ID to jalview sequence object reference (both dataset
+ * and alignment sequences. Populated as XML reps of sequence objects are
+ * created.)
+ */
+ Map<String, SequenceI> seqRefIds = null;
+
+ Vector frefedSequence = null;
+
+ boolean raiseGUI = true; // whether errors are raised in dialog boxes or not
+
/**
* create/return unique hash string for sq
*
}
if (seqsToIds.containsKey(sq))
{
- return (String) seqsToIds.get(sq);
+ return seqsToIds.get(sq);
}
else
{
{
if (seqsToIds == null)
{
- seqsToIds = new IdentityHashMap();
+ seqsToIds = new IdentityHashMap<SequenceI, String>();
}
if (seqRefIds == null)
{
- seqRefIds = new Hashtable();
+ seqRefIds = new HashMap<String, SequenceI>();
}
}
- /**
- * SequenceI reference -> XML ID string in jalview XML. Populated as XML reps
- * of sequence objects are created.
- */
- java.util.IdentityHashMap seqsToIds = null;
-
- /**
- * jalview XML Sequence ID to jalview sequence object reference (both dataset
- * and alignment sequences. Populated as XML reps of sequence objects are
- * created.)
- */
- java.util.Hashtable seqRefIds = null; // key->SequenceI resolution
-
- Vector frefedSequence = null;
-
- boolean raiseGUI = true; // whether errors are raised in dialog boxes or not
-
public Jalview2XML()
{
}
{
if (ref[1] instanceof jalview.datamodel.Mapping)
{
- SequenceI seq = (SequenceI) seqRefIds.get(sref);
+ SequenceI seq = seqRefIds.get(sref);
while (seq.getDatasetSequence() != null)
{
seq = seq.getDatasetSequence();
{
if (ref[1] instanceof jalview.datamodel.AlignedCodonFrame)
{
- SequenceI seq = (SequenceI) seqRefIds.get(sref);
+ SequenceI seq = seqRefIds.get(sref);
while (seq.getDatasetSequence() != null)
{
seq = seq.getDatasetSequence();
/**
* List of pdbfiles added to Jar
*/
- Vector pdbfiles = null;
+ List<String> pdbfiles = null;
// SAVES SEVERAL ALIGNMENT WINDOWS TO SAME JARFILE
- public void SaveState(File statefile)
+ public void saveState(File statefile)
{
+ FileOutputStream fos = null;
try
{
- FileOutputStream fos = new FileOutputStream(statefile);
+ fos = new FileOutputStream(statefile);
JarOutputStream jout = new JarOutputStream(fos);
- SaveState(jout);
+ saveState(jout);
} catch (Exception e)
{
errorMessage += "(output file was '" + statefile + "')";
}
e.printStackTrace();
+ } finally
+ {
+ if (fos != null)
+ {
+ try
+ {
+ fos.close();
+ } catch (IOException e)
+ {
+ // ignore
+ }
+ }
}
reportErrors();
}
*
* @param jout
*/
- public void SaveState(JarOutputStream jout)
+ public void saveState(JarOutputStream jout)
{
JInternalFrame[] frames = Desktop.desktop.getAllFrames();
// NOTE UTF-8 MUST BE USED FOR WRITING UNICODE CHARS
// //////////////////////////////////////////////////
- // NOTE ALSO new PrintWriter must be used for each new JarEntry
- PrintWriter out = null;
Vector shortNames = new Vector();
fileName = fileName + ".xml";
}
- SaveState(apanel, fileName, jout);
+ saveState(apanel, fileName, jout);
String dssid = getDatasetIdRef(af.getViewport().getAlignment()
.getDataset());
}
// USE THIS METHOD TO SAVE A SINGLE ALIGNMENT WINDOW
- public boolean SaveAlignment(AlignFrame af, String jarFile,
+ public boolean saveAlignment(AlignFrame af, String jarFile,
String fileName)
{
try
{
jfileName = jfileName + ".xml";
}
- SaveState(apanel, jfileName, jout);
+ saveState(apanel, jfileName, jout);
String dssid = getDatasetIdRef(af.getViewport().getAlignment()
.getDataset());
if (!dsses.containsKey(dssid))
{
jfileName = jfileName + ".xml";
}
- SaveState(_af.alignPanel, jfileName, true, jout);
+ saveState(_af.alignPanel, jfileName, true, jout);
}
}
/**
- * create a JalviewModel from an algnment view and marshall it to a
+ * create a JalviewModel from an alignment view and marshall it to a
* JarOutputStream
*
* @param ap
* @param out
* jar entry name
*/
- public JalviewModel SaveState(AlignmentPanel ap, String fileName,
+ public JalviewModel saveState(AlignmentPanel ap, String fileName,
JarOutputStream jout)
{
- return SaveState(ap, fileName, false, jout);
+ return saveState(ap, fileName, false, jout);
}
/**
* @param out
* jar entry name
*/
- public JalviewModel SaveState(AlignmentPanel ap, String fileName,
+ public JalviewModel saveState(AlignmentPanel ap, String fileName,
boolean storeDS, JarOutputStream jout)
{
initSeqRefs();
- List<String> chimeraViewIds = new ArrayList<String>();
List<UserColourScheme> userColours = new ArrayList<UserColourScheme>();
AlignViewport av = ap.av;
pdb.setId(entry.getId());
pdb.setType(entry.getType());
- //
- // store any JMol views associated with this sequence
- // this section copes with duplicate entries in the project, so a
- // dataset only view *should* be coped with sensibly
- List<String> jmolViewIds = new ArrayList<String>();
+
+ /*
+ * Store any JMol or Chimera views associated with this sequence. This
+ * section copes with duplicate entries in the project, so a dataset
+ * only view *should* be coped with sensibly.
+ */
+ List<String> viewIds = new ArrayList<String>();
// This must have been loaded, is it still visible?
JInternalFrame[] frames = Desktop.desktop.getAllFrames();
String matchedFile = null;
for (int f = frames.length - 1; f > -1; f--)
{
- if (frames[f] instanceof GStructureViewer)
+ if (frames[f] instanceof StructureViewerBase)
{
- GStructureViewer viewFrame = (GStructureViewer) frames[f];
+ StructureViewerBase viewFrame = (StructureViewerBase) frames[f];
matchedFile = saveStructureState(ap, jds, pdb, entry,
- jmolViewIds, matchedFile, viewFrame);
+ viewIds, matchedFile, viewFrame);
}
}
pdb.setFile(matchedFile); // entry.getFile());
if (pdbfiles == null)
{
- pdbfiles = new Vector();
+ pdbfiles = new ArrayList<String>();
}
if (!pdbfiles.contains(entry.getId()))
{
- pdbfiles.addElement(entry.getId());
+ pdbfiles.add(entry.getId());
+ DataInputStream dis = null;
try
{
File file = new File(matchedFile);
{
byte[] data = new byte[(int) file.length()];
jout.putNextEntry(new JarEntry(entry.getId()));
- DataInputStream dis = new DataInputStream(
+ dis = new DataInputStream(
new FileInputStream(file));
dis.readFully(data);
} catch (Exception ex)
{
ex.printStackTrace();
+ } finally
+ {
+ if (dis != null)
+ {
+ try
+ {
+ dis.close();
+ } catch (IOException e)
+ {
+ // ignore
+ }
+ }
}
}
if (sg.cs instanceof jalview.schemes.UserColourScheme)
{
- groups[i].setColour(SetUserColourScheme(sg.cs, userColours,
+ groups[i].setColour(setUserColourScheme(sg.cs, userColours,
jms));
}
else
else if (sg.cs instanceof jalview.schemes.UserColourScheme)
{
groups[i]
- .setColour(SetUserColourScheme(sg.cs, userColours, jms));
+ .setColour(setUserColourScheme(sg.cs, userColours, jms));
}
else
{
if (av.getGlobalColourScheme() instanceof jalview.schemes.UserColourScheme)
{
- view.setBgColour(SetUserColourScheme(av.getGlobalColourScheme(),
+ view.setBgColour(setUserColourScheme(av.getGlobalColourScheme(),
userColours, jms));
}
else if (av.getGlobalColourScheme() instanceof jalview.schemes.AnnotationColourGradient)
view.setConsThreshold(cs.getConservationInc());
if (cs instanceof jalview.schemes.UserColourScheme)
{
- view.setBgColour(SetUserColourScheme(cs, userColours, jms));
+ view.setBgColour(setUserColourScheme(cs, userColours, jms));
}
}
}
/**
+ * Save the state of a structure viewer
+ *
* @param ap
* @param jds
* @param pdb
+ * the archive XML element under which to save the state
* @param entry
- * @param jmolViewIds
+ * @param viewIds
* @param matchedFile
* @param viewFrame
* @return
*/
- protected String saveStructureState(AlignmentPanel ap,
- jalview.datamodel.SequenceI jds, Pdbids pdb,
- jalview.datamodel.PDBEntry entry, List<String> jmolViewIds,
- String matchedFile, GStructureViewer viewFrame)
+ protected String saveStructureState(AlignmentPanel ap, SequenceI jds,
+ Pdbids pdb, PDBEntry entry, List<String> viewIds,
+ String matchedFile, StructureViewerBase viewFrame)
{
final AAStructureBindingModel bindingModel = viewFrame
.getBinding();
state.setYpos(viewFrame.getY());
state.setWidth(viewFrame.getWidth());
state.setHeight(viewFrame.getHeight());
- state.setViewId(viewFrame.getViewId());
+ final String viewId = viewFrame.getViewId();
+ state.setViewId(viewId);
state.setAlignwithAlignPanel(viewFrame.isUsedforaligment(ap));
state.setColourwithAlignPanel(viewFrame
.isUsedforcolourby(ap));
state.setColourByJmol(viewFrame.isColouredByViewer());
- if (!jmolViewIds.contains(state.getViewId()))
+ /*
+ * Only store each structure viewer's state once in each XML document.
+ */
+ if (!viewIds.contains(viewId))
{
- // Make sure we only store a Jmol state once in each XML
- // document.
- jmolViewIds.add(state.getViewId());
+ viewIds.add(viewId);
state.setContent(statestring.replaceAll("\n", ""));
}
else
}
pdb.addStructureState(state);
}
-
}
}
return matchedFile;
ac.setAnnotation(acg.getAnnotation());
if (acg.getBaseColour() instanceof jalview.schemes.UserColourScheme)
{
- ac.setColourScheme(SetUserColourScheme(acg.getBaseColour(),
+ ac.setColourScheme(setUserColourScheme(acg.getBaseColour(),
userColours, jms));
}
else
return mp;
}
- String SetUserColourScheme(jalview.schemes.ColourSchemeI cs,
+ String setUserColourScheme(jalview.schemes.ColourSchemeI cs,
List<UserColourScheme> userColours, JalviewModelSequence jms)
{
String id = null;
return id;
}
- jalview.schemes.UserColourScheme GetUserColourScheme(
+ jalview.schemes.UserColourScheme getUserColourScheme(
JalviewModelSequence jms, String id)
{
UserColours[] uc = jms.getUserColours();
* @param file
* - HTTP URL or filename
*/
- public AlignFrame LoadJalviewAlign(final String file)
+ public AlignFrame loadJalviewAlign(final String file)
{
jalview.gui.AlignFrame af = null;
// so we can re-open the jar input stream for each entry.
jarInputStreamProvider jprovider = createjarInputStreamProvider(file);
- af = LoadJalviewAlign(jprovider);
+ af = loadJalviewAlign(jprovider);
} catch (MalformedURLException e)
{
* @param jprovider
* @return
*/
- public AlignFrame LoadJalviewAlign(final jarInputStreamProvider jprovider)
+ public AlignFrame loadJalviewAlign(final jarInputStreamProvider jprovider)
{
errorMessage = null;
if (uniqueSetSuffix == null)
}
if (seqRefIds == null)
{
- seqRefIds = new Hashtable();
+ seqRefIds = new HashMap<String, SequenceI>();
}
if (viewportsAdded == null)
{
object = (JalviewModel) unmar.unmarshal(in);
if (true) // !skipViewport(object))
{
- _af = LoadFromObject(object, file, true, jprovider);
+ _af = loadFromObject(object, file, true, jprovider);
if (object.getJalviewModelSequence().getViewportCount() > 0)
{
af = _af;
* data source provider
* @return alignment frame created from view stored in DOM
*/
- AlignFrame LoadFromObject(JalviewModel object, String file,
+ AlignFrame loadFromObject(JalviewModel object, String file,
boolean loadTreesAndStructures, jarInputStreamProvider jprovider)
{
SequenceSet vamsasSet = object.getVamsasModel().getSequenceSet(0);
boolean multipleView = false;
- JSeq[] JSEQ = object.getJalviewModelSequence().getJSeq();
+ JSeq[] jseqs = object.getJalviewModelSequence().getJSeq();
int vi = 0; // counter in vamsasSeq array
- for (int i = 0; i < JSEQ.length; i++)
+ for (int i = 0; i < jseqs.length; i++)
{
- String seqId = JSEQ[i].getId();
+ String seqId = jseqs[i].getId();
if (seqRefIds.get(seqId) != null)
{
jseq = new jalview.datamodel.Sequence(vamsasSeq[vi].getName(),
vamsasSeq[vi].getSequence());
jseq.setDescription(vamsasSeq[vi].getDescription());
- jseq.setStart(JSEQ[i].getStart());
- jseq.setEnd(JSEQ[i].getEnd());
+ jseq.setStart(jseqs[i].getStart());
+ jseq.setEnd(jseqs[i].getEnd());
jseq.setVamsasId(uniqueSetSuffix + seqId);
seqRefIds.put(vamsasSeq[vi].getId(), jseq);
tmpseqs.add(jseq);
vi++;
}
- if (JSEQ[i].getHidden())
+ if (jseqs[i].getHidden())
{
if (hiddenSeqs == null)
{
// structures for the alignment
for (int i = 0; i < vamsasSeq.length; i++)
{
- if (JSEQ[i].getFeaturesCount() > 0)
+ if (jseqs[i].getFeaturesCount() > 0)
{
- Features[] features = JSEQ[i].getFeatures();
+ Features[] features = jseqs[i].getFeatures();
for (int f = 0; f < features.length; f++)
{
jalview.datamodel.SequenceFeature sf = new jalview.datamodel.SequenceFeature(
{
addDBRefs(al.getSequenceAt(i).getDatasetSequence(), vamsasSeq[i]);
}
- if (JSEQ[i].getPdbidsCount() > 0)
+ if (jseqs[i].getPdbidsCount() > 0)
{
- Pdbids[] ids = JSEQ[i].getPdbids();
+ Pdbids[] ids = jseqs[i].getPdbids();
for (int p = 0; p < ids.length; p++)
{
jalview.datamodel.PDBEntry entry = new jalview.datamodel.PDBEntry();
AlcodMap[] maps = alc[i].getAlcodMap();
for (int m = 0; m < maps.length; m++)
{
- SequenceI dnaseq = (SequenceI) seqRefIds
+ SequenceI dnaseq = seqRefIds
.get(maps[m].getDnasq());
// Load Mapping
jalview.datamodel.Mapping mapping = null;
{
if (groups[i].getColour().startsWith("ucs"))
{
- cs = GetUserColourScheme(jms, groups[i].getColour());
+ cs = getUserColourScheme(jms, groups[i].getColour());
}
else if (groups[i].getColour().equals("AnnotationColourGradient")
&& groups[i].getAnnotationColours() != null)
for (int s = 0; s < groups[i].getSeqCount(); s++)
{
String seqId = groups[i].getSeq(s) + "";
- jalview.datamodel.SequenceI ts = (jalview.datamodel.SequenceI) seqRefIds
+ jalview.datamodel.SequenceI ts = seqRefIds
.get(seqId);
if (ts != null)
if (isnewview)
{
- af = loadViewport(file, JSEQ, hiddenSeqs, al, jms, view,
+ af = loadViewport(file, jseqs, hiddenSeqs, al, jms, view,
uniqueSeqSetId, viewId, autoAlan);
av = af.viewport;
ap = af.alignPanel;
// //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();
+ loadStructures(jprovider, jseqs, af, ap);
+ }
+ // and finally return.
+ return af;
+ }
- for (int i = 0; i < JSEQ.length; i++)
+ /**
+ * Load and link any saved structure viewers.
+ *
+ * @param jprovider
+ * @param jseqs
+ * @param af
+ * @param ap
+ */
+ protected void loadStructures(jarInputStreamProvider jprovider,
+ JSeq[] jseqs, AlignFrame af, AlignmentPanel ap)
+ {
+ // run through all PDB ids on the alignment, and collect mappings between
+ // jmol view ids and all sequences referring to it
+ Map<String, ViewerData> jmolViewIds = new HashMap<String, ViewerData>();
+
+ for (int i = 0; i < jseqs.length; i++)
+ {
+ if (jseqs[i].getPdbidsCount() > 0)
{
- if (JSEQ[i].getPdbidsCount() > 0)
+ Pdbids[] ids = jseqs[i].getPdbids();
+ for (int p = 0; p < ids.length; p++)
{
- Pdbids[] ids = JSEQ[i].getPdbids();
- for (int p = 0; p < ids.length; p++)
+ final int structureStateCount = ids[p].getStructureStateCount();
+ for (int s = 0; s < structureStateCount; s++)
{
- for (int s = 0; s < ids[p].getStructureStateCount(); s++)
+ // check to see if we haven't already created this structure view
+ final StructureState structureState = ids[p].getStructureState(s);
+ String sviewid = (structureState.getViewId() == null) ? null
+ : structureState.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 = structureState.getXpos();
+ int y = structureState.getYpos();
+ int width = structureState.getWidth();
+ int height = structureState.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 = seqRefIds
+ .get(jseqs[i].getId() + "");
+ if (sviewid == null)
{
- // 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
- }
+ sviewid = "_jalview_pre2_4_" + x + "," + y + "," + width
+ + "," + height;
+ }
+ if (!jmolViewIds.containsKey(sviewid))
+ {
+ jmolViewIds.put(sviewid, new ViewerData(x, y, width, height,
+ 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())
+ // assemble String[] { pdb files }, String[] { id for each
+ // file }, orig_fileloc, SequenceI[][] {{ seqs_file 1 }, {
+ // seqs_file 2}, boolean[] {
+ // linkAlignPanel,superposeWithAlignpanel}} from hash
+ ViewerData jmoldat = jmolViewIds.get(sviewid);
+ jmoldat.alignWithPanel |= structureState
+ .hasAlignwithAlignPanel() ? structureState.getAlignwithAlignPanel() : false;
+ // never colour by linked panel if not specified
+ jmoldat.colourWithAlignPanel |= structureState
+ .hasColourwithAlignPanel() ? structureState.getColourwithAlignPanel()
+ : false;
+ // default for pre-2.7 projects is that Jmol colouring is enabled
+ jmoldat.colourByViewer &= structureState
+ .hasColourByJmol() ? structureState
+ .getColourByJmol() : true;
+
+ if (jmoldat.stateData.length() < structureState.getContent()
+ .length())
+ {
{
- {
- jmoldat[1] = ids[p].getStructureState(s).getContent();
- }
+ jmoldat.stateData = structureState.getContent();
}
- if (ids[p].getFile() != null)
+ }
+ if (ids[p].getFile() != null)
+ {
+ File mapkey = new File(ids[p].getFile());
+ Object[] seqstrmaps = jmoldat.fileData.get(mapkey);
+ if (seqstrmaps == 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
- }
+ jmoldat.fileData.put(mapkey,
+ seqstrmaps = new Object[]
+ { pdbFile, ids[p].getId(), new Vector(),
+ new Vector() });
}
- else
+ if (!((Vector) seqstrmaps[2]).contains(seq))
{
- 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);
+ ((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, ViewerData> entry : jmolViewIds.entrySet())
{
+ String sviewid = entry.getKey();
+ ViewerData svattrib = entry.getValue();
+ String state = svattrib.stateData;
+ Map<File, Object[]> oldFiles = svattrib.fileData;
+ final boolean useinJmolsuperpos = svattrib.alignWithPanel;
+ final boolean usetoColourbyseq = svattrib.colourWithAlignPanel;
+ final boolean jmolColouring = svattrib.colourByViewer;
+ int x = svattrib.x;
+ int y = svattrib.y;
+ int width = svattrib.width;
+ int height = svattrib.height;
+ // 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>();
- // Instantiate the associated Jmol views
- for (Entry<String, Object[]> entry : jmolViewIds.entrySet())
+ /*
+ * Search for any Jmol windows already open from other alignment views
+ * that exactly match the stored structure state
+ */
+ AppJmol comp = null;
+ JInternalFrame[] frames = getAllFrames();
+ for (JInternalFrame frame : frames)
{
- 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
+ if (frame instanceof AppJmol)
{
- try
+ /*
+ * Post jalview 2.4 schema includes structure view id
+ */
+ if (sviewid != null
+ && ((StructureViewerBase) frame).getViewId().equals(
+ sviewid))
{
- frames = Desktop.desktop.getAllFrames();
- } catch (ArrayIndexOutOfBoundsException e)
- {
- // occasional No such child exceptions are thrown here...
- frames = null;
- try
- {
- Thread.sleep(10);
- } catch (Exception f)
- {
- }
- ;
+ comp = (AppJmol) frame;
}
- } 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)
+ /*
+ * Otherwise test for matching position and size of viewer frame
+ */
+ else if (frame.getX() == x && frame.getY() == y
+ && frame.getHeight() == height
+ && frame.getWidth() == width)
{
- if (sviewid != null
- && ((GStructureViewer) 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];
- }
+ comp = (AppJmol) frame;
}
}
+ }
- if (comp == null)
+ 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)
{
- // 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)
{
- 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);
+ newFileLoc = new StringBuffer();
}
- if (cp > 0)
+ do
{
- // just append rest of state
- newFileLoc.append(state.substring(cp));
- }
- else
+ // 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())
{
- 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("\"");
+ // 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(";");
}
+ newFileLoc.append(";");
+ }
- if (newFileLoc != null)
+ 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)
{
- 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.contains("e"))
+ if (val.trim().equals("true"))
{
- if (val.trim().equals("true"))
- {
- val = "1";
- }
- else
- {
- val = "0";
- }
- newFileLoc.replace(histbug, diff, val);
+ 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
+ }
+ // 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()
{
- javax.swing.SwingUtilities.invokeAndWait(new Runnable()
+ @Override
+ public void run()
{
- @Override
- public void run()
+ JalviewStructureDisplayI sview = null;
+ try
{
- JalviewStructureDisplayI sview = null;
- try
- {
- // JAL-1333 note - we probably can't migrate Jmol views to UCSF Chimera!
- sview = new StructureViewer(alf.alignPanel.getStructureSelectionManager()).createView(StructureViewer.Viewer.JMOL, pdbf, id, sq, alf.alignPanel,
- useinJmolsuperpos, usetoColourbyseq,
- jmolColouring, fileloc, rect, vid);
- addNewStructureViewer(sview);
- } catch (OutOfMemoryError ex)
+ // JAL-1333 note - we probably can't migrate Jmol views to UCSF Chimera!
+ sview = new StructureViewer(alf.alignPanel
+ .getStructureSelectionManager()).createView(
+ StructureViewer.ViewerType.JMOL, 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())
{
- new OOMWarning("restoring structure view for PDB id "
- + id, (OutOfMemoryError) ex.getCause());
- if (sview != null && sview.isVisible())
- {
- sview.closeViewer();
- sview.setVisible(false);
- sview.dispose();
- }
+ 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.getSsm().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)
+ }
+ });
+ } catch (InvocationTargetException ex)
{
- comp.useAlignmentPanelForColourbyseq(ap, !jmolColouring);
- }
- else
+ warn("Unexpected error when opening Jmol view.", ex);
+
+ } catch (InterruptedException e)
{
- comp.excludeAlignmentPanelForColourbyseq(ap);
+ // e.printStackTrace();
}
}
+
+ }
+ else
+ // if (comp != null)
+ {
+ linkStructureViewer(ap, comp, oldFiles, useinJmolsuperpos,
+ usetoColourbyseq, jmolColouring);
}
}
}
- // and finally return.
- return af;
+ }
+
+ /**
+ * Link an AlignmentPanel to an existing JMol viewer.
+ *
+ * @param ap
+ * @param viewer
+ * @param oldFiles
+ * @param useinJmolsuperpos
+ * @param usetoColourbyseq
+ * @param jmolColouring
+ */
+ protected void linkStructureViewer(AlignmentPanel ap, AppJmol viewer,
+ Map<File, Object[]> oldFiles,
+ final boolean useinJmolsuperpos, final boolean usetoColourbyseq,
+ final boolean jmolColouring)
+ {
+ // 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]);
+ viewer.jmb.getSsm().setMapping(seq, null, pdbFile,
+ jalview.io.AppletFormatAdapter.FILE);
+ viewer.jmb.addSequenceForStructFile(pdbFile, seq);
+ }
+ // and add the AlignmentPanel's reference to the Jmol view
+ viewer.addAlignmentPanel(ap);
+ if (useinJmolsuperpos)
+ {
+ viewer.useAlignmentPanelForSuperposition(ap);
+ }
+ else
+ {
+ viewer.excludeAlignmentPanelForSuperposition(ap);
+ }
+ if (usetoColourbyseq)
+ {
+ viewer.useAlignmentPanelForColourbyseq(ap, !jmolColouring);
+ }
+ else
+ {
+ viewer.excludeAlignmentPanelForColourbyseq(ap);
+ }
+ }
+
+ /**
+ * Get all frames within the Desktop.
+ *
+ * @return
+ */
+ protected JInternalFrame[] getAllFrames()
+ {
+ JInternalFrame[] frames = null;
+ // TODO is this necessary - is it safe - risk of hanging?
+ do
+ {
+ try
+ {
+ frames = Desktop.desktop.getAllFrames();
+ } catch (ArrayIndexOutOfBoundsException e)
+ {
+ // occasional No such child exceptions are thrown here...
+ try
+ {
+ Thread.sleep(10);
+ } catch (InterruptedException f)
+ {
+ }
+ }
+ } while (frames == null);
+ return frames;
}
/**
{
if (view.getBgColour().startsWith("ucs"))
{
- cs = GetUserColourScheme(jms, view.getBgColour());
+ cs = getUserColourScheme(jms, view.getBgColour());
}
else if (view.getBgColour().startsWith("Annotation"))
{
{
cs = new AnnotationColourGradient(
annAlignment.getAlignmentAnnotation()[i],
- GetUserColourScheme(jms,
+ getUserColourScheme(jms,
viewAnnColour.getColourScheme()),
viewAnnColour.getAboveThreshold());
}
return false;
}
- public void AddToSkipList(AlignFrame af)
+ public void addToSkipList(AlignFrame af)
{
if (skipList == null)
{
// need to create or add a new dataset sequence reference to this sequence
if (sqid != null)
{
- dsq = (jalview.datamodel.SequenceI) seqRefIds.get(sqid);
+ dsq = seqRefIds.get(sqid);
}
// check again
if (dsq == null)
/**
* recover from hash
*/
- jmap.setTo((SequenceI) seqRefIds.get(dsfor));
+ jmap.setTo(seqRefIds.get(dsfor));
}
else
{
boolean keepSeqRefs)
{
initSeqRefs();
- jalview.schemabinding.version2.JalviewModel jm = SaveState(ap, null,
+ jalview.schemabinding.version2.JalviewModel jm = saveState(ap, null,
null);
if (!keepSeqRefs)
viewportsAdded = new Hashtable();
- AlignFrame af = LoadFromObject(jm, null, false, null);
+ AlignFrame af = loadFromObject(jm, null, false, null);
af.alignPanels.clear();
af.closeMenuItem_actionPerformed(true);
// register sequence object so the XML parser can recover it.
if (seqRefIds == null)
{
- seqRefIds = new Hashtable();
+ seqRefIds = new HashMap<String, SequenceI>();
}
if (seqsToIds == null)
{
- seqsToIds = new IdentityHashMap();
+ seqsToIds = new IdentityHashMap<SequenceI, String>();
}
- seqRefIds.put(jv2vobj.get(jvobj).toString(), jvobj);
- seqsToIds.put(jvobj, id);
+ seqRefIds.put(jv2vobj.get(jvobj).toString(), (SequenceI) jvobj);
+ seqsToIds.put((SequenceI) jvobj, id);
}
else if (jvobj instanceof jalview.datamodel.AlignmentAnnotation)
{