2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.1)
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 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/>.
17 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 import jalview.ws.dbsources.das.api.DasSourceRegistryI;
22 import jalview.ws.dbsources.das.datamodel.DasSourceRegistry;
24 import java.awt.Color;
26 import java.text.DateFormat;
27 import java.text.SimpleDateFormat;
30 import org.apache.log4j.*;
33 * Stores and retrieves Jalview Application Properties Lists and fields within
34 * list entries are separated by '|' symbols unless otherwise stated (|) clauses
35 * are alternative values for a tag. <br>
37 * Current properties include:
40 * logs.Axis.Level - one of the stringified Levels for log4j controlling the
41 * logging level for axis (used for web services) <br>
43 * <li>logs.Castor.Level - one of the stringified Levels for log4j controlling
44 * the logging level for castor (used for serialization) <br>
46 * <li>logs.Jalview.Level - Cache.log stringified level. <br>
48 * <li>SCREEN_WIDTH</li>
49 * <li>SCREEN_HEIGHT</li>
50 * <li>SCREEN_Y=285</li>
51 * <li>SCREEN_X=371</li>
52 * <li>SHOW_FULLSCREEN boolean</li>
53 * <li>FONT_NAME java font name for alignment text display</li>
54 * <li>FONT_SIZE size of displayed alignment text</li>
55 * <li>FONT_STYLE style of font displayed (sequence labels are always italic)</li>
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
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
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>
83 * <li>NOQUESTIONNAIRES true to prevent jalview from checking the questionnaire
85 * <li>QUESTIONNAIRE last questionnaire:responder id string from questionnaire
87 * <li>USAGESTATS (false - user prompted) Enable google analytics tracker for
88 * collecting usage statistics</li>
89 * <li>DAS_LOCAL_SOURCE list of local das sources</li>
90 * <li>SHOW_OVERVIEW boolean for overview window display</li>
91 * <li>ANTI_ALIAS boolean for smooth fonts</li>
92 * <li>RIGHT_ALIGN_IDS boolean</li>
93 * <li>AUTO_CALC_CONSENSUS boolean for automatic recalculation of consensus</li>
94 * <li>PAD_GAPS boolean</li>
95 * <li>ID_ITALICS boolean</li>
96 * <li>SHOW_JV_SUFFIX</li>
97 * <li>WRAP_ALIGNMENT</li>
98 * <li>EPS_RENDERING (Prompt each time|Lineart|Text) default for EPS rendering
100 * <li>SORT_ALIGNMENT (No sort|Id|Pairwise Identity)</li>
101 * <li>SEQUENCE_LINKS list of name|URL pairs for opening a url with
103 * <li>GROUP_LINKS list of name|URL[|<separator>] tuples - see
104 * jalview.utils.GroupURLLink for more info</li>
105 * <li>DAS_REGISTRY_URL the registry to query</li>
106 * <li>DEFAULT_BROWSER for unix</li>
107 * <li>DAS_ACTIVE_SOURCE list of active sources</li>
108 * <li>SHOW_MEMUSAGE boolean show memory usage and warning indicator on desktop
110 * <li>VERSION_CHECK (true) check for the latest release version from
111 * www.jalview.org (or the alias given by the www.jalview.org property)</li>
112 * <li>SHOW_NPFEATS_TOOLTIP (true) show non-positional features in the Sequence
114 * <li>SHOW_DBREFS_TOOLTIP (true) show Database Cross References in the Sequence
116 * <li>SHOW_UNCONSERVED (false) only render unconserved residues - conserved
117 * displayed as '.'</li>
118 * <li>SORT_BY_TREE (false) sort the current alignment view according to the
119 * order of a newly displayed tree</li>
120 * <li>DBFETCH_USEPICR (false) use PICR to recover valid DB references from
121 * sequence ID strings before attempting retrieval from any datasource</li>
122 * <li>SHOW_GROUP_CONSENSUS (false) Show consensus annotation for groups in the
124 * <li>SHOW_GROUP_CONSERVATION (false) Show conservation annotation for groups
125 * in the alignment.</li>
126 * <li>SHOW_CONSENSUS_HISTOGRAM (false) Show consensus annotation row's
128 * <li>SHOW_CONSENSUS_LOGO (false) Show consensus annotation row's sequence
130 * <li>NORMALISE_CONSENSUS_LOGO (false) Show consensus annotation row's sequence
131 * logo normalised to row height rather than histogram height.</li>
132 * <li>FOLLOW_SELECTIONS (true) Controls whether a new alignment view should
133 * respond to selections made in other alignments containing the same sequences.
135 * <li>SHOW_WSDISCOVERY_ERRORS (true) Controls if the web service URL discovery
136 * warning dialog box is displayed.</li>
137 * <li>ANNOTATIONCOLOUR_MIN (orange) Shade used for minimum value of annotation
138 * when shading by annotation</li>
139 * <li>ANNOTATIONCOLOUR_MAX (red) Shade used for maximum value of annotation
140 * when shading by annotation</li>
141 * <li>www.jalview.org (http://www.jalview.org) a property enabling all HTTP
142 * requests to be redirected to a mirror of http://www.jalview.org</li>
144 * <li>FIGURE_AUTOIDWIDTH (false) Expand the left hand column of an exported
145 * alignment figure to accommodate even the longest sequence ID or annotation
147 * <li>FIGURE_FIXEDIDWIDTH Specifies the width to use for the left-hand column
148 * when exporting an alignment as a figure (setting FIGURE_AUTOIDWIDTH to true
149 * will override this).</li>
153 * Deprecated settings:
156 * <li>DISCOVERY_START - Boolean - controls if discovery services are queried on
157 * startup (JWS1 services only)</li>
158 * <li>DISCOVERY_URLS - comma separated list of Discovery Service endpoints.
159 * (JWS1 services only)</li>
160 * <li>SHOW_JWS1_SERVICES (true) enable or disable the original Jalview 2
161 * services in the desktop GUI</li>
162 * <li>ENABLE_RSBS_EDITOR (false for 2.7 release) enable or disable RSBS editing
163 * panel in web service preferences</li>
167 * @version $Revision$
172 * property giving log4j level for CASTOR loggers
174 public static final String CASTORLOGLEVEL = "logs.Castor.level";
177 * property giving log4j level for AXIS loggers
179 public static final String AXISLOGLEVEL = "logs.Axis.level";
182 * property giving log4j level for Jalview Log
184 public static final String JALVIEWLOGLEVEL = "logs.Jalview.level";
186 public static final String DAS_LOCAL_SOURCE = "DAS_LOCAL_SOURCE";
188 public static final String DAS_REGISTRY_URL = "DAS_REGISTRY_URL";
190 public static final String DAS_ACTIVE_SOURCE = "DAS_ACTIVE_SOURCE";
193 * Initialises the Jalview Application Log
195 public static Logger log;
197 /** Jalview Properties */
198 public static Properties applicationProperties = new Properties();
200 /** Default file is ~/.jalview_properties */
201 static String propertiesFile;
203 private static boolean propsAreReadOnly = false;
205 public static void initLogger()
213 // TODO: redirect stdout and stderr here in order to grab the output of
216 ConsoleAppender ap = new ConsoleAppender(new SimpleLayout(),
218 ap.setName("JalviewLogger");
219 org.apache.log4j.Logger.getRootLogger().addAppender(ap); // catch all for
221 Logger laxis = Logger.getLogger("org.apache.axis");
222 Logger lcastor = Logger.getLogger("org.exolab.castor");
223 jalview.bin.Cache.log = Logger.getLogger("jalview.bin.Jalview");
225 laxis.setLevel(Level.toLevel(Cache.getDefault("logs.Axis.Level",
226 Level.INFO.toString())));
227 lcastor.setLevel(Level.toLevel(Cache.getDefault("logs.Castor.Level",
228 Level.INFO.toString())));
229 lcastor = Logger.getLogger("org.exolab.castor.xml");
230 lcastor.setLevel(Level.toLevel(Cache.getDefault("logs.Castor.Level",
231 Level.INFO.toString())));
232 // lcastor = Logger.getLogger("org.exolab.castor.xml.Marshaller");
233 // lcastor.setLevel(Level.toLevel(Cache.getDefault("logs.Castor.Level",
234 // Level.INFO.toString())));
235 jalview.bin.Cache.log.setLevel(Level.toLevel(Cache.getDefault(
236 "logs.Jalview.level", Level.INFO.toString())));
237 // laxis.addAppender(ap);
238 // lcastor.addAppender(ap);
239 // jalview.bin.Cache.log.addAppender(ap);
240 // Tell the user that debug is enabled
241 jalview.bin.Cache.log.debug("Jalview Debugging Output Follows.");
242 } catch (Exception ex)
244 System.err.println("Problems initializing the log4j system\n");
245 ex.printStackTrace(System.err);
249 /** Called when Jalview is started */
250 public static void loadProperties(String propsFile)
252 propertiesFile = propsFile;
253 if (propsFile == null)
255 propertiesFile = System.getProperty("user.home") + File.separatorChar
256 + ".jalview_properties";
260 // don't corrupt the file we've been given.
261 propsAreReadOnly = true;
269 fis = new java.net.URL(propertiesFile).openStream();
270 System.out.println("Loading jalview properties from : "
273 .println("Disabling Jalview writing to user's local properties file.");
274 propsAreReadOnly = true;
276 } catch (Exception ex)
282 fis = new FileInputStream(propertiesFile);
284 applicationProperties.load(fis);
285 applicationProperties.remove("LATEST_VERSION");
286 applicationProperties.remove("VERSION");
288 } catch (Exception ex)
290 System.out.println("Error reading properties file: " + ex);
293 if (getDefault("USE_PROXY", false))
295 String proxyServer = getDefault("PROXY_SERVER", ""), proxyPort = getDefault(
296 "PROXY_PORT", "8080");
298 System.out.println("Using proxyServer: " + proxyServer
299 + " proxyPort: " + proxyPort);
301 System.setProperty("http.proxyHost", proxyServer);
302 System.setProperty("http.proxyPort", proxyPort);
305 // LOAD THE AUTHORS FROM THE authors.props file
308 String authorDetails = "jar:".concat(Cache.class
309 .getProtectionDomain().getCodeSource().getLocation()
310 .toString().concat("!/authors.props"));
312 java.net.URL localJarFileURL = new java.net.URL(authorDetails);
314 InputStream in = localJarFileURL.openStream();
315 applicationProperties.load(in);
317 } catch (Exception ex)
319 System.out.println("Error reading author details: " + ex);
320 applicationProperties.remove("AUTHORS");
321 applicationProperties.remove("AUTHORFNAMES");
322 applicationProperties.remove("YEAR");
325 // FIND THE VERSION NUMBER AND BUILD DATE FROM jalview.jar
326 // MUST FOLLOW READING OF LOCAL PROPERTIES FILE AS THE
327 // VERSION MAY HAVE CHANGED SINCE LAST USING JALVIEW
330 String buildDetails = "jar:".concat(Cache.class.getProtectionDomain()
331 .getCodeSource().getLocation().toString()
332 .concat("!/.build_properties"));
334 java.net.URL localJarFileURL = new java.net.URL(buildDetails);
336 InputStream in = localJarFileURL.openStream();
337 applicationProperties.load(in);
339 } catch (Exception ex)
341 System.out.println("Error reading build details: " + ex);
342 applicationProperties.remove("VERSION");
345 String jnlpVersion = System.getProperty("jalview.version");
346 String codeVersion = getProperty("VERSION");
348 if (codeVersion == null)
350 // THIS SHOULD ONLY BE THE CASE WHEN TESTING!!
351 codeVersion = "Test";
352 jnlpVersion = "Test";
355 System.out.println("Jalview Version: " + codeVersion);
357 // jnlpVersion will be null if we're using InstallAnywhere
358 // Dont do this check if running in headless mode
359 if (jnlpVersion == null
360 && getDefault("VERSION_CHECK", true)
361 && (System.getProperty("java.awt.headless") == null || System
362 .getProperty("java.awt.headless").equals("false")))
365 class VersionChecker extends Thread
369 String orgtimeout = System
370 .getProperty("sun.net.client.defaultConnectTimeout");
371 if (orgtimeout == null)
374 System.out.println("# INFO: Setting default net timeout to "
375 + orgtimeout + " seconds.");
377 String jnlpVersion = null;
380 System.setProperty("sun.net.client.defaultConnectTimeout",
382 java.net.URL url = new java.net.URL(Cache.getDefault(
383 "www.jalview.org", "http://www.jalview.org")
384 + "/webstart/jalview.jnlp");
385 BufferedReader in = new BufferedReader(new InputStreamReader(
388 while ((line = in.readLine()) != null)
390 if (line.indexOf("jalview.version") == -1)
395 line = line.substring(line.indexOf("value=") + 7);
396 line = line.substring(0, line.lastIndexOf("\""));
400 } catch (Exception ex)
403 .println("Non-fatal exceptions when checking version at www.jalview.org :");
404 System.out.println(ex);
405 jnlpVersion = getProperty("VERSION");
407 System.setProperty("sun.net.client.defaultConnectTimeout",
410 setProperty("LATEST_VERSION", jnlpVersion);
414 VersionChecker vc = new VersionChecker();
419 if (jnlpVersion != null)
421 setProperty("LATEST_VERSION", jnlpVersion);
425 applicationProperties.remove("LATEST_VERSION");
429 setProperty("VERSION", codeVersion);
431 // LOAD USERDEFINED COLOURS
432 jalview.gui.UserDefinedColours
433 .initUserColourSchemes(getProperty("USER_DEFINED_COLOURS"));
434 jalview.io.PIRFile.useModellerOutput = Cache.getDefault("PIR_MODELLER",
439 * Gets Jalview application property of given key. Returns null if key not
445 * @return Property value
447 public static String getProperty(String key)
449 return applicationProperties.getProperty(key);
453 * These methods are used when checking if the saved preference is different
454 * to the default setting
457 public static boolean getDefault(String property, boolean def)
459 String string = getProperty(property);
462 def = Boolean.valueOf(string).booleanValue();
469 * These methods are used when checking if the saved preference is different
470 * to the default setting
472 public static String getDefault(String property, String def)
474 String string = getProperty(property);
484 * Stores property in the file "HOME_DIR/.jalview_properties"
489 * String value of property
491 * @return String value of property
493 public static String setProperty(String key, String obj)
498 applicationProperties.setProperty(key, obj);
499 if (!propsAreReadOnly)
501 FileOutputStream out = new FileOutputStream(propertiesFile);
502 applicationProperties.store(out, "---JalviewX Properties File---");
505 } catch (Exception ex)
507 System.out.println("Error setting property: " + key + " " + obj
514 * remove the specified property from the jalview properties file
518 public static void removeProperty(String string)
520 applicationProperties.remove(string);
525 * save the properties to the jalview properties path
527 public static void saveProperties()
529 if (!propsAreReadOnly)
533 FileOutputStream out = new FileOutputStream(propertiesFile);
534 applicationProperties.store(out, "---JalviewX Properties File---");
536 } catch (Exception ex)
538 System.out.println("Error saving properties: " + ex);
544 * internal vamsas class discovery state
546 private static int vamsasJarsArePresent = -1;
549 * Searches for vamsas client classes on class path.
551 * @return true if vamsas client is present on classpath
553 public static boolean vamsasJarsPresent()
555 if (vamsasJarsArePresent == -1)
559 if (jalview.jbgui.GDesktop.class.getClassLoader().loadClass(
560 "uk.ac.vamsas.client.VorbaId") != null)
562 jalview.bin.Cache.log
563 .debug("Found Vamsas Classes (uk.ac..vamsas.client.VorbaId can be loaded)");
564 vamsasJarsArePresent = 1;
565 Logger lvclient = Logger.getLogger("uk.ac.vamsas");
566 lvclient.setLevel(Level.toLevel(Cache.getDefault(
567 "logs.Vamsas.Level", Level.INFO.toString())));
569 lvclient.addAppender(log.getAppender("JalviewLogger"));
570 // Tell the user that debug is enabled
571 lvclient.debug("Jalview Vamsas Client Debugging Output Follows.");
573 } catch (Exception e)
575 vamsasJarsArePresent = 0;
576 jalview.bin.Cache.log.debug("Vamsas Classes are not present");
579 return (vamsasJarsArePresent > 0);
583 * internal vamsas class discovery state
585 private static int groovyJarsArePresent = -1;
588 * Searches for vamsas client classes on class path.
590 * @return true if vamsas client is present on classpath
592 public static boolean groovyJarsPresent()
594 if (groovyJarsArePresent == -1)
598 if (Cache.class.getClassLoader().loadClass(
599 "groovy.lang.GroovyObject") != null)
601 jalview.bin.Cache.log
602 .debug("Found Groovy (groovy.lang.GroovyObject can be loaded)");
603 groovyJarsArePresent = 1;
604 Logger lgclient = Logger.getLogger("groovy");
605 lgclient.setLevel(Level.toLevel(Cache.getDefault(
606 "logs.Groovy.Level", Level.INFO.toString())));
608 lgclient.addAppender(log.getAppender("JalviewLogger"));
609 // Tell the user that debug is enabled
610 lgclient.debug("Jalview Groovy Client Debugging Output Follows.");
614 groovyJarsArePresent = 0;
615 jalview.bin.Cache.log.debug("Groovy Classes are not present", e);
616 } catch (Exception e)
618 groovyJarsArePresent = 0;
619 jalview.bin.Cache.log.debug("Groovy Classes are not present");
622 return (groovyJarsArePresent > 0);
626 * GA tracker object - actually JGoogleAnalyticsTracker null if tracking not
629 protected static Object tracker = null;
631 protected static Class trackerfocus = null;
633 protected static Class jgoogleanalyticstracker = null;
636 * Initialise the google tracker if it is not done already.
638 public static void initGoogleTracker()
642 if (jgoogleanalyticstracker == null)
644 // try to get the tracker class
647 jgoogleanalyticstracker = Cache.class
650 "com.boxysystems.jgoogleanalytics.JGoogleAnalyticsTracker");
651 trackerfocus = Cache.class.getClassLoader().loadClass(
652 "com.boxysystems.jgoogleanalytics.FocusPoint");
653 } catch (Exception e)
655 log.debug("com.boxysystems.jgoogleanalytics package is not present - tracking not enabled.");
657 jgoogleanalyticstracker = null;
662 // now initialise tracker
663 Exception re = null, ex = null;
665 String vrs = "No Version Accessible";
668 // Google analytics tracking code for Library Finder
669 tracker = jgoogleanalyticstracker.getConstructor(new Class[]
670 { String.class, String.class, String.class }).newInstance(
674 (vrs = jalview.bin.Cache.getProperty("VERSION")
676 + jalview.bin.Cache.getDefault("BUILD_DATE",
677 "unknown")), "UA-9060947-1" });
678 jgoogleanalyticstracker.getMethod("trackAsynchronously",
680 { trackerfocus }).invoke(tracker, new Object[]
681 { trackerfocus.getConstructor(new Class[]
682 { String.class }).newInstance(new Object[]
683 { "Application Started." }) });
684 } catch (RuntimeException e)
687 } catch (Exception e)
694 if (re != null || ex != null || err != null)
699 log.debug("Caught runtime exception in googletracker init:", re);
702 "Failed to initialise GoogleTracker for Jalview Desktop with version "
706 "Whilst initing GoogleTracker for Jalview Desktop version "
714 .println("Debug: Caught runtime exception in googletracker init:"
716 re.printStackTrace();
721 .println("Warning: Failed to initialise GoogleTracker for Jalview Desktop with version "
723 ex.printStackTrace();
729 .println("ERROR: Whilst initing GoogleTracker for Jalview Desktop version "
731 err.printStackTrace();
737 log.debug("Successfully initialised tracker.");
743 * get the user's default colour if available
749 public static Color getDefaultColour(String property, Color defcolour)
751 String colprop = getProperty(property);
756 Color col = jalview.schemes.ColourSchemeProperty
757 .getAWTColorFromName(colprop);
762 col = new jalview.schemes.UserColourScheme(colprop).findColour('A');
763 } catch (Exception ex)
765 log.warn("Couldn't parse '" + colprop + "' as a colour for "
770 return (col == null) ? defcolour : col;
774 * store a colour as a Jalview user default property
779 public static void setColourProperty(String property, Color colour)
781 setProperty(property, jalview.util.Format.getHexString(colour));
784 public static final DateFormat date_format = SimpleDateFormat
785 .getDateTimeInstance();
788 * store a date in a jalview property
793 public static void setDateProperty(String property, Date time)
795 setProperty(property, date_format.format(time));
799 * read a date stored in a jalview property
802 * @return valid date as stored by setDateProperty, or null
805 public static Date getDateProperty(String property)
807 String val = getProperty(property);
812 return date_format.parse(val);
813 } catch (Exception ex)
815 System.err.println("Invalid or corrupt date in property '"
816 + property + "' : value was '" + val + "'");
823 * get and parse a property as an integer. send any parsing problems to
827 * @return null or Integer
829 public static Integer getIntegerProperty(String property)
831 String val = getProperty(property);
832 if (val != null && (val = val.trim()).length() > 0)
836 return Integer.valueOf(val);
837 } catch (NumberFormatException x)
839 System.err.println("Invalid integer in property '" + property
840 + "' (value was '" + val + "')");
846 private static DasSourceRegistryI sourceRegistry = null;
851 * @return instance of the das source registry
853 public static DasSourceRegistryI getDasSourceRegistry()
855 if (sourceRegistry == null)
857 sourceRegistry = new DasSourceRegistry();
859 return sourceRegistry;