X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fbin%2FJalviewLite.java;h=3ec841a21f254ce8f235948115ed4a28c3b79053;hb=refs%2Fheads%2Fj2s%2Fdevelop-bh;hp=ae8bc98d92a970750eb4cfe70c4a4dc7184f1513;hpb=7fb90059bba45e0ed35a9c78f440bd7d1563073f;p=jalview.git diff --git a/src/jalview/bin/JalviewLite.java b/src/jalview/bin/JalviewLite.java index ae8bc98..3ec841a 100644 --- a/src/jalview/bin/JalviewLite.java +++ b/src/jalview/bin/JalviewLite.java @@ -1,6 +1,6 @@ /* - * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2) - * Copyright (C) 2014 The Jalview Authors + * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) + * Copyright (C) $$Year-Rel$$ The Jalview Authors * * This file is part of Jalview. * @@ -20,11 +20,17 @@ */ package jalview.bin; +import jalview.analysis.SequenceIdMatcher; import jalview.api.StructureSelectionManagerProvider; import jalview.appletgui.AlignFrame; import jalview.appletgui.AlignViewport; import jalview.appletgui.EmbmenuFrame; import jalview.appletgui.FeatureSettings; +import jalview.appletgui.SplitFrame; +//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; @@ -33,49 +39,70 @@ import jalview.datamodel.PDBEntry; import jalview.datamodel.Sequence; import jalview.datamodel.SequenceGroup; import jalview.datamodel.SequenceI; +import jalview.io.AlignFile; import jalview.io.AnnotationFile; import jalview.io.AppletFormatAdapter; import jalview.io.FileParse; import jalview.io.IdentifyFile; import jalview.io.JnetAnnotationMaker; +//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.javascript.JsSelectionSender; +import jalview.javascript.MouseOverListener; +import jalview.javascript.MouseOverStructureListener; +import jalview.jsdev.GenericFileAdapter; +//import jalview.javascript.MouseOverListener; +//import jalview.javascript.MouseOverStructureListener; +import jalview.schemes.ColourSchemeProperty; +import jalview.schemes.UserColourScheme; import jalview.structure.SelectionListener; import jalview.structure.StructureSelectionManager; import jalview.util.MessageManager; -import java.applet.Applet; -import java.awt.Button; import java.awt.Color; import java.awt.Component; import java.awt.EventQueue; import java.awt.Font; -import java.awt.Frame; import java.awt.Graphics; 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; -import netscape.javascript.JSException; +import javax.swing.JApplet; +import javax.swing.JButton; +import javax.swing.JFrame; + import netscape.javascript.JSObject; +//import netscape.javascript.JSObject; + /** * Jalview Applet. Runs in Java 1.18 runtime * * @author $author$ * @version $Revision: 1.92 $ */ -public class JalviewLite extends Applet implements +public class JalviewLite extends JApplet implements StructureSelectionManagerProvider, JalviewLiteJsApi { + private static final String TRUE = "true"; + + private static final String FALSE = "false"; + public StructureSelectionManager getStructureSelectionManager() { return StructureSelectionManager.getStructureSelectionManager(this); @@ -168,7 +195,7 @@ public class JalviewLite extends Applet implements final String position, final String alignedPosition) { // TODO: could try to highlight in all alignments if alf==null - jalview.analysis.SequenceIdMatcher matcher = new jalview.analysis.SequenceIdMatcher( + SequenceIdMatcher matcher = new SequenceIdMatcher( alf.viewport.getAlignment().getSequencesArray()); final SequenceI sq = matcher.findIdMatch(sequenceId); if (sq != null) @@ -274,7 +301,7 @@ public class JalviewLite extends Applet implements final SequenceGroup sel = new SequenceGroup(); final ColumnSelection csel = new ColumnSelection(); AlignmentI al = alf.viewport.getAlignment(); - jalview.analysis.SequenceIdMatcher matcher = new jalview.analysis.SequenceIdMatcher( + SequenceIdMatcher matcher = new SequenceIdMatcher( alf.viewport.getAlignment().getSequencesArray()); int start = 0, end = al.getWidth(), alw = al.getWidth(); boolean seqsfound = true; @@ -447,12 +474,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)); } } } @@ -494,7 +520,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 @@ -589,7 +615,7 @@ public class JalviewLite extends Applet implements SequenceI[] sqs = null; if (ids != null && ids.length > 0) { - jalview.analysis.SequenceIdMatcher matcher = new jalview.analysis.SequenceIdMatcher( + SequenceIdMatcher matcher = new SequenceIdMatcher( alf.viewport.getAlignment().getSequencesArray()); int s = 0; sqs = new SequenceI[ids.length]; @@ -630,7 +656,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 : ""; } /* @@ -640,7 +666,7 @@ public class JalviewLite extends Applet implements */ public String getAlignment(String format) { - return getAlignmentFrom(getDefaultTargetFrame(), format, "true"); + return getAlignmentFrom(getDefaultTargetFrame(), format, TRUE); } /* @@ -652,7 +678,7 @@ public class JalviewLite extends Applet implements */ public String getAlignmentFrom(AlignFrame alf, String format) { - return getAlignmentFrom(alf, format, "true"); + return getAlignmentFrom(alf, format, TRUE); } /* @@ -678,7 +704,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); @@ -709,8 +735,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); @@ -838,7 +864,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); @@ -867,7 +893,7 @@ public class JalviewLite extends Applet implements setMouseoverListener(currentAlignFrame, listener); } - private Vector javascriptListeners = new Vector(); + private Vector javascriptListeners = new Vector(); /* * (non-Javadoc) @@ -888,7 +914,7 @@ public class JalviewLite extends Applet implements return; } } - jalview.javascript.MouseOverListener mol = new jalview.javascript.MouseOverListener( + MouseOverListener mol = new MouseOverListener( this, af, listener); javascriptListeners.addElement(mol); StructureSelectionManager.getStructureSelectionManager(this) @@ -932,8 +958,7 @@ public class JalviewLite extends Applet implements return; } } - jalview.javascript.JsSelectionSender mol = new jalview.javascript.JsSelectionSender( - this, af, listener); + JsSelectionSender mol = new JsSelectionSender(this, af, listener); javascriptListeners.addElement(mol); StructureSelectionManager.getStructureSelectionManager(this) .addSelectionListener(mol); @@ -965,7 +990,7 @@ public class JalviewLite extends Applet implements return; } } - jalview.javascript.MouseOverStructureListener mol = new jalview.javascript.MouseOverStructureListener( + MouseOverStructureListener mol = new MouseOverStructureListener( this, listener, separatorListToArray(modelSet)); javascriptListeners.addElement(mol); StructureSelectionManager.getStructureSelectionManager(this) @@ -1062,8 +1087,7 @@ public class JalviewLite extends Applet implements { while (javascriptListeners.size() > 0) { - jalview.javascript.JSFunctionExec mol = javascriptListeners - .elementAt(0); + JSFunctionExec mol = javascriptListeners.elementAt(0); javascriptListeners.removeElement(mol); if (mol instanceof SelectionListener) { @@ -1089,7 +1113,7 @@ public class JalviewLite extends Applet implements StructureSelectionManager.release(this); } - private jalview.javascript.JSFunctionExec jsFunctionExec; + private JSFunctionExec jsFunctionExec; /* * (non-Javadoc) @@ -1200,7 +1224,7 @@ public class JalviewLite extends Applet implements public void scrollViewToColumnIn(final AlignFrame alf, final String leftHandColumn) { - java.awt.EventQueue.invokeLater(new Runnable() + EventQueue.invokeLater(new Runnable() { @Override @@ -1233,7 +1257,10 @@ public class JalviewLite extends Applet implements String file = "No file"; - Button launcher = new Button("Start Jalview"); + String file2 = null; + + JButton launcher = new JButton( + MessageManager.getString("label.start_jalview")); /** * The currentAlignFrame is static, it will change if and when the user @@ -1361,11 +1388,8 @@ 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) { @@ -1378,7 +1402,7 @@ public class JalviewLite extends Applet implements if (externalsviewer != null) { useXtrnalSviewer = externalsviewer.trim().toLowerCase() - .equals("true"); + .equals(TRUE); } /** * if true disable the check for jmol @@ -1386,7 +1410,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 @@ -1451,38 +1475,47 @@ 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); - loader.start(); + LoadingThread loader = new LoadingThread(file, file2, this); + /** + * @j2sNative + * + * loader.run(); + */ + { + 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 { @@ -1523,7 +1556,7 @@ public class JalviewLite extends Applet implements { notFailed = true; } - } catch (JSException jsex) + } catch (Exception jsex) { System.err.println("Attempt " + tries + " to access LiveConnect javascript failed."); @@ -1587,7 +1620,7 @@ public class JalviewLite extends Applet implements * @param height * height of new frame */ - public static void addFrame(final Frame frame, String title, int width, + public static void addFrame(final JFrame frame, String title, int width, int height) { frame.setLocation(lastFrameX, lastFrameY); @@ -1756,27 +1789,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); } @@ -1809,44 +1834,138 @@ 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; } - public void run() + public void run() { + /** + * + * @j2sNative + * + * + * System.out.println("BYPASSING JMOL LOADING FOR NOW. THIS WILL BE DONE ANOTHER WAY") + * + */ + { + LoadJmolThread jmolchecker = new LoadJmolThread(); + jmolchecker.start(); + while (jmolchecker.notFinished()) { + // wait around until the Jmol check is complete. + try { + Thread.sleep(2); + } catch (Exception e) { + } + } + } + startLoading(); + // applet.callInitCallback(); + } + + /** + * Load the alignment and any related files as specified by applet + * parameters + */ + private void startLoading() { - LoadJmolThread jmolchecker = new LoadJmolThread(); - jmolchecker.start(); - while (jmolchecker.notFinished()) + dbgMsg("Loading thread started with:\n>>file\n" + _file + ">>endfile"); + + dbgMsg("Loading started."); + + AlignFrame newAlignFrame = readAlignment(_file); + AlignFrame newAlignFrame2 = readAlignment(_file2); + if (newAlignFrame != null) { - // wait around until the Jmol check is complete. - try - { - Thread.sleep(2); - } catch (Exception e) - { - } - ; + addToDisplay(newAlignFrame, newAlignFrame2); + loadTree(newAlignFrame); + + loadScoreFile(newAlignFrame); + + loadFeatures(newAlignFrame); + + loadAnnotations(newAlignFrame); + + loadJnetFile(newAlignFrame); + + loadPdbFiles(newAlignFrame); } - startLoading(); - // applet.callInitCallback(); + else + { + fileFound = false; + applet.remove(launcher); + applet.repaint(); + } + callInitCallback(); } - private void startLoading() + /** + * Add an AlignFrame to the display; or if two are provided, a SplitFrame. + * + * @param af + * @param af2 + */ + public void addToDisplay(AlignFrame af, AlignFrame af2) { - AlignFrame newAlignFrame; - dbgMsg("Loading thread started with:\n>>file\n" + _file + ">>endfile"); - file = setProtocolState(_file); + if (af2 == null) + { + af.addToDisplay(embedded); + } + else + { + SplitFrame sf = new SplitFrame(af, af2); + sf.addToDisplay(embedded, JalviewLite.this); + } + } - format = new jalview.io.IdentifyFile().Identify(file, protocol); + /** + * 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 + "'"); - dbgMsg("Loading started."); - Alignment al = null; + 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."); @@ -1855,9 +1974,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) { @@ -1872,344 +1991,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 + SequenceIdMatcher matcher = (applet.getDefaultParameter( + "relaxedidmatch", false)) ? new 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()) { - 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)); } - } catch (Exception ex) + + 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) { - 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); + 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]; } - // show specific groups - param = applet.getParameter("showfeaturegroups"); - if (param != null) - { - newAlignFrame.setFeatureGroupState(separatorListToArray(param), - true); - // applet.setFeatureGroupStateOn(newAlignFrame, param, true); - } - // 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); + AlignFile predictions = GenericFileAdapter.getFile("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; + } - param = applet.getParameter("showFeatureSettings"); - if (param != null && param.equalsIgnoreCase("true")) + /** + * 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); + + 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; - - do + /** + * 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"); + } + + 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; } /** @@ -2240,48 +2393,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; + } } /** @@ -2560,7 +2753,7 @@ public class JalviewLite extends Applet implements { return def; } - if (stn.toLowerCase().equals("true")) + if (stn.toLowerCase().equals(TRUE)) { return true; } @@ -2689,13 +2882,12 @@ public class JalviewLite extends Applet implements { return defcolour; } - Color col = jalview.schemes.ColourSchemeProperty - .getAWTColorFromName(colprop); + Color col = ColourSchemeProperty.getAWTColorFromName(colprop); if (col == null) { try { - col = new jalview.schemes.UserColourScheme(colprop).findColour('A'); + col = new UserColourScheme(colprop).findColour('A'); } catch (Exception ex) { System.err.println("Couldn't parse '" + colprop @@ -2731,17 +2923,19 @@ public class JalviewLite extends Applet implements private String resolveUrlForLocalOrAbsolute(String url, URL localref) { String codebase = localref.toString(); - if (url.indexOf("/") == 0) - { - url = codebase.substring(0, codebase.length() - - localref.getFile().length()) - + url; - } - else - { - url = localref + url; - } - return url; + // BH removing file name and query + int pt = codebase.indexOf("?"); + if (pt < 0) + pt = codebase.length(); + codebase = codebase.substring(0, pt); + codebase = codebase.substring(0, codebase.lastIndexOf("/") + 1); + // codebase is now http://...xxx/ + if (url.indexOf("/") == 0 && !localref.getProtocol().equals("file")) + { // http:// https:// we do NOT allow going to the root file system directory! + pt = codebase.indexOf("/", 8); + return codebase.substring(0, pt) + url; + } + return codebase + url; } /**