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 +"-groups FILE\tUse the given file to mark groups on the alignment. \nGroups file is in the following tab delimited format\n"
\r
61 +"TEXT<tab>SEQUENCE_ID<tab>SEQUENCE_INDEX<tab>START_RESIDUE<tab>END_RESIDUE<tab>COLOUR\n"
\r
62 +"SequenceID is used in preference to SequenceIndex if both are provided.\n"
\r
63 +"Enter ID_NOT_SPECIFIED for SEQUENCE_ID or -1 for SEQUENCE_INDEX if unknown.\n"
\r
64 +"COLOUR can be hexadecimal RGB or 'red', 'blue' etc.\n\n"
\r
65 +"-fasta FILE\tCreate alignment file FILE in Fasta format.\n"
\r
66 +"-clustal FILE\tCreate alignment file FILE in Clustal format.\n"
\r
67 +"-pfam FILE\tCreate alignment file FILE in PFAM format.\n"
\r
68 +"-msf FILE\tCreate alignment file FILE in MSF format.\n"
\r
69 +"-pileup FILE\tCreate alignment file FILE in Pileup format\n"
\r
70 +"-pir FILE\tCreate alignment file FILE in PIR format.\n"
\r
71 +"-blc FILE\tCreate alignment file FILE in BLC format.\n"
\r
72 +"-jalview FILE\tCreate alignment file FILE in Jalview format.\n"
\r
73 +"-png FILE\tCreate PNG image FILE from alignment.\n"
\r
74 +"-imgMap FILE\tCreate HTML file FILE with image map of PNG image.\n"
\r
75 +"-eps FILE\tCreate EPS file FILE from alignment.");
\r
80 if (aparser.contains("nodisplay"))
\r
82 System.setProperty("java.awt.headless", "true");
\r
84 if (System.getProperty("java.awt.headless") != null
\r
85 && System.getProperty("java.awt.headless").equals("true"))
\r
94 catch (java.lang.NoClassDefFoundError error)
\r
96 error.printStackTrace();
\r
98 "\nEssential logging libraries not found."
\r
99 +"\nUse: java -Djava.ext.dirs=$PATH_TO_LIB$ jalview.bin.Jalview");
\r
103 Cache.loadProperties(aparser.getValue("props"));
\r
105 Desktop desktop = null;
\r
110 UIManager.setLookAndFeel(
\r
111 UIManager.getSystemLookAndFeelClassName()
\r
112 // UIManager.getCrossPlatformLookAndFeelClassName()
\r
113 //"com.sun.java.swing.plaf.gtk.GTKLookAndFeel"
\r
114 //"javax.swing.plaf.metal.MetalLookAndFeel"
\r
115 //"com.sun.java.swing.plaf.windows.WindowsLookAndFeel"
\r
116 //"com.sun.java.swing.plaf.motif.MotifLookAndFeel"
\r
120 catch (Exception ex)
\r
124 desktop = new Desktop();
\r
125 desktop.setVisible(true);
\r
126 desktop.discoverer.start();
\r
130 String file = null, protocol = null, format = null, groups=null;
\r
131 jalview.io.FileLoader fileLoader = new jalview.io.FileLoader();
\r
133 file = aparser.getValue("open");
\r
135 if (file == null && desktop==null)
\r
137 System.out.println("No files to open!");
\r
144 if (!file.startsWith("http://"))
\r
146 if (! (new java.io.File(file)).exists())
\r
148 System.out.println("Can't find " + file);
\r
156 if (file.indexOf("http:") > -1)
\r
161 if (file.endsWith(".jar"))
\r
162 format = "Jalview";
\r
164 format = jalview.io.IdentifyFile.Identify(file, protocol);
\r
166 System.out.println("Opening: " + format + " file " + file);
\r
168 AlignFrame af = fileLoader.LoadFileWaitTillLoaded(file, protocol, format);
\r
170 groups = aparser.getValue("groups");
\r
171 if (groups != null)
\r
173 af.parseGroupsFile(groups);
\r
176 String imageName = "unnamed.png";
\r
177 while (aparser.getSize() > 1)
\r
179 format = aparser.nextValue();
\r
180 file = aparser.nextValue();
\r
182 if (format.equalsIgnoreCase("png"))
\r
184 af.createPNG(new java.io.File(file));
\r
185 imageName = (new java.io.File(file)).getName();
\r
186 System.out.println("Creating PNG image: " + file);
\r
189 else if (format.equalsIgnoreCase("imgMap"))
\r
191 af.createImageMap(new java.io.File(file), imageName);
\r
192 System.out.println("Creating image map: " + file);
\r
195 else if (format.equalsIgnoreCase("eps"))
\r
197 System.out.println("Creating EPS file: " + file);
\r
198 af.createEPS(new java.io.File(file));
\r
202 if (af.saveAlignment(file, format))
\r
203 System.out.println("Written alignment in " + format +
\r
204 " format to " + file);
\r
206 System.out.println("Error writing file " + file + " in " + format +
\r
211 while (aparser.getSize() > 0)
\r
213 System.out.println("Unknown arg: " + aparser.nextValue());
\r
217 // We'll only open the default file if the desktop is visible.
\r
218 //////////////////////
\r
221 jalview.bin.Cache.getDefault("SHOW_STARTUP_FILE", true))
\r
224 file = jalview.bin.Cache.getDefault("STARTUP_FILE",
\r
225 "http://www.jalview.org/examples/exampleFile.jar");
\r
228 if (file.indexOf("http:") > -1)
\r
233 if (file.endsWith(".jar"))
\r
235 Jalview2XML.LoadJalviewAlign(file);
\r
239 format = jalview.io.IdentifyFile.Identify(file, protocol);
\r
240 desktop.LoadFile(file, protocol, format);
\r
248 Vector vargs = null;
\r
249 public ArgsParser(String [] args)
\r
251 vargs = new Vector();
\r
252 for (int i = 0; i < args.length; i++)
\r
254 String arg = args[i].trim();
\r
255 if (arg.charAt(0) == '-')
\r
256 arg = arg.substring(1);
\r
257 vargs.addElement(arg);
\r
261 public String getValue(String arg)
\r
263 int index = vargs.indexOf(arg);
\r
267 ret = vargs.elementAt(index + 1).toString();
\r
268 vargs.removeElementAt(index);
\r
269 vargs.removeElementAt(index);
\r
274 public boolean contains(String arg)
\r
276 if(vargs.contains(arg))
\r
278 vargs.removeElement(arg);
\r
285 public String nextValue()
\r
287 return vargs.remove(0).toString();
\r
290 public int getSize()
\r
292 return vargs.size();
\r