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(System.getProperty("os.arch") + " "
47 + System.getProperty("os.name") + " "
48 + System.getProperty("os.version"));
50 ArgsParser aparser = new ArgsParser(args);
51 boolean headless = false;
53 if (aparser.contains("help") || aparser.contains("h"))
56 "Usage: jalview -open [FILE] [OUTPUT_FORMAT] [OUTPUT_FILE]\n\n"
57 + "-nodisplay\tRun Jalview without User Interface.\n"
59 "-props FILE\tUse the given Jalview properties file instead of users default.\n"
61 "-annotations FILE\tAdd precalculated annotations to the alignment.\n"
63 "-features FILE\tUse the given file to mark features on the alignment.\n"
64 + "-fasta FILE\tCreate alignment file FILE in Fasta format.\n"
65 + "-clustal FILE\tCreate alignment file FILE in Clustal format.\n"
66 + "-pfam FILE\tCreate alignment file FILE in PFAM format.\n"
67 + "-msf FILE\tCreate alignment file FILE in MSF format.\n"
68 + "-pileup FILE\tCreate alignment file FILE in Pileup format\n"
69 + "-pir FILE\tCreate alignment file FILE in PIR format.\n"
70 + "-blc FILE\tCreate alignment file FILE in BLC format.\n"
71 + "-jalview FILE\tCreate alignment file FILE in Jalview format.\n"
72 + "-png FILE\tCreate PNG image FILE from alignment.\n"
74 "-imgMap FILE\tCreate HTML file FILE with image map of PNG image.\n"
75 + "-eps FILE\tCreate EPS file FILE from alignment."
76 + "-questionnaire URL\tQueries the given URL for information about any Jalview user questionnaires."
77 + "\n\n~Read documentation in Application or visit http://www.jalview.org for description of Features and Annotations file~\n\n");
81 Cache.loadProperties(aparser.getValue("props")); // must do this before anything else!
83 if (aparser.contains("nodisplay"))
85 System.setProperty("java.awt.headless", "true");
87 if (System.getProperty("java.awt.headless") != null
88 && System.getProperty("java.awt.headless").equals("true"))
97 catch (java.lang.NoClassDefFoundError error)
99 error.printStackTrace();
101 "\nEssential logging libraries not found."
102 + "\nUse: java -Djava.ext.dirs=$PATH_TO_LIB$ jalview.bin.Jalview");
106 Desktop desktop = null;
110 UIManager.setLookAndFeel(
111 UIManager.getSystemLookAndFeelClassName()
112 // UIManager.getCrossPlatformLookAndFeelClassName()
113 //"com.sun.java.swing.plaf.gtk.GTKLookAndFeel"
114 //"javax.swing.plaf.metal.MetalLookAndFeel"
115 //"com.sun.java.swing.plaf.windows.WindowsLookAndFeel"
116 //"com.sun.java.swing.plaf.motif.MotifLookAndFeel"
124 desktop = new Desktop();
125 desktop.setVisible(true);
126 desktop.discoverer.start();
127 String url = aparser.getValue("questionnaire");
130 // Start the desktop questionnaire prompter with the specified questionnaire
131 Cache.log.debug("Starting questionnaire url at " + url);
132 desktop.checkForQuestionnaire(url);
136 if (Cache.getProperty("NOQUESTIONNAIRES") == null)
138 // Start the desktop questionnaire prompter with the specified questionnaire
139 // String defurl = "http://anaplog.compbio.dundee.ac.uk/cgi-bin/questionnaire.pl"; //
140 String defurl = "http://www.jalview.org/cgi-bin/questionnaire.pl";
141 Cache.log.debug("Starting questionnaire with default url: " + defurl);
142 desktop.checkForQuestionnaire(defurl);
149 String file = null, protocol = null, format = null, data = null;
150 jalview.io.FileLoader fileLoader = new jalview.io.FileLoader();
152 file = aparser.getValue("open");
154 if (file == null && desktop == null)
156 System.out.println("No files to open!");
162 System.out.println("Opening file: " + file);
164 if (!file.startsWith("http://"))
166 if (! (new java.io.File(file)).exists())
168 System.out.println("Can't find " + file);
178 if (file.indexOf("http:") > -1 || file.indexOf("file:") > -1)
183 if (file.endsWith(".jar"))
189 format = new jalview.io.IdentifyFile().Identify(file, protocol);
192 AlignFrame af = fileLoader.LoadFileWaitTillLoaded(file, protocol, format);
196 System.out.println("error");
200 data = aparser.getValue("colour");
203 data.replaceAll("%20", " ");
205 jalview.schemes.ColourSchemeI cs =
206 jalview.schemes.ColourSchemeProperty.getColour(af.getViewport().
207 getAlignment(), data);
211 jalview.schemes.UserColourScheme ucs
212 = new jalview.schemes.UserColourScheme("white");
213 ucs.parseAppletParameter(data);
217 System.out.println("colour is " + data);
221 // Must maintain ability to use the groups flag
222 data = aparser.getValue("groups");
225 af.parseFeaturesFile(data, protocol);
226 System.out.println("Added " + data);
228 data = aparser.getValue("features");
231 af.parseFeaturesFile(data, protocol);
232 System.out.println("Added " + data);
235 data = aparser.getValue("annotations");
238 af.loadJalviewDataFile(data);
239 System.out.println("Added " + data);
242 String imageName = "unnamed.png";
243 while (aparser.getSize() > 1)
245 format = aparser.nextValue();
246 file = aparser.nextValue();
248 if (format.equalsIgnoreCase("png"))
250 af.createPNG(new java.io.File(file));
251 imageName = (new java.io.File(file)).getName();
252 System.out.println("Creating PNG image: " + file);
255 else if (format.equalsIgnoreCase("imgMap"))
257 af.createImageMap(new java.io.File(file), imageName);
258 System.out.println("Creating image map: " + file);
261 else if (format.equalsIgnoreCase("eps"))
263 System.out.println("Creating EPS file: " + file);
264 af.createEPS(new java.io.File(file));
268 if (af.saveAlignment(file, format))
270 System.out.println("Written alignment in " + format +
271 " format to " + file);
275 System.out.println("Error writing file " + file + " in " + format +
281 while (aparser.getSize() > 0)
283 System.out.println("Unknown arg: " + aparser.nextValue());
287 // We'll only open the default file if the desktop is visible.
289 //////////////////////
293 && jalview.bin.Cache.getDefault("SHOW_STARTUP_FILE", true)
297 file = jalview.bin.Cache.getDefault("STARTUP_FILE",
298 "http://www.jalview.org/examples/exampleFile_2_3.jar");
302 if (file.indexOf("http:") > -1)
307 if (file.endsWith(".jar"))
313 format = new jalview.io.IdentifyFile().Identify(file, protocol);
316 fileLoader.LoadFile(file, protocol, format);
325 public ArgsParser(String[] args)
327 vargs = new Vector();
328 for (int i = 0; i < args.length; i++)
330 String arg = args[i].trim();
331 if (arg.charAt(0) == '-')
333 arg = arg.substring(1);
335 vargs.addElement(arg);
339 public String getValue(String arg)
341 int index = vargs.indexOf(arg);
345 ret = vargs.elementAt(index + 1).toString();
346 vargs.removeElementAt(index);
347 vargs.removeElementAt(index);
352 public boolean contains(String arg)
354 if (vargs.contains(arg))
356 vargs.removeElement(arg);
365 public String nextValue()
367 return vargs.remove(0).toString();