*/
package jalview.gui;
+import java.awt.Rectangle;
import java.io.*;
import java.net.*;
import java.util.*;
import org.exolab.castor.xml.*;
import uk.ac.vamsas.objects.utils.MapList;
+import jalview.bin.Cache;
import jalview.datamodel.Alignment;
import jalview.datamodel.AlignmentI;
import jalview.datamodel.SequenceI;
import jalview.schemabinding.version2.*;
import jalview.schemes.*;
import jalview.structure.StructureSelectionManager;
+import jalview.util.jarInputStreamProvider;
/**
* Write out the current jalview desktop state as a Jalview XML stream.
{
// create sequential key
String key = "sq" + (seqsToIds.size() + 1);
+ key = makeHashCode(sq, key); // check we don't have an external reference
+ // for it already.
seqsToIds.put(sq, key);
return key;
}
void clearSeqRefs()
{
- seqRefIds.clear();
- seqsToIds.clear();
+ if (_cleartables)
+ {
+ if (seqRefIds != null)
+ {
+ seqRefIds.clear();
+ }
+ if (seqsToIds != null)
+ {
+ seqsToIds.clear();
+ }
+ // seqRefIds = null;
+ // seqsToIds = null;
+ }
+ else
+ {
+ // do nothing
+ warn("clearSeqRefs called when _cleartables was not set. Doing nothing.");
+ // seqRefIds = new Hashtable();
+ // seqsToIds = new IdentityHashMap();
+ }
}
void initSeqRefs()
}
}
- java.util.IdentityHashMap seqsToIds = null; // SequenceI->key resolution
+ /**
+ * 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;
.println("IMPLEMENTATION ERROR: Unimplemented forward sequence references for "
+ ref[1].getClass() + " type objects.");
}
- frefedSequence.remove(r);
- rSize--;
}
+ frefedSequence.remove(r);
+ rSize--;
}
else
{
}
else
{
+ // empty reference
frefedSequence.remove(r);
rSize--;
}
// SAVES SEVERAL ALIGNMENT WINDOWS TO SAME JARFILE
public void SaveState(File statefile)
{
+ try
+ {
+ FileOutputStream fos = new FileOutputStream(statefile);
+ JarOutputStream jout = new JarOutputStream(fos);
+ SaveState(jout);
+
+ } catch (Exception e)
+ {
+ // TODO: inform user of the problem - they need to know if their data was
+ // not saved !
+ if (errorMessage == null)
+ {
+ errorMessage = "Couldn't write Jalview Archive to output file '"
+ + statefile + "' - See console error log for details";
+ }
+ else
+ {
+ errorMessage += "(output file was '" + statefile + "')";
+ }
+ e.printStackTrace();
+ }
+ reportErrors();
+ }
+
+ /**
+ * Writes a jalview project archive to the given Jar output stream.
+ *
+ * @param jout
+ */
+ public void SaveState(JarOutputStream jout)
+ {
JInternalFrame[] frames = Desktop.desktop.getAllFrames();
if (frames == null)
try
{
- FileOutputStream fos = new FileOutputStream(statefile);
- JarOutputStream jout = new JarOutputStream(fos);
// NOTE UTF-8 MUST BE USED FOR WRITING UNICODE CHARS
// //////////////////////////////////////////////////
if (frames[i] instanceof AlignFrame)
{
AlignFrame af = (AlignFrame) frames[i];
+ // skip ?
+ if (skipList != null
+ && skipList.containsKey(af.getViewport()
+ .getSequenceSetId()))
+ {
+ continue;
+ }
String shortName = af.getTitle();
{
// TODO: inform user of the problem - they need to know if their data was
// not saved !
+ if (errorMessage == null)
+ {
+ errorMessage = "Couldn't write Jalview Archive - see error output for details";
+ }
ex.printStackTrace();
}
}
return true;
} catch (Exception ex)
{
+ errorMessage = "Couldn't Write alignment view to Jalview Archive - see error output for details";
ex.printStackTrace();
return false;
}
if (jal.getDataset() != null)
{
// dataset id is the dataset's hashcode
- vamsasSet.setDatasetId(jal.getDataset().hashCode() + "");
+ vamsasSet.setDatasetId(getDatasetIdRef(jal.getDataset()));
}
if (jal.getProperties() != null)
{
if (frames[f] instanceof AppJmol)
{
jmol = (AppJmol) frames[f];
- if (!jmol.pdbentry.getId().equals(entry.getId()))
+ if (!jmol.pdbentry.getId().equals(entry.getId())
+ && !(entry.getId().length()>4
+ && entry.getId().startsWith(jmol.pdbentry.getId())))
continue;
StructureState state = new StructureState();
state.setYpos(jmol.getY());
state.setWidth(jmol.getWidth());
state.setHeight(jmol.getHeight());
-
+ state.setViewId(jmol.getViewId());
String statestring = jmol.viewer.getStateInfo();
if (state != null)
{
for (int p = 0; p < jac[i].aaWidth; p++)
{
Alcodon cmap = new Alcodon();
- cmap.setPos1(jac[i].codons[p][0]);
- cmap.setPos2(jac[i].codons[p][1]);
- cmap.setPos3(jac[i].codons[p][2]);
+ if (jac[i].codons[p]!=null)
+ {
+ // Null codons indicate a gapped column in the translated peptide alignment.
+ cmap.setPos1(jac[i].codons[p][0]);
+ cmap.setPos2(jac[i].codons[p][1]);
+ cmap.setPos3(jac[i].codons[p][2]);
+ }
alc.addAlcodon(cmap);
}
if (jac[i].getProtMappings() != null
for (int m = 0; m < pmaps.length; m++)
{
AlcodMap alcmap = new AlcodMap();
- alcmap.setDnasq("" + dnas[m].hashCode());
+ alcmap.setDnasq(seqHash(dnas[m]));
alcmap.setMapping(createVamsasMapping(pmaps[m], dnas[m], null,
false));
alc.addAlcodMap(alcmap);
tree.setWidth(tp.getWidth());
tree.setXpos(tp.getX());
tree.setYpos(tp.getY());
-
+ tree.setId(makeHashCode(tp, null));
jms.addTree(tree);
}
}
if (aa[i].sequenceRef != null)
{
+ // TODO later annotation sequenceRef should be the XML ID of the
+ // sequence rather than its display name
an.setSequenceRef(aa[i].sequenceRef.getName());
}
.getGroups().elementAt(i);
groups[i].setStart(sg.getStartRes());
groups[i].setEnd(sg.getEndRes());
- groups[i].setName(sg.getName());
+ groups[i].setName(sg.getName()); // TODO later sequence group should
+ // specify IDs of sequences, not just
+ // names
if (sg.cs != null)
{
if (sg.cs.conservationApplied())
// /////////SAVE VIEWPORT
Viewport view = new Viewport();
view.setTitle(ap.alignFrame.getTitle());
- view.setSequenceSetId(av.getSequenceSetId());
+ view.setSequenceSetId(makeHashCode(av.getSequenceSetId(), av
+ .getSequenceSetId()));
+ view.setId(av.getViewId());
view.setViewName(av.viewName);
view.setGatheredViews(av.gatherViewsHere);
return object;
}
+ /**
+ * External mapping between jalview objects and objects yielding a valid and
+ * unique object ID string. This is null for normal Jalview project IO, but
+ * non-null when a jalview project is being read or written as part of a
+ * vamsas session.
+ */
+ IdentityHashMap jv2vobj = null;
+
+ /**
+ * Construct a unique ID for jvobj using either existing bindings or if none
+ * exist, the result of the hashcode call for the object.
+ *
+ * @param jvobj
+ * jalview data object
+ * @return unique ID for referring to jvobj
+ */
+ private String makeHashCode(Object jvobj, String altCode)
+ {
+ if (jv2vobj != null)
+ {
+ Object id = jv2vobj.get(jvobj);
+ if (id != null)
+ {
+ return id.toString();
+ }
+ // check string ID mappings
+ if (jvids2vobj != null && jvobj instanceof String)
+ {
+ id = jvids2vobj.get(jvobj);
+ }
+ if (id != null)
+ {
+ return id.toString();
+ }
+ // give up and warn that something has gone wrong
+ warn("Cannot find ID for object in external mapping : " + jvobj);
+ }
+ return altCode;
+ }
+
+ /**
+ * return local jalview object mapped to ID, if it exists
+ *
+ * @param idcode
+ * (may be null)
+ * @return null or object bound to idcode
+ */
+ private Object retrieveExistingObj(String idcode)
+ {
+ if (idcode != null && vobj2jv != null)
+ {
+ return vobj2jv.get(idcode);
+ }
+ return null;
+ }
+
+ /**
+ * binding from ID strings from external mapping table to jalview data model
+ * objects.
+ */
+ private Hashtable vobj2jv;
+
private Sequence createVamsasSequence(String id, SequenceI jds)
{
return createVamsasSequence(true, id, jds, null);
else
{
vamsasSeq.setDsseqid(id); // so we can tell which sequences really are
- // dataset sequences only
+ // dataset sequences only
dbrefs = jds.getDBRef();
}
if (dbrefs != null)
}
/**
- * DOCUMENT ME!
+ * contains last error message (if any) encountered by XML loader.
+ */
+ String errorMessage = null;
+
+ /**
+ * flag to control whether the Jalview2XML_V1 parser should be deferred to if
+ * exceptions are raised during project XML parsing
+ */
+ public boolean attemptversion1parse = true;
+
+ /**
+ * Load a jalview project archive from a jar file
*
- * @param file
- * DOCUMENT ME!
+ * @param file -
+ * HTTP URL or filename
*/
public AlignFrame LoadJalviewAlign(final String file)
{
- uniqueSetSuffix = System.currentTimeMillis() % 100000 + "";
jalview.gui.AlignFrame af = null;
- seqRefIds = new Hashtable();
- viewportsAdded = new Hashtable();
- frefedSequence = new Vector();
- Hashtable gatherToThisFrame = new Hashtable();
-
- String errorMessage = null;
-
try
{
// UNMARSHALLER SEEMS TO CLOSE JARINPUTSTREAM, MOST ANNOYING
- URL url = null;
+ // Workaround is to make sure caller implements the JarInputStreamProvider
+ // interface
+ // so we can re-open the jar input stream for each entry.
- if (file.startsWith("http://"))
- {
- url = new URL(file);
- }
+ jarInputStreamProvider jprovider = createjarInputStreamProvider(file);
+ af = LoadJalviewAlign(jprovider);
+ } catch (MalformedURLException e)
+ {
+ errorMessage = "Invalid URL format for '" + file + "'";
+ reportErrors();
+ }
+ return af;
+ }
- JarInputStream jin = null;
- JarEntry jarentry = null;
- int entryCount = 1;
+ private jarInputStreamProvider createjarInputStreamProvider(
+ final String file) throws MalformedURLException
+ {
+ URL url = null;
+ errorMessage = null;
+ uniqueSetSuffix = null;
+ seqRefIds = null;
+ viewportsAdded = null;
+ frefedSequence = null;
- do
+ if (file.startsWith("http://"))
+ {
+ url = new URL(file);
+ }
+ final URL _url = url;
+ return new jarInputStreamProvider()
+ {
+
+ public JarInputStream getJarInputStream() throws IOException
{
- if (url != null)
+ if (_url != null)
{
- jin = new JarInputStream(url.openStream());
+ return new JarInputStream(_url.openStream());
}
else
{
- jin = new JarInputStream(new FileInputStream(file));
+ return new JarInputStream(new FileInputStream(file));
}
+ }
+
+ public String getFilename()
+ {
+ return file;
+ }
+ };
+ }
+
+ /**
+ * Recover jalview session from a jalview project archive. Caller may
+ * initialise uniqueSetSuffix, seqRefIds, viewportsAdded and frefedSequence
+ * themselves. Any null fields will be initialised with default values,
+ * non-null fields are left alone.
+ *
+ * @param jprovider
+ * @return
+ */
+ public AlignFrame LoadJalviewAlign(final jarInputStreamProvider jprovider)
+ {
+ errorMessage = null;
+ if (uniqueSetSuffix == null)
+ {
+ uniqueSetSuffix = System.currentTimeMillis() % 100000 + "";
+ }
+ if (seqRefIds == null)
+ {
+ seqRefIds = new Hashtable();
+ }
+ if (viewportsAdded == null)
+ {
+ viewportsAdded = new Hashtable();
+ }
+ if (frefedSequence == null)
+ {
+ frefedSequence = new Vector();
+ }
+
+ jalview.gui.AlignFrame af = null;
+ Hashtable gatherToThisFrame = new Hashtable();
+ final String file = jprovider.getFilename();
+ try
+ {
+ JarInputStream jin = null;
+ JarEntry jarentry = null;
+ int entryCount = 1;
+ do
+ {
+ jin = jprovider.getJarInputStream();
for (int i = 0; i < entryCount; i++)
{
jarentry = jin.getNextJarEntry();
Unmarshaller unmar = new Unmarshaller(object);
unmar.setValidation(false);
object = (JalviewModel) unmar.unmarshal(in);
-
- af = LoadFromObject(object, file, true);
- if (af.viewport.gatherViewsHere)
+ if (true) // !skipViewport(object))
{
- gatherToThisFrame.put(af.viewport.getSequenceSetId(), af);
+ af = LoadFromObject(object, file, true, jprovider);
+ if (af.viewport.gatherViewsHere)
+ {
+ gatherToThisFrame.put(af.viewport.getSequenceSetId(), af);
+ }
}
entryCount++;
}
{
System.err.println("Parsing as Jalview Version 2 file failed.");
ex.printStackTrace(System.err);
-
- // Is Version 1 Jar file?
- try
+ if (attemptversion1parse)
{
- af = new Jalview2XML_V1(raiseGUI).LoadJalviewAlign(file);
- } catch (Exception ex2)
- {
- System.err.println("Exception whilst loading as jalviewXMLV1:");
- ex2.printStackTrace();
- af = null;
+ // Is Version 1 Jar file?
+ try
+ {
+ af = new Jalview2XML_V1(raiseGUI).LoadJalviewAlign(jprovider);
+ } catch (Exception ex2)
+ {
+ System.err.println("Exception whilst loading as jalviewXMLV1:");
+ ex2.printStackTrace();
+ af = null;
+ }
}
-
if (Desktop.instance != null)
{
Desktop.instance.stopLoading();
System.err.println("Exception whilst loading jalview XML file : "
+ ex + "\n");
+ } catch (OutOfMemoryError e)
+ {
+ new jalview.gui.OOMWarning("loading jalview XML file", e,
+ Desktop.instance);
}
if (Desktop.instance != null)
{
Desktop.instance.gatherViews((AlignFrame) en.nextElement());
}
+ if (errorMessage != null)
+ {
+ reportErrors();
+ }
+ return af;
+ }
+
+ /**
+ * check errorMessage for a valid error message and raise an error box in the
+ * GUI or write the current errorMessage to stderr and then clear the error
+ * state.
+ */
+ protected void reportErrors()
+ {
+ reportErrors(false);
+ }
+ protected void reportErrors(final boolean saving)
+ {
if (errorMessage != null)
{
final String finalErrorMessage = errorMessage;
public void run()
{
JOptionPane.showInternalMessageDialog(Desktop.desktop,
- finalErrorMessage, "Error loading Jalview file",
- JOptionPane.WARNING_MESSAGE);
+ finalErrorMessage, "Error "
+ + (saving ? "saving" : "loading")
+ + " Jalview file", JOptionPane.WARNING_MESSAGE);
}
});
}
System.err.println("Problem loading Jalview file: " + errorMessage);
}
}
-
- return af;
+ errorMessage = null;
}
Hashtable alreadyLoadedPDB;
- String loadPDBFile(String file, String pdbId)
+ /**
+ * when set, local views will be updated from view stored in JalviewXML
+ * Currently (28th Sep 2008) things will go horribly wrong in vamsas document
+ * sync if this is set to true.
+ */
+ private boolean updateLocalViews = false;
+
+ String loadPDBFile(jarInputStreamProvider jprovider, String pdbId)
{
if (alreadyLoadedPDB == null)
alreadyLoadedPDB = new Hashtable();
try
{
- JarInputStream jin = null;
-
- if (file.startsWith("http://"))
- {
- jin = new JarInputStream(new URL(file).openStream());
- }
- else
- {
- jin = new JarInputStream(new FileInputStream(file));
- }
+ JarInputStream jin = jprovider.getJarInputStream();
+ /*
+ * if (jprovider.startsWith("http://")) { jin = new JarInputStream(new
+ * URL(jprovider).openStream()); } else { jin = new JarInputStream(new
+ * FileInputStream(jprovider)); }
+ */
JarEntry entry = null;
do
{
entry = jin.getNextJarEntry();
- } while (!entry.getName().equals(pdbId));
+ } while (entry != null && !entry.getName().equals(pdbId));
+ if (entry != null)
+ {
+ BufferedReader in = new BufferedReader(new InputStreamReader(jin));
+ File outFile = File.createTempFile("jalview_pdb", ".txt");
+ outFile.deleteOnExit();
+ PrintWriter out = new PrintWriter(new FileOutputStream(outFile));
+ String data;
- BufferedReader in = new BufferedReader(new InputStreamReader(jin));
- File outFile = File.createTempFile("jalview_pdb", ".txt");
- outFile.deleteOnExit();
- PrintWriter out = new PrintWriter(new FileOutputStream(outFile));
- String data;
+ while ((data = in.readLine()) != null)
+ {
+ out.println(data);
+ }
+ try
+ {
+ out.flush();
+ } catch (Exception foo)
+ {
+ }
+ ;
+ out.close();
- while ((data = in.readLine()) != null)
- {
- out.println(data);
+ alreadyLoadedPDB.put(pdbId, outFile.getAbsolutePath());
+ return outFile.getAbsolutePath();
}
- try
- {
- out.flush();
- } catch (Exception foo)
+ else
{
+ warn("Couldn't find PDB file entry in Jalview Jar for " + pdbId);
}
- ;
- out.close();
-
- alreadyLoadedPDB.put(pdbId, outFile.getAbsolutePath());
- return outFile.getAbsolutePath();
-
} catch (Exception ex)
{
ex.printStackTrace();
return null;
}
+ /**
+ * Load alignment frame from jalview XML DOM object
+ *
+ * @param object
+ * DOM
+ * @param file
+ * filename source string
+ * @param loadTreesAndStructures
+ * when false only create Viewport
+ * @param jprovider
+ * data source provider
+ * @return alignment frame created from view stored in DOM
+ */
AlignFrame LoadFromObject(JalviewModel object, String file,
- boolean loadTreesAndStructures)
+ boolean loadTreesAndStructures, jarInputStreamProvider jprovider)
{
SequenceSet vamsasSet = object.getVamsasModel().getSequenceSet(0);
Sequence[] vamsasSeq = vamsasSet.getSequence();
JalviewModelSequence jms = object.getJalviewModelSequence();
Viewport view = jms.getViewport(0);
-
// ////////////////////////////////
// LOAD SEQUENCES
int vi = 0; // counter in vamsasSeq array
for (int i = 0; i < JSEQ.length; i++)
{
- String seqId = JSEQ[i].getId() + "";
+ String seqId = JSEQ[i].getId();
if (seqRefIds.get(seqId) != null)
{
jseq.setStart(JSEQ[i].getStart());
jseq.setEnd(JSEQ[i].getEnd());
jseq.setVamsasId(uniqueSetSuffix + seqId);
- seqRefIds.put(vamsasSeq[vi].getId() + "", jseq);
+ seqRefIds.put(vamsasSeq[vi].getId(), jseq);
tmpseqs.add(jseq);
vi++;
}
Hashtable pdbloaded = new Hashtable();
if (!multipleView)
{
+ // load sequence features, database references and any associated PDB
+ // structures for the alignment
for (int i = 0; i < vamsasSeq.length; i++)
{
if (JSEQ[i].getFeaturesCount() > 0)
{
if (!pdbloaded.containsKey(ids[p].getFile()))
{
- entry.setFile(loadPDBFile(file, ids[p].getId()));
+ entry.setFile(loadPDBFile(jprovider, ids[p].getId()));
}
else
{
}
}
}
- }
+ } // end !multipleview
// ///////////////////////////////
// LOAD SEQUENCE MAPPINGS
+
if (vamsasSet.getAlcodonFrameCount() > 0)
{
+ // TODO Potentially this should only be done once for all views of an
+ // alignment
AlcodonFrame[] alc = vamsasSet.getAlcodonFrame();
for (int i = 0; i < alc.length; i++)
{
Alcodon[] alcods = alc[i].getAlcodon();
for (int p = 0; p < cf.codons.length; p++)
{
- cf.codons[p] = new int[3];
- cf.codons[p][0] = (int) alcods[p].getPos1();
- cf.codons[p][1] = (int) alcods[p].getPos2();
- cf.codons[p][2] = (int) alcods[p].getPos3();
+ if (alcods[p].hasPos1() && alcods[p].hasPos2() && alcods[p].hasPos3())
+ {
+ // translated codons require three valid positions
+ cf.codons[p] = new int[3];
+ cf.codons[p][0] = (int) alcods[p].getPos1();
+ cf.codons[p][1] = (int) alcods[p].getPos2();
+ cf.codons[p][2] = (int) alcods[p].getPos3();
+ } else {
+ cf.codons[p] = null;
+ }
}
}
if (alc[i].getAlcodMapCount() > 0)
for (int i = 0; i < an.length; i++)
{
+ // set visibility for automatic annotation for this view
if (an[i].getLabel().equals("Quality"))
{
hideQuality = false;
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();
continue;
}
-
+ // Construct new annotation from model.
AnnotationElement[] ae = an[i].getAnnotationElement();
jalview.datamodel.Annotation[] anot = null;
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)
// ///////////////////////
// LOAD GROUPS
+ // Create alignment markup and styles for this view
if (jms.getJGroupCount() > 0)
{
JGroup[] groups = jms.getJGroup();
// ///////////////////////////////
// LOAD VIEWPORT
- AlignFrame af = new AlignFrame(al, view.getWidth(), view.getHeight());
-
- 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()));
- }
-
// 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.");
+ }
- 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)
- {
-
- af.viewport.historyList = av.historyList;
- af.viewport.redoList = av.redoList;
- }
- else
- {
- viewportsAdded.put(uniqueSeqSetId, af.viewport);
}
-
- PaintRefresher.Register(af.alignPanel, uniqueSeqSetId);
}
- if (hiddenSeqs != null)
+ AlignmentPanel ap = null;
+ boolean isnewview = true;
+ if (viewId != null)
{
- for (int s = 0; s < JSEQ.length; s++)
+ // 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)
{
- jalview.datamodel.SequenceGroup hidden = new jalview.datamodel.SequenceGroup();
-
- for (int r = 0; r < JSEQ[s].getHiddenSequencesCount(); r++)
+ for (int v = 0; v < views.length; v++)
{
- hidden.addSequence(al
- .getSequenceAt(JSEQ[s].getHiddenSequences(r)), false);
+ 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;
+ }
}
- 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++)
+ 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
{
- hseqs[s] = (jalview.datamodel.SequenceI) hiddenSeqs.elementAt(s);
- }
+ for (int t = 0; t < jms.getTreeCount(); t++)
+ {
- af.viewport.hideSequence(hseqs);
+ 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)
+ {
- if ((hideConsensus || hideQuality || hideConservation)
+ }
+ }
+ else
+ {
+ // update local tree attributes ?
+ 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;
+
+ }
+
+ 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)
+ {
+ 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();
+ 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];
+ }
+ }
+ }
+ Desktop.desktop.getComponentAt(x, y);
+
+ String pdbFile = loadPDBFile(jprovider, ids[p].getId());
+
+ jalview.datamodel.SequenceI[] seq = new jalview.datamodel.SequenceI[]
+ { (jalview.datamodel.SequenceI) seqRefIds.get(JSEQ[i].getId()
+ + "") };
+
+ if (comp == null)
+ {
+ // create a new Jmol window
+ String state = ids[p].getStructureState(s).getContent();
+
+ StringBuffer newFileLoc = new StringBuffer(state.substring(
+ 0, state.indexOf("\"", state.indexOf("load")) + 1));
+
+ newFileLoc.append(jpdb.getFile());
+ newFileLoc.append(state.substring(state.indexOf("\"", state
+ .indexOf("load \"") + 6)));
+
+ new AppJmol(pdbFile, ids[p].getId(), seq, af.alignPanel,
+ newFileLoc.toString(), new java.awt.Rectangle(x, y,
+ width, height), sviewid);
+
+ }
+ 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 this sequence to the already open Jmol
+ // instance (if it doesn't already exist)
+ // These
+ StructureSelectionManager.getStructureSelectionManager()
+ .setMapping(seq, null, pdbFile,
+ jalview.io.AppletFormatAdapter.FILE);
+
+ ((AppJmol) comp).addSequence(seq);
+ }
+ }
+ }
+ }
+ }
+ }
+
+ 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;
}
af.alignPanel.adjustAnnotationHeight();
}
-
+ // recover view properties and display parameters
if (view.getViewName() != null)
{
af.viewport.viewName = view.getViewName();
af.viewport.setStartSeq(view.getStartSeq());
ColourSchemeI cs = null;
-
+ // apply colourschemes
if (view.getBgColour() != null)
{
if (view.getBgColour().startsWith("ucs"))
{
af.viewport.showSequenceFeatures = true;
}
-
+ // recover featre settings
if (jms.getFeatureSettings() != null)
{
af.viewport.featuresDisplayed = new Hashtable();
}
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());
+ return af;
+ }
- // LOAD TREES
- // /////////////////////////////////////
- if (loadTreesAndStructures && jms.getTreeCount() > 0)
- {
- try
- {
- for (int t = 0; t < jms.getTreeCount(); t++)
- {
-
- Tree tree = jms.getTree(t);
-
- TreePanel tp = af.ShowNewickTree(new jalview.io.NewickFile(tree
- .getNewick()), tree.getTitle(), tree.getWidth(), tree
- .getHeight(), tree.getXpos(), tree.getYpos());
-
- 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();
+ Hashtable skipList = null;
- if (tree.getCurrentTree())
- {
- af.viewport.setCurrentTree(tp.getTree());
- }
- }
+ /**
+ * 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()); }
+ */
- } catch (Exception ex)
+ /**
+ * 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())
{
- ex.printStackTrace();
+ Cache.log.debug("Skipping seuqence set id " + id);
}
+ return true;
}
+ return false;
+ }
- // //LOAD STRUCTURES
- if (loadTreesAndStructures)
+ public void AddToSkipList(AlignFrame af)
+ {
+ if (skipList == null)
{
- 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++)
- {
- jalview.datamodel.PDBEntry jpdb = new jalview.datamodel.PDBEntry();
-
- jpdb.setFile(loadPDBFile(ids[p].getFile(), 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();
-
- java.awt.Component 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);
- for (int f = 0; f < frames.length; f++)
- {
- if (frames[f] instanceof AppJmol)
- {
- if (frames[f].getX() == x && frames[f].getY() == y
- && frames[f].getHeight() == height
- && frames[f].getWidth() == width)
- {
- comp = frames[f];
- break;
- }
- }
- }
-
- Desktop.desktop.getComponentAt(x, y);
-
- String pdbFile = loadPDBFile(file, ids[p].getId());
-
- jalview.datamodel.SequenceI[] seq = new jalview.datamodel.SequenceI[]
- { (jalview.datamodel.SequenceI) seqRefIds.get(JSEQ[i].getId()
- + "") };
-
- if (comp == null)
- {
- String state = ids[p].getStructureState(s).getContent();
-
- StringBuffer newFileLoc = new StringBuffer(state.substring(
- 0, state.indexOf("\"", state.indexOf("load")) + 1));
-
- newFileLoc.append(jpdb.getFile());
- newFileLoc.append(state.substring(state.indexOf("\"", state
- .indexOf("load \"") + 6)));
-
- new AppJmol(pdbFile, ids[p].getId(), seq, af.alignPanel,
- newFileLoc.toString(), new java.awt.Rectangle(x, y,
- width, height));
-
- }
- else if (comp != null)
- {
- StructureSelectionManager.getStructureSelectionManager()
- .setMapping(seq, null, pdbFile,
- jalview.io.AppletFormatAdapter.FILE);
-
- ((AppJmol) comp).addSequence(seq);
- }
- }
- }
- }
- }
+ skipList = new Hashtable();
}
+ skipList.put(af.getViewport().getSequenceSetId(), af);
+ }
- return af;
+ public void clearSkipList()
+ {
+ if (skipList != null)
+ {
+ skipList.clear();
+ skipList = null;
+ }
}
private void recoverDatasetFor(SequenceSet vamsasSet, Alignment al)
}
java.util.Hashtable datasetIds = null;
-
+ java.util.IdentityHashMap dataset2Ids = null;
private Alignment getDatasetFor(String datasetId)
{
if (datasetIds == null)
}
datasetIds.put(datasetId, dataset);
}
-
+ /**
+ * make a new dataset ID for this jalview dataset alignment
+ * @param dataset
+ * @return
+ */
+ private String getDatasetIdRef(jalview.datamodel.Alignment dataset)
+ {
+ if (dataset.getDataset()!=null)
+ {
+ warn("Serious issue! Dataset Object passed to getDatasetIdRef is not a Jalview DATASET alignment...");
+ }
+ String datasetId=makeHashCode(dataset, null);
+ if (datasetId==null)
+ {
+ // make a new datasetId and record it
+ if (dataset2Ids == null)
+ {
+ dataset2Ids = new IdentityHashMap();
+ } else {
+ datasetId = (String) dataset2Ids.get(dataset);
+ }
+ if (datasetId==null)
+ {
+ datasetId = "ds"+dataset2Ids.size()+1;
+ dataset2Ids.put(dataset,datasetId);
+ }
+ }
+ return datasetId;
+ }
private void addDBRefs(SequenceI datasetSequence, Sequence sequence)
{
for (int d = 0; d < sequence.getDBRefCount(); d++)
MappingChoice mc = m.getMappingChoice();
if (mc.getDseqFor() != null)
{
- if (seqRefIds.containsKey(mc.getDseqFor()))
+ String dsfor = ""+mc.getDseqFor();
+ if (seqRefIds.containsKey(dsfor))
{
/**
* recover from hash
*/
- jmap.setTo((SequenceI) seqRefIds.get(mc.getDseqFor()));
+ jmap.setTo((SequenceI) seqRefIds.get(dsfor));
}
else
{
frefedSequence.add(new Object[]
- { mc.getDseqFor(), jmap });
+ { dsfor, jmap });
}
}
else
System.err
.println("Warning - making up dataset sequence id for DbRef sequence map reference");
sqid = ((Object) ms).toString(); // make up a new hascode for
- // undefined dataset sequence hash
- // (unlikely to happen)
+ // undefined dataset sequence hash
+ // (unlikely to happen)
}
if (djs == null)
public jalview.gui.AlignmentPanel copyAlignPanel(AlignmentPanel ap,
boolean keepSeqRefs)
{
+ initSeqRefs();
jalview.schemabinding.version2.JalviewModel jm = SaveState(ap, null,
null);
else
{
uniqueSetSuffix = "";
+ jm.getJalviewModelSequence().getViewport(0).setId(null); // we don't overwrite the view we just copied
+ }
+ if (this.frefedSequence==null)
+ {
+ frefedSequence = new Vector();
}
viewportsAdded = new Hashtable();
- AlignFrame af = LoadFromObject(jm, null, false);
+ AlignFrame af = LoadFromObject(jm, null, false, null);
af.alignPanels.clear();
af.closeMenuItem_actionPerformed(true);
return af.alignPanel;
}
+ /**
+ * flag indicating if hashtables should be cleared on finalization TODO this
+ * flag may not be necessary
+ */
+ private boolean _cleartables = true;
+
+ private Hashtable jvids2vobj;
+
/*
* (non-Javadoc)
*
protected void finalize() throws Throwable
{
// really make sure we have no buried refs left.
- clearSeqRefs();
+ if (_cleartables)
+ {
+ clearSeqRefs();
+ }
this.seqRefIds = null;
this.seqsToIds = null;
super.finalize();
}
+ private void warn(String msg)
+ {
+ warn(msg, null);
+ }
+
+ private void warn(String msg, Exception e)
+ {
+ if (Cache.log != null)
+ {
+ if (e != null)
+ {
+ Cache.log.warn(msg, e);
+ }
+ else
+ {
+ Cache.log.warn(msg);
+ }
+ }
+ else
+ {
+ System.err.println("Warning: " + msg);
+ if (e != null)
+ {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ /**
+ * set the object to ID mapping tables used to write/recover objects and XML
+ * ID strings for the jalview project. If external tables are provided then
+ * finalize and clearSeqRefs will not clear the tables when the Jalview2XML
+ * object goes out of scope. - also populates the datasetIds hashtable with
+ * alignment objects containing dataset sequences
+ *
+ * @param vobj2jv
+ * Map from ID strings to jalview datamodel
+ * @param jv2vobj
+ * Map from jalview datamodel to ID strings
+ *
+ *
+ */
+ public void setObjectMappingTables(Hashtable vobj2jv,
+ IdentityHashMap jv2vobj)
+ {
+ this.jv2vobj = jv2vobj;
+ this.vobj2jv = vobj2jv;
+ Iterator ds = jv2vobj.keySet().iterator();
+ String id;
+ while (ds.hasNext())
+ {
+ Object jvobj = ds.next();
+ id = jv2vobj.get(jvobj).toString();
+ if (jvobj instanceof jalview.datamodel.Alignment)
+ {
+ if (((jalview.datamodel.Alignment) jvobj).getDataset() == null)
+ {
+ addDatasetRef(id, (jalview.datamodel.Alignment) jvobj);
+ }
+ }
+ else if (jvobj instanceof jalview.datamodel.Sequence)
+ {
+ // register sequence object so the XML parser can recover it.
+ if (seqRefIds == null)
+ {
+ seqRefIds = new Hashtable();
+ }
+ if (seqsToIds == null)
+ {
+ seqsToIds = new IdentityHashMap();
+ }
+ seqRefIds.put(jv2vobj.get(jvobj).toString(), jvobj);
+ seqsToIds.put(jvobj, id);
+ }
+ else if (jvobj instanceof jalview.datamodel.AlignmentAnnotation)
+ {
+ if (annotationIds == null)
+ {
+ annotationIds = new Hashtable();
+ }
+ String anid;
+ annotationIds.put(anid = jv2vobj.get(jvobj).toString(), jvobj);
+ jalview.datamodel.AlignmentAnnotation jvann = (jalview.datamodel.AlignmentAnnotation) jvobj;
+ if (jvann.annotationId == null)
+ {
+ jvann.annotationId = anid;
+ }
+ if (!jvann.annotationId.equals(anid))
+ {
+ // TODO verify that this is the correct behaviour
+ this.warn("Overriding Annotation ID for " + anid
+ + " from different id : " + jvann.annotationId);
+ jvann.annotationId = anid;
+ }
+ }
+ else if (jvobj instanceof String)
+ {
+ if (jvids2vobj == null)
+ {
+ jvids2vobj = new Hashtable();
+ jvids2vobj.put(jvobj, jv2vobj.get(jvobj).toString());
+ }
+ }
+ else
+ Cache.log.debug("Ignoring " + jvobj.getClass() + " (ID = " + id);
+ }
+ }
+
+ /**
+ * set the uniqueSetSuffix used to prefix/suffix object IDs for jalview
+ * objects created from the project archive. If string is null (default for
+ * construction) then suffix will be set automatically.
+ *
+ * @param string
+ */
+ public void setUniqueSetSuffix(String string)
+ {
+ uniqueSetSuffix = string;
+
+ }
+
+ /**
+ * uses skipList2 as the skipList for skipping views on sequence sets
+ * associated with keys in the skipList
+ *
+ * @param skipList2
+ */
+ public void setSkipList(Hashtable skipList2)
+ {
+ skipList = skipList2;
+ }
+
}
package jalview.gui;
import jalview.bin.Cache;
+import jalview.datamodel.AlignmentI;
+import jalview.datamodel.ColumnSelection;
+import jalview.datamodel.SequenceGroup;
import jalview.datamodel.SequenceI;
import jalview.io.VamsasAppDatastore;
+import jalview.structure.SelectionListener;
+import jalview.structure.SelectionSource;
import jalview.structure.StructureSelectionManager;
import jalview.structure.VamsasListener;
import java.beans.PropertyChangeListener;
import java.io.File;
import java.io.IOException;
+import java.util.Enumeration;
import java.util.Hashtable;
import java.util.IdentityHashMap;
+import java.util.Iterator;
import javax.swing.JInternalFrame;
import javax.swing.JOptionPane;
import uk.ac.vamsas.client.picking.IPickManager;
import uk.ac.vamsas.client.picking.Message;
import uk.ac.vamsas.client.picking.MouseOverMessage;
+import uk.ac.vamsas.client.picking.SelectionMessage;
import uk.ac.vamsas.objects.core.Entry;
+import uk.ac.vamsas.objects.core.Input;
+import uk.ac.vamsas.objects.core.Pos;
+import uk.ac.vamsas.objects.core.Seg;
/**
* @author jimp
*
*/
-public class VamsasApplication
+public class VamsasApplication implements SelectionSource
{
IClient vclient = null;
ensureJvVamsas();
VamsasAppDatastore vds = new VamsasAppDatastore(cdoc, vobj2jv, jv2vobj,
baseProvEntry(), alRedoState);
- vds.updateToJalview();
+ try
+ {
+ vds.updateToJalview();
+ } catch (Exception e)
+ {
+ Cache.log.error("Failed to update Jalview from vamsas document.", e);
+ }
+ try
+ {
+ if (firstUpdate)
+ {
+ vds.updateJalviewFromAppdata();
+ // Comment this out to repeatedly read in data from JalviewAppData
+ // firstUpdate=false;
+ }
+ } catch (Exception e)
+ {
+ Cache.log.error(
+ "Exception when updating Jalview settings from Appdata.", e);
+ }
Cache.log.debug(".. finished updating from sesion document.");
}
+ boolean firstUpdate = false;
+
private void ensureJvVamsas()
{
if (jv2vobj == null)
jv2vobj = new IdentityHashMap();
vobj2jv = new Hashtable();
alRedoState = new Hashtable();
+ firstUpdate = true;
}
}
Hashtable alRedoState = null;
+ boolean errorsDuringUpdate = false;
+
+ boolean errorsDuringAppUpdate = false;
+
+ /**
+ * update the document accessed through doc. A backup of the current object
+ * bindings is made.
+ *
+ * @param doc
+ */
public void updateVamsasDocument(IClientDocument doc)
{
ensureJvVamsas();
+ errorsDuringUpdate = false;
+ errorsDuringAppUpdate = false;
+ backup_objectMapping();
VamsasAppDatastore vds = new VamsasAppDatastore(doc, vobj2jv, jv2vobj,
baseProvEntry(), alRedoState);
// wander through frames
{
return;
}
+ Hashtable skipList = new Hashtable();
+ Hashtable viewset = new Hashtable();
try
{
if (frames[i] instanceof AlignFrame)
{
AlignFrame af = (AlignFrame) frames[i];
-
- // update alignment and root from frame.
- vds.storeVAMSAS(af.getViewport(), af.getTitle());
+ if (!viewset.containsKey(af.getViewport().getSequenceSetId()))
+ {
+ // update alignment and root from frame.
+ boolean stored = false;
+ try
+ {
+ stored = vds.storeVAMSAS(af.getViewport(), af.getTitle());
+ } catch (Exception e)
+ {
+ errorsDuringUpdate = true;
+ Cache.log.error("Exception synchronizing "
+ + af.getTitle()
+ + " "
+ + (af.getViewport().viewName == null ? "" : " view "
+ + af.getViewport().viewName)
+ + " to document.", e);
+ stored = false;
+ }
+ if (!stored)
+ { // record skip in skipList
+ skipList.put(af.getViewport().getSequenceSetId(), af);
+ }
+ else
+ {
+ // could try to eliminate sequenceSetId from skiplist ..
+ // (skipList.containsKey(af.getViewport().getSequenceSetId()))
+ // remember sequenceSetId so we can skip all the other views on
+ // same alignment
+ viewset.put(af.getViewport().getSequenceSetId(), af);
+ }
+ }
}
}
// REVERSE ORDER
- for (int i = frames.length - 1; i > -1; i--)
+ // for (int i = frames.length - 1; i > -1; i--)
+ // {
+ // if (frames[i] instanceof AlignFrame)
+ // {
+ // AlignFrame af = (AlignFrame) frames[i];
+ Iterator aframes = viewset.values().iterator();
+ while (aframes.hasNext())
{
- if (frames[i] instanceof AlignFrame)
- {
- AlignFrame af = (AlignFrame) frames[i];
+ AlignFrame af = (AlignFrame) aframes.next();
+ // add any AlignedCodonFrame mappings on this alignment to any other.
+ vds.storeSequenceMappings(af.getViewport(), af.getTitle());
+ }
+ } catch (Exception e)
+ {
+ Cache.log.error("Exception synchronizing Views to Document :", e);
+ errorsDuringUpdate = true;
+ }
- // add any AlignedCodonFrame mappings on this alignment to any other.
- vds.storeSequenceMappings(af.getViewport(), af.getTitle());
- }
+ try
+ {
+ if (viewset.size() > 0)
+ {
+ // Alignment views were synchronized, so store their state in the
+ // appData, too.
+ // The skipList ensures we don't write out any alignments not actually
+ // in the document.
+ vds.setSkipList(skipList);
+ vds.updateJalviewClientAppdata();
}
} catch (Exception e)
{
- Cache.log.error("Vamsas Document store exception", e);
+ Cache.log.error("Client Appdata Write exception", e);
+ errorsDuringAppUpdate = true;
}
+ vds.clearSkipList();
}
private Entry baseProvEntry()
{
System.err.println("Exception whilst updating :");
ee.printStackTrace(System.err);
+ // recover object map backup, since its probably corrupted with references
+ // to Vobjects that don't exist anymore.
+ this.recover_objectMappingBackup();
}
Cache.log.debug("Finished updating from document change.");
disableGui(false);
Desktop.instance.setVamsasUpdate(b);
}
+ Hashtable _backup_vobj2jv;
+
+ IdentityHashMap _backup_jv2vobj;
+
+ /**
+ * make a backup of the object mappings (vobj2jv and jv2vobj)
+ */
+ public void backup_objectMapping()
+ {
+ _backup_vobj2jv = new Hashtable(vobj2jv);
+ _backup_jv2vobj = new IdentityHashMap(jv2vobj);
+ }
+
+ /**
+ * recover original object mappings from the object mapping backup if document
+ * IO failed
+ *
+ * @throws Error
+ * if backup_objectMapping was not called.
+ */
+ public void recover_objectMappingBackup()
+ {
+ if (_backup_vobj2jv == null)
+ {
+ throw new Error(
+ "IMPLEMENTATION ERROR: Cannot recover vamsas object mappings - no backup was made.");
+ }
+ jv2vobj.clear();
+ Iterator el = _backup_jv2vobj.entrySet().iterator();
+ while (el.hasNext())
+ {
+ java.util.Map.Entry mp = (java.util.Map.Entry) el.next();
+ jv2vobj.put(mp.getKey(), mp.getValue());
+ }
+ el = _backup_vobj2jv.entrySet().iterator();
+ while (el.hasNext())
+ {
+ java.util.Map.Entry mp = (java.util.Map.Entry) el.next();
+ vobj2jv.put(mp.getKey(), mp.getValue());
+ }
+ }
+
private boolean joinedSession = false;
private VamsasListener picker = null;
+ private SelectionListener selecter;
+
private void startSession()
{
if (inSession())
final IPickManager pm = vclient.getPickManager();
final StructureSelectionManager ssm = StructureSelectionManager
.getStructureSelectionManager();
+ final SelectionSource me = this;
pm.registerMessageHandler(new IMessageHandler()
{
String last = null;
public void handleMessage(Message message)
{
- if (message instanceof MouseOverMessage && vobj2jv != null)
+ if (vobj2jv == null)
+ {
+ // we are not in a session yet.
+ return;
+ }
+ if (message instanceof MouseOverMessage)
{
MouseOverMessage mm = (MouseOverMessage) message;
String mstring = mm.getVorbaID() + " " + mm.getPosition();
.getPosition());
}
}
+ if (message instanceof uk.ac.vamsas.client.picking.SelectionMessage)
+ {
+ // we only care about AlignmentSequence selections
+ SelectionMessage sm = (SelectionMessage) message;
+ sm.validate();
+ System.err.println("Received\n"+sm.getRawMessage());
+ Object[] jvobjs = sm.getVorbaIDs()==null ? null : new Object[sm.getVorbaIDs().length];
+ if (jvobjs==null)
+ {
+ // TODO: rationalise : can only clear a selection over a referred to object
+ ssm.sendSelection(null,null,me);
+ return;
+ }
+ Class type = null;
+ boolean send = true;
+ for (int o = 0; o < jvobjs.length; o++)
+ {
+ jvobjs[o] = vobj2jv.get(sm.getVorbaIDs()[o]);
+ if (jvobjs[o] == null)
+ {
+ // can't cope with selections for unmapped objects
+ continue;
+ }
+ if (type == null)
+ {
+ type = jvobjs[o].getClass();
+ }
+ ;
+ if (type != jvobjs[o].getClass())
+ {
+ send=false;
+ // discard - can't cope with selections over mixed objects
+ continue;
+ }
+ }
+ SequenceGroup jselection = null;
+ ColumnSelection colsel = null;
+ if (type == jalview.datamodel.Alignment.class)
+ {
+ if (jvobjs.length == 1)
+ {
+ // TODO if (sm.isNone())// send a message to select the specified columns over the
+ // given
+ // alignment
+
+ send = true;
+ }
+ }
+ if (type == jalview.datamodel.Sequence.class)
+ {
+
+ SequenceI seq;
+ boolean aligned = ((jalview.datamodel.Sequence) jvobjs[0])
+ .getDatasetSequence() != null;
+ int maxWidth=0;
+ if (aligned)
+ {
+ jselection = new SequenceGroup();
+ jselection.addSequence(seq =
+ (jalview.datamodel.Sequence) jvobjs[0], false);
+ maxWidth = seq.getLength();
+ }
+ for (int c = 1; aligned && jvobjs.length > 1 && c < jvobjs.length; c++)
+ {
+ if (((jalview.datamodel.Sequence) jvobjs[c])
+ .getDatasetSequence() == null)
+ {
+ aligned = false;
+ continue;
+ }
+ else
+ {
+ jselection.addSequence(
+ seq = (jalview.datamodel.Sequence) jvobjs[c], false);
+ if (maxWidth<seq.getLength())
+ {
+ maxWidth = seq.getLength();
+ }
+
+ }
+ }
+ if (!aligned)
+ {
+ jselection = null;
+ // if cardinality is greater than one then verify all
+ // sequences are alignment sequences.
+ if (jvobjs.length == 1)
+ {
+ // find all instances of this dataset sequence in the
+ // displayed alignments containing the associated range and
+ // select them.
+ }
+ }
+ else
+ {
+ jselection.setStartRes(0);
+ jselection.setEndRes(maxWidth);
+ // locate the alignment containing the given sequences and
+ // select the associated ranges on them.
+ if (sm.getRanges() != null)
+ {
+ int[] prange = uk.ac.vamsas.objects.utils.Range.getBounds(sm.getRanges());
+ boolean rangeset=false;
+ colsel = new ColumnSelection();
+ prange = uk.ac.vamsas.objects.utils.Range.getIntervals(sm.getRanges());
+ for (int p=0;p<prange.length;p+=2)
+ {
+ int d = (prange[p]<=prange[p+1]) ? 1 : -1;
+ if (!rangeset)
+ {
+ if (jselection!=null)
+ {
+ // set the bounds of the selected area using the first interval.
+ jselection.setStartRes(prange[p]-1);
+ jselection.setEndRes(prange[p+1]-1);
+ rangeset=true;
+ }
+ } else {
+ // try to join up adjacent columns to make a larger selection
+ // lower and upper bounds
+ int l=(d<0) ? 1 : 0;
+ int u=(d>0) ? 1 : 0;
+
+ if (jselection.getStartRes()>0 && prange[p+l]==jselection.getStartRes())
+ {
+ jselection.setStartRes(prange[p+l]-1);
+ }
+ if (jselection.getEndRes()<=maxWidth && prange[p+u]==(jselection.getEndRes()+2))
+ {
+ jselection.setEndRes(prange[p+u]-1);
+ }
+ }
+ // mark all the columns in the range.
+ for (int sr=prange[p],er=prange[p+1],de=er+d; sr!=de; sr+=d)
+ {
+ colsel.addElement(sr-1);
+ }
+ }
+ }
+ send = true;
+ }
+ }
+ if (send)
+ {
+ ssm.sendSelection(jselection, colsel, me);
+ }
+ // discard message.
+ for (int c = 0; c < jvobjs.length; c++)
+ {
+ jvobjs[c] = null;
+ }
+ ;
+ jvobjs = null;
+ return;
+ }
}
});
picker = new VamsasListener()
}
}
};
+ selecter = new SelectionListener()
+ {
+
+ public void selection(SequenceGroup seqsel,
+ ColumnSelection colsel, SelectionSource source)
+ {
+ if (source != me)
+ {
+ AlignmentI visal=null;
+ if (source instanceof AlignViewport)
+ {
+ visal = ((AlignViewport) source).getAlignment();
+ }
+ SelectionMessage sm = null;
+ if ((seqsel == null || seqsel.getSize() == 0)
+ && (colsel == null || colsel.getSelected() == null || colsel
+ .getSelected().size() == 0))
+ {
+ if (source instanceof AlignViewport)
+ {
+ // the empty selection.
+ sm = new SelectionMessage("jalview", new String[] { ((AlignViewport)source).getSequenceSetId()}, null, true);
+ } else {
+ // the empty selection.
+ sm = new SelectionMessage("jalview", null, null, true);
+ }
+ }
+ else
+ {
+ String[] vobj = new String[seqsel.getSize()];
+ int o = 0;
+ Enumeration sels = seqsel.getSequences(null).elements();
+ while (sels.hasMoreElements())
+ {
+ SequenceI sel = (SequenceI) sels.nextElement();
+ VorbaId v = (VorbaId) jv2vobj.get(sel);
+ if (v != null)
+ {
+ vobj[o++] = v.toString();
+ }
+ }
+ if (o < vobj.length)
+ {
+ String t[] = vobj;
+ vobj = new String[o];
+ System.arraycopy(t, 0, vobj, 0, o);
+ t = null;
+ }
+ Input range = null;
+ if (seqsel!=null && colsel != null)
+ {
+ // deparse the colsel into positions on the vamsas alignment
+ // sequences
+ range = new Input();
+ if (colsel.getSelected()!=null && colsel.getSelected().size()>0 && visal!=null && seqsel.getSize()==visal.getHeight())
+ {
+ // gather selected columns outwith the sequence positions too
+ Enumeration cols = colsel.getSelected().elements();
+ while (cols.hasMoreElements())
+ {
+ int ival = ((Integer) cols.nextElement()).intValue();
+ Pos p = new Pos();
+ p.setI(ival+1);
+ range.addPos(p);
+ }
+ } else {
+ int[] intervals = colsel.getVisibleContigs(seqsel.getStartRes(), seqsel.getEndRes()+1);
+ for (int iv=0;iv<intervals.length; iv+=2)
+ {
+ Seg s = new Seg();
+ s.setStart(intervals[iv]+1); // vamsas indices begin at 1, not zero.
+ s.setEnd(intervals[iv+1]+1);
+ s.setInclusive(true);
+ range.addSeg(s);
+ }
+ }
+ }
+ sm = new SelectionMessage("jalview", vobj, range);
+ }
+ sm.validate(); // debug
+ Cache.log.debug("Pick Message\n"+sm.getRawMessage());
+ pm.sendMessage(sm);
+ }
+ }
+
+ };
ssm.addStructureViewerListener(picker); // better method here
+ ssm.addSelectionListener(selecter);
} catch (Exception e)
{
Cache.log.error("Failed to init Vamsas Picking", e);