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
41 * Initialises the Apache Axis logger
\r
43 private static void initLogger()
\r
45 Logger laxis = Logger.getLogger("org.apache.axis");
\r
46 Logger lcastor = Logger.getLogger("org.exolab.castor");
\r
48 if (Cache.getProperty("logs.Axis.Level") == null)
\r
50 Cache.setProperty("logs.Axis.Level", Level.INFO.toString());
\r
53 if (Cache.getProperty("logs.Castor.Level") == null)
\r
55 Cache.setProperty("logs.Castor.Level", Level.INFO.toString());
\r
58 laxis.setLevel(Level.toLevel(Cache.getProperty("logs.Axis.Level")));
\r
59 lcastor.setLevel(Level.toLevel(Cache.getProperty("logs.Castor.Level")));
\r
61 ConsoleAppender ap = new ConsoleAppender(new SimpleLayout(),
\r
63 ap.setName("JalviewLogger");
\r
64 laxis.addAppender(ap);
\r
65 lcastor.addAppender(ap);
\r
69 * main class for Jalview application
\r
71 * @param args open <em>filename</em>
\r
73 public static void main(String[] args)
\r
75 ArgsParser aparser = new ArgsParser(args);
\r
76 boolean headless = false;
\r
78 if( aparser.contains("help") || aparser.contains("h") )
\r
80 System.out.println("Usage: jalview -open [FILE] [OUTPUT_FORMAT] [OUTPUT_FILE]\n\n"
\r
81 +"-nodisplay\tRun Jalview without User Interface.\n"
\r
82 +"-props FILE\tUse the given Jalview properties file instead of users default.\n"
\r
83 +"-groups FILE\tUse the given file to mark groups on the alignment. \nGroups file is in the following tab delimited format\n"
\r
84 +"TEXT<tab>SEQUENCE_ID<tab>SEQUENCE_INDEX<tab>START_RESIDUE<tab>END_RESIDUE<tab>COLOUR\n"
\r
85 +"SequenceID is used in preference to SequenceIndex if both are provided.\n"
\r
86 +"Enter ID_NOT_SPECIFIED for SEQUENCE_ID or -1 for SEQUENCE_INDEX if unknown.\n"
\r
87 +"COLOUR can be hexadecimal RGB or 'red', 'blue' etc.\n\n"
\r
88 +"-fasta FILE\tCreate alignment file FILE in Fasta format.\n"
\r
89 +"-clustal FILE\tCreate alignment file FILE in Clustal format.\n"
\r
90 +"-pfam FILE\tCreate alignment file FILE in PFAM format.\n"
\r
91 +"-msf FILE\tCreate alignment file FILE in MSF format.\n"
\r
92 +"-pileup FILE\tCreate alignment file FILE in Pileup format\n"
\r
93 +"-pir FILE\tCreate alignment file FILE in PIR format.\n"
\r
94 +"-blc FILE\tCreate alignment file FILE in BLC format.\n"
\r
95 +"-jalview FILE\tCreate alignment file FILE in Jalview format.\n"
\r
96 +"-png FILE\tCreate PNG image FILE from alignment.\n"
\r
97 +"-imgMap FILE\tCreate HTML file FILE with image map of PNG image.\n"
\r
98 +"-eps FILE\tCreate EPS file FILE from alignment.");
\r
103 if (aparser.contains("nodisplay"))
\r
104 System.setProperty("java.awt.headless", "true");
\r
106 if (System.getProperty("java.awt.headless") != null
\r
107 && System.getProperty("java.awt.headless").equals("true"))
\r
112 Cache.loadProperties(aparser.getValue("props"));
\r
118 catch (Exception e)
\r
120 System.err.println("Problems initializing the log4j system\n");
\r
124 Desktop desktop = null;
\r
129 UIManager.setLookAndFeel(
\r
130 UIManager.getSystemLookAndFeelClassName()
\r
133 catch (Exception ex)
\r
137 desktop = new Desktop();
\r
138 desktop.setVisible(true);
\r
142 String file = null, protocol = null, format = null, groups=null;
\r
143 jalview.io.FileLoader fileLoader = new jalview.io.FileLoader();
\r
145 file = aparser.getValue("open");
\r
147 if (file == null && desktop==null)
\r
149 System.out.println("No files to open!");
\r
156 if (!file.startsWith("http://"))
\r
158 if (! (new java.io.File(file)).exists())
\r
160 System.out.println("Can't find " + file);
\r
167 if (file.indexOf("http:") > -1)
\r
172 if (file.endsWith(".jar"))
\r
173 format = "Jalview";
\r
175 format = jalview.io.IdentifyFile.Identify(file, protocol);
\r
177 System.out.println("Opening: " + format + " file " + file);
\r
179 AlignFrame af = fileLoader.LoadFileWaitTillLoaded(file, protocol, format);
\r
181 groups = aparser.getValue("groups");
\r
182 if (groups != null)
\r
184 af.parseGroupsFile(groups);
\r
187 String imageName = "unnamed.png";
\r
188 while (aparser.getSize() > 1)
\r
190 format = aparser.nextValue();
\r
191 file = aparser.nextValue();
\r
193 if (format.equalsIgnoreCase("png"))
\r
195 af.createPNG(new java.io.File(file));
\r
196 imageName = (new java.io.File(file)).getName();
\r
197 System.out.println("Creating PNG image: " + file);
\r
200 else if (format.equalsIgnoreCase("imgMap"))
\r
202 af.createImageMap(new java.io.File(file), imageName);
\r
203 System.out.println("Creating image map: " + file);
\r
206 else if (format.equalsIgnoreCase("eps"))
\r
208 System.out.println("Creating EPS file: " + file);
\r
209 af.createEPS(new java.io.File(file));
\r
213 if (af.saveAlignment(file, format))
\r
214 System.out.println("Written alignment in " + format +
\r
215 " format to " + file);
\r
217 System.out.println("Error writing file " + file + " in " + format +
\r
222 while (aparser.getSize() > 0)
\r
224 System.out.println("Unknown arg: " + aparser.nextValue());
\r
228 // We'll only open the default file if the desktop is visible.
\r
229 //////////////////////
\r
232 jalview.bin.Cache.getProperty("SHOW_STARTUP_FILE").equals("true") &&
\r
233 jalview.bin.Cache.getProperty("STARTUP_FILE") != null)
\r
236 file = jalview.bin.Cache.getProperty("STARTUP_FILE");
\r
239 if (file.indexOf("http:") > -1)
\r
244 if (file.endsWith(".jar"))
\r
246 Jalview2XML.LoadJalviewAlign(file);
\r
250 format = jalview.io.IdentifyFile.Identify(file, protocol);
\r
251 desktop.LoadFile(file, protocol, format);
\r
263 Vector vargs = null;
\r
264 public ArgsParser(String [] args)
\r
266 vargs = new Vector();
\r
267 for (int i = 0; i < args.length; i++)
\r
269 String arg = args[i].trim();
\r
270 if (arg.charAt(0) == '-')
\r
271 arg = arg.substring(1);
\r
272 vargs.addElement(arg);
\r
276 public String getValue(String arg)
\r
278 int index = vargs.indexOf(arg);
\r
282 ret = vargs.elementAt(index + 1).toString();
\r
283 vargs.removeElementAt(index);
\r
284 vargs.removeElementAt(index);
\r
289 public boolean contains(String arg)
\r
291 if(vargs.contains(arg))
\r
293 vargs.removeElement(arg);
\r
300 public String nextValue()
\r
302 return vargs.remove(0).toString();
\r
305 public int getSize()
\r
307 return vargs.size();
\r