2 * Jalview - A Sequence Alignment Editor and Viewer
3 * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
21 import java.io.IOException;
27 import jalview.io.AppletFormatAdapter;
30 * Main class for Jalview Application <br>
32 * start with java -Djava.ext.dirs=$PATH_TO_LIB$ jalview.bin.Jalview
41 * main class for Jalview application
44 * open <em>filename</em>
46 public static void main(String[] args)
48 System.out.println("Java version: "
49 + System.getProperty("java.version"));
50 System.out.println(System.getProperty("os.arch") + " "
51 + System.getProperty("os.name") + " "
52 + System.getProperty("os.version"));
54 ArgsParser aparser = new ArgsParser(args);
55 boolean headless = false;
57 if (aparser.contains("help") || aparser.contains("h"))
60 .println("Usage: jalview -open [FILE] [OUTPUT_FORMAT] [OUTPUT_FILE]\n\n"
61 + "-nodisplay\tRun Jalview without User Interface.\n"
62 + "-props FILE\tUse the given Jalview properties file instead of users default.\n"
63 + "-annotations FILE\tAdd precalculated annotations to the alignment.\n"
64 + "-tree FILE\tLoad the given newick format tree file onto the alignment\n"
65 + "-features FILE\tUse the given file to mark features on the alignment.\n"
66 + "-fasta FILE\tCreate alignment file FILE in Fasta format.\n"
67 + "-clustal FILE\tCreate alignment file FILE in Clustal format.\n"
68 + "-pfam FILE\tCreate alignment file FILE in PFAM format.\n"
69 + "-msf FILE\tCreate alignment file FILE in MSF format.\n"
70 + "-pileup FILE\tCreate alignment file FILE in Pileup format\n"
71 + "-pir FILE\tCreate alignment file FILE in PIR format.\n"
72 + "-blc FILE\tCreate alignment file FILE in BLC format.\n"
73 + "-jalview FILE\tCreate alignment file FILE in Jalview format.\n"
74 + "-png FILE\tCreate PNG image FILE from alignment.\n"
75 + "-imgMap FILE\tCreate HTML file FILE with image map of PNG image.\n"
76 + "-eps FILE\tCreate EPS file FILE from alignment."
77 + "-questionnaire URL\tQueries the given URL for information about any Jalview user questionnaires."
78 + "-noquestionnaire\tTurn off questionnaire check."
79 + "-dasserver nickname=URL\tAdd and enable a das server with given nickname (alphanumeric or underscores only) for retrieval of features for all alignments."
80 + "-fetchfrom nickname\tQuery nickname for features for the alignments and display them."
81 + "\n\n~Read documentation in Application or visit http://www.jalview.org for description of Features and Annotations file~\n\n");
85 Cache.loadProperties(aparser.getValue("props")); // must do this before
88 if (aparser.contains("nodisplay"))
90 System.setProperty("java.awt.headless", "true");
92 if (System.getProperty("java.awt.headless") != null
93 && System.getProperty("java.awt.headless").equals("true"))
101 } catch (java.lang.NoClassDefFoundError error)
103 error.printStackTrace();
105 .println("\nEssential logging libraries not found."
106 + "\nUse: java -Djava.ext.dirs=$PATH_TO_LIB$ jalview.bin.Jalview");
110 Desktop desktop = null;
114 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()
115 // UIManager.getCrossPlatformLookAndFeelClassName()
116 // "com.sun.java.swing.plaf.gtk.GTKLookAndFeel"
117 // "javax.swing.plaf.metal.MetalLookAndFeel"
118 // "com.sun.java.swing.plaf.windows.WindowsLookAndFeel"
119 // "com.sun.java.swing.plaf.motif.MotifLookAndFeel"
122 } catch (Exception ex)
127 desktop = new Desktop();
128 desktop.setVisible(true);
129 desktop.discoverer.start();
130 if (!aparser.contains("noquestionnaire"))
132 String url = aparser.getValue("questionnaire");
135 // Start the desktop questionnaire prompter with the specified
137 Cache.log.debug("Starting questionnaire url at " + url);
138 desktop.checkForQuestionnaire(url);
142 if (Cache.getProperty("NOQUESTIONNAIRES") == null)
144 // Start the desktop questionnaire prompter with the specified
147 // "http://anaplog.compbio.dundee.ac.uk/cgi-bin/questionnaire.pl";
149 String defurl = "http://www.jalview.org/cgi-bin/questionnaire.pl";
150 Cache.log.debug("Starting questionnaire with default url: "
152 desktop.checkForQuestionnaire(defurl);
159 String file = null, protocol = null, format = null, data = null;
160 jalview.io.FileLoader fileLoader = new jalview.io.FileLoader();
161 Vector getFeatures = null; // vector of das source nicknames to fetch features from
163 file = aparser.getValue("open");
165 if (file == null && desktop == null)
167 System.out.println("No files to open!");
173 System.out.println("Opening file: " + file);
175 if (!file.startsWith("http://"))
177 if (!(new java.io.File(file)).exists())
179 System.out.println("Can't find " + file);
187 protocol = checkProtocol(file);
189 format = new jalview.io.IdentifyFile().Identify(file, protocol);
191 AlignFrame af = fileLoader.LoadFileWaitTillLoaded(file, protocol,
196 System.out.println("error");
200 data = aparser.getValue("colour");
203 data.replaceAll("%20", " ");
205 jalview.schemes.ColourSchemeI cs = jalview.schemes.ColourSchemeProperty
206 .getColour(af.getViewport().getAlignment(), data);
210 jalview.schemes.UserColourScheme ucs = new jalview.schemes.UserColourScheme(
212 ucs.parseAppletParameter(data);
216 System.out.println("colour is " + data);
220 // Must maintain ability to use the groups flag
221 data = aparser.getValue("groups");
224 af.parseFeaturesFile(data, checkProtocol(data));
225 System.out.println("Added " + data);
227 data = aparser.getValue("features");
230 af.parseFeaturesFile(data, checkProtocol(data));
231 System.out.println("Added " + data);
234 data = aparser.getValue("annotations");
237 af.loadJalviewDataFile(data);
238 System.out.println("Added " + data);
240 data = aparser.getValue("tree");
243 jalview.io.NewickFile fin = null;
246 fin = new jalview.io.NewickFile(data, checkProtocol(data));
249 af.getViewport().setCurrentTree(
250 af.ShowNewickTree(fin, data).getTree());
251 System.out.println("Added tree " + data);
253 } catch (IOException ex)
255 System.err.println("Couldn't add tree " + data);
256 ex.printStackTrace(System.err);
259 getFeatures = checkDasArguments(aparser);
260 if (af != null && getFeatures!=null)
262 startFeatureFetching(getFeatures);
263 // need to block until fetching is complete.
264 while (af.operationInProgress())
266 // wait around until fetching is finished.
269 } catch (Exception e)
275 String imageName = "unnamed.png";
276 while (aparser.getSize() > 1)
278 format = aparser.nextValue();
279 file = aparser.nextValue();
281 if (format.equalsIgnoreCase("png"))
283 af.createPNG(new java.io.File(file));
284 imageName = (new java.io.File(file)).getName();
285 System.out.println("Creating PNG image: " + file);
288 else if (format.equalsIgnoreCase("imgMap"))
290 af.createImageMap(new java.io.File(file), imageName);
291 System.out.println("Creating image map: " + file);
294 else if (format.equalsIgnoreCase("eps"))
296 System.out.println("Creating EPS file: " + file);
297 af.createEPS(new java.io.File(file));
301 if (af.saveAlignment(file, format))
303 System.out.println("Written alignment in " + format
304 + " format to " + file);
308 System.out.println("Error writing file " + file + " in " + format
314 while (aparser.getSize() > 0)
316 System.out.println("Unknown arg: " + aparser.nextValue());
319 AlignFrame startUpAlframe = null;
320 // We'll only open the default file if the desktop is visible.
322 // ////////////////////
323 if (!headless && file == null
324 && jalview.bin.Cache.getDefault("SHOW_STARTUP_FILE", true))
326 file = jalview.bin.Cache.getDefault("STARTUP_FILE",
327 "http://www.jalview.org/examples/exampleFile_2_3.jar");
331 if (file.indexOf("http:") > -1)
336 if (file.endsWith(".jar"))
342 format = new jalview.io.IdentifyFile().Identify(file, protocol);
345 startUpAlframe = fileLoader.LoadFileWaitTillLoaded(file, protocol,
347 getFeatures = checkDasArguments(aparser);
349 // Once all loading is done. Retrieve features.
350 if (getFeatures!=null)
352 if (startUpAlframe!=null)
354 startFeatureFetching(getFeatures);
359 * Check commandline for any das server definitions or any fetchfrom switches
360 * @return vector of DAS source nicknames to retrieve from
362 private static Vector checkDasArguments(ArgsParser aparser)
366 String locsources = Cache.getProperty(Cache.DAS_LOCAL_SOURCE);
367 while ((data = aparser.getValue("dasserver"))!=null)
369 String nickname = null;
371 int pos = data.indexOf('=');
374 nickname = data.substring(0, pos);
376 url = data.substring(pos + 1);
377 if (url != null && url.startsWith("http:"))
379 if (nickname == null)
383 if (locsources==null)
389 locsources=locsources+nickname+"|"+url;
391 .println("NOTE! dasserver parameter not yet really supported (got args of "
392 + nickname + "|" + url);
395 source = new Vector();
397 source.addElement(nickname);
399 } // loop until no more server entries are found.
400 if (locsources!=null && locsources.indexOf('|')>-1)
402 Cache.log.debug("Setting local source list in properties file to:\n"+locsources);
403 Cache.setProperty(Cache.DAS_LOCAL_SOURCE, locsources);
405 while ((data = aparser.getValue("fetchfrom"))!=null)
407 System.out.println("adding source '"+data+"'");
410 source = new Vector();
412 source.addElement(data);
417 * start a feature fetcher for every alignment frame
420 private static void startFeatureFetching(final Vector dasSources)
422 AlignFrame afs[] = Desktop.getAlignframes();
423 if (afs==null || afs.length==0)
427 for (int i = 0; i<afs.length; i++)
429 final AlignFrame af = afs[i];
430 SwingUtilities.invokeLater(new Runnable() {
434 af.featureSettings_actionPerformed(null);
435 af.featureSettings.fetchDasFeatures(dasSources);
441 private static String checkProtocol(String file)
443 String protocol = jalview.io.FormatAdapter.FILE;
445 if (file.indexOf("http:") > -1 || file.indexOf("file:") > -1)
447 protocol = jalview.io.FormatAdapter.URL;
454 * Notes: this argParser does not distinguish between parameter switches,
455 * parameter values and argument text. If an argument happens to be identical
456 * to a parameter, it will be taken as such (even though it didn't have a '-' prefixing it).
458 * @author Andrew Waterhouse and JBP documented.
465 public ArgsParser(String[] args)
467 vargs = new Vector();
468 for (int i = 0; i < args.length; i++)
470 String arg = args[i].trim();
471 if (arg.charAt(0) == '-')
473 arg = arg.substring(1);
475 vargs.addElement(arg);
479 * check for and remove first occurence of arg+parameter in arglist.
481 * @return return the argument following the given arg if arg was in list.
483 public String getValue(String arg)
485 int index = vargs.indexOf(arg);
489 ret = vargs.elementAt(index + 1).toString();
490 vargs.removeElementAt(index);
491 vargs.removeElementAt(index);
496 * check for and remove first occurence of arg in arglist.
498 * @return true if arg was present in argslist.
500 public boolean contains(String arg)
502 if (vargs.contains(arg))
504 vargs.removeElement(arg);
513 public String nextValue()
515 return vargs.remove(0).toString();