2 * Jalview - A Sequence Alignment Editor and Viewer (Development Version 2.4.1)
3 * Copyright (C) 2009 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 on
45 * <li>DISCOVERY_URLS - comma separated list of Discovery Service endpoints.</li>
46 * <li>SCREEN_WIDTH</li>
47 * <li>SCREEN_HEIGHT</li>
48 * <li>SCREEN_Y=285</li>
49 * <li>SCREEN_X=371</li>
50 * <li>SHOW_FULLSCREEN boolean</li>
51 * <li>FONT_NAME java font name for alignment text display</li>
52 * <li>FONT_SIZE size of displayed alignment text</li>
53 * <li>FONT_STYLE style of font displayed (sequence labels are always italic)</li>
54 * <li>GAP_SYMBOL character to treat as gap symbol (usually -,.,' ')</li>
55 * <li>LAST_DIRECTORY last directory for browsing alignment</li>
56 * <li>USER_DEFINED_COLOURS list of user defined colour scheme files</li>
57 * <li>SHOW_FULL_ID show id with '/start-end' numbers appended</li>
58 * <li>SHOW_IDENTITY show percentage identity annotation</li>
59 * <li>SHOW_QUALITY show alignment quality annotation</li>
60 * <li>SHOW_ANNOTATIONS show alignment annotation rows</li>
61 * <li>SHOW_CONSERVATION show alignment conservation annotation</li>
62 * <li>CENTRE_COLUMN_LABELS centre the labels at each column in a displayed
64 * <li>DEFAULT_COLOUR default colour scheme to apply for a new alignment</li>
65 * <li>DEFAULT_FILE_FORMAT file format used to save</li>
66 * <li>STARTUP_FILE file loaded on startup (may be a fully qualified url)</li>
67 * <li>SHOW_STARTUP_FILE flag to control loading of startup file</li>
68 * <li>VERSION the version of the jalview build</li>
69 * <li>BUILD_DATE date of this build</li>
70 * <li>LATEST_VERSION the latest jalview version advertised on the
71 * www.jalview.org</li>
72 * <li>PIR_MODELLER boolean indicating if PIR files are written with MODELLER
74 * <li>(FASTA,MSF,PILEUP,CLUSTAL,BLC,PIR,PFAM)_JVSUFFIX boolean for adding jv
76 * <li>RECENT_URL list of recently retrieved URLs</li>
77 * <li>RECENT_FILE list of recently opened files</li>
78 * <li>USE_PROXY flag for whether a http proxy is to be used</li>
79 * <li>PROXY_SERVER the proxy</li>
81 * <li>NOQUESTIONNAIRES true to prevent jalview from checking the questionnaire
83 * <li>QUESTIONNAIRE last questionnaire:responder id string from questionnaire
85 * <li>USAGESTATS (false - user prompted) Enable google analytics tracker for collecting usage
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</li>
92 * <li>PAD_GAPS boolean</li>
93 * <li>ID_ITALICS boolean</li>
94 * <li>SHOW_JV_SUFFIX</li>
95 * <li>WRAP_ALIGNMENT</li>
96 * <li>EPS_RENDERING (Prompt each time|Lineart|Text) default for EPS rendering
98 * <li>SORT_ALIGNMENT (No sort|Id|Pairwise Identity)</li>
99 * <li>SEQUENCE_LINKS list of name|URL pairs for opening a url with
101 * <li>GROUP_LINKS list of name|URL[|<separator>] tuples - see jalview.utils.GroupURLLink for more info
103 * <li>DAS_REGISTRY_URL the registry to query</li>
104 * <li>DEFAULT_BROWSER for unix</li>
105 * <li>DAS_ACTIVE_SOURCE list of active sources</li>
106 * <li>SHOW_MEMUSAGE boolean show memory usage and warning indicator on desktop
108 * <li>VERSION_CHECK (true) check for the latest release version from www.jalview.org</li>
109 * <li>SHOW_NPFEATS_TOOLTIP (true) show non-positional features in the Sequence
111 * <li>SHOW_DBREFS_TOOLTIP (true) show Database Cross References in the Sequence
113 * <li>SHOW_UNCONSERVED (false) only render unconserved residues - conserved
114 * displayed as '.'</li>
115 * <li>SORT_BY_TREE (false) sort the current alignment view according to the
116 * order of a newly displayed tree</li>
117 * <li>DBFETCH_USEPICR (false) use PICR to recover valid DB references from sequence ID strings before attempting retrieval from any datasource</li>
126 * @version $Revision$
131 * property giving log4j level for CASTOR loggers
133 public static final String CASTORLOGLEVEL = "logs.Castor.level";
136 * property giving log4j level for AXIS loggers
138 public static final String AXISLOGLEVEL = "logs.Axis.level";
141 * property giving log4j level for Jalview Log
143 public static final String JALVIEWLOGLEVEL = "logs.Jalview.level";
145 public static final String DAS_LOCAL_SOURCE = "DAS_LOCAL_SOURCE";
147 public static final String DAS_REGISTRY_URL = "DAS_REGISTRY_URL";
149 public static final String DAS_ACTIVE_SOURCE = "DAS_ACTIVE_SOURCE";
152 * Initialises the Jalview Application Log
154 public static Logger log;
156 /** Jalview Properties */
157 public static Properties applicationProperties = new Properties();
159 /** Default file is ~/.jalview_properties */
160 static String propertiesFile;
162 public static void initLogger()
166 // TODO: redirect stdout and stderr here in order to grab the output of the log
168 ConsoleAppender ap = new ConsoleAppender(new SimpleLayout(),
170 ap.setName("JalviewLogger");
171 org.apache.log4j.Logger.getRootLogger().addAppender(ap); // catch all for
173 Logger laxis = Logger.getLogger("org.apache.axis");
174 Logger lcastor = Logger.getLogger("org.exolab.castor");
175 jalview.bin.Cache.log = Logger.getLogger("jalview.bin.Jalview");
177 laxis.setLevel(Level.toLevel(Cache.getDefault("logs.Axis.Level",
178 Level.INFO.toString())));
179 lcastor.setLevel(Level.toLevel(Cache.getDefault("logs.Castor.Level",
180 Level.INFO.toString())));
181 lcastor = Logger.getLogger("org.exolab.castor.xml");
182 lcastor.setLevel(Level.toLevel(Cache.getDefault("logs.Castor.Level",
183 Level.INFO.toString())));
184 // lcastor = Logger.getLogger("org.exolab.castor.xml.Marshaller");
185 // lcastor.setLevel(Level.toLevel(Cache.getDefault("logs.Castor.Level",
186 // Level.INFO.toString())));
187 jalview.bin.Cache.log.setLevel(Level.toLevel(Cache.getDefault(
188 "logs.Jalview.level", Level.INFO.toString())));
189 // laxis.addAppender(ap);
190 // lcastor.addAppender(ap);
191 // jalview.bin.Cache.log.addAppender(ap);
192 // Tell the user that debug is enabled
193 jalview.bin.Cache.log.debug("Jalview Debugging Output Follows.");
194 } catch (Exception ex)
196 System.err.println("Problems initializing the log4j system\n");
197 ex.printStackTrace(System.err);
201 /** Called when Jalview is started */
202 public static void loadProperties(String propsFile)
204 propertiesFile = propsFile;
205 if (propsFile == null)
207 propertiesFile = System.getProperty("user.home") + File.separatorChar
208 + ".jalview_properties";
213 FileInputStream fis = new FileInputStream(propertiesFile);
214 applicationProperties.load(fis);
215 applicationProperties.remove("LATEST_VERSION");
216 applicationProperties.remove("VERSION");
218 } catch (Exception ex)
220 System.out.println("Error reading properties file: " + ex);
223 if (getDefault("USE_PROXY", false))
225 System.out.println("Using proxyServer: "
226 + getDefault("PROXY_SERVER", null) + " proxyPort: "
227 + getDefault("PROXY_PORT", null));
229 .setProperty("http.proxyHost", getDefault("PROXY_SERVER",
231 System.setProperty("http.proxyPort", getDefault("PROXY_PORT", null));
234 // FIND THE VERSION NUMBER AND BUILD DATE FROM jalview.jar
235 // MUST FOLLOW READING OF LOCAL PROPERTIES FILE AS THE
236 // VERSION MAY HAVE CHANGED SINCE LAST USING JALVIEW
239 String buildDetails = "jar:".concat(Cache.class.getProtectionDomain()
240 .getCodeSource().getLocation().toString().concat(
241 "!/.build_properties"));
243 java.net.URL localJarFileURL = new java.net.URL(buildDetails);
245 InputStream in = localJarFileURL.openStream();
246 applicationProperties.load(in);
248 } catch (Exception ex)
250 System.out.println("Error reading build details: " + ex);
251 applicationProperties.remove("VERSION");
254 String jnlpVersion = System.getProperty("jalview.version");
255 String codeVersion = getProperty("VERSION");
257 if (codeVersion == null)
259 // THIS SHOULD ONLY BE THE CASE WHEN TESTING!!
260 codeVersion = "Test";
261 jnlpVersion = "Test";
264 System.out.println("Jalview Version: " + codeVersion);
266 // jnlpVersion will be null if we're using InstallAnywhere
267 // Dont do this check if running in headless mode
268 if (jnlpVersion == null
269 && getDefault("VERSION_CHECK",true)
270 && (System.getProperty("java.awt.headless") == null || System
271 .getProperty("java.awt.headless").equals("false")))
274 class VersionChecker extends Thread
278 String orgtimeout = System
279 .getProperty("sun.net.client.defaultConnectTimeout");
280 if (orgtimeout == null)
283 System.out.println("# INFO: Setting default net timeout to "
284 + orgtimeout + " seconds.");
286 String jnlpVersion = null;
289 System.setProperty("sun.net.client.defaultConnectTimeout",
291 java.net.URL url = new java.net.URL(
292 "http://www.jalview.org/webstart/jalview.jnlp");
293 BufferedReader in = new BufferedReader(new InputStreamReader(
296 while ((line = in.readLine()) != null)
298 if (line.indexOf("jalview.version") == -1)
303 line = line.substring(line.indexOf("value=") + 7);
304 line = line.substring(0, line.lastIndexOf("\""));
308 } catch (Exception ex)
311 .println("Non-fatal exceptions when checking version at www.jalview.org :");
312 System.out.println(ex);
313 jnlpVersion = getProperty("VERSION");
315 System.setProperty("sun.net.client.defaultConnectTimeout",
318 setProperty("LATEST_VERSION", jnlpVersion);
322 VersionChecker vc = new VersionChecker();
327 if (jnlpVersion != null)
329 setProperty("LATEST_VERSION", jnlpVersion);
333 applicationProperties.remove("LATEST_VERSION");
337 setProperty("VERSION", codeVersion);
339 // LOAD USERDEFINED COLOURS
340 jalview.gui.UserDefinedColours
341 .initUserColourSchemes(getProperty("USER_DEFINED_COLOURS"));
342 jalview.io.PIRFile.useModellerOutput = Cache.getDefault("PIR_MODELLER",
347 * Gets Jalview application property of given key. Returns null if key not
353 * @return Property value
355 public static String getProperty(String key)
357 return applicationProperties.getProperty(key);
361 * These methods are used when checking if the saved preference is different
362 * to the default setting
365 public static boolean getDefault(String property, boolean def)
367 String string = getProperty(property);
370 def = Boolean.valueOf(string).booleanValue();
377 * These methods are used when checking if the saved preference is different
378 * to the default setting
380 public static String getDefault(String property, String def)
382 String string = getProperty(property);
392 * Stores property in the file "HOME_DIR/.jalview_properties"
397 * String value of property
399 * @return String value of property
401 public static String setProperty(String key, String obj)
405 FileOutputStream out = new FileOutputStream(propertiesFile);
406 applicationProperties.setProperty(key, obj);
407 applicationProperties.store(out, "---JalviewX Properties File---");
409 } catch (Exception ex)
411 System.out.println("Error setting property: " + key + " " + obj
417 * remove the specified property from the jalview properties file
420 public static void removeProperty(String string)
422 applicationProperties.remove(string);
426 * save the properties to the jalview properties path
428 public static void saveProperties()
432 FileOutputStream out = new FileOutputStream(propertiesFile);
433 applicationProperties.store(out, "---JalviewX Properties File---");
435 } catch (Exception ex)
437 System.out.println("Error saving properties: " + ex);
442 * internal vamsas class discovery state
444 private static int vamsasJarsArePresent = -1;
447 * Searches for vamsas client classes on class path.
449 * @return true if vamsas client is present on classpath
451 public static boolean vamsasJarsPresent()
453 if (vamsasJarsArePresent == -1)
457 if (jalview.jbgui.GDesktop.class.getClassLoader().loadClass(
458 "uk.ac.vamsas.client.VorbaId") != null)
460 jalview.bin.Cache.log
461 .debug("Found Vamsas Classes (uk.ac..vamsas.client.VorbaId can be loaded)");
462 vamsasJarsArePresent = 1;
463 Logger lvclient = Logger.getLogger("uk.ac.vamsas");
464 lvclient.setLevel(Level.toLevel(Cache.getDefault(
465 "logs.Vamsas.Level", Level.INFO.toString())));
467 lvclient.addAppender(log.getAppender("JalviewLogger"));
468 // Tell the user that debug is enabled
469 lvclient.debug("Jalview Vamsas Client Debugging Output Follows.");
471 } catch (Exception e)
473 vamsasJarsArePresent = 0;
474 jalview.bin.Cache.log.debug("Vamsas Classes are not present");
477 return (vamsasJarsArePresent > 0);
481 * internal vamsas class discovery state
483 private static int groovyJarsArePresent = -1;
486 * Searches for vamsas client classes on class path.
488 * @return true if vamsas client is present on classpath
490 public static boolean groovyJarsPresent()
492 if (groovyJarsArePresent == -1)
496 if (Cache.class.getClassLoader().loadClass(
497 "groovy.lang.GroovyObject") != null)
499 jalview.bin.Cache.log
500 .debug("Found Groovy (groovy.lang.GroovyObject can be loaded)");
501 groovyJarsArePresent = 1;
502 Logger lgclient = Logger.getLogger("groovy");
503 lgclient.setLevel(Level.toLevel(Cache.getDefault(
504 "logs.Groovy.Level", Level.INFO.toString())));
506 lgclient.addAppender(log.getAppender("JalviewLogger"));
507 // Tell the user that debug is enabled
508 lgclient.debug("Jalview Groovy Client Debugging Output Follows.");
511 groovyJarsArePresent = 0;
512 jalview.bin.Cache.log.debug("Groovy Classes are not present",e);
515 groovyJarsArePresent = 0;
516 jalview.bin.Cache.log.debug("Groovy Classes are not present");
519 return (groovyJarsArePresent > 0);
522 * generate Das1Sources from the local das source list
524 * @return Vector of Das1Sources
526 public static Vector getLocalDasSources()
528 Vector localSources = new Vector();
529 String local = jalview.bin.Cache.getProperty("DAS_LOCAL_SOURCE");
532 StringTokenizer st = new StringTokenizer(local, "\t");
533 while (st.hasMoreTokens())
535 String token = st.nextToken();
536 int bar = token.indexOf("|");
537 Das1Source source = new Das1Source();
538 source.setUrl(token.substring(bar + 1));
539 if (source.getUrl().startsWith("sequence:"))
541 source.setUrl(source.getUrl().substring(9));
542 // this source also serves sequences as well as features
543 source.setCapabilities(new String[]
544 { "sequence", "features" });
548 // default is that all user added sources serve features
549 source.setCapabilities(new String[]
553 source.setNickname(token.substring(0, bar));
555 localSources.addElement(source);
562 * GA tracker object - actually JGoogleAnalyticsTracker null if tracking not enabled.
564 protected static Object tracker = null;
565 protected static Class trackerfocus = null;
566 protected static Class jgoogleanalyticstracker = null;
569 * Initialise the google tracker if it is not done already.
571 public static void initGoogleTracker()
575 if (jgoogleanalyticstracker==null)
577 // try to get the tracker class
579 jgoogleanalyticstracker = Cache.class.getClassLoader().loadClass(
580 "com.boxysystems.jgoogleanalytics.JGoogleAnalyticsTracker");
581 trackerfocus = Cache.class.getClassLoader().loadClass(
582 "com.boxysystems.jgoogleanalytics.FocusPoint");
583 } catch (Exception e)
585 log.debug("com.boxysystems.jgoogleanalytics package is not present - tracking not enabled.");
587 jgoogleanalyticstracker=null;
592 // now initialise tracker
593 Exception re = null, ex = null;
595 String vrs = "No Version Accessible";
598 // Google analytics tracking code for Library Finder
599 tracker = jgoogleanalyticstracker.getConstructor(new Class[] { String.class,String.class,String.class}).newInstance(new Object[] { "Jalview Desktop",
600 (vrs = jalview.bin.Cache.getProperty("VERSION")
602 + jalview.bin.Cache.getDefault("BUILD_DATE",
603 "unknown")), "UA-9060947-1"});
604 jgoogleanalyticstracker.getMethod("trackAsynchronously", new Class[] { trackerfocus })
605 .invoke(tracker, new Object[] { trackerfocus.getConstructor(
606 new Class[] { String.class}).newInstance(new Object[] { "Application Started." })});
607 } catch (RuntimeException e)
610 } catch (Exception e)
617 if (re != null || ex != null || err != null)
624 "Caught runtime exception in googletracker init:",
628 "Failed to initialise GoogleTracker for Jalview Desktop with version "
632 "Whilst initing GoogleTracker for Jalview Desktop version "
640 .println("Debug: Caught runtime exception in googletracker init:"
642 re.printStackTrace();
647 .println("Warning: Failed to initialise GoogleTracker for Jalview Desktop with version "
649 ex.printStackTrace();
655 .println("ERROR: Whilst initing GoogleTracker for Jalview Desktop version "
657 err.printStackTrace();
663 log.debug("Successfully initialised tracker.");