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.add(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(currentAlignFrame, 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.add(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 (Object lstn : mouseoverListeners)
643 JsCallBack lstner = (JsCallBack) lstn;
644 if ((af == null || lstner.getAlignFrame() == af)
645 && (listener == null || lstner.getListenerFunction().equals(
648 mouseoverListeners.remove(lstner);
649 if (lstner instanceof SelectionListener)
651 StructureSelectionManager.getStructureSelectionManager()
652 .removeSelectionListener((SelectionListener) lstner);
656 StructureSelectionManager.getStructureSelectionManager()
657 .removeStructureViewerListener(lstner, null);
662 System.err.println("Removed listener '" + listener + "'");
668 System.err.println("There are now " + mouseoverListeners.size()
669 + " listeners in total.");
675 if (mouseoverListeners!=null)
677 while (mouseoverListeners.size()>0)
679 Object mol = mouseoverListeners.remove(0);
680 // mouseoverListeners.elementAt(0);
681 if (mol instanceof SelectionListener)
683 StructureSelectionManager.getStructureSelectionManager().removeSelectionListener((SelectionListener)mol);
685 StructureSelectionManager.getStructureSelectionManager().removeStructureViewerListener(mol, null);
691 * send a mouseover message to all the alignment windows associated with the
692 * given residue in the pdbfile
698 public void mouseOverStructure(int pdbResNum, String chain, String pdbfile)
700 StructureSelectionManager.getStructureSelectionManager()
701 .mouseOverStructure(pdbResNum, chain, pdbfile);
704 // //////////////////////////////////////////////
705 // //////////////////////////////////////////////
707 public static int lastFrameX = 200;
709 public static int lastFrameY = 200;
711 boolean fileFound = true;
713 String file = "No file";
715 Button launcher = new Button("Start Jalview");
718 * The currentAlignFrame is static, it will change if and when the user
719 * selects a new window. Note that it will *never* point back to the embedded
720 * AlignFrame if the applet is started as embedded on the page and then
721 * afterwards a new view is created.
723 public static AlignFrame currentAlignFrame = null;
726 * This is the first frame to be displayed, and does not change. API calls
727 * will default to this instance if currentAlignFrame is null.
729 AlignFrame initialAlignFrame = null;
731 boolean embedded = false;
733 private boolean checkForJmol = true;
735 private boolean checkedForJmol = false; // ensure we don't check for jmol
737 // every time the app is re-inited
739 public boolean jmolAvailable = false;
741 private boolean alignPdbStructures = false;
743 public static boolean debug = false;
745 static String builddate = null, version = null;
747 private static void initBuildDetails()
749 if (builddate == null)
751 builddate = "unknown";
753 java.net.URL url = JalviewLite.class
754 .getResource("/.build_properties");
759 BufferedReader reader = new BufferedReader(new InputStreamReader(
762 while ((line = reader.readLine()) != null)
764 if (line.indexOf("VERSION") > -1)
766 version = line.substring(line.indexOf("=") + 1);
768 if (line.indexOf("BUILD_DATE") > -1)
770 builddate = line.substring(line.indexOf("=") + 1);
773 } catch (Exception ex)
775 ex.printStackTrace();
781 public static String getBuildDate()
787 public static String getVersion()
794 * init method for Jalview Applet
798 // remove any handlers that might be hanging around from an earlier instance
801 * turn on extra applet debugging
803 String dbg = getParameter("debug");
806 debug = dbg.toLowerCase().equals("true");
811 System.err.println("JalviewLite Version " + getVersion());
812 System.err.println("Build Date : " + getBuildDate());
816 * if true disable the check for jmol
818 String chkforJmol = getParameter("nojmol");
819 if (chkforJmol != null)
821 checkForJmol = !chkforJmol.equals("true");
824 * get the separator parameter if present
826 String sep = getParameter("separator");
829 if (sep.length() > 0)
834 System.err.println("Separator set to '" + separator + "'");
840 "Invalid separator parameter - must be non-zero length");
846 String param = getParameter("RGB");
852 r = Integer.parseInt(param.substring(0, 2), 16);
853 g = Integer.parseInt(param.substring(2, 4), 16);
854 b = Integer.parseInt(param.substring(4, 6), 16);
855 } catch (Exception ex)
863 param = getParameter("label");
866 launcher.setLabel(param);
869 this.setBackground(new Color(r, g, b));
871 file = getParameter("file");
875 // Maybe the sequences are added as parameters
876 StringBuffer data = new StringBuffer("PASTE");
878 while ((file = getParameter("sequence" + i)) != null)
880 data.append(file.toString() + "\n");
883 if (data.length() > 5)
885 file = data.toString();
889 final JalviewLite applet = this;
890 if (getParameter("embedded") != null
891 && getParameter("embedded").equalsIgnoreCase("true"))
893 // Launch as embedded applet in page
895 LoadingThread loader = new LoadingThread(file, applet);
898 else if (file != null)
900 if (getParameter("showbutton") == null
901 || !getParameter("showbutton").equalsIgnoreCase("false"))
903 // Add the JalviewLite 'Button' to the page
905 launcher.addActionListener(new java.awt.event.ActionListener()
907 public void actionPerformed(ActionEvent e)
909 LoadingThread loader = new LoadingThread(file, applet);
916 // Open jalviewLite immediately.
917 LoadingThread loader = new LoadingThread(file, applet);
923 // jalview initialisation with no alignment. loadAlignment() method can
924 // still be called to open new alignments.
931 * Initialises and displays a new java.awt.Frame
934 * java.awt.Frame to be displayed
940 * height of new frame
942 public static void addFrame(final Frame frame, String title, int width,
945 frame.setLocation(lastFrameX, lastFrameY);
948 frame.setSize(width, height);
949 frame.setTitle(title);
950 frame.addWindowListener(new WindowAdapter()
952 public void windowClosing(WindowEvent e)
954 if (frame instanceof AlignFrame)
956 ((AlignFrame) frame).closeMenuItem_actionPerformed();
958 if (currentAlignFrame == frame)
960 currentAlignFrame = null;
964 if (frame instanceof EmbmenuFrame)
966 ((EmbmenuFrame) frame).destroyMenus();
968 frame.setMenuBar(null);
972 public void windowActivated(WindowEvent e)
974 if (frame instanceof AlignFrame)
976 currentAlignFrame = (AlignFrame) frame;
979 System.err.println("Activated window " + frame);
983 super.windowActivated(e);
986 * Probably not necessary to do this - see TODO above. (non-Javadoc)
989 * java.awt.event.WindowAdapter#windowDeactivated(java.awt.event.WindowEvent
992 * public void windowDeactivated(WindowEvent e) { if (currentAlignFrame ==
993 * frame) { currentAlignFrame = null; if (debug) {
994 * System.err.println("Deactivated window "+frame); } }
995 * super.windowDeactivated(e); }
998 frame.setVisible(true);
1002 * This paints the background surrounding the "Launch Jalview button" <br>
1004 * If file given in parameter not found, displays error message
1009 public void paint(Graphics g)
1013 g.setColor(new Color(200, 200, 200));
1014 g.setColor(Color.cyan);
1015 g.fillRect(0, 0, getSize().width, getSize().height);
1016 g.setColor(Color.red);
1017 g.drawString("Jalview can't open file", 5, 15);
1018 g.drawString("\"" + file + "\"", 5, 30);
1022 g.setColor(Color.black);
1023 g.setFont(new Font("Arial", Font.BOLD, 24));
1024 g.drawString("Jalview Applet", 50, this.getSize().height / 2 - 30);
1025 g.drawString("Loading Data...", 50, this.getSize().height / 2);
1029 class LoadJmolThread extends Thread
1031 private boolean running = false;
1035 if (running || checkedForJmol)
1044 if (!System.getProperty("java.version").startsWith("1.1"))
1046 Class.forName("org.jmol.adapter.smarter.SmarterJmolAdapter");
1047 jmolAvailable = true;
1052 .println("Jmol not available - Using MCview for structures");
1054 } catch (java.lang.ClassNotFoundException ex)
1060 jmolAvailable = false;
1064 .println("Skipping Jmol check. Will use MCView (probably)");
1067 checkedForJmol = true;
1071 public boolean notFinished()
1073 return running || !checkedForJmol;
1077 class LoadingThread extends Thread
1080 * State variable: File source
1085 * State variable: protocol for access to file source
1090 * State variable: format of file source
1098 private void dbgMsg(String msg)
1102 System.err.println(msg);
1107 * update the protocol state variable for accessing the datasource located
1111 * @return possibly updated datasource string
1113 public String setProtocolState(String file)
1115 if (file.startsWith("PASTE"))
1117 file = file.substring(5);
1118 protocol = AppletFormatAdapter.PASTE;
1120 else if (inArchive(file))
1122 protocol = AppletFormatAdapter.CLASSLOADER;
1126 file = addProtocol(file);
1127 protocol = AppletFormatAdapter.URL;
1129 dbgMsg("Protocol identified as '" + protocol + "'");
1133 public LoadingThread(String _file, JalviewLite _applet)
1141 LoadJmolThread jmolchecker = new LoadJmolThread();
1142 jmolchecker.start();
1143 while (jmolchecker.notFinished())
1145 // wait around until the Jmol check is complete.
1149 } catch (Exception e)
1157 private void startLoading()
1159 AlignFrame newAlignFrame;
1160 dbgMsg("Loading thread started with:\n>>file\n" + _file + ">>endfile");
1161 file = setProtocolState(_file);
1163 format = new jalview.io.IdentifyFile().Identify(file, protocol);
1164 dbgMsg("File identified as '" + format + "'");
1165 dbgMsg("Loading started.");
1166 Alignment al = null;
1169 al = new AppletFormatAdapter().readFile(file, protocol, format);
1170 } catch (java.io.IOException ex)
1172 dbgMsg("File load exception.");
1173 ex.printStackTrace();
1178 FileParse fp = new FileParse(file, protocol);
1180 dbgMsg(">>>Dumping contents of '" + file + "' " + "("
1182 while ((ln = fp.nextLine()) != null)
1186 dbgMsg(">>>Dump finished.");
1187 } catch (Exception e)
1190 .println("Exception when trying to dump the content of the file parameter.");
1191 e.printStackTrace();
1195 if ((al != null) && (al.getHeight() > 0))
1197 dbgMsg("Successfully loaded file.");
1198 newAlignFrame = new AlignFrame(al, applet, file, embedded);
1199 if (initialAlignFrame == null)
1201 initialAlignFrame = newAlignFrame;
1203 // update the focus.
1204 currentAlignFrame = newAlignFrame;
1206 if (protocol == jalview.io.AppletFormatAdapter.PASTE)
1208 newAlignFrame.setTitle("Sequences from " + getDocumentBase());
1211 newAlignFrame.statusBar.setText("Successfully loaded file " + file);
1213 String treeFile = applet.getParameter("tree");
1214 if (treeFile == null)
1216 treeFile = applet.getParameter("treeFile");
1219 if (treeFile != null)
1223 treeFile = setProtocolState(treeFile);
1225 * if (inArchive(treeFile)) { protocol =
1226 * AppletFormatAdapter.CLASSLOADER; } else { protocol =
1227 * AppletFormatAdapter.URL; treeFile = addProtocol(treeFile); }
1229 jalview.io.NewickFile fin = new jalview.io.NewickFile(treeFile,
1234 if (fin.getTree() != null)
1236 newAlignFrame.loadTree(fin, treeFile);
1237 dbgMsg("Successfuly imported tree.");
1241 dbgMsg("Tree parameter did not resolve to a valid tree.");
1243 } catch (Exception ex)
1245 ex.printStackTrace();
1249 String param = getParameter("features");
1252 param = setProtocolState(param);
1254 newAlignFrame.parseFeaturesFile(param, protocol);
1257 param = getParameter("showFeatureSettings");
1258 if (param != null && param.equalsIgnoreCase("true"))
1260 newAlignFrame.viewport.showSequenceFeatures(true);
1261 new FeatureSettings(newAlignFrame.alignPanel);
1264 param = getParameter("annotations");
1267 param = setProtocolState(param);
1269 if (new AnnotationFile().readAnnotationFile(
1270 newAlignFrame.viewport.getAlignment(), param, protocol))
1272 newAlignFrame.alignPanel.fontChanged();
1273 newAlignFrame.alignPanel.setScrollValues(0, 0);
1278 .println("Annotations were not added from annotation file '"
1284 param = getParameter("jnetfile");
1289 param = setProtocolState(param);
1290 jalview.io.JPredFile predictions = new jalview.io.JPredFile(
1292 JnetAnnotationMaker.add_annotation(predictions,
1293 newAlignFrame.viewport.getAlignment(), 0, false); // false==do
1301 newAlignFrame.alignPanel.fontChanged();
1302 newAlignFrame.alignPanel.setScrollValues(0, 0);
1303 } catch (Exception ex)
1305 ex.printStackTrace();
1309 * <param name="alignpdbfiles" value="false/true"/> Undocumented for 2.6
1310 * - related to JAL-434
1312 applet.setAlignPdbStructures(getDefaultParameter("alignpdbfiles",
1315 * <param name="PDBfile" value="1gaq.txt PDB|1GAQ|1GAQ|A PDB|1GAQ|1GAQ|B
1318 * <param name="PDBfile2" value="1gaq.txt A=SEQA B=SEQB C=SEQB">
1320 * <param name="PDBfile3" value="1q0o Q45135_9MICO">
1323 int pdbFileCount = 0;
1324 // Accumulate pdbs here if they are heading for the same view (if
1325 // alignPdbStructures is true)
1326 Vector pdbs = new Vector();
1329 if (pdbFileCount > 0)
1330 param = getParameter("PDBFILE" + pdbFileCount);
1332 param = getParameter("PDBFILE");
1336 PDBEntry pdb = new PDBEntry();
1339 SequenceI[] seqs = null;
1340 String[] chains = null;
1342 StringTokenizer st = new StringTokenizer(param, " ");
1344 if (st.countTokens() < 2)
1346 String sequence = applet.getParameter("PDBSEQ");
1347 if (sequence != null)
1348 seqs = new SequenceI[]
1349 { (Sequence) newAlignFrame.getAlignViewport()
1350 .getAlignment().findName(sequence) };
1355 param = st.nextToken();
1356 Vector tmp = new Vector();
1357 Vector tmp2 = new Vector();
1359 while (st.hasMoreTokens())
1361 seqstring = st.nextToken();
1362 StringTokenizer st2 = new StringTokenizer(seqstring, "=");
1363 if (st2.countTokens() > 1)
1365 // This is the chain
1366 tmp2.addElement(st2.nextToken());
1367 seqstring = st2.nextToken();
1369 tmp.addElement((Sequence) newAlignFrame.getAlignViewport()
1370 .getAlignment().findName(seqstring));
1373 seqs = new SequenceI[tmp.size()];
1375 if (tmp2.size() == tmp.size())
1377 chains = new String[tmp2.size()];
1378 tmp2.copyInto(chains);
1381 param = setProtocolState(param);
1383 if (// !jmolAvailable
1385 protocol == AppletFormatAdapter.CLASSLOADER)
1387 // TODO: verify this Re:
1388 // https://mantis.lifesci.dundee.ac.uk/view.php?id=36605
1389 // This exception preserves the current behaviour where, even if
1390 // the local pdb file was identified in the class loader
1391 protocol = AppletFormatAdapter.URL; // this is probably NOT
1393 param = addProtocol(param); //
1400 for (int i = 0; i < seqs.length; i++)
1402 if (seqs[i] != null)
1404 ((Sequence) seqs[i]).addPDBId(pdb);
1408 if (JalviewLite.debug)
1410 // this may not really be a problem but we give a warning
1413 .println("Warning: Possible input parsing error: Null sequence for attachment of PDB (sequence "
1419 if (!alignPdbStructures)
1421 newAlignFrame.newStructureView(applet, pdb, seqs, chains,
1426 pdbs.addElement(new Object[]
1427 { pdb, seqs, chains, new String(protocol) });
1433 } while (pdbFileCount < 10);
1434 if (pdbs.size() > 0)
1436 SequenceI[][] seqs = new SequenceI[pdbs.size()][];
1437 PDBEntry[] pdb = new PDBEntry[pdbs.size()];
1438 String[][] chains = new String[pdbs.size()][];
1439 String[] protocols = new String[pdbs.size()];
1440 for (int pdbsi = 0, pdbsiSize = pdbs.size(); pdbsi < pdbsiSize; pdbsi++)
1442 Object[] o = (Object[]) pdbs.elementAt(pdbsi);
1443 pdb[pdbsi] = (PDBEntry) o[0];
1444 seqs[pdbsi] = (SequenceI[]) o[1];
1445 chains[pdbsi] = (String[]) o[2];
1446 protocols[pdbsi] = (String) o[3];
1448 newAlignFrame.alignedStructureView(applet, pdb, seqs, chains,
1452 // ///////////////////////////
1453 // modify display of features
1455 // hide specific groups
1456 param = getParameter("hidefeaturegroups");
1459 applet.setFeatureGroupStateOn(newAlignFrame, param, false);
1461 // show specific groups
1462 param = getParameter("showfeaturegroups");
1465 applet.setFeatureGroupStateOn(newAlignFrame, param, true);
1477 * Discovers whether the given file is in the Applet Archive
1483 boolean inArchive(String file)
1485 // This might throw a security exception in certain browsers
1486 // Netscape Communicator for instance.
1489 boolean rtn = (getClass().getResourceAsStream("/" + file) != null);
1492 System.err.println("Resource '" + file + "' was "
1493 + (rtn ? "" : "not") + " located by classloader.");
1496 } catch (Exception ex)
1498 System.out.println("Exception checking resources: " + file + " "
1504 String addProtocol(String file)
1506 if (file.indexOf("://") == -1)
1508 file = getCodeBase() + file;
1511 System.err.println("Prepended codebase for resource: '" + file
1521 * @return the default alignFrame acted on by the public applet methods. May
1522 * return null with an error message on System.err indicating the
1525 protected AlignFrame getDefaultTargetFrame()
1527 if (currentAlignFrame != null)
1529 return currentAlignFrame;
1531 if (initialAlignFrame != null)
1533 return initialAlignFrame;
1536 .println("Implementation error: Jalview Applet API cannot work out which AlignFrame to use.");
1541 * separator used for separatorList
1543 protected String separator = "|"; // this is a safe(ish) separator - tabs
1545 // don't work for firefox
1548 * parse the string into a list
1551 * @return elements separated by separator
1553 public String[] separatorListToArray(String list)
1555 return separatorListToArray(list, separator);
1559 * parse the string into a list
1563 * @return elements separated by separator
1565 public String[] separatorListToArray(String list, String separator)
1567 // note separator local variable intentionally masks object field
1568 int seplen = separator.length();
1569 if (list == null || list.equals("") || list.equals(separator))
1571 java.util.Vector jv = new Vector();
1573 while ((pos = list.indexOf(separator, cp)) > cp)
1575 jv.addElement(list.substring(cp, pos));
1578 if (cp < list.length())
1580 jv.addElement(list.substring(cp));
1584 String[] v = new String[jv.size()];
1585 for (int i = 0; i < v.length; i++)
1587 v[i] = (String) jv.elementAt(i);
1589 jv.removeAllElements();
1592 System.err.println("Array from '" + separator
1593 + "' separated List:\n" + v.length);
1594 for (int i = 0; i < v.length; i++)
1596 System.err.println("item " + i + " '" + v[i] + "'");
1603 System.err.println("Empty Array from '" + separator
1604 + "' separated List");
1610 * concatenate the list with separator
1613 * @return concatenated string
1615 public String arrayToSeparatorList(String[] list)
1617 return arrayToSeparatorList(list, separator);
1621 * concatenate the list with separator
1625 * @return concatenated string
1627 public String arrayToSeparatorList(String[] list, String separator)
1629 StringBuffer v = new StringBuffer();
1630 if (list != null && list.length > 0)
1632 for (int i = 0, iSize = list.length - 1; i < iSize; i++)
1634 if (list[i] != null)
1638 v.append(separator);
1640 if (list[list.length - 1] != null)
1642 v.append(list[list.length - 1]);
1646 System.err.println("Returning '" + separator
1647 + "' separated List:\n");
1648 System.err.println(v);
1650 return v.toString();
1654 System.err.println("Returning empty '" + separator
1655 + "' separated List\n");
1657 return "" + separator;
1662 * @see jalview.appletgui.AlignFrame#getFeatureGroups()
1664 public String getFeatureGroups()
1666 String lst = arrayToSeparatorList(getDefaultTargetFrame()
1667 .getFeatureGroups());
1673 * alignframe to get feature groups on
1675 * @see jalview.appletgui.AlignFrame#getFeatureGroups()
1677 public String getFeatureGroupsOn(AlignFrame alf)
1679 String lst = arrayToSeparatorList(alf.getFeatureGroups());
1686 * @see jalview.appletgui.AlignFrame#getFeatureGroupsOfState(boolean)
1688 public String getFeatureGroupsOfState(boolean visible)
1690 return arrayToSeparatorList(getDefaultTargetFrame()
1691 .getFeatureGroupsOfState(visible));
1696 * align frame to get groups of state visible
1699 * @see jalview.appletgui.AlignFrame#getFeatureGroupsOfState(boolean)
1701 public String getFeatureGroupsOfStateOn(AlignFrame alf, boolean visible)
1703 return arrayToSeparatorList(alf.getFeatureGroupsOfState(visible));
1708 * tab separated list of group names
1711 * @see jalview.appletgui.AlignFrame#setFeatureGroupState(java.lang.String[],
1714 public void setFeatureGroupStateOn(AlignFrame alf, String groups,
1717 boolean st = state;// !(state==null || state.equals("") ||
1718 // state.toLowerCase().equals("false"));
1719 alf.setFeatureGroupState(separatorListToArray(groups), st);
1722 public void setFeatureGroupState(String groups, boolean state)
1724 setFeatureGroupStateOn(getDefaultTargetFrame(), groups, state);
1728 * List separator string
1730 * @return the separator
1732 public String getSeparator()
1738 * List separator string
1741 * the separator to set
1743 public void setSeparator(String separator)
1745 this.separator = separator;
1749 * get boolean value of applet parameter 'name' and return default if
1750 * parameter is not set
1755 * the value to return otherwise
1756 * @return true or false
1758 public boolean getDefaultParameter(String name, boolean def)
1761 if ((stn = getParameter(name)) == null)
1765 if (stn.toLowerCase().equals("true"))
1773 * bind a pdb file to a sequence in the given alignFrame.
1776 * - null or specific alignFrame. This specifies the dataset that
1777 * will be searched for a seuqence called sequenceId
1779 * - sequenceId within the dataset.
1780 * @param pdbEntryString
1781 * - the short name for the PDB file
1783 * - pdb file - either a URL or a valid PDB file.
1784 * @return true if binding was as success TODO: consider making an exception
1785 * structure for indicating when PDB parsing or seqeunceId location
1788 public boolean addPdbFile(AlignFrame alFrame, String sequenceId,
1789 String pdbEntryString, String pdbFile)
1791 return alFrame.addPdbFile(sequenceId, pdbEntryString, pdbFile);
1794 protected void setAlignPdbStructures(boolean alignPdbStructures)
1796 this.alignPdbStructures = alignPdbStructures;
1799 public boolean isAlignPdbStructures()
1801 return alignPdbStructures;
1805 * get all components associated with the applet of the given type
1810 public Vector getAppletWindow(Class class1)
1812 Vector wnds = new Vector();
1813 Component[] cmp = getComponents();
1816 for (int i = 0; i < cmp.length; i++)
1818 if (class1.isAssignableFrom(cmp[i].getClass()))
1820 wnds.addElement(cmp);
1828 * bind structures in a viewer to any matching sequences in an alignFrame (use
1829 * sequenceIds to limit scope of search to specific sequences)
1833 * @param sequenceIds
1834 * @return TODO: consider making an exception structure for indicating when
1835 * binding fails public SequenceStructureBinding
1836 * addStructureViewInstance( AlignFrame alFrame, Object viewer, String
1839 * if (sequenceIds != null && sequenceIds.length() > 0) { return
1840 * alFrame.addStructureViewInstance(viewer,
1841 * separatorListToArray(sequenceIds)); } else { return
1842 * alFrame.addStructureViewInstance(viewer, null); } // return null; }