boolean raiseGUI = true; // whether errors are raised in dialog boxes or not
+ /*
+ * Map of reconstructed AlignFrame objects that appear to have come from
+ * SplitFrame objects (have a dna/protein complement view).
+ */
+ private Map<Viewport, AlignFrame> splitFrameCandidates = new HashMap<Viewport, AlignFrame>();
+
/**
* create/return unique hash string for sq
*
}
/**
- * This maintains a list of viewports, the key being the seqSetId. Important
- * to set historyItem and redoList for multiple views
+ * This maintains a map of viewports, the key being the seqSetId. Important to
+ * set historyItem and redoList for multiple views
*/
- Hashtable viewportsAdded;
+ Map<String, AlignViewport> viewportsAdded = new HashMap<String, AlignViewport>();
- Hashtable annotationIds = new Hashtable();
+ Map<String, AlignmentAnnotation> annotationIds = new HashMap<String, AlignmentAnnotation>();
String uniqueSetSuffix = "";
view.setSequenceSetId(makeHashCode(av.getSequenceSetId(),
av.getSequenceSetId()));
view.setId(av.getViewId());
+ if (av.getCodingComplement() != null)
+ {
+ view.setComplementId(av.getCodingComplement().getViewId());
+ }
view.setViewName(av.viewName);
view.setGatheredViews(av.isGatherViewsHere());
}
}
throw new Error(MessageManager.formatMessage(
- "error.unsupported_version_calcIdparam", new String[]
+ "error.unsupported_version_calcIdparam", new Object[]
{ calcIdParam.toString() }));
}
errorMessage = null;
uniqueSetSuffix = null;
seqRefIds = null;
- viewportsAdded = null;
+ viewportsAdded.clear();
frefedSequence = null;
if (file.startsWith("http://"))
{
seqRefIds = new HashMap<String, SequenceI>();
}
- if (viewportsAdded == null)
- {
- viewportsAdded = new Hashtable();
- }
if (frefedSequence == null)
{
frefedSequence = new Vector();
}
- jalview.gui.AlignFrame af = null, _af = null;
- Hashtable gatherToThisFrame = new Hashtable();
+ AlignFrame af = null, _af = null;
+ Map<String, AlignFrame> gatherToThisFrame = new HashMap<String, AlignFrame>();
final String file = jprovider.getFilename();
try
{
Desktop.instance.stopLoading();
}
- Enumeration en = gatherToThisFrame.elements();
- while (en.hasMoreElements())
+ for (AlignFrame fr : gatherToThisFrame.values())
{
- Desktop.instance.gatherViews((AlignFrame) en.nextElement());
+ Desktop.instance.gatherViews(fr);
}
+
+ restoreSplitFrames();
+
if (errorMessage != null)
{
reportErrors();
}
/**
+ * Try to reconstruct and display SplitFrame windows, where each contains
+ * complementary dna and protein alignments. Done by pairing up AlignFrame
+ * objects (created earlier) which have complementary viewport ids associated.
+ */
+ protected void restoreSplitFrames()
+ {
+ List<SplitFrame> gatherTo = new ArrayList<SplitFrame>();
+ List<AlignFrame> addedToSplitFrames = new ArrayList<AlignFrame>();
+ Map<String, AlignFrame> dna = new HashMap<String, AlignFrame>();
+
+ /*
+ * Identify the DNA alignments
+ */
+ for (Entry<Viewport, AlignFrame> candidate : splitFrameCandidates
+ .entrySet())
+ {
+ AlignFrame af = candidate.getValue();
+ if (af.getViewport().getAlignment().isNucleotide())
+ {
+ dna.put(candidate.getKey().getId(), af);
+ }
+ }
+
+ /*
+ * Try to match up the protein complements
+ */
+ for (Entry<Viewport, AlignFrame> candidate : splitFrameCandidates
+ .entrySet())
+ {
+ AlignFrame af = candidate.getValue();
+ if (!af.getViewport().getAlignment().isNucleotide())
+ {
+ String complementId = candidate.getKey().getComplementId();
+ // only non-null complements should be in the Map
+ if (complementId != null && dna.containsKey(complementId))
+ {
+ final AlignFrame dnaFrame = dna.get(complementId);
+ SplitFrame sf = createSplitFrame(dnaFrame, af);
+ addedToSplitFrames.add(dnaFrame);
+ addedToSplitFrames.add(af);
+ if (af.viewport.isGatherViewsHere())
+ {
+ gatherTo.add(sf);
+ }
+ }
+ }
+ }
+
+ /*
+ * Open any that we failed to pair up (which shouldn't happen!) as
+ * standalone AlignFrame's.
+ */
+ for (Entry<Viewport, AlignFrame> candidate : splitFrameCandidates
+ .entrySet())
+ {
+ AlignFrame af = candidate.getValue();
+ if (!addedToSplitFrames.contains(af)) {
+ Viewport view = candidate.getKey();
+ Desktop.addInternalFrame(af, view.getTitle(), view.getWidth(),
+ view.getHeight());
+ System.err.println("Failed to restore view " + view.getTitle()
+ + " to split frame");
+ }
+ }
+
+ /*
+ * Gather back into tabbed views as flagged.
+ */
+ for (SplitFrame sf : gatherTo)
+ {
+ Desktop.instance.gatherViews(sf);
+ }
+
+ splitFrameCandidates.clear();
+ }
+
+ /**
+ * Construct and display one SplitFrame holding DNA and protein alignments.
+ *
+ * @param dnaFrame
+ * @param proteinFrame
+ * @return
+ */
+ protected SplitFrame createSplitFrame(AlignFrame dnaFrame,
+ AlignFrame proteinFrame)
+ {
+ dnaFrame.setVisible(true);
+ proteinFrame.setVisible(true);
+ proteinFrame.getViewport().setCodingComplement(dnaFrame.getViewport());
+ final StructureSelectionManager ssm = StructureSelectionManager
+ .getStructureSelectionManager(Desktop.instance);
+ ssm.addCommandListener(proteinFrame.getViewport());
+ ssm.addCommandListener(dnaFrame.getViewport());
+
+ SplitFrame splitFrame = new SplitFrame(dnaFrame, proteinFrame);
+ String title = MessageManager.getString("label.linked_view_title");
+ Desktop.addInternalFrame(splitFrame, title, -1, -1);
+ return splitFrame;
+ }
+
+ /**
* 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.
errorMessage = null;
}
- Hashtable<String, String> alreadyLoadedPDB;
+ Map<String, String> alreadyLoadedPDB = new HashMap<String, String>();
/**
* when set, local views will be updated from view stored in JalviewXML
String loadPDBFile(jarInputStreamProvider jprovider, String pdbId)
{
- if (alreadyLoadedPDB == null)
- {
- alreadyLoadedPDB = new Hashtable();
- }
-
if (alreadyLoadedPDB.containsKey(pdbId))
{
return alreadyLoadedPDB.get(pdbId).toString();
// ////////////////////////////////
// LOAD SEQUENCES
- Vector hiddenSeqs = null;
+ List<SequenceI> hiddenSeqs = null;
jalview.datamodel.Sequence jseq;
- ArrayList tmpseqs = new ArrayList();
+ List<SequenceI> tmpseqs = new ArrayList<SequenceI>();
boolean multipleView = false;
{
if (hiddenSeqs == null)
{
- hiddenSeqs = new Vector();
+ hiddenSeqs = new ArrayList<SequenceI>();
}
- hiddenSeqs.addElement(seqRefIds.get(seqId));
+ hiddenSeqs.add(seqRefIds.get(seqId));
}
}
// /
// Create the alignment object from the sequence set
// ///////////////////////////////
- jalview.datamodel.Sequence[] orderedSeqs = new jalview.datamodel.Sequence[tmpseqs
- .size()];
+ SequenceI[] orderedSeqs = tmpseqs
+ .toArray(new SequenceI[tmpseqs.size()]);
- tmpseqs.toArray(orderedSeqs);
-
- jalview.datamodel.Alignment al = new jalview.datamodel.Alignment(
- orderedSeqs);
+ Alignment al = new Alignment(orderedSeqs);
// / Add the alignment properties
for (int i = 0; i < vamsasSet.getSequenceSetPropertiesCount(); i++)
}
// ///////////////////////////////
- Hashtable pdbloaded = new Hashtable();
+ Hashtable pdbloaded = new Hashtable(); // TODO nothing writes to this??
if (!multipleView)
{
// load sequence features, database references and any associated PDB
// ////////////////////////////////
// LOAD ANNOTATIONS
- ArrayList<JvAnnotRow> autoAlan = new ArrayList<JvAnnotRow>();
+ List<JvAnnotRow> autoAlan = new ArrayList<JvAnnotRow>();
/**
* store any annotations which forward reference a group's ID
*/
if (an[i].getId() != null
&& annotationIds.containsKey(an[i].getId()))
{
- jalview.datamodel.AlignmentAnnotation jda = (jalview.datamodel.AlignmentAnnotation) annotationIds
- .get(an[i].getId());
+ AlignmentAnnotation jda = annotationIds.get(an[i].getId());
// in principle Visible should always be true for annotation displayed
// in multiple views
if (an[i].hasVisible())
}
}
- AlignFrame loadViewport(String file, JSeq[] JSEQ, Vector hiddenSeqs,
- Alignment al, JalviewModelSequence jms, Viewport view,
- String uniqueSeqSetId, String viewId,
- ArrayList<JvAnnotRow> autoAlan)
+ AlignFrame loadViewport(String file, JSeq[] JSEQ,
+ List<SequenceI> hiddenSeqs, Alignment al,
+ JalviewModelSequence jms, Viewport view, String uniqueSeqSetId,
+ String viewId, List<JvAnnotRow> autoAlan)
{
AlignFrame af = null;
af = new AlignFrame(al, view.getWidth(), view.getHeight(),
if (view.getSequenceSetId() != null)
{
- AlignmentViewport av = (AlignmentViewport) viewportsAdded
- .get(uniqueSeqSetId);
+ AlignmentViewport av = viewportsAdded.get(uniqueSeqSetId);
af.viewport.setSequenceSetId(uniqueSeqSetId);
if (av != null)
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);
- }
+ // 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);
+ // }
+ SequenceI[] hseqs = hiddenSeqs.toArray(new SequenceI[hiddenSeqs
+ .size()]);
af.viewport.hideSequence(hseqs);
}
}
}
af.setMenusFromViewport(af.viewport);
+
// TODO: we don't need to do this if the viewport is aready visible.
- Desktop.addInternalFrame(af, view.getTitle(), view.getWidth(),
- view.getHeight());
- af.alignPanel.updateAnnotation(false, true); // recompute any autoannotation
- reorderAutoannotation(af, al, autoAlan);
- af.alignPanel.alignmentChanged();
+ /*
+ * Add the AlignFrame to the desktop (it may be 'gathered' later), unless it
+ * has a 'cdna/protein complement' view, in which case save it in order to
+ * populate a SplitFrame once all views have been read in.
+ */
+ String complementaryViewId = view.getComplementId();
+ if (complementaryViewId == null)
+ {
+ Desktop.addInternalFrame(af, view.getTitle(), view.getWidth(),
+ view.getHeight());
+ // recompute any autoannotation
+ af.alignPanel.updateAnnotation(false, true);
+ reorderAutoannotation(af, al, autoAlan);
+ af.alignPanel.alignmentChanged();
+ }
+ else
+ {
+ splitFrameCandidates.put(view, af);
+ }
return af;
}
}
private void reorderAutoannotation(AlignFrame af, Alignment al,
- ArrayList<JvAnnotRow> autoAlan)
+ List<JvAnnotRow> autoAlan)
{
// copy over visualization settings for autocalculated annotation in the
// view
+ auan.template.getCalcId()), auan);
}
int hSize = al.getAlignmentAnnotation().length;
- ArrayList<JvAnnotRow> reorder = new ArrayList<JvAnnotRow>();
+ List<JvAnnotRow> reorder = new ArrayList<JvAnnotRow>();
// work through any autoCalculated annotation already on the view
// removing it if it should be placed in a different location on the
// annotation panel.
- List<String> remains = new ArrayList(visan.keySet());
+ List<String> remains = new ArrayList<String>(visan.keySet());
for (int h = 0; h < hSize; h++)
{
jalview.datamodel.AlignmentAnnotation jalan = al
// if (pre || post)
if (sq != dsq)
{
- StringBuffer sb = new StringBuffer();
+ // StringBuffer sb = new StringBuffer();
String newres = jalview.analysis.AlignSeq.extractGaps(
jalview.util.Comparison.GapChars, sq.getSequenceAsString());
if (!newres.equalsIgnoreCase(dsq.getSequenceAsString())
frefedSequence = new Vector();
}
- viewportsAdded = new Hashtable();
+ viewportsAdded.clear();
AlignFrame af = loadFromObject(jm, null, false, null);
af.alignPanels.clear();
}
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;
+ AlignmentAnnotation jvann = (AlignmentAnnotation) jvobj;
+ annotationIds.put(anid = jv2vobj.get(jvobj).toString(), jvann);
if (jvann.annotationId == null)
{
jvann.annotationId = anid;