2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.6)
3 * Copyright (C) 2010 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
11 * Jalview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
20 import jalview.appletgui.AlignFrame;
21 import jalview.appletgui.EmbmenuFrame;
22 import jalview.appletgui.FeatureSettings;
23 import jalview.datamodel.Alignment;
24 import jalview.datamodel.AlignmentI;
25 import jalview.datamodel.ColumnSelection;
26 import jalview.datamodel.PDBEntry;
27 import jalview.datamodel.Sequence;
28 import jalview.datamodel.SequenceGroup;
29 import jalview.datamodel.SequenceI;
30 import jalview.io.AnnotationFile;
31 import jalview.io.AppletFormatAdapter;
32 import jalview.io.FileParse;
33 import jalview.io.IdentifyFile;
34 import jalview.io.JnetAnnotationMaker;
35 import jalview.javascript.JsCallBack;
36 import jalview.structure.SelectionListener;
37 import jalview.structure.StructureSelectionManager;
39 import java.applet.Applet;
40 import java.awt.Button;
41 import java.awt.Color;
42 import java.awt.Component;
44 import java.awt.Frame;
45 import java.awt.Graphics;
46 import java.awt.event.ActionEvent;
47 import java.awt.event.WindowAdapter;
48 import java.awt.event.WindowEvent;
49 import java.io.BufferedReader;
50 import java.io.InputStreamReader;
51 import java.util.StringTokenizer;
52 import java.util.Vector;
55 * Jalview Applet. Runs in Java 1.18 runtime
60 public class JalviewLite extends Applet
63 // /////////////////////////////////////////
64 // The following public methods maybe called
65 // externally, eg via javascript in HTML page
67 * @return String list of selected sequence IDs, each terminated by "¬"
70 public String getSelectedSequences()
72 return getSelectedSequencesFrom(getDefaultTargetFrame());
77 * separator string or null for default
78 * @return String list of selected sequence IDs, each terminated by sep or
81 public String getSelectedSequences(String sep)
83 return getSelectedSequencesFrom(getDefaultTargetFrame(), sep);
88 * alignframe containing selection
89 * @return String list of selected sequence IDs, each terminated by "¬"
92 public String getSelectedSequencesFrom(AlignFrame alf)
94 return getSelectedSequencesFrom(alf, "¬");
98 * get list of selected sequence IDs separated by given separator
101 * window containing selection
103 * separator string to use - default is "¬"
104 * @return String list of selected sequence IDs, each terminated by the given
107 public String getSelectedSequencesFrom(AlignFrame alf, String sep)
109 StringBuffer result = new StringBuffer("");
110 if (sep == null || sep.length() == 0)
114 if (alf.viewport.getSelectionGroup() != null)
116 SequenceI[] seqs = alf.viewport.getSelectionGroup()
117 .getSequencesInOrder(alf.viewport.getAlignment());
119 for (int i = 0; i < seqs.length; i++)
121 result.append(seqs[i].getName());
126 return result.toString();
131 * @param sequenceId id of sequence to highlight
132 * @param position integer position [ tobe implemented or range ] on sequence
133 * @param alignedPosition true/false/empty string - indicate if position is an alignment column or unaligned sequence position
135 public void highlight(String sequenceId, String position, String alignedPosition)
137 highlight(currentAlignFrame, sequenceId, position, alignedPosition);
141 * @param sequenceId id of sequence to highlight
142 * @param position integer position [ tobe implemented or range ] on sequence
143 * @param alignedPosition false, blank or something else - indicate if position is an alignment column or unaligned sequence position
145 public void highlight(AlignFrame alf, String sequenceId, String position, String alignedPosition)
147 SequenceI sq = alf.getAlignViewport().getAlignment().findName(sequenceId);
152 apos = new Integer(position).intValue();
154 } catch (NumberFormatException ex)
158 // use vamsas listener to broadcast to all listeners in scope
159 if (alignedPosition!=null && (alignedPosition.trim().length()==0 || alignedPosition.toLowerCase().indexOf("false")>-1))
161 StructureSelectionManager.getStructureSelectionManager().mouseOverVamsasSequence(sq,sq.findIndex(apos));
163 StructureSelectionManager.getStructureSelectionManager().mouseOverVamsasSequence(sq,apos);
169 * select regions of the currrent alignment frame
171 * @param sequenceIds String separated list of sequence ids or empty string
173 * String separated list { column range or column, ..} or empty string
175 public void select(String sequenceIds, String columns)
177 select(currentAlignFrame, sequenceIds, columns, "¬");
181 * select regions of the currrent alignment frame
184 * String separated list { column range, seq1...seqn sequence ids }
186 * separator between toselect fields
188 public void select(String sequenceIds, String columns, String sep)
190 select(currentAlignFrame, sequenceIds, columns, sep);
194 * select regions of the given alignment frame
198 * String separated list { column range, seq1...seqn sequence ids }
200 * separator between toselect fields
202 public void select(AlignFrame alf, String sequenceIds, String columns)
204 select(alf, sequenceIds, columns, separator);
208 * select regions of the given alignment frame
212 * String separated list { column range, seq1...seqn sequence ids }
214 * separator between toselect fields
216 public void select(AlignFrame alf, String sequenceIds, String columns,
219 if (sep == null || sep.length() == 0)
224 String[] ids = separatorListToArray(sequenceIds, sep);
225 String[] cols = separatorListToArray(columns, sep);
226 SequenceGroup sel = new SequenceGroup();
227 ColumnSelection csel = new ColumnSelection();
228 AlignmentI al = alf.viewport.getAlignment();
229 int start = 0, end = al.getWidth(), alw = al.getWidth();
230 if (ids != null && ids.length > 0)
232 for (int i = 0; i < ids.length; i++)
234 if (ids[i].trim().length() == 0)
238 SequenceI sq = al.findName(ids[i]);
241 sel.addSequence(sq, false);
245 if (cols != null && cols.length > 0)
247 boolean seset = false;
248 for (int i = 0; i < cols.length; i++)
250 String cl = cols[i].trim();
251 if (cl.length() == 0)
256 if ((p = cl.indexOf("-")) > -1)
258 int from = -1, to = -1;
261 from = new Integer(cl.substring(0, p)).intValue();
263 } catch (NumberFormatException ex)
266 .println("ERROR: Couldn't parse first integer in range element column selection string '"
267 + cl + "' - format is 'from-to'");
272 to = new Integer(cl.substring(p + 1)).intValue();
274 } catch (NumberFormatException ex)
277 .println("ERROR: Couldn't parse second integer in range element column selection string '"
278 + cl + "' - format is 'from-to'");
281 if (from >= 0 && to >= 0)
298 // comment to prevent range extension
308 for (int r = from; r <= to; r++)
310 if (r >= 0 && r < alw)
317 System.err.println("Range '" + cl + "' deparsed as [" + from
323 System.err.println("ERROR: Invalid Range '" + cl
324 + "' deparsed as [" + from + "," + to + "]");
332 r = new Integer(cl).intValue();
334 } catch (NumberFormatException ex)
337 .println("ERROR: Couldn't parse integer from point selection element of column selection string '"
341 if (r >= 0 && r <= alw)
351 // comment to prevent range extension
364 System.err.println("Point selection '" + cl
365 + "' deparsed as [" + r + "]");
370 System.err.println("ERROR: Invalid Point selection '" + cl
371 + "' deparsed as [" + r + "]");
376 sel.setStartRes(start);
378 alf.select(sel, csel);
383 * get sequences selected in current alignFrame and return their alignment in
384 * format 'format' either with or without suffix
387 * - where selection is
389 * - format of alignment file
391 * - "true" to append /start-end string to each sequence ID
392 * @return selected sequences as flat file or empty string if there was no
395 public String getSelectedSequencesAsAlignment(String format, String suffix)
397 return getSelectedSequencesAsAlignmentFrom(currentAlignFrame, format,
402 * get sequences selected in alf and return their alignment in format 'format'
403 * either with or without suffix
406 * - where selection is
408 * - format of alignment file
410 * - "true" to append /start-end string to each sequence ID
411 * @return selected sequences as flat file or empty string if there was no
414 public String getSelectedSequencesAsAlignmentFrom(AlignFrame alf,
415 String format, String suffix)
419 boolean seqlimits = suffix.equalsIgnoreCase("true");
420 if (alf.viewport.getSelectionGroup() != null)
422 String reply = new AppletFormatAdapter().formatSequences(format,
423 new Alignment(alf.viewport.getSelectionAsNewSequence()),
427 } catch (Exception ex)
429 ex.printStackTrace();
430 return "Error retrieving alignment in " + format + " format. ";
435 public String getAlignment(String format)
437 return getAlignmentFrom(getDefaultTargetFrame(), format, "true");
440 public String getAlignmentFrom(AlignFrame alf, String format)
442 return getAlignmentFrom(alf, format, "true");
445 public String getAlignment(String format, String suffix)
447 return getAlignmentFrom(getDefaultTargetFrame(), format, suffix);
450 public String getAlignmentFrom(AlignFrame alf, String format,
455 boolean seqlimits = suffix.equalsIgnoreCase("true");
457 String reply = new AppletFormatAdapter().formatSequences(format,
458 alf.viewport.getAlignment(), seqlimits);
460 } catch (Exception ex)
462 ex.printStackTrace();
463 return "Error retrieving alignment in " + format + " format. ";
467 public void loadAnnotation(String annotation)
469 loadAnnotationFrom(getDefaultTargetFrame(), annotation);
472 public void loadAnnotationFrom(AlignFrame alf, String annotation)
474 if (new AnnotationFile().readAnnotationFile(alf.getAlignViewport()
475 .getAlignment(), annotation, AppletFormatAdapter.PASTE))
477 alf.alignPanel.fontChanged();
478 alf.alignPanel.setScrollValues(0, 0);
482 alf.parseFeaturesFile(annotation, AppletFormatAdapter.PASTE);
486 public String getFeatures(String format)
488 return getFeaturesFrom(getDefaultTargetFrame(), format);
491 public String getFeaturesFrom(AlignFrame alf, String format)
493 return alf.outputFeatures(false, format);
496 public String getAnnotation()
498 return getAnnotationFrom(getDefaultTargetFrame());
501 public String getAnnotationFrom(AlignFrame alf)
503 return alf.outputAnnotations(false);
506 public AlignFrame newView()
508 return newViewFrom(getDefaultTargetFrame());
511 public AlignFrame newView(String name)
513 return newViewFrom(getDefaultTargetFrame(), name);
516 public AlignFrame newViewFrom(AlignFrame alf)
518 return alf.newView(null);
521 public AlignFrame newViewFrom(AlignFrame alf, String name)
523 return alf.newView(name);
529 * alignment file as a string
532 * @return null or new alignment frame
534 public AlignFrame loadAlignment(String text, String title)
538 String format = new IdentifyFile().Identify(text,
539 AppletFormatAdapter.PASTE);
542 al = new AppletFormatAdapter().readFile(text,
543 AppletFormatAdapter.PASTE, format);
544 if (al.getHeight() > 0)
546 return new AlignFrame(al, this, title, false);
548 } catch (java.io.IOException ex)
550 ex.printStackTrace();
555 public void setMouseoverListener(String listener)
557 setMouseoverListener(currentAlignFrame, listener);
560 private Vector mouseoverListeners = new Vector();
562 public void setMouseoverListener(AlignFrame af, String listener)
564 if (listener != null)
566 listener = listener.trim();
567 if (listener.length() == 0)
570 .println("jalview Javascript error: Ignoring empty function for mouseover listener.");
574 jalview.javascript.MouseOverListener mol = new jalview.javascript.MouseOverListener(
576 mouseoverListeners.addElement(mol);
577 StructureSelectionManager.getStructureSelectionManager()
578 .addStructureViewerListener(mol);
581 System.err.println("Added a mouseover listener for "
582 + ((af == null) ? "All frames" : "Just views for "
583 + af.getAlignViewport().getSequenceSetId()));
584 System.err.println("There are now " + mouseoverListeners.size()
585 + " listeners in total.");
589 public void setSelectionListener(String listener)
591 setSelectionListener(null, listener);
594 public void setSelectionListener(AlignFrame af, String listener)
596 if (listener != null)
598 listener = listener.trim();
599 if (listener.length() == 0)
602 .println("jalview Javascript error: Ignoring empty function for selection listener.");
606 jalview.javascript.JsSelectionSender mol = new jalview.javascript.JsSelectionSender(
608 mouseoverListeners.addElement(mol);
609 StructureSelectionManager.getStructureSelectionManager()
610 .addSelectionListener(mol);
613 System.err.println("Added a selection listener for "
614 + ((af == null) ? "All frames" : "Just views for "
615 + af.getAlignViewport().getSequenceSetId()));
616 System.err.println("There are now " + mouseoverListeners.size()
617 + " listeners in total.");
622 * remove any callback using the given listener function and associated with
623 * the given alignFrame (or null for all callbacks)
630 public void removeJavascriptListener(AlignFrame af, String listener)
632 if (listener != null)
634 listener = listener.trim();
635 if (listener.length() == 0)
640 boolean rprt = false;
641 for (int ms=0,msSize=mouseoverListeners.size();ms<msSize;)
643 Object lstn = mouseoverListeners.elementAt(ms);
644 JsCallBack lstner = (JsCallBack) lstn;
645 if ((af == null || lstner.getAlignFrame() == af)
646 && (listener == null || lstner.getListenerFunction().equals(
649 mouseoverListeners.removeElement(lstner);
651 if (lstner instanceof SelectionListener)
653 StructureSelectionManager.getStructureSelectionManager()
654 .removeSelectionListener((SelectionListener) lstner);
658 StructureSelectionManager.getStructureSelectionManager()
659 .removeStructureViewerListener(lstner, null);
664 System.err.println("Removed listener '" + listener + "'");
672 System.err.println("There are now " + mouseoverListeners.size()
673 + " listeners in total.");
679 if (mouseoverListeners!=null)
681 while (mouseoverListeners.size()>0)
683 Object mol = mouseoverListeners.elementAt(0);
684 mouseoverListeners.removeElement(mol);
685 if (mol instanceof SelectionListener)
687 StructureSelectionManager.getStructureSelectionManager().removeSelectionListener((SelectionListener)mol);
689 StructureSelectionManager.getStructureSelectionManager().removeStructureViewerListener(mol, null);
695 * send a mouseover message to all the alignment windows associated with the
696 * given residue in the pdbfile
702 public void mouseOverStructure(int pdbResNum, String chain, String pdbfile)
704 StructureSelectionManager.getStructureSelectionManager()
705 .mouseOverStructure(pdbResNum, chain, pdbfile);
708 // //////////////////////////////////////////////
709 // //////////////////////////////////////////////
711 public static int lastFrameX = 200;
713 public static int lastFrameY = 200;
715 boolean fileFound = true;
717 String file = "No file";
719 Button launcher = new Button("Start Jalview");
722 * The currentAlignFrame is static, it will change if and when the user
723 * selects a new window. Note that it will *never* point back to the embedded
724 * AlignFrame if the applet is started as embedded on the page and then
725 * afterwards a new view is created.
727 public static AlignFrame currentAlignFrame = null;
730 * This is the first frame to be displayed, and does not change. API calls
731 * will default to this instance if currentAlignFrame is null.
733 AlignFrame initialAlignFrame = null;
735 boolean embedded = false;
737 private boolean checkForJmol = true;
739 private boolean checkedForJmol = false; // ensure we don't check for jmol
741 // every time the app is re-inited
743 public boolean jmolAvailable = false;
745 private boolean alignPdbStructures = false;
747 public static boolean debug = false;
749 static String builddate = null, version = null;
751 private static void initBuildDetails()
753 if (builddate == null)
755 builddate = "unknown";
757 java.net.URL url = JalviewLite.class
758 .getResource("/.build_properties");
763 BufferedReader reader = new BufferedReader(new InputStreamReader(
766 while ((line = reader.readLine()) != null)
768 if (line.indexOf("VERSION") > -1)
770 version = line.substring(line.indexOf("=") + 1);
772 if (line.indexOf("BUILD_DATE") > -1)
774 builddate = line.substring(line.indexOf("=") + 1);
777 } catch (Exception ex)
779 ex.printStackTrace();
785 public static String getBuildDate()
791 public static String getVersion()
798 * init method for Jalview Applet
802 // remove any handlers that might be hanging around from an earlier instance
805 * turn on extra applet debugging
807 String dbg = getParameter("debug");
810 debug = dbg.toLowerCase().equals("true");
815 System.err.println("JalviewLite Version " + getVersion());
816 System.err.println("Build Date : " + getBuildDate());
820 * if true disable the check for jmol
822 String chkforJmol = getParameter("nojmol");
823 if (chkforJmol != null)
825 checkForJmol = !chkforJmol.equals("true");
828 * get the separator parameter if present
830 String sep = getParameter("separator");
833 if (sep.length() > 0)
838 System.err.println("Separator set to '" + separator + "'");
844 "Invalid separator parameter - must be non-zero length");
850 String param = getParameter("RGB");
856 r = Integer.parseInt(param.substring(0, 2), 16);
857 g = Integer.parseInt(param.substring(2, 4), 16);
858 b = Integer.parseInt(param.substring(4, 6), 16);
859 } catch (Exception ex)
867 param = getParameter("label");
870 launcher.setLabel(param);
873 this.setBackground(new Color(r, g, b));
875 file = getParameter("file");
879 // Maybe the sequences are added as parameters
880 StringBuffer data = new StringBuffer("PASTE");
882 while ((file = getParameter("sequence" + i)) != null)
884 data.append(file.toString() + "\n");
887 if (data.length() > 5)
889 file = data.toString();
893 final JalviewLite applet = this;
894 if (getParameter("embedded") != null
895 && getParameter("embedded").equalsIgnoreCase("true"))
897 // Launch as embedded applet in page
899 LoadingThread loader = new LoadingThread(file, applet);
902 else if (file != null)
904 if (getParameter("showbutton") == null
905 || !getParameter("showbutton").equalsIgnoreCase("false"))
907 // Add the JalviewLite 'Button' to the page
909 launcher.addActionListener(new java.awt.event.ActionListener()
911 public void actionPerformed(ActionEvent e)
913 LoadingThread loader = new LoadingThread(file, applet);
920 // Open jalviewLite immediately.
921 LoadingThread loader = new LoadingThread(file, applet);
927 // jalview initialisation with no alignment. loadAlignment() method can
928 // still be called to open new alignments.
935 * Initialises and displays a new java.awt.Frame
938 * java.awt.Frame to be displayed
944 * height of new frame
946 public static void addFrame(final Frame frame, String title, int width,
949 frame.setLocation(lastFrameX, lastFrameY);
952 frame.setSize(width, height);
953 frame.setTitle(title);
954 frame.addWindowListener(new WindowAdapter()
956 public void windowClosing(WindowEvent e)
958 if (frame instanceof AlignFrame)
960 ((AlignFrame) frame).closeMenuItem_actionPerformed();
962 if (currentAlignFrame == frame)
964 currentAlignFrame = null;
968 if (frame instanceof EmbmenuFrame)
970 ((EmbmenuFrame) frame).destroyMenus();
972 frame.setMenuBar(null);
976 public void windowActivated(WindowEvent e)
978 if (frame instanceof AlignFrame)
980 currentAlignFrame = (AlignFrame) frame;
983 System.err.println("Activated window " + frame);
987 super.windowActivated(e);
990 * Probably not necessary to do this - see TODO above. (non-Javadoc)
993 * java.awt.event.WindowAdapter#windowDeactivated(java.awt.event.WindowEvent
996 * public void windowDeactivated(WindowEvent e) { if (currentAlignFrame ==
997 * frame) { currentAlignFrame = null; if (debug) {
998 * System.err.println("Deactivated window "+frame); } }
999 * super.windowDeactivated(e); }
1002 frame.setVisible(true);
1006 * This paints the background surrounding the "Launch Jalview button" <br>
1008 * If file given in parameter not found, displays error message
1013 public void paint(Graphics g)
1017 g.setColor(new Color(200, 200, 200));
1018 g.setColor(Color.cyan);
1019 g.fillRect(0, 0, getSize().width, getSize().height);
1020 g.setColor(Color.red);
1021 g.drawString("Jalview can't open file", 5, 15);
1022 g.drawString("\"" + file + "\"", 5, 30);
1026 g.setColor(Color.black);
1027 g.setFont(new Font("Arial", Font.BOLD, 24));
1028 g.drawString("Jalview Applet", 50, this.getSize().height / 2 - 30);
1029 g.drawString("Loading Data...", 50, this.getSize().height / 2);
1033 class LoadJmolThread extends Thread
1035 private boolean running = false;
1039 if (running || checkedForJmol)
1048 if (!System.getProperty("java.version").startsWith("1.1"))
1050 Class.forName("org.jmol.adapter.smarter.SmarterJmolAdapter");
1051 jmolAvailable = true;
1056 .println("Jmol not available - Using MCview for structures");
1058 } catch (java.lang.ClassNotFoundException ex)
1064 jmolAvailable = false;
1068 .println("Skipping Jmol check. Will use MCView (probably)");
1071 checkedForJmol = true;
1075 public boolean notFinished()
1077 return running || !checkedForJmol;
1081 class LoadingThread extends Thread
1084 * State variable: File source
1089 * State variable: protocol for access to file source
1094 * State variable: format of file source
1102 private void dbgMsg(String msg)
1106 System.err.println(msg);
1111 * update the protocol state variable for accessing the datasource located
1115 * @return possibly updated datasource string
1117 public String setProtocolState(String file)
1119 if (file.startsWith("PASTE"))
1121 file = file.substring(5);
1122 protocol = AppletFormatAdapter.PASTE;
1124 else if (inArchive(file))
1126 protocol = AppletFormatAdapter.CLASSLOADER;
1130 file = addProtocol(file);
1131 protocol = AppletFormatAdapter.URL;
1133 dbgMsg("Protocol identified as '" + protocol + "'");
1137 public LoadingThread(String _file, JalviewLite _applet)
1145 LoadJmolThread jmolchecker = new LoadJmolThread();
1146 jmolchecker.start();
1147 while (jmolchecker.notFinished())
1149 // wait around until the Jmol check is complete.
1153 } catch (Exception e)
1161 private void startLoading()
1163 AlignFrame newAlignFrame;
1164 dbgMsg("Loading thread started with:\n>>file\n" + _file + ">>endfile");
1165 file = setProtocolState(_file);
1167 format = new jalview.io.IdentifyFile().Identify(file, protocol);
1168 dbgMsg("File identified as '" + format + "'");
1169 dbgMsg("Loading started.");
1170 Alignment al = null;
1173 al = new AppletFormatAdapter().readFile(file, protocol, format);
1174 } catch (java.io.IOException ex)
1176 dbgMsg("File load exception.");
1177 ex.printStackTrace();
1182 FileParse fp = new FileParse(file, protocol);
1184 dbgMsg(">>>Dumping contents of '" + file + "' " + "("
1186 while ((ln = fp.nextLine()) != null)
1190 dbgMsg(">>>Dump finished.");
1191 } catch (Exception e)
1194 .println("Exception when trying to dump the content of the file parameter.");
1195 e.printStackTrace();
1199 if ((al != null) && (al.getHeight() > 0))
1201 dbgMsg("Successfully loaded file.");
1202 newAlignFrame = new AlignFrame(al, applet, file, embedded);
1203 if (initialAlignFrame == null)
1205 initialAlignFrame = newAlignFrame;
1207 // update the focus.
1208 currentAlignFrame = newAlignFrame;
1210 if (protocol == jalview.io.AppletFormatAdapter.PASTE)
1212 newAlignFrame.setTitle("Sequences from " + getDocumentBase());
1215 newAlignFrame.statusBar.setText("Successfully loaded file " + file);
1217 String treeFile = applet.getParameter("tree");
1218 if (treeFile == null)
1220 treeFile = applet.getParameter("treeFile");
1223 if (treeFile != null)
1227 treeFile = setProtocolState(treeFile);
1229 * if (inArchive(treeFile)) { protocol =
1230 * AppletFormatAdapter.CLASSLOADER; } else { protocol =
1231 * AppletFormatAdapter.URL; treeFile = addProtocol(treeFile); }
1233 jalview.io.NewickFile fin = new jalview.io.NewickFile(treeFile,
1238 if (fin.getTree() != null)
1240 newAlignFrame.loadTree(fin, treeFile);
1241 dbgMsg("Successfuly imported tree.");
1245 dbgMsg("Tree parameter did not resolve to a valid tree.");
1247 } catch (Exception ex)
1249 ex.printStackTrace();
1253 String param = getParameter("features");
1256 param = setProtocolState(param);
1258 newAlignFrame.parseFeaturesFile(param, protocol);
1261 param = getParameter("showFeatureSettings");
1262 if (param != null && param.equalsIgnoreCase("true"))
1264 newAlignFrame.viewport.showSequenceFeatures(true);
1265 new FeatureSettings(newAlignFrame.alignPanel);
1268 param = getParameter("annotations");
1271 param = setProtocolState(param);
1273 if (new AnnotationFile().readAnnotationFile(
1274 newAlignFrame.viewport.getAlignment(), param, protocol))
1276 newAlignFrame.alignPanel.fontChanged();
1277 newAlignFrame.alignPanel.setScrollValues(0, 0);
1282 .println("Annotations were not added from annotation file '"
1288 param = getParameter("jnetfile");
1293 param = setProtocolState(param);
1294 jalview.io.JPredFile predictions = new jalview.io.JPredFile(
1296 JnetAnnotationMaker.add_annotation(predictions,
1297 newAlignFrame.viewport.getAlignment(), 0, false); // false==do
1305 newAlignFrame.alignPanel.fontChanged();
1306 newAlignFrame.alignPanel.setScrollValues(0, 0);
1307 } catch (Exception ex)
1309 ex.printStackTrace();
1313 * <param name="alignpdbfiles" value="false/true"/> Undocumented for 2.6
1314 * - related to JAL-434
1316 applet.setAlignPdbStructures(getDefaultParameter("alignpdbfiles",
1319 * <param name="PDBfile" value="1gaq.txt PDB|1GAQ|1GAQ|A PDB|1GAQ|1GAQ|B
1322 * <param name="PDBfile2" value="1gaq.txt A=SEQA B=SEQB C=SEQB">
1324 * <param name="PDBfile3" value="1q0o Q45135_9MICO">
1327 int pdbFileCount = 0;
1328 // Accumulate pdbs here if they are heading for the same view (if
1329 // alignPdbStructures is true)
1330 Vector pdbs = new Vector();
1333 if (pdbFileCount > 0)
1334 param = getParameter("PDBFILE" + pdbFileCount);
1336 param = getParameter("PDBFILE");
1340 PDBEntry pdb = new PDBEntry();
1343 SequenceI[] seqs = null;
1344 String[] chains = null;
1346 StringTokenizer st = new StringTokenizer(param, " ");
1348 if (st.countTokens() < 2)
1350 String sequence = applet.getParameter("PDBSEQ");
1351 if (sequence != null)
1352 seqs = new SequenceI[]
1353 { (Sequence) newAlignFrame.getAlignViewport()
1354 .getAlignment().findName(sequence) };
1359 param = st.nextToken();
1360 Vector tmp = new Vector();
1361 Vector tmp2 = new Vector();
1363 while (st.hasMoreTokens())
1365 seqstring = st.nextToken();
1366 StringTokenizer st2 = new StringTokenizer(seqstring, "=");
1367 if (st2.countTokens() > 1)
1369 // This is the chain
1370 tmp2.addElement(st2.nextToken());
1371 seqstring = st2.nextToken();
1373 tmp.addElement((Sequence) newAlignFrame.getAlignViewport()
1374 .getAlignment().findName(seqstring));
1377 seqs = new SequenceI[tmp.size()];
1379 if (tmp2.size() == tmp.size())
1381 chains = new String[tmp2.size()];
1382 tmp2.copyInto(chains);
1385 param = setProtocolState(param);
1387 if (// !jmolAvailable
1389 protocol == AppletFormatAdapter.CLASSLOADER)
1391 // TODO: verify this Re:
1392 // https://mantis.lifesci.dundee.ac.uk/view.php?id=36605
1393 // This exception preserves the current behaviour where, even if
1394 // the local pdb file was identified in the class loader
1395 protocol = AppletFormatAdapter.URL; // this is probably NOT
1397 param = addProtocol(param); //
1404 for (int i = 0; i < seqs.length; i++)
1406 if (seqs[i] != null)
1408 ((Sequence) seqs[i]).addPDBId(pdb);
1412 if (JalviewLite.debug)
1414 // this may not really be a problem but we give a warning
1417 .println("Warning: Possible input parsing error: Null sequence for attachment of PDB (sequence "
1423 if (!alignPdbStructures)
1425 newAlignFrame.newStructureView(applet, pdb, seqs, chains,
1430 pdbs.addElement(new Object[]
1431 { pdb, seqs, chains, new String(protocol) });
1437 } while (pdbFileCount < 10);
1438 if (pdbs.size() > 0)
1440 SequenceI[][] seqs = new SequenceI[pdbs.size()][];
1441 PDBEntry[] pdb = new PDBEntry[pdbs.size()];
1442 String[][] chains = new String[pdbs.size()][];
1443 String[] protocols = new String[pdbs.size()];
1444 for (int pdbsi = 0, pdbsiSize = pdbs.size(); pdbsi < pdbsiSize; pdbsi++)
1446 Object[] o = (Object[]) pdbs.elementAt(pdbsi);
1447 pdb[pdbsi] = (PDBEntry) o[0];
1448 seqs[pdbsi] = (SequenceI[]) o[1];
1449 chains[pdbsi] = (String[]) o[2];
1450 protocols[pdbsi] = (String) o[3];
1452 newAlignFrame.alignedStructureView(applet, pdb, seqs, chains,
1456 // ///////////////////////////
1457 // modify display of features
1459 // hide specific groups
1460 param = getParameter("hidefeaturegroups");
1463 applet.setFeatureGroupStateOn(newAlignFrame, param, false);
1465 // show specific groups
1466 param = getParameter("showfeaturegroups");
1469 applet.setFeatureGroupStateOn(newAlignFrame, param, true);
1481 * Discovers whether the given file is in the Applet Archive
1487 boolean inArchive(String file)
1489 // This might throw a security exception in certain browsers
1490 // Netscape Communicator for instance.
1493 boolean rtn = (getClass().getResourceAsStream("/" + file) != null);
1496 System.err.println("Resource '" + file + "' was "
1497 + (rtn ? "" : "not") + " located by classloader.");
1500 } catch (Exception ex)
1502 System.out.println("Exception checking resources: " + file + " "
1508 String addProtocol(String file)
1510 if (file.indexOf("://") == -1)
1512 file = getCodeBase() + file;
1515 System.err.println("Prepended codebase for resource: '" + file
1525 * @return the default alignFrame acted on by the public applet methods. May
1526 * return null with an error message on System.err indicating the
1529 protected AlignFrame getDefaultTargetFrame()
1531 if (currentAlignFrame != null)
1533 return currentAlignFrame;
1535 if (initialAlignFrame != null)
1537 return initialAlignFrame;
1540 .println("Implementation error: Jalview Applet API cannot work out which AlignFrame to use.");
1545 * separator used for separatorList
1547 protected String separator = "|"; // this is a safe(ish) separator - tabs
1549 // don't work for firefox
1552 * parse the string into a list
1555 * @return elements separated by separator
1557 public String[] separatorListToArray(String list)
1559 return separatorListToArray(list, separator);
1563 * parse the string into a list
1567 * @return elements separated by separator
1569 public String[] separatorListToArray(String list, String separator)
1571 // note separator local variable intentionally masks object field
1572 int seplen = separator.length();
1573 if (list == null || list.equals("") || list.equals(separator))
1575 java.util.Vector jv = new Vector();
1577 while ((pos = list.indexOf(separator, cp)) > cp)
1579 jv.addElement(list.substring(cp, pos));
1582 if (cp < list.length())
1584 jv.addElement(list.substring(cp));
1588 String[] v = new String[jv.size()];
1589 for (int i = 0; i < v.length; i++)
1591 v[i] = (String) jv.elementAt(i);
1593 jv.removeAllElements();
1596 System.err.println("Array from '" + separator
1597 + "' separated List:\n" + v.length);
1598 for (int i = 0; i < v.length; i++)
1600 System.err.println("item " + i + " '" + v[i] + "'");
1607 System.err.println("Empty Array from '" + separator
1608 + "' separated List");
1614 * concatenate the list with separator
1617 * @return concatenated string
1619 public String arrayToSeparatorList(String[] list)
1621 return arrayToSeparatorList(list, separator);
1625 * concatenate the list with separator
1629 * @return concatenated string
1631 public String arrayToSeparatorList(String[] list, String separator)
1633 StringBuffer v = new StringBuffer();
1634 if (list != null && list.length > 0)
1636 for (int i = 0, iSize = list.length - 1; i < iSize; i++)
1638 if (list[i] != null)
1642 v.append(separator);
1644 if (list[list.length - 1] != null)
1646 v.append(list[list.length - 1]);
1650 System.err.println("Returning '" + separator
1651 + "' separated List:\n");
1652 System.err.println(v);
1654 return v.toString();
1658 System.err.println("Returning empty '" + separator
1659 + "' separated List\n");
1661 return "" + separator;
1666 * @see jalview.appletgui.AlignFrame#getFeatureGroups()
1668 public String getFeatureGroups()
1670 String lst = arrayToSeparatorList(getDefaultTargetFrame()
1671 .getFeatureGroups());
1677 * alignframe to get feature groups on
1679 * @see jalview.appletgui.AlignFrame#getFeatureGroups()
1681 public String getFeatureGroupsOn(AlignFrame alf)
1683 String lst = arrayToSeparatorList(alf.getFeatureGroups());
1690 * @see jalview.appletgui.AlignFrame#getFeatureGroupsOfState(boolean)
1692 public String getFeatureGroupsOfState(boolean visible)
1694 return arrayToSeparatorList(getDefaultTargetFrame()
1695 .getFeatureGroupsOfState(visible));
1700 * align frame to get groups of state visible
1703 * @see jalview.appletgui.AlignFrame#getFeatureGroupsOfState(boolean)
1705 public String getFeatureGroupsOfStateOn(AlignFrame alf, boolean visible)
1707 return arrayToSeparatorList(alf.getFeatureGroupsOfState(visible));
1712 * tab separated list of group names
1715 * @see jalview.appletgui.AlignFrame#setFeatureGroupState(java.lang.String[],
1718 public void setFeatureGroupStateOn(AlignFrame alf, String groups,
1721 boolean st = state;// !(state==null || state.equals("") ||
1722 // state.toLowerCase().equals("false"));
1723 alf.setFeatureGroupState(separatorListToArray(groups), st);
1726 public void setFeatureGroupState(String groups, boolean state)
1728 setFeatureGroupStateOn(getDefaultTargetFrame(), groups, state);
1732 * List separator string
1734 * @return the separator
1736 public String getSeparator()
1742 * List separator string
1745 * the separator to set
1747 public void setSeparator(String separator)
1749 this.separator = separator;
1753 * get boolean value of applet parameter 'name' and return default if
1754 * parameter is not set
1759 * the value to return otherwise
1760 * @return true or false
1762 public boolean getDefaultParameter(String name, boolean def)
1765 if ((stn = getParameter(name)) == null)
1769 if (stn.toLowerCase().equals("true"))
1777 * bind a pdb file to a sequence in the given alignFrame.
1780 * - null or specific alignFrame. This specifies the dataset that
1781 * will be searched for a seuqence called sequenceId
1783 * - sequenceId within the dataset.
1784 * @param pdbEntryString
1785 * - the short name for the PDB file
1787 * - pdb file - either a URL or a valid PDB file.
1788 * @return true if binding was as success TODO: consider making an exception
1789 * structure for indicating when PDB parsing or seqeunceId location
1792 public boolean addPdbFile(AlignFrame alFrame, String sequenceId,
1793 String pdbEntryString, String pdbFile)
1795 return alFrame.addPdbFile(sequenceId, pdbEntryString, pdbFile);
1798 protected void setAlignPdbStructures(boolean alignPdbStructures)
1800 this.alignPdbStructures = alignPdbStructures;
1803 public boolean isAlignPdbStructures()
1805 return alignPdbStructures;
1809 * get all components associated with the applet of the given type
1814 public Vector getAppletWindow(Class class1)
1816 Vector wnds = new Vector();
1817 Component[] cmp = getComponents();
1820 for (int i = 0; i < cmp.length; i++)
1822 if (class1.isAssignableFrom(cmp[i].getClass()))
1824 wnds.addElement(cmp);
1832 * bind structures in a viewer to any matching sequences in an alignFrame (use
1833 * sequenceIds to limit scope of search to specific sequences)
1837 * @param sequenceIds
1838 * @return TODO: consider making an exception structure for indicating when
1839 * binding fails public SequenceStructureBinding
1840 * addStructureViewInstance( AlignFrame alFrame, Object viewer, String
1843 * if (sequenceIds != null && sequenceIds.length() > 0) { return
1844 * alFrame.addStructureViewInstance(viewer,
1845 * separatorListToArray(sequenceIds)); } else { return
1846 * alFrame.addStructureViewInstance(viewer, null); } // return null; }