2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.6)
3 * Copyright (C) 2010 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
11 * Jalview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
23 import org.apache.log4j.*;
24 import org.biojava.dasobert.dasregistry.Das1Source;
27 * Stores and retrieves Jalview Application Properties Lists and fields within
28 * list entries are separated by '|' symbols unless otherwise stated (|) clauses
29 * are alternative values for a tag. <br>
31 * Current properties include:
34 * logs.Axis.Level - one of the stringified Levels for log4j controlling the
35 * logging level for axis (used for web services) <br>
37 * <li>logs.Castor.Level - one of the stringified Levels for log4j controlling
38 * the logging level for castor (used for serialization) <br>
40 * <li>logs.Jalview.Level - Cache.log stringified level. <br>
42 * <li>DISCOVERY_START - Boolean - controls if discovery services are queried on
44 * <li>DISCOVERY_URLS - comma separated list of Discovery Service endpoints.</li>
45 * <li>SCREEN_WIDTH</li>
46 * <li>SCREEN_HEIGHT</li>
47 * <li>SCREEN_Y=285</li>
48 * <li>SCREEN_X=371</li>
49 * <li>SHOW_FULLSCREEN boolean</li>
50 * <li>FONT_NAME java font name for alignment text display</li>
51 * <li>FONT_SIZE size of displayed alignment text</li>
52 * <li>FONT_STYLE style of font displayed (sequence labels are always italic)</li>
53 * <li>GAP_SYMBOL character to treat as gap symbol (usually -,.,' ')</li>
54 * <li>LAST_DIRECTORY last directory for browsing alignment</li>
55 * <li>USER_DEFINED_COLOURS list of user defined colour scheme files</li>
56 * <li>SHOW_FULL_ID show id with '/start-end' numbers appended</li>
57 * <li>SHOW_IDENTITY show percentage identity annotation</li>
58 * <li>SHOW_QUALITY show alignment quality annotation</li>
59 * <li>SHOW_ANNOTATIONS show alignment annotation rows</li>
60 * <li>SHOW_CONSERVATION show alignment conservation annotation</li>
61 * <li>CENTRE_COLUMN_LABELS centre the labels at each column in a displayed
63 * <li>DEFAULT_COLOUR default colour scheme to apply for a new alignment</li>
64 * <li>DEFAULT_FILE_FORMAT file format used to save</li>
65 * <li>STARTUP_FILE file loaded on startup (may be a fully qualified url)</li>
66 * <li>SHOW_STARTUP_FILE flag to control loading of startup file</li>
67 * <li>VERSION the version of the jalview build</li>
68 * <li>BUILD_DATE date of this build</li>
69 * <li>LATEST_VERSION the latest jalview version advertised on the
70 * www.jalview.org</li>
71 * <li>PIR_MODELLER boolean indicating if PIR files are written with MODELLER
73 * <li>(FASTA,MSF,PILEUP,CLUSTAL,BLC,PIR,PFAM)_JVSUFFIX boolean for adding jv
75 * <li>RECENT_URL list of recently retrieved URLs</li>
76 * <li>RECENT_FILE list of recently opened files</li>
77 * <li>USE_PROXY flag for whether a http proxy is to be used</li>
78 * <li>PROXY_SERVER the proxy</li>
80 * <li>NOQUESTIONNAIRES true to prevent jalview from checking the questionnaire
82 * <li>QUESTIONNAIRE last questionnaire:responder id string from questionnaire
84 * <li>USAGESTATS (false - user prompted) Enable google analytics tracker for
85 * collecting usage statistics</li>
86 * <li>DAS_LOCAL_SOURCE list of local das sources</li>
87 * <li>SHOW_OVERVIEW boolean for overview window display</li>
88 * <li>ANTI_ALIAS boolean for smooth fonts</li>
89 * <li>RIGHT_ALIGN_IDS boolean</li>
90 * <li>AUTO_CALC_CONSENSUS boolean for automatic recalculation of consensus</li>
91 * <li>PAD_GAPS boolean</li>
92 * <li>ID_ITALICS boolean</li>
93 * <li>SHOW_JV_SUFFIX</li>
94 * <li>WRAP_ALIGNMENT</li>
95 * <li>EPS_RENDERING (Prompt each time|Lineart|Text) default for EPS rendering
97 * <li>SORT_ALIGNMENT (No sort|Id|Pairwise Identity)</li>
98 * <li>SEQUENCE_LINKS list of name|URL pairs for opening a url with
100 * <li>GROUP_LINKS list of name|URL[|<separator>] tuples - see
101 * jalview.utils.GroupURLLink for more info</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>VERSION_CHECK (true) check for the latest release version from
108 * 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
118 * sequence ID strings before attempting retrieval from any datasource</li>
119 * <li>SHOW_GROUP_CONSENSUS (false) Show consensus annotation for groups in the
121 * <li>SHOW_GROUP_CONSERVATION (false) Show conservation annotation for groups
122 * in the alignment.</li>
123 * <li>SHOW_CONSENSUS_HISTOGRAM (false) Show consensus annotation row's
125 * <li>SHOW_CONSENSUS_LOGO (false) Show consensus annotation row's sequence
127 * <li>FOLLOW_SELECTIONS (true) Controls whether a new alignment view should
128 * respond to selections made in other alignments containing the same sequences.
130 * <li>SHOW_WSDISCOVERY_ERRORS (true) Controls if the web service URL discovery
131 * warning dialog box is displayed.</li>
140 * @version $Revision$
145 * property giving log4j level for CASTOR loggers
147 public static final String CASTORLOGLEVEL = "logs.Castor.level";
150 * property giving log4j level for AXIS loggers
152 public static final String AXISLOGLEVEL = "logs.Axis.level";
155 * property giving log4j level for Jalview Log
157 public static final String JALVIEWLOGLEVEL = "logs.Jalview.level";
159 public static final String DAS_LOCAL_SOURCE = "DAS_LOCAL_SOURCE";
161 public static final String DAS_REGISTRY_URL = "DAS_REGISTRY_URL";
163 public static final String DAS_ACTIVE_SOURCE = "DAS_ACTIVE_SOURCE";
166 * Initialises the Jalview Application Log
168 public static Logger log;
170 /** Jalview Properties */
171 public static Properties applicationProperties = new Properties();
173 /** Default file is ~/.jalview_properties */
174 static String propertiesFile;
176 public static void initLogger()
184 // TODO: redirect stdout and stderr here in order to grab the output of
187 ConsoleAppender ap = new ConsoleAppender(new SimpleLayout(),
189 ap.setName("JalviewLogger");
190 org.apache.log4j.Logger.getRootLogger().addAppender(ap); // catch all for
192 Logger laxis = Logger.getLogger("org.apache.axis");
193 Logger lcastor = Logger.getLogger("org.exolab.castor");
194 jalview.bin.Cache.log = Logger.getLogger("jalview.bin.Jalview");
196 laxis.setLevel(Level.toLevel(Cache.getDefault("logs.Axis.Level",
197 Level.INFO.toString())));
198 lcastor.setLevel(Level.toLevel(Cache.getDefault("logs.Castor.Level",
199 Level.INFO.toString())));
200 lcastor = Logger.getLogger("org.exolab.castor.xml");
201 lcastor.setLevel(Level.toLevel(Cache.getDefault("logs.Castor.Level",
202 Level.INFO.toString())));
203 // lcastor = Logger.getLogger("org.exolab.castor.xml.Marshaller");
204 // lcastor.setLevel(Level.toLevel(Cache.getDefault("logs.Castor.Level",
205 // Level.INFO.toString())));
206 jalview.bin.Cache.log.setLevel(Level.toLevel(Cache.getDefault(
207 "logs.Jalview.level", Level.INFO.toString())));
208 // laxis.addAppender(ap);
209 // lcastor.addAppender(ap);
210 // jalview.bin.Cache.log.addAppender(ap);
211 // Tell the user that debug is enabled
212 jalview.bin.Cache.log.debug("Jalview Debugging Output Follows.");
213 } catch (Exception ex)
215 System.err.println("Problems initializing the log4j system\n");
216 ex.printStackTrace(System.err);
220 /** Called when Jalview is started */
221 public static void loadProperties(String propsFile)
223 propertiesFile = propsFile;
224 if (propsFile == null)
226 propertiesFile = System.getProperty("user.home") + File.separatorChar
227 + ".jalview_properties";
232 FileInputStream fis = new FileInputStream(propertiesFile);
233 applicationProperties.load(fis);
234 applicationProperties.remove("LATEST_VERSION");
235 applicationProperties.remove("VERSION");
237 } catch (Exception ex)
239 System.out.println("Error reading properties file: " + ex);
242 if (getDefault("USE_PROXY", false))
244 System.out.println("Using proxyServer: "
245 + getDefault("PROXY_SERVER", null) + " proxyPort: "
246 + getDefault("PROXY_PORT", null));
247 System.setProperty("http.proxyHost", getDefault("PROXY_SERVER", null));
248 System.setProperty("http.proxyPort", getDefault("PROXY_PORT", null));
251 // FIND THE VERSION NUMBER AND BUILD DATE FROM jalview.jar
252 // MUST FOLLOW READING OF LOCAL PROPERTIES FILE AS THE
253 // VERSION MAY HAVE CHANGED SINCE LAST USING JALVIEW
256 String buildDetails = "jar:".concat(Cache.class.getProtectionDomain()
257 .getCodeSource().getLocation().toString()
258 .concat("!/.build_properties"));
260 java.net.URL localJarFileURL = new java.net.URL(buildDetails);
262 InputStream in = localJarFileURL.openStream();
263 applicationProperties.load(in);
265 } catch (Exception ex)
267 System.out.println("Error reading build details: " + ex);
268 applicationProperties.remove("VERSION");
271 String jnlpVersion = System.getProperty("jalview.version");
272 String codeVersion = getProperty("VERSION");
274 if (codeVersion == null)
276 // THIS SHOULD ONLY BE THE CASE WHEN TESTING!!
277 codeVersion = "Test";
278 jnlpVersion = "Test";
281 System.out.println("Jalview Version: " + codeVersion);
283 // jnlpVersion will be null if we're using InstallAnywhere
284 // Dont do this check if running in headless mode
285 if (jnlpVersion == null
286 && getDefault("VERSION_CHECK", true)
287 && (System.getProperty("java.awt.headless") == null || System
288 .getProperty("java.awt.headless").equals("false")))
291 class VersionChecker extends Thread
295 String orgtimeout = System
296 .getProperty("sun.net.client.defaultConnectTimeout");
297 if (orgtimeout == null)
300 System.out.println("# INFO: Setting default net timeout to "
301 + orgtimeout + " seconds.");
303 String jnlpVersion = null;
306 System.setProperty("sun.net.client.defaultConnectTimeout",
308 java.net.URL url = new java.net.URL(
309 "http://www.jalview.org/webstart/jalview.jnlp");
310 BufferedReader in = new BufferedReader(new InputStreamReader(
313 while ((line = in.readLine()) != null)
315 if (line.indexOf("jalview.version") == -1)
320 line = line.substring(line.indexOf("value=") + 7);
321 line = line.substring(0, line.lastIndexOf("\""));
325 } catch (Exception ex)
328 .println("Non-fatal exceptions when checking version at www.jalview.org :");
329 System.out.println(ex);
330 jnlpVersion = getProperty("VERSION");
332 System.setProperty("sun.net.client.defaultConnectTimeout",
335 setProperty("LATEST_VERSION", jnlpVersion);
339 VersionChecker vc = new VersionChecker();
344 if (jnlpVersion != null)
346 setProperty("LATEST_VERSION", jnlpVersion);
350 applicationProperties.remove("LATEST_VERSION");
354 setProperty("VERSION", codeVersion);
356 // LOAD USERDEFINED COLOURS
357 jalview.gui.UserDefinedColours
358 .initUserColourSchemes(getProperty("USER_DEFINED_COLOURS"));
359 jalview.io.PIRFile.useModellerOutput = Cache.getDefault("PIR_MODELLER",
364 * Gets Jalview application property of given key. Returns null if key not
370 * @return Property value
372 public static String getProperty(String key)
374 return applicationProperties.getProperty(key);
378 * These methods are used when checking if the saved preference is different
379 * to the default setting
382 public static boolean getDefault(String property, boolean def)
384 String string = getProperty(property);
387 def = Boolean.valueOf(string).booleanValue();
394 * These methods are used when checking if the saved preference is different
395 * to the default setting
397 public static String getDefault(String property, String def)
399 String string = getProperty(property);
409 * Stores property in the file "HOME_DIR/.jalview_properties"
414 * String value of property
416 * @return String value of property
418 public static String setProperty(String key, String obj)
422 FileOutputStream out = new FileOutputStream(propertiesFile);
423 applicationProperties.setProperty(key, obj);
424 applicationProperties.store(out, "---JalviewX Properties File---");
426 } catch (Exception ex)
428 System.out.println("Error setting property: " + key + " " + obj
435 * remove the specified property from the jalview properties file
439 public static void removeProperty(String string)
441 applicationProperties.remove(string);
446 * save the properties to the jalview properties path
448 public static void saveProperties()
452 FileOutputStream out = new FileOutputStream(propertiesFile);
453 applicationProperties.store(out, "---JalviewX Properties File---");
455 } catch (Exception ex)
457 System.out.println("Error saving properties: " + ex);
462 * internal vamsas class discovery state
464 private static int vamsasJarsArePresent = -1;
467 * Searches for vamsas client classes on class path.
469 * @return true if vamsas client is present on classpath
471 public static boolean vamsasJarsPresent()
473 if (vamsasJarsArePresent == -1)
477 if (jalview.jbgui.GDesktop.class.getClassLoader().loadClass(
478 "uk.ac.vamsas.client.VorbaId") != null)
480 jalview.bin.Cache.log
481 .debug("Found Vamsas Classes (uk.ac..vamsas.client.VorbaId can be loaded)");
482 vamsasJarsArePresent = 1;
483 Logger lvclient = Logger.getLogger("uk.ac.vamsas");
484 lvclient.setLevel(Level.toLevel(Cache.getDefault(
485 "logs.Vamsas.Level", Level.INFO.toString())));
487 lvclient.addAppender(log.getAppender("JalviewLogger"));
488 // Tell the user that debug is enabled
489 lvclient.debug("Jalview Vamsas Client Debugging Output Follows.");
491 } catch (Exception e)
493 vamsasJarsArePresent = 0;
494 jalview.bin.Cache.log.debug("Vamsas Classes are not present");
497 return (vamsasJarsArePresent > 0);
501 * internal vamsas class discovery state
503 private static int groovyJarsArePresent = -1;
506 * Searches for vamsas client classes on class path.
508 * @return true if vamsas client is present on classpath
510 public static boolean groovyJarsPresent()
512 if (groovyJarsArePresent == -1)
516 if (Cache.class.getClassLoader().loadClass(
517 "groovy.lang.GroovyObject") != null)
519 jalview.bin.Cache.log
520 .debug("Found Groovy (groovy.lang.GroovyObject can be loaded)");
521 groovyJarsArePresent = 1;
522 Logger lgclient = Logger.getLogger("groovy");
523 lgclient.setLevel(Level.toLevel(Cache.getDefault(
524 "logs.Groovy.Level", Level.INFO.toString())));
526 lgclient.addAppender(log.getAppender("JalviewLogger"));
527 // Tell the user that debug is enabled
528 lgclient.debug("Jalview Groovy Client Debugging Output Follows.");
532 groovyJarsArePresent = 0;
533 jalview.bin.Cache.log.debug("Groovy Classes are not present", e);
534 } catch (Exception e)
536 groovyJarsArePresent = 0;
537 jalview.bin.Cache.log.debug("Groovy Classes are not present");
540 return (groovyJarsArePresent > 0);
544 * generate Das1Sources from the local das source list
546 * @return Vector of Das1Sources
548 public static Vector getLocalDasSources()
550 Vector localSources = new Vector();
551 String local = jalview.bin.Cache.getProperty("DAS_LOCAL_SOURCE");
554 StringTokenizer st = new StringTokenizer(local, "\t");
555 while (st.hasMoreTokens())
557 String token = st.nextToken();
558 int bar = token.indexOf("|");
559 Das1Source source = new Das1Source();
560 source.setUrl(token.substring(bar + 1));
561 if (source.getUrl().startsWith("sequence:"))
563 source.setUrl(source.getUrl().substring(9));
564 // this source also serves sequences as well as features
565 source.setCapabilities(new String[]
566 { "sequence", "features" });
570 // default is that all user added sources serve features
571 source.setCapabilities(new String[]
575 source.setNickname(token.substring(0, bar));
577 localSources.addElement(source);
584 * GA tracker object - actually JGoogleAnalyticsTracker null if tracking not
587 protected static Object tracker = null;
589 protected static Class trackerfocus = null;
591 protected static Class jgoogleanalyticstracker = null;
594 * Initialise the google tracker if it is not done already.
596 public static void initGoogleTracker()
600 if (jgoogleanalyticstracker == null)
602 // try to get the tracker class
605 jgoogleanalyticstracker = Cache.class
608 "com.boxysystems.jgoogleanalytics.JGoogleAnalyticsTracker");
609 trackerfocus = Cache.class.getClassLoader().loadClass(
610 "com.boxysystems.jgoogleanalytics.FocusPoint");
611 } catch (Exception e)
613 log.debug("com.boxysystems.jgoogleanalytics package is not present - tracking not enabled.");
615 jgoogleanalyticstracker = null;
620 // now initialise tracker
621 Exception re = null, ex = null;
623 String vrs = "No Version Accessible";
626 // Google analytics tracking code for Library Finder
627 tracker = jgoogleanalyticstracker.getConstructor(new Class[]
628 { String.class, String.class, String.class }).newInstance(
632 (vrs = jalview.bin.Cache.getProperty("VERSION")
634 + jalview.bin.Cache.getDefault("BUILD_DATE",
635 "unknown")), "UA-9060947-1" });
636 jgoogleanalyticstracker.getMethod("trackAsynchronously",
638 { trackerfocus }).invoke(tracker, new Object[]
639 { trackerfocus.getConstructor(new Class[]
640 { String.class }).newInstance(new Object[]
641 { "Application Started." }) });
642 } catch (RuntimeException e)
645 } catch (Exception e)
652 if (re != null || ex != null || err != null)
657 log.debug("Caught runtime exception in googletracker init:", re);
660 "Failed to initialise GoogleTracker for Jalview Desktop with version "
664 "Whilst initing GoogleTracker for Jalview Desktop version "
672 .println("Debug: Caught runtime exception in googletracker init:"
674 re.printStackTrace();
679 .println("Warning: Failed to initialise GoogleTracker for Jalview Desktop with version "
681 ex.printStackTrace();
687 .println("ERROR: Whilst initing GoogleTracker for Jalview Desktop version "
689 err.printStackTrace();
695 log.debug("Successfully initialised tracker.");