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
32 * <br>start with java -Djava.ext.dirs=$PATH_TO_LIB$ jalview.bin.Jalview
41 * main class for Jalview application
43 * @param args open <em>filename</em>
45 public static void main(String[] args)
47 System.out.println("Java version: " + System.getProperty("java.version"));
48 System.out.println(System.getProperty("os.arch") + " "
49 + System.getProperty("os.name") + " "
50 + System.getProperty("os.version"));
52 ArgsParser aparser = new ArgsParser(args);
53 boolean headless = false;
55 if (aparser.contains("help") || aparser.contains("h"))
58 "Usage: jalview -open [FILE] [OUTPUT_FORMAT] [OUTPUT_FILE]\n\n"
59 + "-nodisplay\tRun Jalview without User Interface.\n"
61 "-props FILE\tUse the given Jalview properties file instead of users default.\n"
63 "-annotations FILE\tAdd precalculated annotations to the alignment.\n"
65 "-tree FILE\tLoad the given newick format tree file onto the alignment\n"
67 "-features FILE\tUse the given file to mark features on the alignment.\n"
68 + "-fasta FILE\tCreate alignment file FILE in Fasta format.\n"
69 + "-clustal FILE\tCreate alignment file FILE in Clustal format.\n"
70 + "-pfam FILE\tCreate alignment file FILE in PFAM format.\n"
71 + "-msf FILE\tCreate alignment file FILE in MSF format.\n"
72 + "-pileup FILE\tCreate alignment file FILE in Pileup format\n"
73 + "-pir FILE\tCreate alignment file FILE in PIR format.\n"
74 + "-blc FILE\tCreate alignment file FILE in BLC format.\n"
75 + "-jalview FILE\tCreate alignment file FILE in Jalview format.\n"
76 + "-png FILE\tCreate PNG image FILE from alignment.\n"
78 "-imgMap FILE\tCreate HTML file FILE with image map of PNG image.\n"
79 + "-eps FILE\tCreate EPS file FILE from alignment."
80 + "-questionnaire URL\tQueries the given URL for information about any Jalview user questionnaires."
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 anything else!
87 if (aparser.contains("nodisplay"))
89 System.setProperty("java.awt.headless", "true");
91 if (System.getProperty("java.awt.headless") != null
92 && System.getProperty("java.awt.headless").equals("true"))
101 catch (java.lang.NoClassDefFoundError error)
103 error.printStackTrace();
105 "\nEssential logging libraries not found."
106 + "\nUse: java -Djava.ext.dirs=$PATH_TO_LIB$ jalview.bin.Jalview");
110 Desktop desktop = null;
114 UIManager.setLookAndFeel(
115 UIManager.getSystemLookAndFeelClassName()
116 // UIManager.getCrossPlatformLookAndFeelClassName()
117 //"com.sun.java.swing.plaf.gtk.GTKLookAndFeel"
118 //"javax.swing.plaf.metal.MetalLookAndFeel"
119 //"com.sun.java.swing.plaf.windows.WindowsLookAndFeel"
120 //"com.sun.java.swing.plaf.motif.MotifLookAndFeel"
128 desktop = new Desktop();
129 desktop.setVisible(true);
130 desktop.discoverer.start();
131 String url = aparser.getValue("questionnaire");
134 // Start the desktop questionnaire prompter with the specified questionnaire
135 Cache.log.debug("Starting questionnaire url at " + url);
136 desktop.checkForQuestionnaire(url);
140 if (Cache.getProperty("NOQUESTIONNAIRES") == null)
142 // Start the desktop questionnaire prompter with the specified questionnaire
143 // String defurl = "http://anaplog.compbio.dundee.ac.uk/cgi-bin/questionnaire.pl"; //
144 String defurl = "http://www.jalview.org/cgi-bin/questionnaire.pl";
145 Cache.log.debug("Starting questionnaire with default url: " + defurl);
146 desktop.checkForQuestionnaire(defurl);
153 String file = null, protocol = null, format = null, data = null;
154 jalview.io.FileLoader fileLoader = new jalview.io.FileLoader();
156 file = aparser.getValue("open");
158 if (file == null && desktop == null)
160 System.out.println("No files to open!");
166 System.out.println("Opening file: " + file);
168 if (!file.startsWith("http://"))
170 if (! (new java.io.File(file)).exists())
172 System.out.println("Can't find " + file);
180 protocol = checkProtocol(file);
182 format = new jalview.io.IdentifyFile().Identify(file, protocol);
184 AlignFrame af = fileLoader.LoadFileWaitTillLoaded(file, protocol, format);
188 System.out.println("error");
192 data = aparser.getValue("colour");
195 data.replaceAll("%20", " ");
197 jalview.schemes.ColourSchemeI cs =
198 jalview.schemes.ColourSchemeProperty.getColour(af.getViewport().
199 getAlignment(), data);
203 jalview.schemes.UserColourScheme ucs
204 = new jalview.schemes.UserColourScheme("white");
205 ucs.parseAppletParameter(data);
209 System.out.println("colour is " + data);
213 // Must maintain ability to use the groups flag
214 data = aparser.getValue("groups");
217 af.parseFeaturesFile(data, checkProtocol(data));
218 System.out.println("Added " + data);
220 data = aparser.getValue("features");
223 af.parseFeaturesFile(data, checkProtocol(data));
224 System.out.println("Added " + data);
227 data = aparser.getValue("annotations");
230 af.loadJalviewDataFile(data);
231 System.out.println("Added " + data);
233 data = aparser.getValue("tree");
236 jalview.io.NewickFile fin = null;
238 fin = new jalview.io.NewickFile(data, checkProtocol(data));
241 af.getViewport().setCurrentTree(af.ShowNewickTree(fin, data).getTree());
242 System.out.println("Added tree " + data);
245 catch (IOException ex)
247 System.err.println("Couldn't add tree "+data);
248 ex.printStackTrace(System.err);
252 String imageName = "unnamed.png";
253 while (aparser.getSize() > 1)
255 format = aparser.nextValue();
256 file = aparser.nextValue();
258 if (format.equalsIgnoreCase("png"))
260 af.createPNG(new java.io.File(file));
261 imageName = (new java.io.File(file)).getName();
262 System.out.println("Creating PNG image: " + file);
265 else if (format.equalsIgnoreCase("imgMap"))
267 af.createImageMap(new java.io.File(file), imageName);
268 System.out.println("Creating image map: " + file);
271 else if (format.equalsIgnoreCase("eps"))
273 System.out.println("Creating EPS file: " + file);
274 af.createEPS(new java.io.File(file));
278 if (af.saveAlignment(file, format))
280 System.out.println("Written alignment in " + format +
281 " format to " + file);
285 System.out.println("Error writing file " + file + " in " + format +
291 while (aparser.getSize() > 0)
293 System.out.println("Unknown arg: " + aparser.nextValue());
297 // We'll only open the default file if the desktop is visible.
299 //////////////////////
303 && jalview.bin.Cache.getDefault("SHOW_STARTUP_FILE", true)
307 file = jalview.bin.Cache.getDefault("STARTUP_FILE",
308 "http://www.jalview.org/examples/exampleFile_2_3.jar");
312 if (file.indexOf("http:") > -1)
317 if (file.endsWith(".jar"))
323 format = new jalview.io.IdentifyFile().Identify(file, protocol);
326 fileLoader.LoadFile(file, protocol, format);
332 private static String checkProtocol(String file)
334 String protocol = jalview.io.FormatAdapter.FILE;
336 if (file.indexOf("http:") > -1 || file.indexOf("file:") > -1)
338 protocol = jalview.io.FormatAdapter.URL;
346 public ArgsParser(String[] args)
348 vargs = new Vector();
349 for (int i = 0; i < args.length; i++)
351 String arg = args[i].trim();
352 if (arg.charAt(0) == '-')
354 arg = arg.substring(1);
356 vargs.addElement(arg);
360 public String getValue(String arg)
362 int index = vargs.indexOf(arg);
366 ret = vargs.elementAt(index + 1).toString();
367 vargs.removeElementAt(index);
368 vargs.removeElementAt(index);
373 public boolean contains(String arg)
375 if (vargs.contains(arg))
377 vargs.removeElement(arg);
386 public String nextValue()
388 return vargs.remove(0).toString();