2 * Jalview - A Sequence Alignment Editor and Viewer
3 * Copyright (C) 2006 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
25 import java.util.Vector;
29 * Main class for Jalview Application
31 * <br>start with java -Djava.ext.dirs=$PATH_TO_LIB$ jalview.bin.Jalview
40 * main class for Jalview application
42 * @param args open <em>filename</em>
44 public static void main(String[] args)
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"));
52 ArgsParser aparser = new ArgsParser(args);
53 boolean headless = false;
55 if( aparser.contains("help") || aparser.contains("h") )
57 System.out.println("Usage: jalview -open [FILE] [OUTPUT_FORMAT] [OUTPUT_FILE]\n\n"
58 +"-nodisplay\tRun Jalview without User Interface.\n"
59 +"-props FILE\tUse the given Jalview properties file instead of users default.\n"
60 +"-annotations FILE\tAdd precalculated annotations to the alignment.\n"
61 +"-features FILE\tUse the given file to mark features on the alignment.\n"
62 +"-fasta FILE\tCreate alignment file FILE in Fasta format.\n"
63 +"-clustal FILE\tCreate alignment file FILE in Clustal format.\n"
64 +"-pfam FILE\tCreate alignment file FILE in PFAM format.\n"
65 +"-msf FILE\tCreate alignment file FILE in MSF format.\n"
66 +"-pileup FILE\tCreate alignment file FILE in Pileup format\n"
67 +"-pir FILE\tCreate alignment file FILE in PIR format.\n"
68 +"-blc FILE\tCreate alignment file FILE in BLC format.\n"
69 +"-jalview FILE\tCreate alignment file FILE in Jalview format.\n"
70 +"-png FILE\tCreate PNG image FILE from alignment.\n"
71 +"-imgMap FILE\tCreate HTML file FILE with image map of PNG image.\n"
72 +"-eps FILE\tCreate EPS file FILE from alignment."
73 +"-questionnaire URL\tQueries the given URL for information about any Jalview user questionnaires."
74 +"\n\n~Read documentation in Application or visit http://www.jalview.org for description of Features and Annotations file~\n\n");
78 Cache.loadProperties(aparser.getValue("props")); // must do this before anything else!
80 if (aparser.contains("nodisplay"))
82 System.setProperty("java.awt.headless", "true");
84 if (System.getProperty("java.awt.headless") != null
85 && System.getProperty("java.awt.headless").equals("true"))
94 catch (java.lang.NoClassDefFoundError error)
96 error.printStackTrace();
98 "\nEssential logging libraries not found."
99 +"\nUse: java -Djava.ext.dirs=$PATH_TO_LIB$ jalview.bin.Jalview");
103 Desktop desktop = null;
108 UIManager.setLookAndFeel(
109 UIManager.getSystemLookAndFeelClassName()
110 // UIManager.getCrossPlatformLookAndFeelClassName()
111 //"com.sun.java.swing.plaf.gtk.GTKLookAndFeel"
112 //"javax.swing.plaf.metal.MetalLookAndFeel"
113 //"com.sun.java.swing.plaf.windows.WindowsLookAndFeel"
114 //"com.sun.java.swing.plaf.motif.MotifLookAndFeel"
122 desktop = new Desktop();
123 desktop.setVisible(true);
124 desktop.discoverer.start();
126 String url = aparser.getValue("questionnaire");
127 if (url!=null && !headless) {
128 // Start the desktop questionnaire prompter
129 Cache.log.debug("Starting questionnaire url at "+url);
131 desktop.checkForQuestionnaire(url);
136 String file = null, protocol = null, format = null, data=null;
137 jalview.io.FileLoader fileLoader = new jalview.io.FileLoader();
139 file = aparser.getValue("open");
141 if (file == null && desktop==null)
143 System.out.println("No files to open!");
149 System.out.println("Opening file: " + file);
151 if (!file.startsWith("http://"))
153 if (! (new java.io.File(file)).exists())
155 System.out.println("Can't find " + file);
163 if (file.indexOf("http:") > -1 || file.indexOf("file:") >-1)
170 if (file.endsWith(".jar"))
173 format = new jalview.io.IdentifyFile().Identify(file, protocol);
177 AlignFrame af = fileLoader.LoadFileWaitTillLoaded(file, protocol, format);
181 System.out.println("error");
185 data = aparser.getValue("colour");
188 data.replaceAll("%20", " ");
190 jalview.schemes.ColourSchemeI cs =
191 jalview.schemes.ColourSchemeProperty.getColour(af.getViewport().
192 getAlignment(), data);
196 jalview.schemes.UserColourScheme ucs
197 = new jalview.schemes.UserColourScheme("white");
198 ucs.parseAppletParameter(data);
202 System.out.println("colour is " + data);
203 af.changeColour( cs );
207 // Must maintain ability to use the groups flag
208 data = aparser.getValue("groups");
211 af.parseFeaturesFile(data, protocol);
212 System.out.println("Added "+data);
214 data = aparser.getValue("features");
217 af.parseFeaturesFile(data, protocol);
218 System.out.println("Added "+data);
221 data = aparser.getValue("annotations");
224 af.loadJalviewDataFile(data);
225 System.out.println("Added "+data);
229 String imageName = "unnamed.png";
230 while (aparser.getSize() > 1)
232 format = aparser.nextValue();
233 file = aparser.nextValue();
235 if (format.equalsIgnoreCase("png"))
237 af.createPNG(new java.io.File(file));
238 imageName = (new java.io.File(file)).getName();
239 System.out.println("Creating PNG image: " + file);
242 else if (format.equalsIgnoreCase("imgMap"))
244 af.createImageMap(new java.io.File(file), imageName);
245 System.out.println("Creating image map: " + file);
248 else if (format.equalsIgnoreCase("eps"))
250 System.out.println("Creating EPS file: " + file);
251 af.createEPS(new java.io.File(file));
255 if (af.saveAlignment(file, format))
256 System.out.println("Written alignment in " + format +
257 " format to " + file);
259 System.out.println("Error writing file " + file + " in " + format +
264 while (aparser.getSize() > 0)
266 System.out.println("Unknown arg: " + aparser.nextValue());
270 // We'll only open the default file if the desktop is visible.
272 //////////////////////
276 && jalview.bin.Cache.getDefault("SHOW_STARTUP_FILE", true)
280 file = jalview.bin.Cache.getDefault("STARTUP_FILE",
281 "http://www.jalview.org/examples/exampleFile.jar");
285 if (file.indexOf("http:") > -1)
290 if (file.endsWith(".jar"))
296 format = new jalview.io.IdentifyFile().Identify(file, protocol);
299 fileLoader.LoadFile(file, protocol, format);
308 public ArgsParser(String [] args)
310 vargs = new Vector();
311 for (int i = 0; i < args.length; i++)
313 String arg = args[i].trim();
314 if (arg.charAt(0) == '-')
315 arg = arg.substring(1);
316 vargs.addElement(arg);
320 public String getValue(String arg)
322 int index = vargs.indexOf(arg);
326 ret = vargs.elementAt(index + 1).toString();
327 vargs.removeElementAt(index);
328 vargs.removeElementAt(index);
333 public boolean contains(String arg)
335 if(vargs.contains(arg))
337 vargs.removeElement(arg);
344 public String nextValue()
346 return vargs.remove(0).toString();