import jalview.appletgui.AlignViewport;
import jalview.appletgui.EmbmenuFrame;
import jalview.appletgui.FeatureSettings;
+import jalview.appletgui.SplitFrame;
import jalview.datamodel.Alignment;
import jalview.datamodel.AlignmentI;
import jalview.datamodel.AlignmentOrder;
import jalview.io.AppletFormatAdapter;
import jalview.io.FileParse;
import jalview.io.IdentifyFile;
+import jalview.io.JPredFile;
import jalview.io.JnetAnnotationMaker;
+import jalview.io.NewickFile;
import jalview.javascript.JSFunctionExec;
import jalview.javascript.JalviewLiteJsApi;
import jalview.javascript.JsCallBack;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.Hashtable;
StructureSelectionManagerProvider, JalviewLiteJsApi
{
+ private static final String TRUE = "true";
+
+ private static final String FALSE = "false";
+
public StructureSelectionManager getStructureSelectionManager()
{
return StructureSelectionManager.getStructureSelectionManager(this);
{
try
{
- boolean seqlimits = suffix.equalsIgnoreCase("true");
+ boolean seqlimits = suffix.equalsIgnoreCase(TRUE);
if (alf.viewport.getSelectionGroup() != null)
{
// JBPNote: getSelectionAsNewSequence behaviour has changed - this
final String _undoName = undoName;
// TODO: deal with synchronization here: cannot raise any events until after
// this has returned.
- return alf.sortBy(aorder, _undoName) ? "true" : "";
+ return alf.sortBy(aorder, _undoName) ? TRUE : "";
}
/*
*/
public String getAlignment(String format)
{
- return getAlignmentFrom(getDefaultTargetFrame(), format, "true");
+ return getAlignmentFrom(getDefaultTargetFrame(), format, TRUE);
}
/*
*/
public String getAlignmentFrom(AlignFrame alf, String format)
{
- return getAlignmentFrom(alf, format, "true");
+ return getAlignmentFrom(alf, format, TRUE);
}
/*
{
try
{
- boolean seqlimits = suffix.equalsIgnoreCase("true");
+ boolean seqlimits = suffix.equalsIgnoreCase(TRUE);
String reply = new AppletFormatAdapter().formatSequences(format,
alf.viewport.getAlignment(), seqlimits);
String file = "No file";
- Button launcher = new Button("Start Jalview");
+ String file2 = "No file";
+
+ Button launcher = new Button(
+ MessageManager.getString("label.start_jalview"));
/**
* The currentAlignFrame is static, it will change if and when the user
/**
* turn on extra applet debugging
*/
- String dbg = getParameter("debug");
- if (dbg != null)
- {
- debug = dbg.toLowerCase().equals("true");
- }
+ debug = TRUE.equalsIgnoreCase(getParameter("debug"));
if (debug)
{
if (externalsviewer != null)
{
useXtrnalSviewer = externalsviewer.trim().toLowerCase()
- .equals("true");
+ .equals(TRUE);
}
/**
* if true disable the check for jmol
String chkforJmol = getParameter("nojmol");
if (chkforJmol != null)
{
- checkForJmol = !chkforJmol.equals("true");
+ checkForJmol = !chkforJmol.equals(TRUE);
}
/**
* get the separator parameter if present
file = data.toString();
}
}
+ file2 = getParameter("file2");
- final JalviewLite jvapplet = this;
- if (getParameter("embedded") != null
- && getParameter("embedded").equalsIgnoreCase("true"))
+ embedded = TRUE.equalsIgnoreCase(getParameter("embedded"));
+ if (embedded)
{
- // Launch as embedded applet in page
- embedded = true;
- LoadingThread loader = new LoadingThread(file, jvapplet);
+ LoadingThread loader = new LoadingThread(file, file2, this);
loader.start();
}
else if (file != null)
{
- if (getParameter("showbutton") == null
- || !getParameter("showbutton").equalsIgnoreCase("false"))
+ /*
+ * Start the applet immediately or show a button to start it
+ */
+ if (FALSE.equalsIgnoreCase(getParameter("showbutton")))
+ {
+ LoadingThread loader = new LoadingThread(file, file2, this);
+ loader.start();
+ }
+ else
{
- // Add the JalviewLite 'Button' to the page
add(launcher);
launcher.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(ActionEvent e)
{
- LoadingThread loader = new LoadingThread(file, jvapplet);
+ LoadingThread loader = new LoadingThread(file, file2,
+ JalviewLite.this);
loader.start();
}
});
}
- else
- {
- // Open jalviewLite immediately.
- LoadingThread loader = new LoadingThread(file, jvapplet);
- loader.start();
- }
}
else
{
class LoadingThread extends Thread
{
/**
- * State variable: File source
- */
- String file;
-
- /**
* State variable: protocol for access to file source
*/
String protocol;
- /**
- * State variable: format of file source
- */
- String format;
+ String _file; // alignment file or URL spec
- String _file;
+ String _file2; // second alignment file or URL spec
JalviewLite applet;
private void dbgMsg(String msg)
{
- if (applet.debug)
+ if (JalviewLite.debug)
{
System.err.println(msg);
}
return file;
}
- public LoadingThread(String _file, JalviewLite _applet)
+ // public LoadingThread(String _file, JalviewLite _applet)
+ // {
+ // this._file = _file;
+ // applet = _applet;
+ // }
+
+ public LoadingThread(String file, String file2, JalviewLite _applet)
{
- this._file = _file;
+ this._file = file;
+ this._file2 = file2;
applet = _applet;
}
} catch (Exception e)
{
}
- ;
}
startLoading();
// applet.callInitCallback();
}
+ /**
+ * Load the alignment and any related files as specified by applet
+ * parameters
+ */
private void startLoading()
{
- AlignFrame newAlignFrame;
dbgMsg("Loading thread started with:\n>>file\n" + _file + ">>endfile");
- file = setProtocolState(_file);
- format = new jalview.io.IdentifyFile().Identify(file, protocol);
- dbgMsg("File identified as '" + format + "'");
dbgMsg("Loading started.");
- Alignment al = null;
+
+ AlignFrame newAlignFrame = readAlignment(_file);
+ AlignFrame newAlignFrame2 = readAlignment(_file2);
+ if (newAlignFrame != null)
+ {
+ addToDisplay(newAlignFrame, newAlignFrame2);
+ loadTree(newAlignFrame);
+
+ loadScoreFile(newAlignFrame);
+
+ loadFeatures(newAlignFrame);
+
+ loadAnnotations(newAlignFrame);
+
+ loadJnetFile(newAlignFrame);
+
+ loadPdbFiles(newAlignFrame);
+ }
+ else
+ {
+ fileFound = false;
+ applet.remove(launcher);
+ applet.repaint();
+ }
+ callInitCallback();
+ }
+
+ /**
+ * Add an AlignFrame to the display; or if two are provided, a SplitFrame.
+ *
+ * @param af
+ * @param af2
+ */
+ public void addToDisplay(AlignFrame af, AlignFrame af2)
+ {
+ if (af2 == null)
+ {
+ af.addToDisplay(embedded);
+ }
+ else
+ {
+ SplitFrame sf = new SplitFrame(af, af2);
+ sf.addToDisplay(embedded, JalviewLite.this);
+ }
+ }
+
+ /**
+ * Read the alignment file (from URL, text 'paste', or archive by
+ * classloader).
+ *
+ * @return
+ */
+ protected AlignFrame readAlignment(String fileParam)
+ {
+ if (fileParam == null)
+ {
+ return null;
+ }
+ String resolvedFile = setProtocolState(fileParam);
+ String format = new IdentifyFile().Identify(resolvedFile, protocol);
+ dbgMsg("File identified as '" + format + "'");
+ AlignmentI al = null;
try
{
- al = new AppletFormatAdapter().readFile(file, protocol, format);
+ al = new AppletFormatAdapter().readFile(resolvedFile, protocol, format);
+ if ((al != null) && (al.getHeight() > 0))
+ {
+ dbgMsg("Successfully loaded file.");
+ AlignFrame newAlignFrame = new AlignFrame(al, applet,
+ resolvedFile, embedded, false);
+ newAlignFrame.setTitle(resolvedFile);
+ if (initialAlignFrame == null)
+ {
+ initialAlignFrame = newAlignFrame;
+ }
+ // update the focus.
+ currentAlignFrame = newAlignFrame;
+
+ if (protocol == AppletFormatAdapter.PASTE)
+ {
+ newAlignFrame.setTitle(MessageManager.formatMessage(
+ "label.sequences_from", new Object[]
+ { applet.getDocumentBase().toString() }));
+ }
+
+ newAlignFrame.statusBar.setText(MessageManager.formatMessage(
+ "label.successfully_loaded_file", new Object[]
+ { resolvedFile }));
+
+ return newAlignFrame;
+ }
} catch (java.io.IOException ex)
{
dbgMsg("File load exception.");
{
try
{
- FileParse fp = new FileParse(file, protocol);
+ FileParse fp = new FileParse(resolvedFile, protocol);
String ln = null;
- dbgMsg(">>>Dumping contents of '" + file + "' " + "("
+ dbgMsg(">>>Dumping contents of '" + resolvedFile + "' " + "("
+ protocol + ")");
while ((ln = fp.nextLine()) != null)
{
}
}
}
- if ((al != null) && (al.getHeight() > 0))
+ return null;
+ }
+
+ /**
+ * Load PDBFiles if any specified by parameter(s). Returns true if loaded,
+ * else false.
+ *
+ * @param alignFrame
+ * @return
+ */
+ protected boolean loadPdbFiles(AlignFrame alignFrame)
+ {
+ boolean result = false;
+ /*
+ * <param name="alignpdbfiles" value="false/true"/> Undocumented for 2.6 -
+ * related to JAL-434
+ */
+
+ applet.setAlignPdbStructures(getDefaultParameter("alignpdbfiles",
+ false));
+ /*
+ * <param name="PDBfile" value="1gaq.txt PDB|1GAQ|1GAQ|A PDB|1GAQ|1GAQ|B
+ * PDB|1GAQ|1GAQ|C">
+ *
+ * <param name="PDBfile2" value="1gaq.txt A=SEQA B=SEQB C=SEQB">
+ *
+ * <param name="PDBfile3" value="1q0o Q45135_9MICO">
+ */
+
+ int pdbFileCount = 0;
+ // Accumulate pdbs here if they are heading for the same view (if
+ // alignPdbStructures is true)
+ Vector pdbs = new Vector();
+ // create a lazy matcher if we're asked to
+ jalview.analysis.SequenceIdMatcher matcher = (applet
+ .getDefaultParameter("relaxedidmatch", false)) ? new jalview.analysis.SequenceIdMatcher(
+ alignFrame.getAlignViewport().getAlignment()
+ .getSequencesArray()) : null;
+
+ String param;
+ do
{
- dbgMsg("Successfully loaded file.");
- newAlignFrame = new AlignFrame(al, applet, file, embedded);
- if (initialAlignFrame == null)
+ if (pdbFileCount > 0)
{
- initialAlignFrame = newAlignFrame;
+ param = applet.getParameter("PDBFILE" + pdbFileCount);
}
- // update the focus.
- currentAlignFrame = newAlignFrame;
-
- if (protocol == jalview.io.AppletFormatAdapter.PASTE)
+ else
{
- newAlignFrame.setTitle(MessageManager.formatMessage(
- "label.sequences_from", new String[]
- { applet.getDocumentBase().toString() }));
+ param = applet.getParameter("PDBFILE");
}
- newAlignFrame.statusBar.setText(MessageManager.formatMessage(
- "label.successfully_loaded_file", new String[]
- { file }));
-
- String treeFile = applet.getParameter("tree");
- if (treeFile == null)
+ if (param != null)
{
- treeFile = applet.getParameter("treeFile");
- }
+ PDBEntry pdb = new PDBEntry();
- if (treeFile != null)
- {
- try
+ String seqstring;
+ SequenceI[] seqs = null;
+ String[] chains = null;
+
+ StringTokenizer st = new StringTokenizer(param, " ");
+
+ if (st.countTokens() < 2)
{
- treeFile = setProtocolState(treeFile);
- /*
- * if (inArchive(treeFile)) { protocol =
- * AppletFormatAdapter.CLASSLOADER; } else { protocol =
- * AppletFormatAdapter.URL; treeFile = addProtocol(treeFile); }
- */
- jalview.io.NewickFile fin = new jalview.io.NewickFile(treeFile,
- protocol);
-
- fin.parse();
-
- if (fin.getTree() != null)
+ String sequence = applet.getParameter("PDBSEQ");
+ if (sequence != null)
{
- newAlignFrame.loadTree(fin, treeFile);
- dbgMsg("Successfuly imported tree.");
+ seqs = new SequenceI[]
+ { matcher == null ? (Sequence) alignFrame.getAlignViewport()
+ .getAlignment().findName(sequence) : matcher
+ .findIdMatch(sequence) };
}
- else
+
+ }
+ else
+ {
+ param = st.nextToken();
+ Vector tmp = new Vector();
+ Vector tmp2 = new Vector();
+
+ while (st.hasMoreTokens())
+ {
+ seqstring = st.nextToken();
+ StringTokenizer st2 = new StringTokenizer(seqstring, "=");
+ if (st2.countTokens() > 1)
+ {
+ // This is the chain
+ tmp2.addElement(st2.nextToken());
+ seqstring = st2.nextToken();
+ }
+ tmp.addElement(matcher == null ? (Sequence) alignFrame
+ .getAlignViewport().getAlignment()
+ .findName(seqstring) : matcher.findIdMatch(seqstring));
+ }
+
+ seqs = new SequenceI[tmp.size()];
+ tmp.copyInto(seqs);
+ if (tmp2.size() == tmp.size())
{
- dbgMsg("Tree parameter did not resolve to a valid tree.");
+ chains = new String[tmp2.size()];
+ tmp2.copyInto(chains);
}
- } catch (Exception ex)
+ }
+ param = setProtocolState(param);
+
+ if (// !jmolAvailable
+ // &&
+ protocol == AppletFormatAdapter.CLASSLOADER && !useXtrnalSviewer)
{
- ex.printStackTrace();
+ // Re: JAL-357 : the bug isn't a problem if we are using an
+ // external viewer!
+ // TODO: verify this Re:
+ // https://mantis.lifesci.dundee.ac.uk/view.php?id=36605
+ // This exception preserves the current behaviour where, even if
+ // the local pdb file was identified in the class loader
+ protocol = AppletFormatAdapter.URL; // this is probably NOT
+ // CORRECT!
+ param = addProtocol(param); //
}
- }
- /*
- * Try to load T-Coffee score file
- */
- String sScoreFile = applet.getParameter("scoreFile");
- if (sScoreFile != null && !"".equals(sScoreFile))
- {
- try
+ pdb.setFile(param);
+
+ if (seqs != null)
{
- if (debug)
+ for (int i = 0; i < seqs.length; i++)
{
- System.err
- .println("Attempting to load T-COFFEE score file from the scoreFile parameter");
+ if (seqs[i] != null)
+ {
+ ((Sequence) seqs[i]).addPDBId(pdb);
+ StructureSelectionManager.getStructureSelectionManager(
+ applet).registerPDBEntry(pdb);
+ }
+ else
+ {
+ if (JalviewLite.debug)
+ {
+ // this may not really be a problem but we give a warning
+ // anyway
+ System.err
+ .println("Warning: Possible input parsing error: Null sequence for attachment of PDB (sequence "
+ + i + ")");
+ }
+ }
}
- if (!newAlignFrame.loadScoreFile(sScoreFile))
+
+ if (!alignPdbStructures)
{
- System.err
- .println("Failed to parse T-COFFEE parameter as a valid score file ('"
- + sScoreFile + "')");
+ alignFrame.newStructureView(applet, pdb, seqs, chains,
+ protocol);
+ }
+ else
+ {
+ pdbs.addElement(new Object[]
+ { pdb, seqs, chains, new String(protocol) });
}
- } catch (Exception e)
- {
- System.err.printf("Cannot read score file: '%s'. Cause: %s \n",
- sScoreFile, e.getMessage());
}
}
- // ///////////////////////////
- // modify display of features
- // we do this before any features have been loaded, ensuring any hidden
- // groups are hidden when features first displayed
- //
- // hide specific groups
- //
- String param = applet.getParameter("hidefeaturegroups");
- if (param != null)
- {
- newAlignFrame.setFeatureGroupState(separatorListToArray(param),
- false);
- // applet.setFeatureGroupStateOn(newAlignFrame, param, false);
- }
- // show specific groups
- param = applet.getParameter("showfeaturegroups");
- if (param != null)
- {
- newAlignFrame.setFeatureGroupState(separatorListToArray(param),
- true);
- // applet.setFeatureGroupStateOn(newAlignFrame, param, true);
+ pdbFileCount++;
+ } while (param != null || pdbFileCount < 10);
+ if (pdbs.size() > 0)
+ {
+ SequenceI[][] seqs = new SequenceI[pdbs.size()][];
+ PDBEntry[] pdb = new PDBEntry[pdbs.size()];
+ String[][] chains = new String[pdbs.size()][];
+ String[] protocols = new String[pdbs.size()];
+ for (int pdbsi = 0, pdbsiSize = pdbs.size(); pdbsi < pdbsiSize; pdbsi++)
+ {
+ Object[] o = (Object[]) pdbs.elementAt(pdbsi);
+ pdb[pdbsi] = (PDBEntry) o[0];
+ seqs[pdbsi] = (SequenceI[]) o[1];
+ chains[pdbsi] = (String[]) o[2];
+ protocols[pdbsi] = (String) o[3];
}
- // and now load features
- param = applet.getParameter("features");
- if (param != null)
+ alignFrame.alignedStructureView(applet, pdb, seqs, chains,
+ protocols);
+ result = true;
+ }
+ return result;
+ }
+
+ /**
+ * Load in a Jnetfile if specified by parameter. Returns true if loaded,
+ * else false.
+ *
+ * @param alignFrame
+ * @return
+ */
+ protected boolean loadJnetFile(AlignFrame alignFrame)
+ {
+ boolean result = false;
+ String param = applet.getParameter("jnetfile");
+ if (param != null)
+ {
+ try
{
param = setProtocolState(param);
-
- newAlignFrame.parseFeaturesFile(param, protocol);
+ JPredFile predictions = new JPredFile(param, protocol);
+ JnetAnnotationMaker.add_annotation(predictions,
+ alignFrame.viewport.getAlignment(), 0, false);
+ // false == do not add sequence profile from concise output
+ SequenceI repseq = alignFrame.viewport.getAlignment()
+ .getSequenceAt(0);
+ alignFrame.viewport.getAlignment().setSeqrep(repseq);
+ ColumnSelection cs = new ColumnSelection();
+ cs.hideInsertionsFor(repseq);
+ alignFrame.viewport.setColumnSelection(cs);
+ alignFrame.alignPanel.fontChanged();
+ alignFrame.alignPanel.setScrollValues(0, 0);
+ result = true;
+ } catch (Exception ex)
+ {
+ ex.printStackTrace();
}
+ }
+ return result;
+ }
+
+ /**
+ * Load annotations if specified by parameter. Returns true if loaded, else
+ * false.
+ *
+ * @param alignFrame
+ * @return
+ */
+ protected boolean loadAnnotations(AlignFrame alignFrame)
+ {
+ boolean result = false;
+ String param = applet.getParameter("annotations");
+ if (param != null)
+ {
+ param = setProtocolState(param);
- param = applet.getParameter("showFeatureSettings");
- if (param != null && param.equalsIgnoreCase("true"))
+ if (new AnnotationFile().annotateAlignmentView(alignFrame.viewport,
+ param, protocol))
{
- newAlignFrame.viewport.setShowSequenceFeatures(true);
- new FeatureSettings(newAlignFrame.alignPanel);
+ alignFrame.alignPanel.fontChanged();
+ alignFrame.alignPanel.setScrollValues(0, 0);
+ result = true;
}
-
- param = applet.getParameter("annotations");
- if (param != null)
+ else
{
- param = setProtocolState(param);
+ System.err
+ .println("Annotations were not added from annotation file '"
+ + param + "'");
+ }
+ }
+ return result;
+ }
- if (new AnnotationFile().annotateAlignmentView(
- newAlignFrame.viewport, param, protocol))
- {
- newAlignFrame.alignPanel.fontChanged();
- newAlignFrame.alignPanel.setScrollValues(0, 0);
- }
- else
- {
- System.err
- .println("Annotations were not added from annotation file '"
- + param + "'");
- }
+ /**
+ * Load features file and view settings as specified by parameters. Returns
+ * true if features were loaded, else false.
+ *
+ * @param alignFrame
+ * @return
+ */
+ protected boolean loadFeatures(AlignFrame alignFrame)
+ {
+ boolean result = false;
+ // ///////////////////////////
+ // modify display of features
+ // we do this before any features have been loaded, ensuring any hidden
+ // groups are hidden when features first displayed
+ //
+ // hide specific groups
+ //
+ String param = applet.getParameter("hidefeaturegroups");
+ if (param != null)
+ {
+ alignFrame.setFeatureGroupState(separatorListToArray(param), false);
+ // applet.setFeatureGroupStateOn(newAlignFrame, param, false);
+ }
+ // show specific groups
+ param = applet.getParameter("showfeaturegroups");
+ if (param != null)
+ {
+ alignFrame.setFeatureGroupState(separatorListToArray(param), true);
+ // applet.setFeatureGroupStateOn(newAlignFrame, param, true);
+ }
+ // and now load features
+ param = applet.getParameter("features");
+ if (param != null)
+ {
+ param = setProtocolState(param);
- }
+ result = alignFrame.parseFeaturesFile(param, protocol);
+ }
- param = applet.getParameter("jnetfile");
- if (param != null)
+ param = applet.getParameter("showFeatureSettings");
+ if (param != null && param.equalsIgnoreCase(TRUE))
+ {
+ alignFrame.viewport.setShowSequenceFeatures(true);
+ new FeatureSettings(alignFrame.alignPanel);
+ }
+ return result;
+ }
+
+ /**
+ * Load a score file if specified by parameter. Returns true if file was
+ * loaded, else false.
+ *
+ * @param alignFrame
+ */
+ protected boolean loadScoreFile(AlignFrame alignFrame)
+ {
+ boolean result = false;
+ String sScoreFile = applet.getParameter("scoreFile");
+ if (sScoreFile != null && !"".equals(sScoreFile))
+ {
+ try
{
- try
+ if (debug)
{
- param = setProtocolState(param);
- jalview.io.JPredFile predictions = new jalview.io.JPredFile(
- param, protocol);
- JnetAnnotationMaker.add_annotation(predictions,
- newAlignFrame.viewport.getAlignment(), 0, false); // false==do
- SequenceI repseq = newAlignFrame.viewport.getAlignment()
- .getSequenceAt(0);
- newAlignFrame.viewport.getAlignment().setSeqrep(repseq);
- ColumnSelection cs = new ColumnSelection();
- cs.hideInsertionsFor(repseq);
- newAlignFrame.viewport.setColumnSelection(cs);
- // not
- // add
- // sequence
- // profile
- // from
- // concise
- // output
- newAlignFrame.alignPanel.fontChanged();
- newAlignFrame.alignPanel.setScrollValues(0, 0);
- } catch (Exception ex)
+ System.err
+ .println("Attempting to load T-COFFEE score file from the scoreFile parameter");
+ }
+ result = alignFrame.loadScoreFile(sScoreFile);
+ if (!result)
{
- ex.printStackTrace();
+ System.err
+ .println("Failed to parse T-COFFEE parameter as a valid score file ('"
+ + sScoreFile + "')");
}
+ } catch (Exception e)
+ {
+ System.err.printf("Cannot read score file: '%s'. Cause: %s \n",
+ sScoreFile, e.getMessage());
}
- /*
- * <param name="alignpdbfiles" value="false/true"/> Undocumented for 2.6
- * - related to JAL-434
- */
- applet.setAlignPdbStructures(getDefaultParameter("alignpdbfiles",
- false));
- /*
- * <param name="PDBfile" value="1gaq.txt PDB|1GAQ|1GAQ|A PDB|1GAQ|1GAQ|B
- * PDB|1GAQ|1GAQ|C">
- *
- * <param name="PDBfile2" value="1gaq.txt A=SEQA B=SEQB C=SEQB">
- *
- * <param name="PDBfile3" value="1q0o Q45135_9MICO">
- */
+ }
+ return result;
+ }
- int pdbFileCount = 0;
- // Accumulate pdbs here if they are heading for the same view (if
- // alignPdbStructures is true)
- Vector pdbs = new Vector();
- // create a lazy matcher if we're asked to
- jalview.analysis.SequenceIdMatcher matcher = (applet
- .getDefaultParameter("relaxedidmatch", false)) ? new jalview.analysis.SequenceIdMatcher(
- newAlignFrame.getAlignViewport().getAlignment()
- .getSequencesArray()) : null;
+ /**
+ * Load a tree for the alignment if specified by parameter. Returns true if
+ * a tree was loaded, else false.
+ *
+ * @param alignFrame
+ * @return
+ */
+ protected boolean loadTree(AlignFrame alignFrame)
+ {
+ boolean result = false;
+ String treeFile = applet.getParameter("tree");
+ if (treeFile == null)
+ {
+ treeFile = applet.getParameter("treeFile");
+ }
- do
+ if (treeFile != null)
+ {
+ try
{
- if (pdbFileCount > 0)
+ treeFile = setProtocolState(treeFile);
+ NewickFile fin = new NewickFile(treeFile, protocol);
+ fin.parse();
+
+ if (fin.getTree() != null)
{
- param = applet.getParameter("PDBFILE" + pdbFileCount);
+ alignFrame.loadTree(fin, treeFile);
+ result = true;
+ dbgMsg("Successfully imported tree.");
}
else
{
- param = applet.getParameter("PDBFILE");
- }
-
- if (param != null)
- {
- PDBEntry pdb = new PDBEntry();
-
- String seqstring;
- SequenceI[] seqs = null;
- String[] chains = null;
-
- StringTokenizer st = new StringTokenizer(param, " ");
-
- if (st.countTokens() < 2)
- {
- String sequence = applet.getParameter("PDBSEQ");
- if (sequence != null)
- {
- seqs = new SequenceI[]
- { matcher == null ? (Sequence) newAlignFrame
- .getAlignViewport().getAlignment()
- .findName(sequence) : matcher.findIdMatch(sequence) };
- }
-
- }
- else
- {
- param = st.nextToken();
- Vector tmp = new Vector();
- Vector tmp2 = new Vector();
-
- while (st.hasMoreTokens())
- {
- seqstring = st.nextToken();
- StringTokenizer st2 = new StringTokenizer(seqstring, "=");
- if (st2.countTokens() > 1)
- {
- // This is the chain
- tmp2.addElement(st2.nextToken());
- seqstring = st2.nextToken();
- }
- tmp.addElement(matcher == null ? (Sequence) newAlignFrame
- .getAlignViewport().getAlignment()
- .findName(seqstring) : matcher
- .findIdMatch(seqstring));
- }
-
- seqs = new SequenceI[tmp.size()];
- tmp.copyInto(seqs);
- if (tmp2.size() == tmp.size())
- {
- chains = new String[tmp2.size()];
- tmp2.copyInto(chains);
- }
- }
- param = setProtocolState(param);
-
- if (// !jmolAvailable
- // &&
- protocol == AppletFormatAdapter.CLASSLOADER
- && !useXtrnalSviewer)
- {
- // Re: JAL-357 : the bug isn't a problem if we are using an
- // external viewer!
- // TODO: verify this Re:
- // https://mantis.lifesci.dundee.ac.uk/view.php?id=36605
- // This exception preserves the current behaviour where, even if
- // the local pdb file was identified in the class loader
- protocol = AppletFormatAdapter.URL; // this is probably NOT
- // CORRECT!
- param = addProtocol(param); //
- }
-
- pdb.setFile(param);
-
- if (seqs != null)
- {
- for (int i = 0; i < seqs.length; i++)
- {
- if (seqs[i] != null)
- {
- ((Sequence) seqs[i]).addPDBId(pdb);
- StructureSelectionManager.getStructureSelectionManager(
- applet).registerPDBEntry(pdb);
- }
- else
- {
- if (JalviewLite.debug)
- {
- // this may not really be a problem but we give a warning
- // anyway
- System.err
- .println("Warning: Possible input parsing error: Null sequence for attachment of PDB (sequence "
- + i + ")");
- }
- }
- }
-
- if (!alignPdbStructures)
- {
- newAlignFrame.newStructureView(applet, pdb, seqs, chains,
- protocol);
- }
- else
- {
- pdbs.addElement(new Object[]
- { pdb, seqs, chains, new String(protocol) });
- }
- }
+ dbgMsg("Tree parameter did not resolve to a valid tree.");
}
-
- pdbFileCount++;
- } while (param != null || pdbFileCount < 10);
- if (pdbs.size() > 0)
+ } catch (Exception ex)
{
- SequenceI[][] seqs = new SequenceI[pdbs.size()][];
- PDBEntry[] pdb = new PDBEntry[pdbs.size()];
- String[][] chains = new String[pdbs.size()][];
- String[] protocols = new String[pdbs.size()];
- for (int pdbsi = 0, pdbsiSize = pdbs.size(); pdbsi < pdbsiSize; pdbsi++)
- {
- Object[] o = (Object[]) pdbs.elementAt(pdbsi);
- pdb[pdbsi] = (PDBEntry) o[0];
- seqs[pdbsi] = (SequenceI[]) o[1];
- chains[pdbsi] = (String[]) o[2];
- protocols[pdbsi] = (String) o[3];
- }
- newAlignFrame.alignedStructureView(applet, pdb, seqs, chains,
- protocols);
-
+ ex.printStackTrace();
}
}
- else
- {
- fileFound = false;
- applet.remove(launcher);
- applet.repaint();
- }
- callInitCallback();
+ return result;
}
/**
}
}
- String addProtocol(String file)
+ /**
+ * If the file is not already in URL format, tries to locate it by resolving
+ * as a URL.
+ *
+ * @param file
+ * @return
+ */
+ String addProtocol(final String file)
{
if (file.indexOf("://") == -1)
{
- String fl = applet.resolveUrlForLocalOrAbsolute(file,
+ /*
+ * Try relative to document base
+ */
+ String url = applet.resolveUrlForLocalOrAbsolute(file,
getDocumentBase());
- try
+ if (urlExists(url))
{
- if (new java.net.URL(fl).openStream() != null)
+ if (debug)
{
- if (debug)
- {
- System.err.println("Prepended document base for resource: '"
- + file + "'");
- }
- return fl;
+ System.err.println("Prepended document base for resource: '"
+ + file + "'");
}
- } catch (Exception x)
- {
+ return url;
}
- ;
- fl = applet.resolveUrlForLocalOrAbsolute(file, getCodeBase());
- try
+
+ /*
+ * Try relative to codebase
+ */
+ url = applet.resolveUrlForLocalOrAbsolute(file, getCodeBase());
+ if (urlExists(url))
{
- if (new java.net.URL(fl).openStream() != null)
+ if (debug)
{
- if (debug)
- {
- System.err.println("Prepended codebase for resource: '"
- + file + "'");
- }
- return fl;
+ System.err.println("Prepended codebase for resource: '" + file
+ + "'");
}
- } catch (Exception x)
- {
+ return url;
}
- ;
-
}
+ /*
+ * Not resolved, leave unchanged
+ */
return file;
}
+
+ /**
+ * Returns true if an input stream can be opened on the specified URL, else
+ * false.
+ *
+ * @param url
+ * @return
+ */
+ private boolean urlExists(String url)
+ {
+ InputStream is = null;
+ try
+ {
+ is = new URL(url).openStream();
+ if (is != null)
+ {
+ return true;
+ }
+ } catch (Exception x)
+ {
+ // ignore
+ } finally
+ {
+ if (is != null)
+ {
+ try
+ {
+ is.close();
+ } catch (IOException e)
+ {
+ // ignore
+ }
+ }
+ }
+ return false;
+ }
}
/**
{
return def;
}
- if (stn.toLowerCase().equals("true"))
+ if (stn.toLowerCase().equals(TRUE))
{
return true;
}