2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
\r
5 * This program is free software; you can redistribute it and/or
\r
6 * modify it under the terms of the GNU General Public License
\r
7 * as published by the Free Software Foundation; either version 2
\r
8 * of the License, or (at your option) any later version.
\r
10 * This program is distributed in the hope that it will be useful,
\r
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 * GNU General Public License for more details.
\r
15 * You should have received a copy of the GNU General Public License
\r
16 * along with this program; if not, write to the Free Software
\r
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
\r
19 package jalview.bin;
\r
21 import jalview.gui.*;
\r
23 import javax.swing.*;
\r
25 import java.util.Vector;
\r
29 * Main class for Jalview Application
\r
31 * <br>start with java -Djava.ext.dirs=$PATH_TO_LIB$ jalview.bin.Jalview
\r
34 * @version $Revision$
\r
36 public class Jalview
\r
40 * main class for Jalview application
\r
42 * @param args open <em>filename</em>
\r
44 public static void main(String[] args)
\r
46 System.out.println("Java version: "+System.getProperty("java.version"));
\r
47 System.out.println(System.getProperty("os.arch")+" "
\r
48 +System.getProperty("os.name")+" "
\r
49 +System.getProperty("os.version"));
\r
52 ArgsParser aparser = new ArgsParser(args);
\r
53 boolean headless = false;
\r
55 if( aparser.contains("help") || aparser.contains("h") )
\r
57 System.out.println("Usage: jalview -open [FILE] [OUTPUT_FORMAT] [OUTPUT_FILE]\n\n"
\r
58 +"-nodisplay\tRun Jalview without User Interface.\n"
\r
59 +"-props FILE\tUse the given Jalview properties file instead of users default.\n"
\r
60 +"-annotations FILE\tAdd precalculated annotations to the alignment.\n"
\r
61 +"-features FILE\tUse the given file to mark features on the alignment.\n"
\r
62 +"-fasta FILE\tCreate alignment file FILE in Fasta format.\n"
\r
63 +"-clustal FILE\tCreate alignment file FILE in Clustal format.\n"
\r
64 +"-pfam FILE\tCreate alignment file FILE in PFAM format.\n"
\r
65 +"-msf FILE\tCreate alignment file FILE in MSF format.\n"
\r
66 +"-pileup FILE\tCreate alignment file FILE in Pileup format\n"
\r
67 +"-pir FILE\tCreate alignment file FILE in PIR format.\n"
\r
68 +"-blc FILE\tCreate alignment file FILE in BLC format.\n"
\r
69 +"-jalview FILE\tCreate alignment file FILE in Jalview format.\n"
\r
70 +"-png FILE\tCreate PNG image FILE from alignment.\n"
\r
71 +"-imgMap FILE\tCreate HTML file FILE with image map of PNG image.\n"
\r
72 +"-eps FILE\tCreate EPS file FILE from alignment."
\r
73 +"\n\n~Read documentation in Application or visit http://www.jalview.org for description of Features and Annotations file~\n\n");
\r
77 Cache.loadProperties(aparser.getValue("props")); // must do this before anything else!
\r
79 if (aparser.contains("nodisplay"))
\r
81 System.setProperty("java.awt.headless", "true");
\r
83 if (System.getProperty("java.awt.headless") != null
\r
84 && System.getProperty("java.awt.headless").equals("true"))
\r
93 catch (java.lang.NoClassDefFoundError error)
\r
95 error.printStackTrace();
\r
97 "\nEssential logging libraries not found."
\r
98 +"\nUse: java -Djava.ext.dirs=$PATH_TO_LIB$ jalview.bin.Jalview");
\r
102 Desktop desktop = null;
\r
107 UIManager.setLookAndFeel(
\r
108 UIManager.getSystemLookAndFeelClassName()
\r
109 // UIManager.getCrossPlatformLookAndFeelClassName()
\r
110 //"com.sun.java.swing.plaf.gtk.GTKLookAndFeel"
\r
111 //"javax.swing.plaf.metal.MetalLookAndFeel"
\r
112 //"com.sun.java.swing.plaf.windows.WindowsLookAndFeel"
\r
113 //"com.sun.java.swing.plaf.motif.MotifLookAndFeel"
\r
117 catch (Exception ex)
\r
121 desktop = new Desktop();
\r
122 desktop.setVisible(true);
\r
123 desktop.discoverer.start();
\r
127 String file = null, protocol = null, format = null, data=null;
\r
128 jalview.io.FileLoader fileLoader = new jalview.io.FileLoader();
\r
130 file = aparser.getValue("open");
\r
132 if (file == null && desktop==null)
\r
134 System.out.println("No files to open!");
\r
141 if (!file.startsWith("http://"))
\r
143 if (! (new java.io.File(file)).exists())
\r
145 System.out.println("Can't find " + file);
\r
153 if (file.indexOf("http:") > -1 || file.indexOf("file:") >-1)
\r
158 if (file.endsWith(".jar"))
\r
159 format = "Jalview";
\r
161 format = new jalview.io.IdentifyFile().Identify(file, protocol);
\r
163 System.out.println("Opening: " + format + " file " + file);
\r
165 AlignFrame af = fileLoader.LoadFileWaitTillLoaded(file, protocol, format);
\r
167 data = aparser.getValue("colour");
\r
170 data.replaceAll("%20", " ");
\r
172 jalview.schemes.ColourSchemeI cs =
\r
173 jalview.schemes.ColourSchemeProperty.getColour(af.getViewport().
\r
174 getAlignment(), data);
\r
178 jalview.schemes.UserColourScheme ucs
\r
179 = new jalview.schemes.UserColourScheme("white");
\r
180 ucs.parseAppletParameter(data);
\r
184 System.out.println("colour is " + data);
\r
185 af.changeColour( cs );
\r
189 // Must maintain ability to use the groups flag
\r
190 data = aparser.getValue("groups");
\r
193 af.parseFeaturesFile(data, protocol);
\r
194 System.out.println("Added "+data);
\r
196 data = aparser.getValue("features");
\r
199 af.parseFeaturesFile(data, protocol);
\r
200 System.out.println("Added "+data);
\r
203 data = aparser.getValue("annotations");
\r
206 af.loadJalviewDataFile(data);
\r
207 System.out.println("Added "+data);
\r
211 String imageName = "unnamed.png";
\r
212 while (aparser.getSize() > 1)
\r
214 format = aparser.nextValue();
\r
215 file = aparser.nextValue();
\r
217 if (format.equalsIgnoreCase("png"))
\r
219 af.createPNG(new java.io.File(file));
\r
220 imageName = (new java.io.File(file)).getName();
\r
221 System.out.println("Creating PNG image: " + file);
\r
224 else if (format.equalsIgnoreCase("imgMap"))
\r
226 af.createImageMap(new java.io.File(file), imageName);
\r
227 System.out.println("Creating image map: " + file);
\r
230 else if (format.equalsIgnoreCase("eps"))
\r
232 System.out.println("Creating EPS file: " + file);
\r
233 af.createEPS(new java.io.File(file));
\r
237 if (af.saveAlignment(file, format))
\r
238 System.out.println("Written alignment in " + format +
\r
239 " format to " + file);
\r
241 System.out.println("Error writing file " + file + " in " + format +
\r
246 while (aparser.getSize() > 0)
\r
248 System.out.println("Unknown arg: " + aparser.nextValue());
\r
252 // We'll only open the default file if the desktop is visible.
\r
254 //////////////////////
\r
258 && jalview.bin.Cache.getDefault("SHOW_STARTUP_FILE", true)
\r
262 file = jalview.bin.Cache.getDefault("STARTUP_FILE",
\r
263 "http://www.jalview.org/examples/exampleFile.jar");
\r
267 if (file.indexOf("http:") > -1)
\r
272 if (file.endsWith(".jar"))
\r
274 new Jalview2XML().LoadJalviewAlign(file);
\r
278 format = new jalview.io.IdentifyFile().Identify(file, protocol);
\r
279 new jalview.io.FileLoader().LoadFile(file, protocol, format);
\r
287 Vector vargs = null;
\r
288 public ArgsParser(String [] args)
\r
290 vargs = new Vector();
\r
291 for (int i = 0; i < args.length; i++)
\r
293 String arg = args[i].trim();
\r
294 if (arg.charAt(0) == '-')
\r
295 arg = arg.substring(1);
\r
296 vargs.addElement(arg);
\r
300 public String getValue(String arg)
\r
302 int index = vargs.indexOf(arg);
\r
306 ret = vargs.elementAt(index + 1).toString();
\r
307 vargs.removeElementAt(index);
\r
308 vargs.removeElementAt(index);
\r
313 public boolean contains(String arg)
\r
315 if(vargs.contains(arg))
\r
317 vargs.removeElement(arg);
\r
324 public String nextValue()
\r
326 return vargs.remove(0).toString();
\r
329 public int getSize()
\r
331 return vargs.size();
\r