2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.4)
3 * Copyright (C) 2008 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
24 import org.apache.log4j.*;
25 import org.biojava.dasobert.dasregistry.Das1Source;
28 * Stores and retrieves Jalview Application Properties Lists and fields within
29 * list entries are separated by '|' symbols unless otherwise stated (|) clauses
30 * are alternative values for a tag. <br>
32 * Current properties include:
35 * logs.Axis.Level - one of the stringified Levels for log4j controlling the
36 * logging level for axis (used for web services) <br>
38 * <li>logs.Castor.Level - one of the stringified Levels for log4j controlling
39 * the logging level for castor (used for serialization) <br>
41 * <li>logs.Jalview.Level - Cache.log stringified level. <br>
43 * <li>DISCOVERY_START - Boolean - controls if discovery services are queried
45 * <li>DISCOVERY_URLS - comma separated list of Discovery Service endpoints.
47 * <li>SCREEN_WIDTH </li>
48 * <li>SCREEN_HEIGHT </li>
49 * <li>SCREEN_Y=285 </li>
50 * <li>SCREEN_X=371 </li>
51 * <li>SHOW_FULLSCREEN boolean </li>
52 * <li>FONT_NAME java font name for alignment text display </li>
53 * <li>FONT_SIZE size of displayed alignment text </li>
54 * <li>FONT_STYLE style of font displayed (sequence labels are always italic)
56 * <li>GAP_SYMBOL character to treat as gap symbol (usually -,.,' ') </li>
57 * <li>LAST_DIRECTORY last directory for browsing alignment </li>
58 * <li>USER_DEFINED_COLOURS list of user defined colour scheme files </li>
59 * <li>SHOW_FULL_ID show id with '/start-end' numbers appended </li>
60 * <li>SHOW_IDENTITY show percentage identity annotation </li>
61 * <li>SHOW_QUALITY show alignment quality annotation </li>
62 * <li>SHOW_ANNOTATIONS show alignment annotation rows </li>
63 * <li>SHOW_CONSERVATION show alignment conservation annotation </li>
64 * <li>CENTRE_COLUMN_LABELS centre the labels at each column in a displayed
65 * annotation row </li>
66 * <li>DEFAULT_COLOUR default colour scheme to apply for a new alignment </li>
67 * <li>DEFAULT_FILE_FORMAT file format used to save </li>
68 * <li>STARTUP_FILE file loaded on startup (may be a fully qualified url) </li>
69 * <li>SHOW_STARTUP_FILE flag to control loading of startup file </li>
70 * <li>VERSION the version of the jalview build </li>
71 * <li>BUILD_DATE date of this build </li>
72 * <li>LATEST_VERSION the latest jalview version advertised on the
73 * www.jalview.org </li>
74 * <li>PIR_MODELLER boolean indicating if PIR files are written with MODELLER
76 * <li>(FASTA,MSF,PILEUP,CLUSTAL,BLC,PIR,PFAM)_JVSUFFIX boolean for adding jv
77 * suffix to file </li>
78 * <li>RECENT_URL list of recently retrieved URLs </li>
79 * <li>RECENT_FILE list of recently opened files </li>
80 * <li>USE_PROXY flag for whether a http proxy is to be used </li>
81 * <li>PROXY_SERVER the proxy </li>
82 * <li>PROXY_PORT </li>
83 * <li>NOQUESTIONNAIRES true to prevent jalview from checking the questionnaire
85 * <li>QUESTIONNAIRE last questionnaire:responder id string from questionnaire
87 * <li>DAS_LOCAL_SOURCE list of local das sources </li>
88 * <li>SHOW_OVERVIEW boolean for overview window display </li>
89 * <li>ANTI_ALIAS boolean for smooth fonts </li>
90 * <li>RIGHT_ALIGN_IDS boolean </li>
91 * <li>AUTO_CALC_CONSENSUS boolean for automatic recalculation of consensus
93 * <li>PAD_GAPS boolean </li>
94 * <li>ID_ITALICS boolean </li>
95 * <li>SHOW_JV_SUFFIX </li>
96 * <li>WRAP_ALIGNMENT </li>
97 * <li>EPS_RENDERING (Prompt each time|Lineart|Text) default for EPS rendering
99 * <li>SORT_ALIGNMENT (No sort|Id|Pairwise Identity) </li>
100 * <li>SEQUENCE_LINKS list of name|URL pairs for opening a url with
101 * $SEQUENCE_ID$ </li>
102 * <li>DAS_REGISTRY_URL the registry to query </li>
103 * <li>DEFAULT_BROWSER for unix </li>
104 * <li>DAS_ACTIVE_SOURCE list of active sources </li>
105 * <li>SHOW_MEMUSAGE boolean show memory usage and warning indicator on desktop
107 * <li>SHOW_NPFEATS_TOOLTIP (true) show non-positional features in the Sequence ID tooltip</li>
108 * <li>SHOW_DBREFS_TOOLTIP (true) show Database Cross References in the Sequence ID tooltip</li>
109 * <li>SHOW_UNCONSERVED (false) only render unconserved residues - conserved displayed as '.'</li>
110 * <li>SORT_BY_TREE (false) sort the current alignment view according to the order of a newly displayed tree</li>
117 * @version $Revision$
122 * property giving log4j level for CASTOR loggers
124 public static final String CASTORLOGLEVEL = "logs.Castor.level";
127 * property giving log4j level for AXIS loggers
129 public static final String AXISLOGLEVEL = "logs.Axis.level";
132 * property giving log4j level for Jalview Log
134 public static final String JALVIEWLOGLEVEL = "logs.Jalview.level";
136 public static final String DAS_LOCAL_SOURCE = "DAS_LOCAL_SOURCE";
138 public static final String DAS_REGISTRY_URL = "DAS_REGISTRY_URL";
140 public static final String DAS_ACTIVE_SOURCE = "DAS_ACTIVE_SOURCE";
143 * Initialises the Jalview Application Log
145 public static Logger log;
147 /** Jalview Properties */
148 public static Properties applicationProperties = new Properties();
150 /** Default file is ~/.jalview_properties */
151 static String propertiesFile;
153 public static void initLogger()
157 ConsoleAppender ap = new ConsoleAppender(new SimpleLayout(),
159 ap.setName("JalviewLogger");
160 org.apache.log4j.Logger.getRootLogger().addAppender(ap); // catch all for
162 Logger laxis = Logger.getLogger("org.apache.axis");
163 Logger lcastor = Logger.getLogger("org.exolab.castor");
164 jalview.bin.Cache.log = Logger.getLogger("jalview.bin.Jalview");
166 laxis.setLevel(Level.toLevel(Cache.getDefault("logs.Axis.Level",
167 Level.INFO.toString())));
168 lcastor.setLevel(Level.toLevel(Cache.getDefault("logs.Castor.Level",
169 Level.INFO.toString())));
170 lcastor = Logger.getLogger("org.exolab.castor.xml");
171 lcastor.setLevel(Level.toLevel(Cache.getDefault("logs.Castor.Level",
172 Level.INFO.toString())));
173 // lcastor = Logger.getLogger("org.exolab.castor.xml.Marshaller");
174 // lcastor.setLevel(Level.toLevel(Cache.getDefault("logs.Castor.Level",
175 // Level.INFO.toString())));
176 jalview.bin.Cache.log.setLevel(Level.toLevel(Cache.getDefault(
177 "logs.Jalview.level", Level.INFO.toString())));
178 // laxis.addAppender(ap);
179 // lcastor.addAppender(ap);
180 // jalview.bin.Cache.log.addAppender(ap);
181 // Tell the user that debug is enabled
182 jalview.bin.Cache.log.debug("Jalview Debugging Output Follows.");
183 } catch (Exception ex)
185 System.err.println("Problems initializing the log4j system\n");
186 ex.printStackTrace(System.err);
190 /** Called when Jalview is started */
191 public static void loadProperties(String propsFile)
193 propertiesFile = propsFile;
194 if (propsFile == null)
196 propertiesFile = System.getProperty("user.home") + File.separatorChar
197 + ".jalview_properties";
202 FileInputStream fis = new FileInputStream(propertiesFile);
203 applicationProperties.load(fis);
204 applicationProperties.remove("LATEST_VERSION");
205 applicationProperties.remove("VERSION");
207 } catch (Exception ex)
209 System.out.println("Error reading properties file: " + ex);
212 if (getDefault("USE_PROXY", false))
214 System.out.println("Using proxyServer: "
215 + getDefault("PROXY_SERVER", null) + " proxyPort: "
216 + getDefault("PROXY_PORT", null));
218 .setProperty("http.proxyHost", getDefault("PROXY_SERVER",
220 System.setProperty("http.proxyPort", getDefault("PROXY_PORT", null));
223 // FIND THE VERSION NUMBER AND BUILD DATE FROM jalview.jar
224 // MUST FOLLOW READING OF LOCAL PROPERTIES FILE AS THE
225 // VERSION MAY HAVE CHANGED SINCE LAST USING JALVIEW
228 String buildDetails = "jar:".concat(Cache.class.getProtectionDomain()
229 .getCodeSource().getLocation().toString().concat(
230 "!/.build_properties"));
232 java.net.URL localJarFileURL = new java.net.URL(buildDetails);
234 InputStream in = localJarFileURL.openStream();
235 applicationProperties.load(in);
237 } catch (Exception ex)
239 System.out.println("Error reading build details: " + ex);
240 applicationProperties.remove("VERSION");
243 String jnlpVersion = System.getProperty("jalview.version");
244 String codeVersion = getProperty("VERSION");
246 if (codeVersion == null)
248 // THIS SHOULD ONLY BE THE CASE WHEN TESTING!!
249 codeVersion = "Test";
250 jnlpVersion = "Test";
253 System.out.println("Jalview Version: " + codeVersion);
255 // jnlpVersion will be null if we're using InstallAnywhere
256 // Dont do this check if running in headless mode
257 if (jnlpVersion == null
258 && (System.getProperty("java.awt.headless") == null || System
259 .getProperty("java.awt.headless").equals("false")))
262 class VersionChecker extends Thread
266 String orgtimeout = System
267 .getProperty("sun.net.client.defaultConnectTimeout");
268 if (orgtimeout == null)
271 System.out.println("# INFO: Setting default net timeout to "
272 + orgtimeout + " seconds.");
274 String jnlpVersion = null;
277 System.setProperty("sun.net.client.defaultConnectTimeout",
279 java.net.URL url = new java.net.URL(
280 "http://www.jalview.org/webstart/jalview.jnlp");
281 BufferedReader in = new BufferedReader(new InputStreamReader(
284 while ((line = in.readLine()) != null)
286 if (line.indexOf("jalview.version") == -1)
291 line = line.substring(line.indexOf("value=") + 7);
292 line = line.substring(0, line.lastIndexOf("\""));
296 } catch (Exception ex)
299 .println("Non-fatal exceptions when checking version at www.jalview.org :");
300 System.out.println(ex);
301 jnlpVersion = getProperty("VERSION");
303 System.setProperty("sun.net.client.defaultConnectTimeout",
306 setProperty("LATEST_VERSION", jnlpVersion);
310 VersionChecker vc = new VersionChecker();
315 if (jnlpVersion != null)
317 setProperty("LATEST_VERSION", jnlpVersion);
321 applicationProperties.remove("LATEST_VERSION");
325 setProperty("VERSION", codeVersion);
327 // LOAD USERDEFINED COLOURS
328 jalview.gui.UserDefinedColours
329 .initUserColourSchemes(getProperty("USER_DEFINED_COLOURS"));
330 jalview.io.PIRFile.useModellerOutput = Cache.getDefault("PIR_MODELLER",
335 * Gets Jalview application property of given key. Returns null if key not
341 * @return Property value
343 public static String getProperty(String key)
345 return applicationProperties.getProperty(key);
349 * These methods are used when checking if the saved preference is different
350 * to the default setting
353 public static boolean getDefault(String property, boolean def)
355 String string = getProperty(property);
358 def = Boolean.valueOf(string).booleanValue();
365 * These methods are used when checking if the saved preference is different
366 * to the default setting
368 public static String getDefault(String property, String def)
370 String string = getProperty(property);
380 * Stores property in the file "HOME_DIR/.jalview_properties"
385 * String value of property
387 * @return String value of property
389 public static String setProperty(String key, String obj)
393 FileOutputStream out = new FileOutputStream(propertiesFile);
394 applicationProperties.setProperty(key, obj);
395 applicationProperties.store(out, "---JalviewX Properties File---");
397 } catch (Exception ex)
399 System.out.println("Error setting property: " + key + " " + obj
405 public static void saveProperties()
409 FileOutputStream out = new FileOutputStream(propertiesFile);
410 applicationProperties.store(out, "---JalviewX Properties File---");
412 } catch (Exception ex)
414 System.out.println("Error saving properties: " + ex);
419 * internal vamsas class discovery state
421 private static int vamsasJarsArePresent = -1;
424 * Searches for vamsas client classes on class path.
426 * @return true if vamsas client is present on classpath
428 public static boolean vamsasJarsPresent()
430 if (vamsasJarsArePresent == -1)
434 if (jalview.jbgui.GDesktop.class.getClassLoader().loadClass(
435 "uk.ac.vamsas.client.VorbaId") != null)
437 jalview.bin.Cache.log
438 .debug("Found Vamsas Classes (uk.ac..vamsas.client.VorbaId can be loaded)");
439 vamsasJarsArePresent = 1;
440 Logger lvclient = Logger.getLogger("uk.ac.vamsas");
441 lvclient.setLevel(Level.toLevel(Cache.getDefault(
442 "logs.Vamsas.Level", Level.INFO.toString())));
444 lvclient.addAppender(log.getAppender("JalviewLogger"));
445 // Tell the user that debug is enabled
446 lvclient.debug("Jalview Vamsas Client Debugging Output Follows.");
448 } catch (Exception e)
450 vamsasJarsArePresent = 0;
451 jalview.bin.Cache.log.debug("Vamsas Classes are not present");
454 return (vamsasJarsArePresent > 0);
458 * internal vamsas class discovery state
460 private static int groovyJarsArePresent = -1;
463 * Searches for vamsas client classes on class path.
465 * @return true if vamsas client is present on classpath
467 public static boolean groovyJarsPresent()
469 if (groovyJarsArePresent == -1)
473 if (Cache.class.getClassLoader().loadClass(
474 "groovy.lang.GroovyObject") != null)
476 jalview.bin.Cache.log
477 .debug("Found Groovy (groovy.lang.GroovyObject can be loaded)");
478 groovyJarsArePresent = 1;
479 Logger lgclient = Logger.getLogger("groovy");
480 lgclient.setLevel(Level.toLevel(Cache.getDefault(
481 "logs.Groovy.Level", Level.INFO.toString())));
483 lgclient.addAppender(log.getAppender("JalviewLogger"));
484 // Tell the user that debug is enabled
485 lgclient.debug("Jalview Groovy Client Debugging Output Follows.");
487 } catch (Exception e)
489 groovyJarsArePresent = 0;
490 jalview.bin.Cache.log.debug("Groovy Classes are not present");
493 return (groovyJarsArePresent > 0);
497 * generate Das1Sources from the local das source list
498 * @return Vector of Das1Sources
500 public static Vector getLocalDasSources()
502 Vector localSources = new Vector();
503 String local = jalview.bin.Cache.getProperty("DAS_LOCAL_SOURCE");
506 StringTokenizer st = new StringTokenizer(local, "\t");
507 while (st.hasMoreTokens())
509 String token = st.nextToken();
510 int bar = token.indexOf("|");
511 Das1Source source = new Das1Source();
512 source.setUrl(token.substring(bar + 1));
513 if (source.getUrl().startsWith("sequence:"))
515 source.setUrl(source.getUrl().substring(9));
516 // this source also serves sequences as well as features
517 source.setCapabilities(new String[] { "sequence", "features"});
519 // default is that all user added sources serve features
520 source.setCapabilities(new String[] { "features"});
523 source.setNickname(token.substring(0, bar));
525 localSources.addElement(source);