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 org.apache.log4j.*;
\r
25 import javax.swing.*;
\r
27 import java.util.Vector;
\r
31 * Main class for Jalview Application
\r
33 * <br>start with java -Djava.ext.dirs=$PATH_TO_LIB$ jalview.bin.Jalview
\r
36 * @version $Revision$
\r
38 public class Jalview
\r
42 * main class for Jalview application
\r
44 * @param args open <em>filename</em>
\r
46 public static void main(String[] args)
\r
48 System.out.println("Java version: "+System.getProperty("java.version"));
\r
49 System.out.println(System.getProperty("os.arch")+" "
\r
50 +System.getProperty("os.name")+" "
\r
51 +System.getProperty("os.version"));
\r
54 ArgsParser aparser = new ArgsParser(args);
\r
55 boolean headless = false;
\r
57 if( aparser.contains("help") || aparser.contains("h") )
\r
59 System.out.println("Usage: jalview -open [FILE] [OUTPUT_FORMAT] [OUTPUT_FILE]\n\n"
\r
60 +"-nodisplay\tRun Jalview without User Interface.\n"
\r
61 +"-props FILE\tUse the given Jalview properties file instead of users default.\n"
\r
62 +"-groups FILE\tUse the given file to mark groups on the alignment. \nGroups file is in the following tab delimited format\n"
\r
63 +"TEXT<tab>SEQUENCE_ID<tab>SEQUENCE_INDEX<tab>START_RESIDUE<tab>END_RESIDUE<tab>COLOUR\n"
\r
64 +"SequenceID is used in preference to SequenceIndex if both are provided.\n"
\r
65 +"Enter ID_NOT_SPECIFIED for SEQUENCE_ID or -1 for SEQUENCE_INDEX if unknown.\n"
\r
66 +"COLOUR can be hexadecimal RGB or 'red', 'blue' etc.\n\n"
\r
67 +"-fasta FILE\tCreate alignment file FILE in Fasta format.\n"
\r
68 +"-clustal FILE\tCreate alignment file FILE in Clustal format.\n"
\r
69 +"-pfam FILE\tCreate alignment file FILE in PFAM format.\n"
\r
70 +"-msf FILE\tCreate alignment file FILE in MSF format.\n"
\r
71 +"-pileup FILE\tCreate alignment file FILE in Pileup format\n"
\r
72 +"-pir FILE\tCreate alignment file FILE in PIR format.\n"
\r
73 +"-blc FILE\tCreate alignment file FILE in BLC format.\n"
\r
74 +"-jalview FILE\tCreate alignment file FILE in Jalview format.\n"
\r
75 +"-png FILE\tCreate PNG image FILE from alignment.\n"
\r
76 +"-imgMap FILE\tCreate HTML file FILE with image map of PNG image.\n"
\r
77 +"-eps FILE\tCreate EPS file FILE from alignment.");
\r
82 if (aparser.contains("nodisplay"))
\r
83 System.setProperty("java.awt.headless", "true");
\r
85 if (System.getProperty("java.awt.headless") != null
\r
86 && System.getProperty("java.awt.headless").equals("true"))
\r
95 catch (java.lang.NoClassDefFoundError error)
\r
97 error.printStackTrace();
\r
99 "\nEssential logging libraries not found."
\r
100 +"\nUse: java -Djava.ext.dirs=$PATH_TO_LIB$ jalview.bin.Jalview");
\r
104 Cache.loadProperties(aparser.getValue("props"));
\r
106 Desktop desktop = null;
\r
111 UIManager.setLookAndFeel(
\r
112 UIManager.getSystemLookAndFeelClassName()
\r
113 // UIManager.getCrossPlatformLookAndFeelClassName()
\r
114 //"com.sun.java.swing.plaf.gtk.GTKLookAndFeel"
\r
115 //"javax.swing.plaf.metal.MetalLookAndFeel"
\r
116 //"com.sun.java.swing.plaf.windows.WindowsLookAndFeel"
\r
117 //"com.sun.java.swing.plaf.motif.MotifLookAndFeel"
\r
121 catch (Exception ex)
\r
125 desktop = new Desktop();
\r
126 desktop.setVisible(true);
\r
127 desktop.discoverer.start();
\r
131 String file = null, protocol = null, format = null, groups=null;
\r
132 jalview.io.FileLoader fileLoader = new jalview.io.FileLoader();
\r
134 file = aparser.getValue("open");
\r
136 if (file == null && desktop==null)
\r
138 System.out.println("No files to open!");
\r
145 if (!file.startsWith("http://"))
\r
147 if (! (new java.io.File(file)).exists())
\r
149 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
252 Vector vargs = null;
\r
253 public ArgsParser(String [] args)
\r
255 vargs = new Vector();
\r
256 for (int i = 0; i < args.length; i++)
\r
258 String arg = args[i].trim();
\r
259 if (arg.charAt(0) == '-')
\r
260 arg = arg.substring(1);
\r
261 vargs.addElement(arg);
\r
265 public String getValue(String arg)
\r
267 int index = vargs.indexOf(arg);
\r
271 ret = vargs.elementAt(index + 1).toString();
\r
272 vargs.removeElementAt(index);
\r
273 vargs.removeElementAt(index);
\r
278 public boolean contains(String arg)
\r
280 if(vargs.contains(arg))
\r
282 vargs.removeElement(arg);
\r
289 public String nextValue()
\r
291 return vargs.remove(0).toString();
\r
294 public int getSize()
\r
296 return vargs.size();
\r