X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=inline;f=src%2Fjalview%2Fbin%2FJalviewLite.java;h=8a9c54bfc91f60370520bc2c2335488e4ea10d52;hb=31a33833640b743a506f7801388b17f96e915ef3;hp=8fe90f53f0c8b89e72ff2d99c4283a4e8582a782;hpb=31e04d77fb5043481cc20fb455a8135ebc9951de;p=jalview.git
diff --git a/src/jalview/bin/JalviewLite.java b/src/jalview/bin/JalviewLite.java
index 8fe90f5..8a9c54b 100644
--- a/src/jalview/bin/JalviewLite.java
+++ b/src/jalview/bin/JalviewLite.java
@@ -1,19 +1,22 @@
/*
- * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8)
- * Copyright (C) 2012 J Procter, AM Waterhouse, LM Lui, J Engelhardt, G Barton, M Clamp, S Searle
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
*
* This file is part of Jalview.
*
* Jalview is free software: you can redistribute it and/or
* modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
*
* Jalview is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
- * You should have received a copy of the GNU General Public License along with Jalview. If not, see .
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview. If not, see .
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
*/
package jalview.bin;
@@ -22,6 +25,7 @@ import jalview.appletgui.AlignFrame;
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;
@@ -34,12 +38,15 @@ import jalview.io.AnnotationFile;
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 jalview.structure.SelectionListener;
import jalview.structure.StructureSelectionManager;
+import jalview.util.MessageManager;
import java.applet.Applet;
import java.awt.Button;
@@ -53,9 +60,12 @@ import java.awt.event.ActionEvent;
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;
+import java.util.List;
import java.util.StringTokenizer;
import java.util.Vector;
@@ -71,6 +81,10 @@ public class JalviewLite extends Applet implements
StructureSelectionManagerProvider, JalviewLiteJsApi
{
+ private static final String TRUE = "true";
+
+ private static final String FALSE = "false";
+
public StructureSelectionManager getStructureSelectionManager()
{
return StructureSelectionManager.getStructureSelectionManager(this);
@@ -442,12 +456,11 @@ public class JalviewLite extends Applet implements
end = rs.findIndex(end);
if (csel != null)
{
- Vector cs = csel.getSelected();
+ List cs = csel.getSelected();
csel.clear();
- for (int csi = 0, csiS = cs.size(); csi < csiS; csi++)
+ for (Integer selectedCol : cs)
{
- csel.addElement(rs.findIndex(((Integer) cs.elementAt(csi))
- .intValue()));
+ csel.addElement(rs.findIndex(selectedCol));
}
}
}
@@ -489,7 +502,7 @@ public class JalviewLite extends Applet implements
{
try
{
- boolean seqlimits = suffix.equalsIgnoreCase("true");
+ boolean seqlimits = suffix.equalsIgnoreCase(TRUE);
if (alf.viewport.getSelectionGroup() != null)
{
// JBPNote: getSelectionAsNewSequence behaviour has changed - this
@@ -625,7 +638,7 @@ public class JalviewLite extends Applet implements
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 : "";
}
/*
@@ -635,7 +648,7 @@ public class JalviewLite extends Applet implements
*/
public String getAlignment(String format)
{
- return getAlignmentFrom(getDefaultTargetFrame(), format, "true");
+ return getAlignmentFrom(getDefaultTargetFrame(), format, TRUE);
}
/*
@@ -647,7 +660,7 @@ public class JalviewLite extends Applet implements
*/
public String getAlignmentFrom(AlignFrame alf, String format)
{
- return getAlignmentFrom(alf, format, "true");
+ return getAlignmentFrom(alf, format, TRUE);
}
/*
@@ -673,7 +686,7 @@ public class JalviewLite extends Applet implements
{
try
{
- boolean seqlimits = suffix.equalsIgnoreCase("true");
+ boolean seqlimits = suffix.equalsIgnoreCase(TRUE);
String reply = new AppletFormatAdapter().formatSequences(format,
alf.viewport.getAlignment(), seqlimits);
@@ -704,8 +717,8 @@ public class JalviewLite extends Applet implements
*/
public void loadAnnotationFrom(AlignFrame alf, String annotation)
{
- if (new AnnotationFile().readAnnotationFile(alf.getAlignViewport()
- .getAlignment(), annotation, AppletFormatAdapter.PASTE))
+ if (new AnnotationFile().annotateAlignmentView(alf.getAlignViewport(),
+ annotation, AppletFormatAdapter.PASTE))
{
alf.alignPanel.fontChanged();
alf.alignPanel.setScrollValues(0, 0);
@@ -833,7 +846,7 @@ public class JalviewLite extends Applet implements
*/
public AlignFrame loadAlignment(String text, String title)
{
- Alignment al = null;
+ AlignmentI al = null;
String format = new IdentifyFile().Identify(text,
AppletFormatAdapter.PASTE);
@@ -1228,7 +1241,10 @@ public class JalviewLite extends Applet implements
String file = "No file";
- Button launcher = new Button("Start Jalview");
+ String file2 = null;
+
+ Button launcher = new Button(
+ MessageManager.getString("label.start_jalview"));
/**
* The currentAlignFrame is static, it will change if and when the user
@@ -1264,7 +1280,7 @@ public class JalviewLite extends Applet implements
public static boolean debug = false;
- static String builddate = null, version = null;
+ static String builddate = null, version = null, installation = null;
private static void initBuildDetails()
{
@@ -1272,6 +1288,7 @@ public class JalviewLite extends Applet implements
{
builddate = "unknown";
version = "test";
+ installation = "Webstart";
java.net.URL url = JalviewLite.class
.getResource("/.build_properties");
if (url != null)
@@ -1291,6 +1308,10 @@ public class JalviewLite extends Applet implements
{
builddate = line.substring(line.indexOf("=") + 1);
}
+ if (line.indexOf("INSTALLATION") > -1)
+ {
+ installation = line.substring(line.indexOf("=") + 1);
+ }
}
} catch (Exception ex)
{
@@ -1306,6 +1327,12 @@ public class JalviewLite extends Applet implements
return builddate;
}
+ public static String getInstallation()
+ {
+ initBuildDetails();
+ return installation;
+ }
+
public static String getVersion()
{
initBuildDetails();
@@ -1345,23 +1372,20 @@ public class JalviewLite extends Applet implements
/**
* turn on extra applet debugging
*/
- String dbg = getParameter("debug");
- if (dbg != null)
- {
- debug = dbg.toLowerCase().equals("true");
- }
+ debug = TRUE.equalsIgnoreCase(getParameter("debug"));
if (debug)
{
System.err.println("JalviewLite Version " + getVersion());
System.err.println("Build Date : " + getBuildDate());
+ System.err.println("Installation : " + getInstallation());
}
String externalsviewer = getParameter("externalstructureviewer");
if (externalsviewer != null)
{
useXtrnalSviewer = externalsviewer.trim().toLowerCase()
- .equals("true");
+ .equals(TRUE);
}
/**
* if true disable the check for jmol
@@ -1369,7 +1393,7 @@ public class JalviewLite extends Applet implements
String chkforJmol = getParameter("nojmol");
if (chkforJmol != null)
{
- checkForJmol = !chkforJmol.equals("true");
+ checkForJmol = !chkforJmol.equals(TRUE);
}
/**
* get the separator parameter if present
@@ -1387,8 +1411,7 @@ public class JalviewLite extends Applet implements
}
else
{
- throw new Error(
- "Invalid separator parameter - must be non-zero length");
+ throw new Error(MessageManager.getString("error.invalid_separator_parameter"));
}
}
int r = 255;
@@ -1435,38 +1458,40 @@ public class JalviewLite extends Applet implements
file = data.toString();
}
}
+ if (TRUE.equalsIgnoreCase(getParameter("enableSplitFrame")))
+ {
+ 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
{
@@ -1478,6 +1503,43 @@ public class JalviewLite extends Applet implements
}
}
+ private void initLiveConnect()
+ {
+ // try really hard to get the liveConnect thing working
+ boolean notFailed = false;
+ int tries = 0;
+ while (!notFailed && tries < 10)
+ {
+ if (tries > 0)
+ {
+ System.err.println("LiveConnect request thread going to sleep.");
+ }
+ try
+ {
+ Thread.sleep(700 * (1 + tries));
+ } catch (InterruptedException q)
+ {
+ }
+ ;
+ if (tries++ > 0)
+ {
+ System.err.println("LiveConnect request thread woken up.");
+ }
+ try
+ {
+ JSObject scriptObject = JSObject.getWindow(this);
+ if (scriptObject.eval("navigator") != null)
+ {
+ notFailed = true;
+ }
+ } catch (Exception jsex)
+ {
+ System.err.println("Attempt " + tries
+ + " to access LiveConnect javascript failed.");
+ }
+ }
+ }
+
private void callInitCallback()
{
String initjscallback = getParameter("oninit");
@@ -1496,6 +1558,9 @@ public class JalviewLite extends Applet implements
{
}
;
+ // try really hard to let the browser plugin know we want liveconnect
+ initLiveConnect();
+
if (scriptObject != null)
{
try
@@ -1610,15 +1675,19 @@ public class JalviewLite extends Applet implements
g.setColor(Color.cyan);
g.fillRect(0, 0, getSize().width, getSize().height);
g.setColor(Color.red);
- g.drawString("Jalview can't open file", 5, 15);
+ g.drawString(
+ MessageManager.getString("label.jalview_cannot_open_file"),
+ 5, 15);
g.drawString("\"" + file + "\"", 5, 30);
}
else if (embedded)
{
g.setColor(Color.black);
g.setFont(new Font("Arial", Font.BOLD, 24));
- g.drawString("Jalview Applet", 50, getSize().height / 2 - 30);
- g.drawString("Loading Data...", 50, getSize().height / 2);
+ g.drawString(MessageManager.getString("label.jalview_applet"), 50,
+ getSize().height / 2 - 30);
+ g.drawString(MessageManager.getString("label.loading_data") + "...",
+ 50, getSize().height / 2);
}
}
@@ -1696,27 +1765,19 @@ public class JalviewLite extends Applet implements
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);
}
@@ -1749,9 +1810,10 @@ public class JalviewLite extends Applet implements
return file;
}
- public LoadingThread(String _file, JalviewLite _applet)
+ public LoadingThread(String file, String file2, JalviewLite _applet)
{
- this._file = _file;
+ this._file = file;
+ this._file2 = file2;
applet = _applet;
}
@@ -1768,25 +1830,112 @@ public class JalviewLite extends Applet implements
} 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.");
+ al.setDataset(null);
+ 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.");
@@ -1795,9 +1944,9 @@ public class JalviewLite extends Applet implements
{
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)
{
@@ -1812,337 +1961,378 @@ public class JalviewLite extends Applet implements
}
}
}
- 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;
+ /*
+ * Undocumented for 2.6 -
+ * related to JAL-434
+ */
+
+ applet.setAlignPdbStructures(getDefaultParameter("alignpdbfiles",
+ false));
+ /*
+ *
+ *
+ *
+ *
+ *
+ */
+
+ 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("Sequences from "
- + applet.getDocumentBase());
+ param = applet.getParameter("PDBFILE");
}
- newAlignFrame.statusBar.setText("Successfully loaded file " + 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())
{
- dbgMsg("Tree parameter did not resolve to a valid tree.");
+ 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())
+ {
+ 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)
+ 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++)
{
- newAlignFrame.setFeatureGroupState(separatorListToArray(param),
- true);
- // applet.setFeatureGroupStateOn(newAlignFrame, param, true);
+ 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.showSequenceFeatures(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().readAnnotationFile(
- newAlignFrame.viewport.getAlignment(), 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
- // 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());
}
- /*
- * Undocumented for 2.6
- * - related to JAL-434
- */
- applet.setAlignPdbStructures(getDefaultParameter("alignpdbfiles",
- false));
- /*
- *
- *
- *
- *
- *
- */
+ }
+ 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);
- }
- 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;
}
/**
@@ -2173,48 +2363,88 @@ public class JalviewLite extends Applet implements
}
}
- 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;
+ }
}
/**
@@ -2272,7 +2502,9 @@ public class JalviewLite extends Applet implements
// note separator local variable intentionally masks object field
int seplen = separator.length();
if (list == null || list.equals("") || list.equals(separator))
+ {
return null;
+ }
java.util.Vector jv = new Vector();
int cp = 0, pos;
while ((pos = list.indexOf(separator, cp)) > cp)
@@ -2491,7 +2723,7 @@ public class JalviewLite extends Applet implements
{
return def;
}
- if (stn.toLowerCase().equals("true"))
+ if (stn.toLowerCase().equals(TRUE))
{
return true;
}