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
28 * Main class for Jalview Application
30 * <br>start with java -Djava.ext.dirs=$PATH_TO_LIB$ jalview.bin.Jalview
39 * main class for Jalview application
41 * @param args open <em>filename</em>
43 public static void main(String[] args)
45 System.out.println("Java version: " + System.getProperty("java.version"));
46 System.out.println("Java version: " + System.getProperty("java.version"));
47 System.out.println(System.getProperty("os.arch") + " "
48 + System.getProperty("os.name") + " "
49 + System.getProperty("os.version"));
51 ArgsParser aparser = new ArgsParser(args);
52 boolean headless = false;
54 if (aparser.contains("help") || aparser.contains("h"))
57 "Usage: jalview -open [FILE] [OUTPUT_FORMAT] [OUTPUT_FILE]\n\n"
58 + "-nodisplay\tRun Jalview without User Interface.\n"
60 "-props FILE\tUse the given Jalview properties file instead of users default.\n"
62 "-annotations FILE\tAdd precalculated annotations to the alignment.\n"
64 "-features FILE\tUse the given file to mark features on the alignment.\n"
65 + "-fasta FILE\tCreate alignment file FILE in Fasta format.\n"
66 + "-clustal FILE\tCreate alignment file FILE in Clustal format.\n"
67 + "-pfam FILE\tCreate alignment file FILE in PFAM format.\n"
68 + "-msf FILE\tCreate alignment file FILE in MSF format.\n"
69 + "-pileup FILE\tCreate alignment file FILE in Pileup format\n"
70 + "-pir FILE\tCreate alignment file FILE in PIR format.\n"
71 + "-blc FILE\tCreate alignment file FILE in BLC format.\n"
72 + "-jalview FILE\tCreate alignment file FILE in Jalview format.\n"
73 + "-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 + "\n\n~Read documentation in Application or visit http://www.jalview.org for description of Features and Annotations file~\n\n");
82 Cache.loadProperties(aparser.getValue("props")); // must do this before anything else!
84 if (aparser.contains("nodisplay"))
86 System.setProperty("java.awt.headless", "true");
88 if (System.getProperty("java.awt.headless") != null
89 && System.getProperty("java.awt.headless").equals("true"))
98 catch (java.lang.NoClassDefFoundError error)
100 error.printStackTrace();
102 "\nEssential logging libraries not found."
103 + "\nUse: java -Djava.ext.dirs=$PATH_TO_LIB$ jalview.bin.Jalview");
107 Desktop desktop = null;
111 UIManager.setLookAndFeel(
112 UIManager.getSystemLookAndFeelClassName()
113 // UIManager.getCrossPlatformLookAndFeelClassName()
114 //"com.sun.java.swing.plaf.gtk.GTKLookAndFeel"
115 //"javax.swing.plaf.metal.MetalLookAndFeel"
116 //"com.sun.java.swing.plaf.windows.WindowsLookAndFeel"
117 //"com.sun.java.swing.plaf.motif.MotifLookAndFeel"
125 desktop = new Desktop();
126 desktop.setVisible(true);
127 desktop.discoverer.start();
128 String url = aparser.getValue("questionnaire");
131 // Start the desktop questionnaire prompter with the specified questionnaire
132 Cache.log.debug("Starting questionnaire url at " + url);
133 desktop.checkForQuestionnaire(url);
137 if (Cache.getProperty("NOQUESTIONNAIRES") == null)
139 // Start the desktop questionnaire prompter with the specified questionnaire
140 // String defurl = "http://anaplog.compbio.dundee.ac.uk/cgi-bin/questionnaire.pl"; //
141 String defurl = "http://www.jalview.org/cgi-bin/questionnaire.pl";
142 Cache.log.debug("Starting questionnaire with default url: " + defurl);
143 desktop.checkForQuestionnaire(defurl);
150 String file = null, protocol = null, format = null, data = null;
151 jalview.io.FileLoader fileLoader = new jalview.io.FileLoader();
153 file = aparser.getValue("open");
155 if (file == null && desktop == null)
157 System.out.println("No files to open!");
163 System.out.println("Opening file: " + file);
165 if (!file.startsWith("http://"))
167 if (! (new java.io.File(file)).exists())
169 System.out.println("Can't find " + file);
179 if (file.indexOf("http:") > -1 || file.indexOf("file:") > -1)
184 if (file.endsWith(".jar"))
190 format = new jalview.io.IdentifyFile().Identify(file, protocol);
193 AlignFrame af = fileLoader.LoadFileWaitTillLoaded(file, protocol, format);
197 System.out.println("error");
201 data = aparser.getValue("colour");
204 data.replaceAll("%20", " ");
206 jalview.schemes.ColourSchemeI cs =
207 jalview.schemes.ColourSchemeProperty.getColour(af.getViewport().
208 getAlignment(), data);
212 jalview.schemes.UserColourScheme ucs
213 = new jalview.schemes.UserColourScheme("white");
214 ucs.parseAppletParameter(data);
218 System.out.println("colour is " + data);
222 // Must maintain ability to use the groups flag
223 data = aparser.getValue("groups");
226 af.parseFeaturesFile(data, protocol);
227 System.out.println("Added " + data);
229 data = aparser.getValue("features");
232 af.parseFeaturesFile(data, protocol);
233 System.out.println("Added " + data);
236 data = aparser.getValue("annotations");
239 af.loadJalviewDataFile(data);
240 System.out.println("Added " + data);
243 String imageName = "unnamed.png";
244 while (aparser.getSize() > 1)
246 format = aparser.nextValue();
247 file = aparser.nextValue();
249 if (format.equalsIgnoreCase("png"))
251 af.createPNG(new java.io.File(file));
252 imageName = (new java.io.File(file)).getName();
253 System.out.println("Creating PNG image: " + file);
256 else if (format.equalsIgnoreCase("imgMap"))
258 af.createImageMap(new java.io.File(file), imageName);
259 System.out.println("Creating image map: " + file);
262 else if (format.equalsIgnoreCase("eps"))
264 System.out.println("Creating EPS file: " + file);
265 af.createEPS(new java.io.File(file));
269 if (af.saveAlignment(file, format))
271 System.out.println("Written alignment in " + format +
272 " format to " + file);
276 System.out.println("Error writing file " + file + " in " + format +
282 while (aparser.getSize() > 0)
284 System.out.println("Unknown arg: " + aparser.nextValue());
288 // We'll only open the default file if the desktop is visible.
290 //////////////////////
294 && jalview.bin.Cache.getDefault("SHOW_STARTUP_FILE", true)
298 file = jalview.bin.Cache.getDefault("STARTUP_FILE",
299 "http://www.jalview.org/examples/exampleFile_2_3.jar");
303 if (file.indexOf("http:") > -1)
308 if (file.endsWith(".jar"))
314 format = new jalview.io.IdentifyFile().Identify(file, protocol);
317 fileLoader.LoadFile(file, protocol, format);
326 public ArgsParser(String[] args)
328 vargs = new Vector();
329 for (int i = 0; i < args.length; i++)
331 String arg = args[i].trim();
332 if (arg.charAt(0) == '-')
334 arg = arg.substring(1);
336 vargs.addElement(arg);
340 public String getValue(String arg)
342 int index = vargs.indexOf(arg);
346 ret = vargs.elementAt(index + 1).toString();
347 vargs.removeElementAt(index);
348 vargs.removeElementAt(index);
353 public boolean contains(String arg)
355 if (vargs.contains(arg))
357 vargs.removeElement(arg);
366 public String nextValue()
368 return vargs.remove(0).toString();