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;
27 import java.io.BufferedReader;
29 import java.io.FileInputStream;
30 import java.io.FileOutputStream;
31 import java.io.InputStream;
32 import java.io.InputStreamReader;
33 import java.text.DateFormat;
34 import java.text.SimpleDateFormat;
35 import java.util.Date;
36 import java.util.Properties;
38 import org.apache.log4j.ConsoleAppender;
39 import org.apache.log4j.Level;
40 import org.apache.log4j.Logger;
41 import org.apache.log4j.SimpleLayout;
44 * Stores and retrieves Jalview Application Properties Lists and fields within
45 * list entries are separated by '|' symbols unless otherwise stated (|) clauses
46 * are alternative values for a tag. <br>
48 * Current properties include:
51 * logs.Axis.Level - one of the stringified Levels for log4j controlling the
52 * logging level for axis (used for web services) <br>
54 * <li>logs.Castor.Level - one of the stringified Levels for log4j controlling
55 * the logging level for castor (used for serialization) <br>
57 * <li>logs.Jalview.Level - Cache.log stringified level. <br>
59 * <li>SCREEN_WIDTH</li>
60 * <li>SCREEN_HEIGHT</li>
61 * <li>SCREEN_Y=285</li>
62 * <li>SCREEN_X=371</li>
63 * <li>SHOW_FULLSCREEN boolean</li>
64 * <li>FONT_NAME java font name for alignment text display</li>
65 * <li>FONT_SIZE size of displayed alignment text</li>
66 * <li>FONT_STYLE style of font displayed (sequence labels are always italic)</li>
67 * <li>GAP_SYMBOL character to treat as gap symbol (usually -,.,' ')</li>
68 * <li>LAST_DIRECTORY last directory for browsing alignment</li>
69 * <li>USER_DEFINED_COLOURS list of user defined colour scheme files</li>
70 * <li>SHOW_FULL_ID show id with '/start-end' numbers appended</li>
71 * <li>SHOW_IDENTITY show percentage identity annotation</li>
72 * <li>SHOW_QUALITY show alignment quality annotation</li>
73 * <li>SHOW_ANNOTATIONS show alignment annotation rows</li>
74 * <li>SHOW_CONSERVATION show alignment conservation annotation</li>
75 * <li>SORT_ANNOTATIONS currently either SEQUENCE_AND_TYPE or TYPE_AND_SEQUENCE</li>
76 * <li>CENTRE_COLUMN_LABELS centre the labels at each column in a displayed
78 * <li>DEFAULT_COLOUR default colour scheme to apply for a new alignment</li>
79 * <li>DEFAULT_FILE_FORMAT file format used to save</li>
80 * <li>STARTUP_FILE file loaded on startup (may be a fully qualified url)</li>
81 * <li>SHOW_STARTUP_FILE flag to control loading of startup file</li>
82 * <li>VERSION the version of the jalview build</li>
83 * <li>BUILD_DATE date of this build</li>
84 * <li>LATEST_VERSION the latest jalview version advertised on the
85 * www.jalview.org</li>
86 * <li>PIR_MODELLER boolean indicating if PIR files are written with MODELLER
88 * <li>(FASTA,MSF,PILEUP,CLUSTAL,BLC,PIR,PFAM)_JVSUFFIX boolean for adding jv
90 * <li>RECENT_URL list of recently retrieved URLs</li>
91 * <li>RECENT_FILE list of recently opened files</li>
92 * <li>USE_PROXY flag for whether a http proxy is to be used</li>
93 * <li>PROXY_SERVER the proxy</li>
95 * <li>NOQUESTIONNAIRES true to prevent jalview from checking the questionnaire
97 * <li>QUESTIONNAIRE last questionnaire:responder id string from questionnaire
99 * <li>USAGESTATS (false - user prompted) Enable google analytics tracker for
100 * collecting usage statistics</li>
101 * <li>DAS_LOCAL_SOURCE list of local das sources</li>
102 * <li>SHOW_OVERVIEW boolean for overview window display</li>
103 * <li>ANTI_ALIAS boolean for smooth fonts</li>
104 * <li>RIGHT_ALIGN_IDS boolean</li>
105 * <li>AUTO_CALC_CONSENSUS boolean for automatic recalculation of consensus</li>
106 * <li>PAD_GAPS boolean</li>
107 * <li>ID_ITALICS boolean</li>
108 * <li>SHOW_JV_SUFFIX</li>
109 * <li>WRAP_ALIGNMENT</li>
110 * <li>EPS_RENDERING (Prompt each time|Lineart|Text) default for EPS rendering
112 * <li>SORT_ALIGNMENT (No sort|Id|Pairwise Identity)</li>
113 * <li>SEQUENCE_LINKS list of name|URL pairs for opening a url with
115 * <li>GROUP_LINKS list of name|URL[|<separator>] tuples - see
116 * jalview.utils.GroupURLLink for more info</li>
117 * <li>DAS_REGISTRY_URL the registry to query</li>
118 * <li>DEFAULT_BROWSER for unix</li>
119 * <li>DAS_ACTIVE_SOURCE list of active sources</li>
120 * <li>SHOW_MEMUSAGE boolean show memory usage and warning indicator on desktop
122 * <li>VERSION_CHECK (true) check for the latest release version from
123 * www.jalview.org (or the alias given by the www.jalview.org property)</li>
124 * <li>SHOW_NPFEATS_TOOLTIP (true) show non-positional features in the Sequence
126 * <li>SHOW_DBREFS_TOOLTIP (true) show Database Cross References in the Sequence
128 * <li>SHOW_UNCONSERVED (false) only render unconserved residues - conserved
129 * displayed as '.'</li>
130 * <li>SORT_BY_TREE (false) sort the current alignment view according to the
131 * order of a newly displayed tree</li>
132 * <li>DBFETCH_USEPICR (false) use PICR to recover valid DB references from
133 * sequence ID strings before attempting retrieval from any datasource</li>
134 * <li>SHOW_GROUP_CONSENSUS (false) Show consensus annotation for groups in the
136 * <li>SHOW_GROUP_CONSERVATION (false) Show conservation annotation for groups
137 * in the alignment.</li>
138 * <li>SHOW_CONSENSUS_HISTOGRAM (false) Show consensus annotation row's
140 * <li>SHOW_CONSENSUS_LOGO (false) Show consensus annotation row's sequence
142 * <li>NORMALISE_CONSENSUS_LOGO (false) Show consensus annotation row's sequence
143 * logo normalised to row height rather than histogram height.</li>
144 * <li>FOLLOW_SELECTIONS (true) Controls whether a new alignment view should
145 * respond to selections made in other alignments containing the same sequences.
147 * <li>SHOW_WSDISCOVERY_ERRORS (true) Controls if the web service URL discovery
148 * warning dialog box is displayed.</li>
149 * <li>ANNOTATIONCOLOUR_MIN (orange) Shade used for minimum value of annotation
150 * when shading by annotation</li>
151 * <li>ANNOTATIONCOLOUR_MAX (red) Shade used for maximum value of annotation
152 * when shading by annotation</li>
153 * <li>www.jalview.org (http://www.jalview.org) a property enabling all HTTP
154 * requests to be redirected to a mirror of http://www.jalview.org</li>
156 * <li>FIGURE_AUTOIDWIDTH (false) Expand the left hand column of an exported
157 * alignment figure to accommodate even the longest sequence ID or annotation
159 * <li>FIGURE_FIXEDIDWIDTH Specifies the width to use for the left-hand column
160 * when exporting an alignment as a figure (setting FIGURE_AUTOIDWIDTH to true
161 * will override this).</li>
165 * Deprecated settings:
168 * <li>DISCOVERY_START - Boolean - controls if discovery services are queried on
169 * startup (JWS1 services only)</li>
170 * <li>DISCOVERY_URLS - comma separated list of Discovery Service endpoints.
171 * (JWS1 services only)</li>
172 * <li>SHOW_JWS1_SERVICES (true) enable or disable the original Jalview 2
173 * services in the desktop GUI</li>
174 * <li>ENABLE_RSBS_EDITOR (false for 2.7 release) enable or disable RSBS editing
175 * panel in web service preferences</li>
179 * @version $Revision$
184 * property giving log4j level for CASTOR loggers
186 public static final String CASTORLOGLEVEL = "logs.Castor.level";
189 * property giving log4j level for AXIS loggers
191 public static final String AXISLOGLEVEL = "logs.Axis.level";
194 * property giving log4j level for Jalview Log
196 public static final String JALVIEWLOGLEVEL = "logs.Jalview.level";
198 public static final String DAS_LOCAL_SOURCE = "DAS_LOCAL_SOURCE";
200 public static final String DAS_REGISTRY_URL = "DAS_REGISTRY_URL";
202 public static final String DAS_ACTIVE_SOURCE = "DAS_ACTIVE_SOURCE";
205 * Initialises the Jalview Application Log
207 public static Logger log;
209 /** Jalview Properties */
210 public static Properties applicationProperties = new Properties();
212 /** Default file is ~/.jalview_properties */
213 static String propertiesFile;
215 private static boolean propsAreReadOnly = false;
217 public static void initLogger()
225 // TODO: redirect stdout and stderr here in order to grab the output of
228 ConsoleAppender ap = new ConsoleAppender(new SimpleLayout(),
230 ap.setName("JalviewLogger");
231 org.apache.log4j.Logger.getRootLogger().addAppender(ap); // catch all for
233 Logger laxis = Logger.getLogger("org.apache.axis");
234 Logger lcastor = Logger.getLogger("org.exolab.castor");
235 jalview.bin.Cache.log = Logger.getLogger("jalview.bin.Jalview");
237 laxis.setLevel(Level.toLevel(Cache.getDefault("logs.Axis.Level",
238 Level.INFO.toString())));
239 lcastor.setLevel(Level.toLevel(Cache.getDefault("logs.Castor.Level",
240 Level.INFO.toString())));
241 lcastor = Logger.getLogger("org.exolab.castor.xml");
242 lcastor.setLevel(Level.toLevel(Cache.getDefault("logs.Castor.Level",
243 Level.INFO.toString())));
244 // lcastor = Logger.getLogger("org.exolab.castor.xml.Marshaller");
245 // lcastor.setLevel(Level.toLevel(Cache.getDefault("logs.Castor.Level",
246 // Level.INFO.toString())));
247 jalview.bin.Cache.log.setLevel(Level.toLevel(Cache.getDefault(
248 "logs.Jalview.level", Level.INFO.toString())));
249 // laxis.addAppender(ap);
250 // lcastor.addAppender(ap);
251 // jalview.bin.Cache.log.addAppender(ap);
252 // Tell the user that debug is enabled
253 jalview.bin.Cache.log.debug("Jalview Debugging Output Follows.");
254 } catch (Exception ex)
256 System.err.println("Problems initializing the log4j system\n");
257 ex.printStackTrace(System.err);
261 /** Called when Jalview is started */
262 public static void loadProperties(String propsFile)
264 propertiesFile = propsFile;
265 if (propsFile == null)
267 propertiesFile = System.getProperty("user.home") + File.separatorChar
268 + ".jalview_properties";
272 // don't corrupt the file we've been given.
273 propsAreReadOnly = true;
281 fis = new java.net.URL(propertiesFile).openStream();
282 System.out.println("Loading jalview properties from : "
285 .println("Disabling Jalview writing to user's local properties file.");
286 propsAreReadOnly = true;
288 } catch (Exception ex)
294 fis = new FileInputStream(propertiesFile);
296 applicationProperties.load(fis);
298 // remove any old build properties
300 deleteBuildProperties();
302 } catch (Exception ex)
304 System.out.println("Error reading properties file: " + ex);
307 if (getDefault("USE_PROXY", false))
309 String proxyServer = getDefault("PROXY_SERVER", ""), proxyPort = getDefault(
310 "PROXY_PORT", "8080");
312 System.out.println("Using proxyServer: " + proxyServer
313 + " proxyPort: " + proxyPort);
315 System.setProperty("http.proxyHost", proxyServer);
316 System.setProperty("http.proxyPort", proxyPort);
319 // LOAD THE AUTHORS FROM THE authors.props file
322 String authorDetails = "jar:".concat(Cache.class
323 .getProtectionDomain().getCodeSource().getLocation()
324 .toString().concat("!/authors.props"));
326 java.net.URL localJarFileURL = new java.net.URL(authorDetails);
328 InputStream in = localJarFileURL.openStream();
329 applicationProperties.load(in);
331 } catch (Exception ex)
333 System.out.println("Error reading author details: " + ex);
334 applicationProperties.remove("AUTHORS");
335 applicationProperties.remove("AUTHORFNAMES");
336 applicationProperties.remove("YEAR");
339 // FIND THE VERSION NUMBER AND BUILD DATE FROM jalview.jar
340 // MUST FOLLOW READING OF LOCAL PROPERTIES FILE AS THE
341 // VERSION MAY HAVE CHANGED SINCE LAST USING JALVIEW
344 String buildDetails = "jar:".concat(Cache.class.getProtectionDomain()
345 .getCodeSource().getLocation().toString()
346 .concat("!/.build_properties"));
348 java.net.URL localJarFileURL = new java.net.URL(buildDetails);
350 InputStream in = localJarFileURL.openStream();
351 applicationProperties.load(in);
353 } catch (Exception ex)
355 System.out.println("Error reading build details: " + ex);
356 applicationProperties.remove("VERSION");
359 String jnlpVersion = System.getProperty("jalview.version");
360 String codeVersion = getProperty("VERSION");
362 if (codeVersion == null)
364 // THIS SHOULD ONLY BE THE CASE WHEN TESTING!!
365 codeVersion = "Test";
366 jnlpVersion = "Test";
369 System.out.println("Jalview Version: " + codeVersion);
371 // jnlpVersion will be null if we're using InstallAnywhere
372 // Dont do this check if running in headless mode
373 if (jnlpVersion == null
374 && getDefault("VERSION_CHECK", true)
375 && (System.getProperty("java.awt.headless") == null || System
376 .getProperty("java.awt.headless").equals("false")))
379 class VersionChecker extends Thread
383 String orgtimeout = System
384 .getProperty("sun.net.client.defaultConnectTimeout");
385 if (orgtimeout == null)
388 System.out.println("# INFO: Setting default net timeout to "
389 + orgtimeout + " seconds.");
391 String jnlpVersion = null;
394 System.setProperty("sun.net.client.defaultConnectTimeout",
396 java.net.URL url = new java.net.URL(Cache.getDefault(
397 "www.jalview.org", "http://www.jalview.org")
398 + "/webstart/jalview.jnlp");
399 BufferedReader in = new BufferedReader(new InputStreamReader(
402 while ((line = in.readLine()) != null)
404 if (line.indexOf("jalview.version") == -1)
409 line = line.substring(line.indexOf("value=") + 7);
410 line = line.substring(0, line.lastIndexOf("\""));
414 } catch (Exception ex)
417 .println("Non-fatal exceptions when checking version at www.jalview.org :");
418 System.out.println(ex);
419 jnlpVersion = getProperty("VERSION");
421 System.setProperty("sun.net.client.defaultConnectTimeout",
424 setProperty("LATEST_VERSION", jnlpVersion);
428 VersionChecker vc = new VersionChecker();
433 if (jnlpVersion != null)
435 setProperty("LATEST_VERSION", jnlpVersion);
439 applicationProperties.remove("LATEST_VERSION");
443 setProperty("VERSION", codeVersion);
445 // LOAD USERDEFINED COLOURS
446 jalview.gui.UserDefinedColours
447 .initUserColourSchemes(getProperty("USER_DEFINED_COLOURS"));
448 jalview.io.PIRFile.useModellerOutput = Cache.getDefault("PIR_MODELLER",
452 private static void deleteBuildProperties()
454 applicationProperties.remove("LATEST_VERSION");
455 applicationProperties.remove("VERSION");
456 applicationProperties.remove("AUTHORS");
457 applicationProperties.remove("AUTHORFNAMES");
458 applicationProperties.remove("YEAR");
462 * Gets Jalview application property of given key. Returns null if key not
468 * @return Property value
470 public static String getProperty(String key)
472 return applicationProperties.getProperty(key);
476 * These methods are used when checking if the saved preference is different
477 * to the default setting
480 public static boolean getDefault(String property, boolean def)
482 String string = getProperty(property);
485 def = Boolean.valueOf(string).booleanValue();
492 * These methods are used when checking if the saved preference is different
493 * to the default setting
495 public static String getDefault(String property, String def)
497 String string = getProperty(property);
507 * Stores property in the file "HOME_DIR/.jalview_properties"
512 * String value of property
514 * @return String value of property
516 public static String setProperty(String key, String obj)
521 applicationProperties.setProperty(key, obj);
522 if (!propsAreReadOnly)
524 FileOutputStream out = new FileOutputStream(propertiesFile);
525 applicationProperties.store(out, "---JalviewX Properties File---");
528 } catch (Exception ex)
530 System.out.println("Error setting property: " + key + " " + obj
537 * remove the specified property from the jalview properties file
541 public static void removeProperty(String string)
543 applicationProperties.remove(string);
548 * save the properties to the jalview properties path
550 public static void saveProperties()
552 if (!propsAreReadOnly)
556 FileOutputStream out = new FileOutputStream(propertiesFile);
557 applicationProperties.store(out, "---JalviewX Properties File---");
559 } catch (Exception ex)
561 System.out.println("Error saving properties: " + ex);
567 * internal vamsas class discovery state
569 private static int vamsasJarsArePresent = -1;
572 * Searches for vamsas client classes on class path.
574 * @return true if vamsas client is present on classpath
576 public static boolean vamsasJarsPresent()
578 if (vamsasJarsArePresent == -1)
582 if (jalview.jbgui.GDesktop.class.getClassLoader().loadClass(
583 "uk.ac.vamsas.client.VorbaId") != null)
585 jalview.bin.Cache.log
586 .debug("Found Vamsas Classes (uk.ac..vamsas.client.VorbaId can be loaded)");
587 vamsasJarsArePresent = 1;
588 Logger lvclient = Logger.getLogger("uk.ac.vamsas");
589 lvclient.setLevel(Level.toLevel(Cache.getDefault(
590 "logs.Vamsas.Level", Level.INFO.toString())));
592 lvclient.addAppender(log.getAppender("JalviewLogger"));
593 // Tell the user that debug is enabled
594 lvclient.debug("Jalview Vamsas Client Debugging Output Follows.");
596 } catch (Exception e)
598 vamsasJarsArePresent = 0;
599 jalview.bin.Cache.log.debug("Vamsas Classes are not present");
602 return (vamsasJarsArePresent > 0);
606 * internal vamsas class discovery state
608 private static int groovyJarsArePresent = -1;
611 * Searches for vamsas client classes on class path.
613 * @return true if vamsas client is present on classpath
615 public static boolean groovyJarsPresent()
617 if (groovyJarsArePresent == -1)
621 if (Cache.class.getClassLoader().loadClass(
622 "groovy.lang.GroovyObject") != null)
624 jalview.bin.Cache.log
625 .debug("Found Groovy (groovy.lang.GroovyObject can be loaded)");
626 groovyJarsArePresent = 1;
627 Logger lgclient = Logger.getLogger("groovy");
628 lgclient.setLevel(Level.toLevel(Cache.getDefault(
629 "logs.Groovy.Level", Level.INFO.toString())));
631 lgclient.addAppender(log.getAppender("JalviewLogger"));
632 // Tell the user that debug is enabled
633 lgclient.debug("Jalview Groovy Client Debugging Output Follows.");
637 groovyJarsArePresent = 0;
638 jalview.bin.Cache.log.debug("Groovy Classes are not present", e);
639 } catch (Exception e)
641 groovyJarsArePresent = 0;
642 jalview.bin.Cache.log.debug("Groovy Classes are not present");
645 return (groovyJarsArePresent > 0);
649 * GA tracker object - actually JGoogleAnalyticsTracker null if tracking not
652 protected static Object tracker = null;
654 protected static Class trackerfocus = null;
656 protected static Class jgoogleanalyticstracker = null;
659 * Initialise the google tracker if it is not done already.
661 public static void initGoogleTracker()
665 if (jgoogleanalyticstracker == null)
667 // try to get the tracker class
670 jgoogleanalyticstracker = Cache.class
673 "com.boxysystems.jgoogleanalytics.JGoogleAnalyticsTracker");
674 trackerfocus = Cache.class.getClassLoader().loadClass(
675 "com.boxysystems.jgoogleanalytics.FocusPoint");
676 } catch (Exception e)
678 log.debug("com.boxysystems.jgoogleanalytics package is not present - tracking not enabled.");
680 jgoogleanalyticstracker = null;
685 // now initialise tracker
686 Exception re = null, ex = null;
688 String vrs = "No Version Accessible";
691 // Google analytics tracking code for Library Finder
692 tracker = jgoogleanalyticstracker.getConstructor(new Class[]
693 { String.class, String.class, String.class }).newInstance(
697 (vrs = jalview.bin.Cache.getProperty("VERSION")
699 + jalview.bin.Cache.getDefault("BUILD_DATE",
700 "unknown")), "UA-9060947-1" });
701 jgoogleanalyticstracker.getMethod("trackAsynchronously",
703 { trackerfocus }).invoke(tracker, new Object[]
704 { trackerfocus.getConstructor(new Class[]
705 { String.class }).newInstance(new Object[]
706 { "Application Started." }) });
707 } catch (RuntimeException e)
710 } catch (Exception e)
717 if (re != null || ex != null || err != null)
723 log.debug("Caught runtime exception in googletracker init:", re);
728 "Failed to initialise GoogleTracker for Jalview Desktop with version "
734 "Whilst initing GoogleTracker for Jalview Desktop version "
743 .println("Debug: Caught runtime exception in googletracker init:"
745 re.printStackTrace();
750 .println("Warning: Failed to initialise GoogleTracker for Jalview Desktop with version "
752 ex.printStackTrace();
758 .println("ERROR: Whilst initing GoogleTracker for Jalview Desktop version "
760 err.printStackTrace();
766 log.debug("Successfully initialised tracker.");
772 * get the user's default colour if available
778 public static Color getDefaultColour(String property, Color defcolour)
780 String colprop = getProperty(property);
785 Color col = jalview.schemes.ColourSchemeProperty
786 .getAWTColorFromName(colprop);
791 col = new jalview.schemes.UserColourScheme(colprop).findColour('A');
792 } catch (Exception ex)
794 log.warn("Couldn't parse '" + colprop + "' as a colour for "
799 return (col == null) ? defcolour : col;
803 * store a colour as a Jalview user default property
808 public static void setColourProperty(String property, Color colour)
810 setProperty(property, jalview.util.Format.getHexString(colour));
813 public static final DateFormat date_format = SimpleDateFormat
814 .getDateTimeInstance();
817 * store a date in a jalview property
822 public static void setDateProperty(String property, Date time)
824 setProperty(property, date_format.format(time));
828 * read a date stored in a jalview property
831 * @return valid date as stored by setDateProperty, or null
834 public static Date getDateProperty(String property)
836 String val = getProperty(property);
841 return date_format.parse(val);
842 } catch (Exception ex)
844 System.err.println("Invalid or corrupt date in property '"
845 + property + "' : value was '" + val + "'");
852 * get and parse a property as an integer. send any parsing problems to
856 * @return null or Integer
858 public static Integer getIntegerProperty(String property)
860 String val = getProperty(property);
861 if (val != null && (val = val.trim()).length() > 0)
865 return Integer.valueOf(val);
866 } catch (NumberFormatException x)
868 System.err.println("Invalid integer in property '" + property
869 + "' (value was '" + val + "')");
875 private static DasSourceRegistryI sourceRegistry = null;
880 * @return instance of the das source registry
882 public static DasSourceRegistryI getDasSourceRegistry()
884 if (sourceRegistry == null)
886 sourceRegistry = new DasSourceRegistry();
888 return sourceRegistry;