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);
288 // remove any old build properties
290 deleteBuildProperties();
292 } catch (Exception ex)
294 System.out.println("Error reading properties file: " + ex);
297 if (getDefault("USE_PROXY", false))
299 String proxyServer = getDefault("PROXY_SERVER", ""), proxyPort = getDefault(
300 "PROXY_PORT", "8080");
302 System.out.println("Using proxyServer: " + proxyServer
303 + " proxyPort: " + proxyPort);
305 System.setProperty("http.proxyHost", proxyServer);
306 System.setProperty("http.proxyPort", proxyPort);
309 // LOAD THE AUTHORS FROM THE authors.props file
312 String authorDetails = "jar:".concat(Cache.class
313 .getProtectionDomain().getCodeSource().getLocation()
314 .toString().concat("!/authors.props"));
316 java.net.URL localJarFileURL = new java.net.URL(authorDetails);
318 InputStream in = localJarFileURL.openStream();
319 applicationProperties.load(in);
321 } catch (Exception ex)
323 System.out.println("Error reading author details: " + ex);
324 applicationProperties.remove("AUTHORS");
325 applicationProperties.remove("AUTHORFNAMES");
326 applicationProperties.remove("YEAR");
329 // FIND THE VERSION NUMBER AND BUILD DATE FROM jalview.jar
330 // MUST FOLLOW READING OF LOCAL PROPERTIES FILE AS THE
331 // VERSION MAY HAVE CHANGED SINCE LAST USING JALVIEW
334 String buildDetails = "jar:".concat(Cache.class.getProtectionDomain()
335 .getCodeSource().getLocation().toString()
336 .concat("!/.build_properties"));
338 java.net.URL localJarFileURL = new java.net.URL(buildDetails);
340 InputStream in = localJarFileURL.openStream();
341 applicationProperties.load(in);
343 } catch (Exception ex)
345 System.out.println("Error reading build details: " + ex);
346 applicationProperties.remove("VERSION");
349 String jnlpVersion = System.getProperty("jalview.version");
350 String codeVersion = getProperty("VERSION");
352 if (codeVersion == null)
354 // THIS SHOULD ONLY BE THE CASE WHEN TESTING!!
355 codeVersion = "Test";
356 jnlpVersion = "Test";
359 System.out.println("Jalview Version: " + codeVersion);
361 // jnlpVersion will be null if we're using InstallAnywhere
362 // Dont do this check if running in headless mode
363 if (jnlpVersion == null
364 && getDefault("VERSION_CHECK", true)
365 && (System.getProperty("java.awt.headless") == null || System
366 .getProperty("java.awt.headless").equals("false")))
369 class VersionChecker extends Thread
373 String orgtimeout = System
374 .getProperty("sun.net.client.defaultConnectTimeout");
375 if (orgtimeout == null)
378 System.out.println("# INFO: Setting default net timeout to "
379 + orgtimeout + " seconds.");
381 String jnlpVersion = null;
384 System.setProperty("sun.net.client.defaultConnectTimeout",
386 java.net.URL url = new java.net.URL(Cache.getDefault(
387 "www.jalview.org", "http://www.jalview.org")
388 + "/webstart/jalview.jnlp");
389 BufferedReader in = new BufferedReader(new InputStreamReader(
392 while ((line = in.readLine()) != null)
394 if (line.indexOf("jalview.version") == -1)
399 line = line.substring(line.indexOf("value=") + 7);
400 line = line.substring(0, line.lastIndexOf("\""));
404 } catch (Exception ex)
407 .println("Non-fatal exceptions when checking version at www.jalview.org :");
408 System.out.println(ex);
409 jnlpVersion = getProperty("VERSION");
411 System.setProperty("sun.net.client.defaultConnectTimeout",
414 setProperty("LATEST_VERSION", jnlpVersion);
418 VersionChecker vc = new VersionChecker();
423 if (jnlpVersion != null)
425 setProperty("LATEST_VERSION", jnlpVersion);
429 applicationProperties.remove("LATEST_VERSION");
433 setProperty("VERSION", codeVersion);
435 // LOAD USERDEFINED COLOURS
436 jalview.gui.UserDefinedColours
437 .initUserColourSchemes(getProperty("USER_DEFINED_COLOURS"));
438 jalview.io.PIRFile.useModellerOutput = Cache.getDefault("PIR_MODELLER",
442 private static void deleteBuildProperties()
444 applicationProperties.remove("LATEST_VERSION");
445 applicationProperties.remove("VERSION");
446 applicationProperties.remove("AUTHORS");
447 applicationProperties.remove("AUTHORFNAMES");
448 applicationProperties.remove("YEAR");
452 * Gets Jalview application property of given key. Returns null if key not
458 * @return Property value
460 public static String getProperty(String key)
462 return applicationProperties.getProperty(key);
466 * These methods are used when checking if the saved preference is different
467 * to the default setting
470 public static boolean getDefault(String property, boolean def)
472 String string = getProperty(property);
475 def = Boolean.valueOf(string).booleanValue();
482 * These methods are used when checking if the saved preference is different
483 * to the default setting
485 public static String getDefault(String property, String def)
487 String string = getProperty(property);
497 * Stores property in the file "HOME_DIR/.jalview_properties"
502 * String value of property
504 * @return String value of property
506 public static String setProperty(String key, String obj)
511 applicationProperties.setProperty(key, obj);
512 if (!propsAreReadOnly)
514 FileOutputStream out = new FileOutputStream(propertiesFile);
515 applicationProperties.store(out, "---JalviewX Properties File---");
518 } catch (Exception ex)
520 System.out.println("Error setting property: " + key + " " + obj
527 * remove the specified property from the jalview properties file
531 public static void removeProperty(String string)
533 applicationProperties.remove(string);
538 * save the properties to the jalview properties path
540 public static void saveProperties()
542 if (!propsAreReadOnly)
546 FileOutputStream out = new FileOutputStream(propertiesFile);
547 applicationProperties.store(out, "---JalviewX Properties File---");
549 } catch (Exception ex)
551 System.out.println("Error saving properties: " + ex);
557 * internal vamsas class discovery state
559 private static int vamsasJarsArePresent = -1;
562 * Searches for vamsas client classes on class path.
564 * @return true if vamsas client is present on classpath
566 public static boolean vamsasJarsPresent()
568 if (vamsasJarsArePresent == -1)
572 if (jalview.jbgui.GDesktop.class.getClassLoader().loadClass(
573 "uk.ac.vamsas.client.VorbaId") != null)
575 jalview.bin.Cache.log
576 .debug("Found Vamsas Classes (uk.ac..vamsas.client.VorbaId can be loaded)");
577 vamsasJarsArePresent = 1;
578 Logger lvclient = Logger.getLogger("uk.ac.vamsas");
579 lvclient.setLevel(Level.toLevel(Cache.getDefault(
580 "logs.Vamsas.Level", Level.INFO.toString())));
582 lvclient.addAppender(log.getAppender("JalviewLogger"));
583 // Tell the user that debug is enabled
584 lvclient.debug("Jalview Vamsas Client Debugging Output Follows.");
586 } catch (Exception e)
588 vamsasJarsArePresent = 0;
589 jalview.bin.Cache.log.debug("Vamsas Classes are not present");
592 return (vamsasJarsArePresent > 0);
596 * internal vamsas class discovery state
598 private static int groovyJarsArePresent = -1;
601 * Searches for vamsas client classes on class path.
603 * @return true if vamsas client is present on classpath
605 public static boolean groovyJarsPresent()
607 if (groovyJarsArePresent == -1)
611 if (Cache.class.getClassLoader().loadClass(
612 "groovy.lang.GroovyObject") != null)
614 jalview.bin.Cache.log
615 .debug("Found Groovy (groovy.lang.GroovyObject can be loaded)");
616 groovyJarsArePresent = 1;
617 Logger lgclient = Logger.getLogger("groovy");
618 lgclient.setLevel(Level.toLevel(Cache.getDefault(
619 "logs.Groovy.Level", Level.INFO.toString())));
621 lgclient.addAppender(log.getAppender("JalviewLogger"));
622 // Tell the user that debug is enabled
623 lgclient.debug("Jalview Groovy Client Debugging Output Follows.");
627 groovyJarsArePresent = 0;
628 jalview.bin.Cache.log.debug("Groovy Classes are not present", e);
629 } catch (Exception e)
631 groovyJarsArePresent = 0;
632 jalview.bin.Cache.log.debug("Groovy Classes are not present");
635 return (groovyJarsArePresent > 0);
639 * GA tracker object - actually JGoogleAnalyticsTracker null if tracking not
642 protected static Object tracker = null;
644 protected static Class trackerfocus = null;
646 protected static Class jgoogleanalyticstracker = null;
649 * Initialise the google tracker if it is not done already.
651 public static void initGoogleTracker()
655 if (jgoogleanalyticstracker == null)
657 // try to get the tracker class
660 jgoogleanalyticstracker = Cache.class
663 "com.boxysystems.jgoogleanalytics.JGoogleAnalyticsTracker");
664 trackerfocus = Cache.class.getClassLoader().loadClass(
665 "com.boxysystems.jgoogleanalytics.FocusPoint");
666 } catch (Exception e)
668 log.debug("com.boxysystems.jgoogleanalytics package is not present - tracking not enabled.");
670 jgoogleanalyticstracker = null;
675 // now initialise tracker
676 Exception re = null, ex = null;
678 String vrs = "No Version Accessible";
681 // Google analytics tracking code for Library Finder
682 tracker = jgoogleanalyticstracker.getConstructor(new Class[]
683 { String.class, String.class, String.class }).newInstance(
687 (vrs = jalview.bin.Cache.getProperty("VERSION")
689 + jalview.bin.Cache.getDefault("BUILD_DATE",
690 "unknown")), "UA-9060947-1" });
691 jgoogleanalyticstracker.getMethod("trackAsynchronously",
693 { trackerfocus }).invoke(tracker, new Object[]
694 { trackerfocus.getConstructor(new Class[]
695 { String.class }).newInstance(new Object[]
696 { "Application Started." }) });
697 } catch (RuntimeException e)
700 } catch (Exception e)
707 if (re != null || ex != null || err != null)
712 log.debug("Caught runtime exception in googletracker init:", re);
715 "Failed to initialise GoogleTracker for Jalview Desktop with version "
719 "Whilst initing GoogleTracker for Jalview Desktop version "
727 .println("Debug: Caught runtime exception in googletracker init:"
729 re.printStackTrace();
734 .println("Warning: Failed to initialise GoogleTracker for Jalview Desktop with version "
736 ex.printStackTrace();
742 .println("ERROR: Whilst initing GoogleTracker for Jalview Desktop version "
744 err.printStackTrace();
750 log.debug("Successfully initialised tracker.");
756 * get the user's default colour if available
762 public static Color getDefaultColour(String property, Color defcolour)
764 String colprop = getProperty(property);
769 Color col = jalview.schemes.ColourSchemeProperty
770 .getAWTColorFromName(colprop);
775 col = new jalview.schemes.UserColourScheme(colprop).findColour('A');
776 } catch (Exception ex)
778 log.warn("Couldn't parse '" + colprop + "' as a colour for "
783 return (col == null) ? defcolour : col;
787 * store a colour as a Jalview user default property
792 public static void setColourProperty(String property, Color colour)
794 setProperty(property, jalview.util.Format.getHexString(colour));
797 public static final DateFormat date_format = SimpleDateFormat
798 .getDateTimeInstance();
801 * store a date in a jalview property
806 public static void setDateProperty(String property, Date time)
808 setProperty(property, date_format.format(time));
812 * read a date stored in a jalview property
815 * @return valid date as stored by setDateProperty, or null
818 public static Date getDateProperty(String property)
820 String val = getProperty(property);
825 return date_format.parse(val);
826 } catch (Exception ex)
828 System.err.println("Invalid or corrupt date in property '"
829 + property + "' : value was '" + val + "'");
836 * get and parse a property as an integer. send any parsing problems to
840 * @return null or Integer
842 public static Integer getIntegerProperty(String property)
844 String val = getProperty(property);
845 if (val != null && (val = val.trim()).length() > 0)
849 return Integer.valueOf(val);
850 } catch (NumberFormatException x)
852 System.err.println("Invalid integer in property '" + property
853 + "' (value was '" + val + "')");
859 private static DasSourceRegistryI sourceRegistry = null;
864 * @return instance of the das source registry
866 public static DasSourceRegistryI getDasSourceRegistry()
868 if (sourceRegistry == null)
870 sourceRegistry = new DasSourceRegistry();
872 return sourceRegistry;