2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
3 * Copyright (C) 2014 The Jalview Authors
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
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
23 import jalview.ws.dbsources.das.api.DasSourceRegistryI;
24 import jalview.ws.dbsources.das.datamodel.DasSourceRegistry;
26 import java.awt.Color;
28 import java.text.DateFormat;
29 import java.text.SimpleDateFormat;
32 import org.apache.log4j.*;
35 * Stores and retrieves Jalview Application Properties Lists and fields within
36 * list entries are separated by '|' symbols unless otherwise stated (|) clauses
37 * are alternative values for a tag. <br>
39 * Current properties include:
42 * logs.Axis.Level - one of the stringified Levels for log4j controlling the
43 * logging level for axis (used for web services) <br>
45 * <li>logs.Castor.Level - one of the stringified Levels for log4j controlling
46 * the logging level for castor (used for serialization) <br>
48 * <li>logs.Jalview.Level - Cache.log stringified level. <br>
50 * <li>SCREEN_WIDTH</li>
51 * <li>SCREEN_HEIGHT</li>
52 * <li>SCREEN_Y=285</li>
53 * <li>SCREEN_X=371</li>
54 * <li>SHOW_FULLSCREEN boolean</li>
55 * <li>FONT_NAME java font name for alignment text display</li>
56 * <li>FONT_SIZE size of displayed alignment text</li>
57 * <li>FONT_STYLE style of font displayed (sequence labels are always italic)</li>
58 * <li>GAP_SYMBOL character to treat as gap symbol (usually -,.,' ')</li>
59 * <li>LAST_DIRECTORY last directory for browsing alignment</li>
60 * <li>USER_DEFINED_COLOURS list of user defined colour scheme files</li>
61 * <li>SHOW_FULL_ID show id with '/start-end' numbers appended</li>
62 * <li>SHOW_IDENTITY show percentage identity annotation</li>
63 * <li>SHOW_QUALITY show alignment quality annotation</li>
64 * <li>SHOW_ANNOTATIONS show alignment annotation rows</li>
65 * <li>SHOW_CONSERVATION show alignment conservation annotation</li>
66 * <li>CENTRE_COLUMN_LABELS centre the labels at each column in a displayed
68 * <li>DEFAULT_COLOUR default colour scheme to apply for a new alignment</li>
69 * <li>DEFAULT_FILE_FORMAT file format used to save</li>
70 * <li>STARTUP_FILE file loaded on startup (may be a fully qualified url)</li>
71 * <li>SHOW_STARTUP_FILE flag to control loading of startup file</li>
72 * <li>VERSION the version of the jalview build</li>
73 * <li>BUILD_DATE date of this build</li>
74 * <li>LATEST_VERSION the latest jalview version advertised on the
75 * www.jalview.org</li>
76 * <li>PIR_MODELLER boolean indicating if PIR files are written with MODELLER
78 * <li>(FASTA,MSF,PILEUP,CLUSTAL,BLC,PIR,PFAM)_JVSUFFIX boolean for adding jv
80 * <li>RECENT_URL list of recently retrieved URLs</li>
81 * <li>RECENT_FILE list of recently opened files</li>
82 * <li>USE_PROXY flag for whether a http proxy is to be used</li>
83 * <li>PROXY_SERVER the proxy</li>
85 * <li>NOQUESTIONNAIRES true to prevent jalview from checking the questionnaire
87 * <li>QUESTIONNAIRE last questionnaire:responder id string from questionnaire
89 * <li>USAGESTATS (false - user prompted) Enable google analytics tracker for
90 * collecting usage statistics</li>
91 * <li>DAS_LOCAL_SOURCE list of local das sources</li>
92 * <li>SHOW_OVERVIEW boolean for overview window display</li>
93 * <li>ANTI_ALIAS boolean for smooth fonts</li>
94 * <li>RIGHT_ALIGN_IDS boolean</li>
95 * <li>AUTO_CALC_CONSENSUS boolean for automatic recalculation of consensus</li>
96 * <li>PAD_GAPS boolean</li>
97 * <li>ID_ITALICS boolean</li>
98 * <li>SHOW_JV_SUFFIX</li>
99 * <li>WRAP_ALIGNMENT</li>
100 * <li>EPS_RENDERING (Prompt each time|Lineart|Text) default for EPS rendering
102 * <li>SORT_ALIGNMENT (No sort|Id|Pairwise Identity)</li>
103 * <li>SEQUENCE_LINKS list of name|URL pairs for opening a url with
105 * <li>GROUP_LINKS list of name|URL[|<separator>] tuples - see
106 * jalview.utils.GroupURLLink for more info</li>
107 * <li>DAS_REGISTRY_URL the registry to query</li>
108 * <li>DEFAULT_BROWSER for unix</li>
109 * <li>DAS_ACTIVE_SOURCE list of active sources</li>
110 * <li>SHOW_MEMUSAGE boolean show memory usage and warning indicator on desktop
112 * <li>VERSION_CHECK (true) check for the latest release version from
113 * www.jalview.org (or the alias given by the www.jalview.org property)</li>
114 * <li>SHOW_NPFEATS_TOOLTIP (true) show non-positional features in the Sequence
116 * <li>SHOW_DBREFS_TOOLTIP (true) show Database Cross References in the Sequence
118 * <li>SHOW_UNCONSERVED (false) only render unconserved residues - conserved
119 * displayed as '.'</li>
120 * <li>SORT_BY_TREE (false) sort the current alignment view according to the
121 * order of a newly displayed tree</li>
122 * <li>DBFETCH_USEPICR (false) use PICR to recover valid DB references from
123 * sequence ID strings before attempting retrieval from any datasource</li>
124 * <li>SHOW_GROUP_CONSENSUS (false) Show consensus annotation for groups in the
126 * <li>SHOW_GROUP_CONSERVATION (false) Show conservation annotation for groups
127 * in the alignment.</li>
128 * <li>SHOW_CONSENSUS_HISTOGRAM (false) Show consensus annotation row's
130 * <li>SHOW_CONSENSUS_LOGO (false) Show consensus annotation row's sequence
132 * <li>NORMALISE_CONSENSUS_LOGO (false) Show consensus annotation row's sequence
133 * logo normalised to row height rather than histogram height.</li>
134 * <li>FOLLOW_SELECTIONS (true) Controls whether a new alignment view should
135 * respond to selections made in other alignments containing the same sequences.
137 * <li>SHOW_WSDISCOVERY_ERRORS (true) Controls if the web service URL discovery
138 * warning dialog box is displayed.</li>
139 * <li>ANNOTATIONCOLOUR_MIN (orange) Shade used for minimum value of annotation
140 * when shading by annotation</li>
141 * <li>ANNOTATIONCOLOUR_MAX (red) Shade used for maximum value of annotation
142 * when shading by annotation</li>
143 * <li>www.jalview.org (http://www.jalview.org) a property enabling all HTTP
144 * requests to be redirected to a mirror of http://www.jalview.org</li>
146 * <li>FIGURE_AUTOIDWIDTH (false) Expand the left hand column of an exported
147 * alignment figure to accommodate even the longest sequence ID or annotation
149 * <li>FIGURE_FIXEDIDWIDTH Specifies the width to use for the left-hand column
150 * when exporting an alignment as a figure (setting FIGURE_AUTOIDWIDTH to true
151 * will override this).</li>
155 * Deprecated settings:
158 * <li>DISCOVERY_START - Boolean - controls if discovery services are queried on
159 * startup (JWS1 services only)</li>
160 * <li>DISCOVERY_URLS - comma separated list of Discovery Service endpoints.
161 * (JWS1 services only)</li>
162 * <li>SHOW_JWS1_SERVICES (true) enable or disable the original Jalview 2
163 * services in the desktop GUI</li>
164 * <li>ENABLE_RSBS_EDITOR (false for 2.7 release) enable or disable RSBS editing
165 * panel in web service preferences</li>
169 * @version $Revision$
174 * property giving log4j level for CASTOR loggers
176 public static final String CASTORLOGLEVEL = "logs.Castor.level";
179 * property giving log4j level for AXIS loggers
181 public static final String AXISLOGLEVEL = "logs.Axis.level";
184 * property giving log4j level for Jalview Log
186 public static final String JALVIEWLOGLEVEL = "logs.Jalview.level";
188 public static final String DAS_LOCAL_SOURCE = "DAS_LOCAL_SOURCE";
190 public static final String DAS_REGISTRY_URL = "DAS_REGISTRY_URL";
192 public static final String DAS_ACTIVE_SOURCE = "DAS_ACTIVE_SOURCE";
195 * Initialises the Jalview Application Log
197 public static Logger log;
199 /** Jalview Properties */
200 public static Properties applicationProperties = new Properties();
202 /** Default file is ~/.jalview_properties */
203 static String propertiesFile;
205 private static boolean propsAreReadOnly = false;
207 public static void initLogger()
215 // TODO: redirect stdout and stderr here in order to grab the output of
218 ConsoleAppender ap = new ConsoleAppender(new SimpleLayout(),
220 ap.setName("JalviewLogger");
221 org.apache.log4j.Logger.getRootLogger().addAppender(ap); // catch all for
223 Logger laxis = Logger.getLogger("org.apache.axis");
224 Logger lcastor = Logger.getLogger("org.exolab.castor");
225 jalview.bin.Cache.log = Logger.getLogger("jalview.bin.Jalview");
227 laxis.setLevel(Level.toLevel(Cache.getDefault("logs.Axis.Level",
228 Level.INFO.toString())));
229 lcastor.setLevel(Level.toLevel(Cache.getDefault("logs.Castor.Level",
230 Level.INFO.toString())));
231 lcastor = Logger.getLogger("org.exolab.castor.xml");
232 lcastor.setLevel(Level.toLevel(Cache.getDefault("logs.Castor.Level",
233 Level.INFO.toString())));
234 // lcastor = Logger.getLogger("org.exolab.castor.xml.Marshaller");
235 // lcastor.setLevel(Level.toLevel(Cache.getDefault("logs.Castor.Level",
236 // Level.INFO.toString())));
237 jalview.bin.Cache.log.setLevel(Level.toLevel(Cache.getDefault(
238 "logs.Jalview.level", Level.INFO.toString())));
239 // laxis.addAppender(ap);
240 // lcastor.addAppender(ap);
241 // jalview.bin.Cache.log.addAppender(ap);
242 // Tell the user that debug is enabled
243 jalview.bin.Cache.log.debug("Jalview Debugging Output Follows.");
244 } catch (Exception ex)
246 System.err.println("Problems initializing the log4j system\n");
247 ex.printStackTrace(System.err);
251 /** Called when Jalview is started */
252 public static void loadProperties(String propsFile)
254 propertiesFile = propsFile;
255 if (propsFile == null)
257 propertiesFile = System.getProperty("user.home") + File.separatorChar
258 + ".jalview_properties";
262 // don't corrupt the file we've been given.
263 propsAreReadOnly = true;
271 fis = new java.net.URL(propertiesFile).openStream();
272 System.out.println("Loading jalview properties from : "
275 .println("Disabling Jalview writing to user's local properties file.");
276 propsAreReadOnly = true;
278 } catch (Exception ex)
284 fis = new FileInputStream(propertiesFile);
286 applicationProperties.load(fis);
287 applicationProperties.remove("LATEST_VERSION");
288 applicationProperties.remove("VERSION");
290 } catch (Exception ex)
292 System.out.println("Error reading properties file: " + ex);
295 if (getDefault("USE_PROXY", false))
297 String proxyServer = getDefault("PROXY_SERVER", ""), proxyPort = getDefault(
298 "PROXY_PORT", "8080");
300 System.out.println("Using proxyServer: " + proxyServer
301 + " proxyPort: " + proxyPort);
303 System.setProperty("http.proxyHost", proxyServer);
304 System.setProperty("http.proxyPort", proxyPort);
307 // LOAD THE AUTHORS FROM THE authors.props file
310 String authorDetails = "jar:".concat(Cache.class
311 .getProtectionDomain().getCodeSource().getLocation()
312 .toString().concat("!/authors.props"));
314 java.net.URL localJarFileURL = new java.net.URL(authorDetails);
316 InputStream in = localJarFileURL.openStream();
317 applicationProperties.load(in);
319 } catch (Exception ex)
321 System.out.println("Error reading author details: " + ex);
322 applicationProperties.remove("AUTHORS");
323 applicationProperties.remove("AUTHORFNAMES");
324 applicationProperties.remove("YEAR");
327 // FIND THE VERSION NUMBER AND BUILD DATE FROM jalview.jar
328 // MUST FOLLOW READING OF LOCAL PROPERTIES FILE AS THE
329 // VERSION MAY HAVE CHANGED SINCE LAST USING JALVIEW
332 String buildDetails = "jar:".concat(Cache.class.getProtectionDomain()
333 .getCodeSource().getLocation().toString()
334 .concat("!/.build_properties"));
336 java.net.URL localJarFileURL = new java.net.URL(buildDetails);
338 InputStream in = localJarFileURL.openStream();
339 applicationProperties.load(in);
341 } catch (Exception ex)
343 System.out.println("Error reading build details: " + ex);
344 applicationProperties.remove("VERSION");
347 String jnlpVersion = System.getProperty("jalview.version");
348 String codeVersion = getProperty("VERSION");
350 if (codeVersion == null)
352 // THIS SHOULD ONLY BE THE CASE WHEN TESTING!!
353 codeVersion = "Test";
354 jnlpVersion = "Test";
357 System.out.println("Jalview Version: " + codeVersion);
359 // jnlpVersion will be null if we're using InstallAnywhere
360 // Dont do this check if running in headless mode
361 if (jnlpVersion == null
362 && getDefault("VERSION_CHECK", true)
363 && (System.getProperty("java.awt.headless") == null || System
364 .getProperty("java.awt.headless").equals("false")))
367 class VersionChecker extends Thread
371 String orgtimeout = System
372 .getProperty("sun.net.client.defaultConnectTimeout");
373 if (orgtimeout == null)
376 System.out.println("# INFO: Setting default net timeout to "
377 + orgtimeout + " seconds.");
379 String jnlpVersion = null;
382 System.setProperty("sun.net.client.defaultConnectTimeout",
384 java.net.URL url = new java.net.URL(Cache.getDefault(
385 "www.jalview.org", "http://www.jalview.org")
386 + "/webstart/jalview.jnlp");
387 BufferedReader in = new BufferedReader(new InputStreamReader(
390 while ((line = in.readLine()) != null)
392 if (line.indexOf("jalview.version") == -1)
397 line = line.substring(line.indexOf("value=") + 7);
398 line = line.substring(0, line.lastIndexOf("\""));
402 } catch (Exception ex)
405 .println("Non-fatal exceptions when checking version at www.jalview.org :");
406 System.out.println(ex);
407 jnlpVersion = getProperty("VERSION");
409 System.setProperty("sun.net.client.defaultConnectTimeout",
412 setProperty("LATEST_VERSION", jnlpVersion);
416 VersionChecker vc = new VersionChecker();
421 if (jnlpVersion != null)
423 setProperty("LATEST_VERSION", jnlpVersion);
427 applicationProperties.remove("LATEST_VERSION");
431 setProperty("VERSION", codeVersion);
433 // LOAD USERDEFINED COLOURS
434 jalview.gui.UserDefinedColours
435 .initUserColourSchemes(getProperty("USER_DEFINED_COLOURS"));
436 jalview.io.PIRFile.useModellerOutput = Cache.getDefault("PIR_MODELLER",
441 * Gets Jalview application property of given key. Returns null if key not
447 * @return Property value
449 public static String getProperty(String key)
451 return applicationProperties.getProperty(key);
455 * These methods are used when checking if the saved preference is different
456 * to the default setting
459 public static boolean getDefault(String property, boolean def)
461 String string = getProperty(property);
464 def = Boolean.valueOf(string).booleanValue();
471 * These methods are used when checking if the saved preference is different
472 * to the default setting
474 public static String getDefault(String property, String def)
476 String string = getProperty(property);
486 * Stores property in the file "HOME_DIR/.jalview_properties"
491 * String value of property
493 * @return String value of property
495 public static String setProperty(String key, String obj)
500 applicationProperties.setProperty(key, obj);
501 if (!propsAreReadOnly)
503 FileOutputStream out = new FileOutputStream(propertiesFile);
504 applicationProperties.store(out, "---JalviewX Properties File---");
507 } catch (Exception ex)
509 System.out.println("Error setting property: " + key + " " + obj
516 * remove the specified property from the jalview properties file
520 public static void removeProperty(String string)
522 applicationProperties.remove(string);
527 * save the properties to the jalview properties path
529 public static void saveProperties()
531 if (!propsAreReadOnly)
535 FileOutputStream out = new FileOutputStream(propertiesFile);
536 applicationProperties.store(out, "---JalviewX Properties File---");
538 } catch (Exception ex)
540 System.out.println("Error saving properties: " + ex);
546 * internal vamsas class discovery state
548 private static int vamsasJarsArePresent = -1;
551 * Searches for vamsas client classes on class path.
553 * @return true if vamsas client is present on classpath
555 public static boolean vamsasJarsPresent()
557 if (vamsasJarsArePresent == -1)
561 if (jalview.jbgui.GDesktop.class.getClassLoader().loadClass(
562 "uk.ac.vamsas.client.VorbaId") != null)
564 jalview.bin.Cache.log
565 .debug("Found Vamsas Classes (uk.ac..vamsas.client.VorbaId can be loaded)");
566 vamsasJarsArePresent = 1;
567 Logger lvclient = Logger.getLogger("uk.ac.vamsas");
568 lvclient.setLevel(Level.toLevel(Cache.getDefault(
569 "logs.Vamsas.Level", Level.INFO.toString())));
571 lvclient.addAppender(log.getAppender("JalviewLogger"));
572 // Tell the user that debug is enabled
573 lvclient.debug("Jalview Vamsas Client Debugging Output Follows.");
575 } catch (Exception e)
577 vamsasJarsArePresent = 0;
578 jalview.bin.Cache.log.debug("Vamsas Classes are not present");
581 return (vamsasJarsArePresent > 0);
585 * internal vamsas class discovery state
587 private static int groovyJarsArePresent = -1;
590 * Searches for vamsas client classes on class path.
592 * @return true if vamsas client is present on classpath
594 public static boolean groovyJarsPresent()
596 if (groovyJarsArePresent == -1)
600 if (Cache.class.getClassLoader().loadClass(
601 "groovy.lang.GroovyObject") != null)
603 jalview.bin.Cache.log
604 .debug("Found Groovy (groovy.lang.GroovyObject can be loaded)");
605 groovyJarsArePresent = 1;
606 Logger lgclient = Logger.getLogger("groovy");
607 lgclient.setLevel(Level.toLevel(Cache.getDefault(
608 "logs.Groovy.Level", Level.INFO.toString())));
610 lgclient.addAppender(log.getAppender("JalviewLogger"));
611 // Tell the user that debug is enabled
612 lgclient.debug("Jalview Groovy Client Debugging Output Follows.");
616 groovyJarsArePresent = 0;
617 jalview.bin.Cache.log.debug("Groovy Classes are not present", e);
618 } catch (Exception e)
620 groovyJarsArePresent = 0;
621 jalview.bin.Cache.log.debug("Groovy Classes are not present");
624 return (groovyJarsArePresent > 0);
628 * GA tracker object - actually JGoogleAnalyticsTracker null if tracking not
631 protected static Object tracker = null;
633 protected static Class trackerfocus = null;
635 protected static Class jgoogleanalyticstracker = null;
638 * Initialise the google tracker if it is not done already.
640 public static void initGoogleTracker()
644 if (jgoogleanalyticstracker == null)
646 // try to get the tracker class
649 jgoogleanalyticstracker = Cache.class
652 "com.boxysystems.jgoogleanalytics.JGoogleAnalyticsTracker");
653 trackerfocus = Cache.class.getClassLoader().loadClass(
654 "com.boxysystems.jgoogleanalytics.FocusPoint");
655 } catch (Exception e)
657 log.debug("com.boxysystems.jgoogleanalytics package is not present - tracking not enabled.");
659 jgoogleanalyticstracker = null;
664 // now initialise tracker
665 Exception re = null, ex = null;
667 String vrs = "No Version Accessible";
670 // Google analytics tracking code for Library Finder
671 tracker = jgoogleanalyticstracker.getConstructor(new Class[]
672 { String.class, String.class, String.class }).newInstance(
676 (vrs = jalview.bin.Cache.getProperty("VERSION")
678 + jalview.bin.Cache.getDefault("BUILD_DATE",
679 "unknown")), "UA-9060947-1" });
680 jgoogleanalyticstracker.getMethod("trackAsynchronously",
682 { trackerfocus }).invoke(tracker, new Object[]
683 { trackerfocus.getConstructor(new Class[]
684 { String.class }).newInstance(new Object[]
685 { "Application Started." }) });
686 } catch (RuntimeException e)
689 } catch (Exception e)
696 if (re != null || ex != null || err != null)
701 log.debug("Caught runtime exception in googletracker init:", re);
704 "Failed to initialise GoogleTracker for Jalview Desktop with version "
708 "Whilst initing GoogleTracker for Jalview Desktop version "
716 .println("Debug: Caught runtime exception in googletracker init:"
718 re.printStackTrace();
723 .println("Warning: Failed to initialise GoogleTracker for Jalview Desktop with version "
725 ex.printStackTrace();
731 .println("ERROR: Whilst initing GoogleTracker for Jalview Desktop version "
733 err.printStackTrace();
739 log.debug("Successfully initialised tracker.");
745 * get the user's default colour if available
751 public static Color getDefaultColour(String property, Color defcolour)
753 String colprop = getProperty(property);
758 Color col = jalview.schemes.ColourSchemeProperty
759 .getAWTColorFromName(colprop);
764 col = new jalview.schemes.UserColourScheme(colprop).findColour('A');
765 } catch (Exception ex)
767 log.warn("Couldn't parse '" + colprop + "' as a colour for "
772 return (col == null) ? defcolour : col;
776 * store a colour as a Jalview user default property
781 public static void setColourProperty(String property, Color colour)
783 setProperty(property, jalview.util.Format.getHexString(colour));
786 public static final DateFormat date_format = SimpleDateFormat
787 .getDateTimeInstance();
790 * store a date in a jalview property
795 public static void setDateProperty(String property, Date time)
797 setProperty(property, date_format.format(time));
801 * read a date stored in a jalview property
804 * @return valid date as stored by setDateProperty, or null
807 public static Date getDateProperty(String property)
809 String val = getProperty(property);
814 return date_format.parse(val);
815 } catch (Exception ex)
817 System.err.println("Invalid or corrupt date in property '"
818 + property + "' : value was '" + val + "'");
825 * get and parse a property as an integer. send any parsing problems to
829 * @return null or Integer
831 public static Integer getIntegerProperty(String property)
833 String val = getProperty(property);
834 if (val != null && (val = val.trim()).length() > 0)
838 return Integer.valueOf(val);
839 } catch (NumberFormatException x)
841 System.err.println("Invalid integer in property '" + property
842 + "' (value was '" + val + "')");
848 private static DasSourceRegistryI sourceRegistry = null;
853 * @return instance of the das source registry
855 public static DasSourceRegistryI getDasSourceRegistry()
857 if (sourceRegistry == null)
859 sourceRegistry = new DasSourceRegistry();
861 return sourceRegistry;