2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)
3 * Copyright (C) 2011 J Procter, AM Waterhouse, J Engelhardt, LM Lui, 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/>.
20 import jalview.ws.dbsources.das.api.DasSourceRegistryI;
21 import jalview.ws.dbsources.das.datamodel.DasSourceRegistry;
23 import java.awt.Color;
25 import java.text.DateFormat;
26 import java.text.SimpleDateFormat;
29 import org.apache.log4j.*;
32 * Stores and retrieves Jalview Application Properties Lists and fields within
33 * list entries are separated by '|' symbols unless otherwise stated (|) clauses
34 * are alternative values for a tag. <br>
36 * Current properties include:
39 * logs.Axis.Level - one of the stringified Levels for log4j controlling the
40 * logging level for axis (used for web services) <br>
42 * <li>logs.Castor.Level - one of the stringified Levels for log4j controlling
43 * the logging level for castor (used for serialization) <br>
45 * <li>logs.Jalview.Level - Cache.log stringified level. <br>
47 * <li>SCREEN_WIDTH</li>
48 * <li>SCREEN_HEIGHT</li>
49 * <li>SCREEN_Y=285</li>
50 * <li>SCREEN_X=371</li>
51 * <li>SHOW_FULLSCREEN boolean</li>
52 * <li>FONT_NAME java font name for alignment text display</li>
53 * <li>FONT_SIZE size of displayed alignment text</li>
54 * <li>FONT_STYLE style of font displayed (sequence labels are always italic)</li>
55 * <li>GAP_SYMBOL character to treat as gap symbol (usually -,.,' ')</li>
56 * <li>LAST_DIRECTORY last directory for browsing alignment</li>
57 * <li>USER_DEFINED_COLOURS list of user defined colour scheme files</li>
58 * <li>SHOW_FULL_ID show id with '/start-end' numbers appended</li>
59 * <li>SHOW_IDENTITY show percentage identity annotation</li>
60 * <li>SHOW_QUALITY show alignment quality annotation</li>
61 * <li>SHOW_ANNOTATIONS show alignment annotation rows</li>
62 * <li>SHOW_CONSERVATION show alignment conservation annotation</li>
63 * <li>CENTRE_COLUMN_LABELS centre the labels at each column in a displayed
65 * <li>DEFAULT_COLOUR default colour scheme to apply for a new alignment</li>
66 * <li>DEFAULT_FILE_FORMAT file format used to save</li>
67 * <li>STARTUP_FILE file loaded on startup (may be a fully qualified url)</li>
68 * <li>SHOW_STARTUP_FILE flag to control loading of startup file</li>
69 * <li>VERSION the version of the jalview build</li>
70 * <li>BUILD_DATE date of this build</li>
71 * <li>LATEST_VERSION the latest jalview version advertised on the
72 * www.jalview.org</li>
73 * <li>PIR_MODELLER boolean indicating if PIR files are written with MODELLER
75 * <li>(FASTA,MSF,PILEUP,CLUSTAL,BLC,PIR,PFAM)_JVSUFFIX boolean for adding jv
77 * <li>RECENT_URL list of recently retrieved URLs</li>
78 * <li>RECENT_FILE list of recently opened files</li>
79 * <li>USE_PROXY flag for whether a http proxy is to be used</li>
80 * <li>PROXY_SERVER the proxy</li>
82 * <li>NOQUESTIONNAIRES true to prevent jalview from checking the questionnaire
84 * <li>QUESTIONNAIRE last questionnaire:responder id string from questionnaire
86 * <li>USAGESTATS (false - user prompted) Enable google analytics tracker for
87 * collecting usage statistics</li>
88 * <li>DAS_LOCAL_SOURCE list of local das sources</li>
89 * <li>SHOW_OVERVIEW boolean for overview window display</li>
90 * <li>ANTI_ALIAS boolean for smooth fonts</li>
91 * <li>RIGHT_ALIGN_IDS boolean</li>
92 * <li>AUTO_CALC_CONSENSUS boolean for automatic recalculation of consensus</li>
93 * <li>PAD_GAPS boolean</li>
94 * <li>ID_ITALICS boolean</li>
95 * <li>SHOW_JV_SUFFIX</li>
96 * <li>WRAP_ALIGNMENT</li>
97 * <li>EPS_RENDERING (Prompt each time|Lineart|Text) default for EPS rendering
99 * <li>SORT_ALIGNMENT (No sort|Id|Pairwise Identity)</li>
100 * <li>SEQUENCE_LINKS list of name|URL pairs for opening a url with
102 * <li>GROUP_LINKS list of name|URL[|<separator>] tuples - see
103 * jalview.utils.GroupURLLink for more info</li>
104 * <li>DAS_REGISTRY_URL the registry to query</li>
105 * <li>DEFAULT_BROWSER for unix</li>
106 * <li>DAS_ACTIVE_SOURCE list of active sources</li>
107 * <li>SHOW_MEMUSAGE boolean show memory usage and warning indicator on desktop
109 * <li>VERSION_CHECK (true) check for the latest release version from
110 * www.jalview.org (or the alias given by the www.jalview.org property)</li>
111 * <li>SHOW_NPFEATS_TOOLTIP (true) show non-positional features in the Sequence
113 * <li>SHOW_DBREFS_TOOLTIP (true) show Database Cross References in the Sequence
115 * <li>SHOW_UNCONSERVED (false) only render unconserved residues - conserved
116 * displayed as '.'</li>
117 * <li>SORT_BY_TREE (false) sort the current alignment view according to the
118 * order of a newly displayed tree</li>
119 * <li>DBFETCH_USEPICR (false) use PICR to recover valid DB references from
120 * sequence ID strings before attempting retrieval from any datasource</li>
121 * <li>SHOW_GROUP_CONSENSUS (false) Show consensus annotation for groups in the
123 * <li>SHOW_GROUP_CONSERVATION (false) Show conservation annotation for groups
124 * in the alignment.</li>
125 * <li>SHOW_CONSENSUS_HISTOGRAM (false) Show consensus annotation row's
127 * <li>SHOW_CONSENSUS_LOGO (false) Show consensus annotation row's sequence
129 * <li>NORMALISE_CONSENSUS_LOGO (false) Show consensus annotation row's sequence
130 * logo normalised to row height rather than histogram height.</li>
131 * <li>FOLLOW_SELECTIONS (true) Controls whether a new alignment view should
132 * respond to selections made in other alignments containing the same sequences.
134 * <li>SHOW_WSDISCOVERY_ERRORS (true) Controls if the web service URL discovery
135 * warning dialog box is displayed.</li>
136 * <li>ANNOTATIONCOLOUR_MIN (orange) Shade used for minimum value of annotation when shading by annotation</li>
137 * <li>ANNOTATIONCOLOUR_MAX (red) Shade used for maximum value of annotation when shading by annotation</li>
138 * <li>www.jalview.org (http://www.jalview.org) a property enabling all HTTP requests to be redirected to a mirror of http://www.jalview.org</li>
140 * <li>FIGURE_AUTOIDWIDTH (false) Expand the left hand column of an exported alignment figure to accommodate even the longest sequence ID or annotation label.</li>
141 * <li>FIGURE_FIXEDIDWIDTH Specifies the width to use for the left-hand column when exporting an alignment as a figure (setting FIGURE_AUTOIDWIDTH to true will override this).</li>
145 * Deprecated settings:
147 * * <li>DISCOVERY_START - Boolean - controls if discovery services are queried on
148 * startup (JWS1 services only)</li>
149 * <li>DISCOVERY_URLS - comma separated list of Discovery Service endpoints. (JWS1 services only)</li>
150 * <li>SHOW_JWS1_SERVICES (true) enable or disable the original Jalview 2 services in the desktop GUI</li>
151 * <li>ENABLE_RSBS_EDITOR (false for 2.7 release) enable or disable RSBS editing panel in web service preferences</li>
154 * @version $Revision$
159 * property giving log4j level for CASTOR loggers
161 public static final String CASTORLOGLEVEL = "logs.Castor.level";
164 * property giving log4j level for AXIS loggers
166 public static final String AXISLOGLEVEL = "logs.Axis.level";
169 * property giving log4j level for Jalview Log
171 public static final String JALVIEWLOGLEVEL = "logs.Jalview.level";
173 public static final String DAS_LOCAL_SOURCE = "DAS_LOCAL_SOURCE";
175 public static final String DAS_REGISTRY_URL = "DAS_REGISTRY_URL";
177 public static final String DAS_ACTIVE_SOURCE = "DAS_ACTIVE_SOURCE";
180 * Initialises the Jalview Application Log
182 public static Logger log;
184 /** Jalview Properties */
185 public static Properties applicationProperties = new Properties();
187 /** Default file is ~/.jalview_properties */
188 static String propertiesFile;
190 private static boolean propsAreReadOnly=false;
192 public static void initLogger()
200 // TODO: redirect stdout and stderr here in order to grab the output of
203 ConsoleAppender ap = new ConsoleAppender(new SimpleLayout(),
205 ap.setName("JalviewLogger");
206 org.apache.log4j.Logger.getRootLogger().addAppender(ap); // catch all for
208 Logger laxis = Logger.getLogger("org.apache.axis");
209 Logger lcastor = Logger.getLogger("org.exolab.castor");
210 jalview.bin.Cache.log = Logger.getLogger("jalview.bin.Jalview");
212 laxis.setLevel(Level.toLevel(Cache.getDefault("logs.Axis.Level",
213 Level.INFO.toString())));
214 lcastor.setLevel(Level.toLevel(Cache.getDefault("logs.Castor.Level",
215 Level.INFO.toString())));
216 lcastor = Logger.getLogger("org.exolab.castor.xml");
217 lcastor.setLevel(Level.toLevel(Cache.getDefault("logs.Castor.Level",
218 Level.INFO.toString())));
219 // lcastor = Logger.getLogger("org.exolab.castor.xml.Marshaller");
220 // lcastor.setLevel(Level.toLevel(Cache.getDefault("logs.Castor.Level",
221 // Level.INFO.toString())));
222 jalview.bin.Cache.log.setLevel(Level.toLevel(Cache.getDefault(
223 "logs.Jalview.level", Level.INFO.toString())));
224 // laxis.addAppender(ap);
225 // lcastor.addAppender(ap);
226 // jalview.bin.Cache.log.addAppender(ap);
227 // Tell the user that debug is enabled
228 jalview.bin.Cache.log.debug("Jalview Debugging Output Follows.");
229 } catch (Exception ex)
231 System.err.println("Problems initializing the log4j system\n");
232 ex.printStackTrace(System.err);
236 /** Called when Jalview is started */
237 public static void loadProperties(String propsFile)
239 propertiesFile = propsFile;
240 if (propsFile == null)
242 propertiesFile = System.getProperty("user.home") + File.separatorChar
243 + ".jalview_properties";
245 // don't corrupt the file we've been given.
246 propsAreReadOnly = true;
254 fis = new java.net.URL(propertiesFile).openStream();
255 System.out.println("Loading jalview properties from : "
258 .println("Disabling Jalview writing to user's local properties file.");
259 propsAreReadOnly = true;
261 } catch (Exception ex)
267 fis = new FileInputStream(propertiesFile);
269 applicationProperties.load(fis);
270 applicationProperties.remove("LATEST_VERSION");
271 applicationProperties.remove("VERSION");
273 } catch (Exception ex)
275 System.out.println("Error reading properties file: " + ex);
278 if (getDefault("USE_PROXY", false))
280 System.out.println("Using proxyServer: "
281 + getDefault("PROXY_SERVER", null) + " proxyPort: "
282 + getDefault("PROXY_PORT", null));
283 System.setProperty("http.proxyHost", getDefault("PROXY_SERVER", null));
284 System.setProperty("http.proxyPort", getDefault("PROXY_PORT", null));
287 // LOAD THE AUTHORS FROM THE authors.props file
290 String authorDetails = "jar:".concat(Cache.class.getProtectionDomain()
291 .getCodeSource().getLocation().toString()
292 .concat("!/authors.props"));
294 java.net.URL localJarFileURL = new java.net.URL(authorDetails);
296 InputStream in = localJarFileURL.openStream();
297 applicationProperties.load(in);
299 } catch (Exception ex)
301 System.out.println("Error reading author details: " + ex);
302 applicationProperties.remove("AUTHORS");
303 applicationProperties.remove("AUTHORFNAMES");
304 applicationProperties.remove("YEAR");
307 // FIND THE VERSION NUMBER AND BUILD DATE FROM jalview.jar
308 // MUST FOLLOW READING OF LOCAL PROPERTIES FILE AS THE
309 // VERSION MAY HAVE CHANGED SINCE LAST USING JALVIEW
312 String buildDetails = "jar:".concat(Cache.class.getProtectionDomain()
313 .getCodeSource().getLocation().toString()
314 .concat("!/.build_properties"));
316 java.net.URL localJarFileURL = new java.net.URL(buildDetails);
318 InputStream in = localJarFileURL.openStream();
319 applicationProperties.load(in);
321 } catch (Exception ex)
323 System.out.println("Error reading build details: " + ex);
324 applicationProperties.remove("VERSION");
327 String jnlpVersion = System.getProperty("jalview.version");
328 String codeVersion = getProperty("VERSION");
330 if (codeVersion == null)
332 // THIS SHOULD ONLY BE THE CASE WHEN TESTING!!
333 codeVersion = "Test";
334 jnlpVersion = "Test";
337 System.out.println("Jalview Version: " + codeVersion);
339 // jnlpVersion will be null if we're using InstallAnywhere
340 // Dont do this check if running in headless mode
341 if (jnlpVersion == null
342 && getDefault("VERSION_CHECK", true)
343 && (System.getProperty("java.awt.headless") == null || System
344 .getProperty("java.awt.headless").equals("false")))
347 class VersionChecker extends Thread
351 String orgtimeout = System
352 .getProperty("sun.net.client.defaultConnectTimeout");
353 if (orgtimeout == null)
356 System.out.println("# INFO: Setting default net timeout to "
357 + orgtimeout + " seconds.");
359 String jnlpVersion = null;
362 System.setProperty("sun.net.client.defaultConnectTimeout",
364 java.net.URL url = new java.net.URL(
365 Cache.getDefault("www.jalview.org", "http://www.jalview.org")+"/webstart/jalview.jnlp");
366 BufferedReader in = new BufferedReader(new InputStreamReader(
369 while ((line = in.readLine()) != null)
371 if (line.indexOf("jalview.version") == -1)
376 line = line.substring(line.indexOf("value=") + 7);
377 line = line.substring(0, line.lastIndexOf("\""));
381 } catch (Exception ex)
384 .println("Non-fatal exceptions when checking version at www.jalview.org :");
385 System.out.println(ex);
386 jnlpVersion = getProperty("VERSION");
388 System.setProperty("sun.net.client.defaultConnectTimeout",
391 setProperty("LATEST_VERSION", jnlpVersion);
395 VersionChecker vc = new VersionChecker();
400 if (jnlpVersion != null)
402 setProperty("LATEST_VERSION", jnlpVersion);
406 applicationProperties.remove("LATEST_VERSION");
410 setProperty("VERSION", codeVersion);
412 // LOAD USERDEFINED COLOURS
413 jalview.gui.UserDefinedColours
414 .initUserColourSchemes(getProperty("USER_DEFINED_COLOURS"));
415 jalview.io.PIRFile.useModellerOutput = Cache.getDefault("PIR_MODELLER",
420 * Gets Jalview application property of given key. Returns null if key not
426 * @return Property value
428 public static String getProperty(String key)
430 return applicationProperties.getProperty(key);
434 * These methods are used when checking if the saved preference is different
435 * to the default setting
438 public static boolean getDefault(String property, boolean def)
440 String string = getProperty(property);
443 def = Boolean.valueOf(string).booleanValue();
450 * These methods are used when checking if the saved preference is different
451 * to the default setting
453 public static String getDefault(String property, String def)
455 String string = getProperty(property);
465 * Stores property in the file "HOME_DIR/.jalview_properties"
470 * String value of property
472 * @return String value of property
474 public static String setProperty(String key, String obj)
479 applicationProperties.setProperty(key, obj);
480 if (!propsAreReadOnly)
482 FileOutputStream out = new FileOutputStream(propertiesFile);
483 applicationProperties.store(out, "---JalviewX Properties File---");
486 } catch (Exception ex)
488 System.out.println("Error setting property: " + key + " " + obj
495 * remove the specified property from the jalview properties file
499 public static void removeProperty(String string)
501 applicationProperties.remove(string);
506 * save the properties to the jalview properties path
508 public static void saveProperties()
510 if (!propsAreReadOnly)
514 FileOutputStream out = new FileOutputStream(propertiesFile);
515 applicationProperties.store(out, "---JalviewX Properties File---");
517 } catch (Exception ex)
519 System.out.println("Error saving properties: " + ex);
525 * internal vamsas class discovery state
527 private static int vamsasJarsArePresent = -1;
530 * Searches for vamsas client classes on class path.
532 * @return true if vamsas client is present on classpath
534 public static boolean vamsasJarsPresent()
536 if (vamsasJarsArePresent == -1)
540 if (jalview.jbgui.GDesktop.class.getClassLoader().loadClass(
541 "uk.ac.vamsas.client.VorbaId") != null)
543 jalview.bin.Cache.log
544 .debug("Found Vamsas Classes (uk.ac..vamsas.client.VorbaId can be loaded)");
545 vamsasJarsArePresent = 1;
546 Logger lvclient = Logger.getLogger("uk.ac.vamsas");
547 lvclient.setLevel(Level.toLevel(Cache.getDefault(
548 "logs.Vamsas.Level", Level.INFO.toString())));
550 lvclient.addAppender(log.getAppender("JalviewLogger"));
551 // Tell the user that debug is enabled
552 lvclient.debug("Jalview Vamsas Client Debugging Output Follows.");
554 } catch (Exception e)
556 vamsasJarsArePresent = 0;
557 jalview.bin.Cache.log.debug("Vamsas Classes are not present");
560 return (vamsasJarsArePresent > 0);
564 * internal vamsas class discovery state
566 private static int groovyJarsArePresent = -1;
569 * Searches for vamsas client classes on class path.
571 * @return true if vamsas client is present on classpath
573 public static boolean groovyJarsPresent()
575 if (groovyJarsArePresent == -1)
579 if (Cache.class.getClassLoader().loadClass(
580 "groovy.lang.GroovyObject") != null)
582 jalview.bin.Cache.log
583 .debug("Found Groovy (groovy.lang.GroovyObject can be loaded)");
584 groovyJarsArePresent = 1;
585 Logger lgclient = Logger.getLogger("groovy");
586 lgclient.setLevel(Level.toLevel(Cache.getDefault(
587 "logs.Groovy.Level", Level.INFO.toString())));
589 lgclient.addAppender(log.getAppender("JalviewLogger"));
590 // Tell the user that debug is enabled
591 lgclient.debug("Jalview Groovy Client Debugging Output Follows.");
595 groovyJarsArePresent = 0;
596 jalview.bin.Cache.log.debug("Groovy Classes are not present", e);
597 } catch (Exception e)
599 groovyJarsArePresent = 0;
600 jalview.bin.Cache.log.debug("Groovy Classes are not present");
603 return (groovyJarsArePresent > 0);
607 * GA tracker object - actually JGoogleAnalyticsTracker null if tracking not
610 protected static Object tracker = null;
612 protected static Class trackerfocus = null;
614 protected static Class jgoogleanalyticstracker = null;
617 * Initialise the google tracker if it is not done already.
619 public static void initGoogleTracker()
623 if (jgoogleanalyticstracker == null)
625 // try to get the tracker class
628 jgoogleanalyticstracker = Cache.class
631 "com.boxysystems.jgoogleanalytics.JGoogleAnalyticsTracker");
632 trackerfocus = Cache.class.getClassLoader().loadClass(
633 "com.boxysystems.jgoogleanalytics.FocusPoint");
634 } catch (Exception e)
636 log.debug("com.boxysystems.jgoogleanalytics package is not present - tracking not enabled.");
638 jgoogleanalyticstracker = null;
643 // now initialise tracker
644 Exception re = null, ex = null;
646 String vrs = "No Version Accessible";
649 // Google analytics tracking code for Library Finder
650 tracker = jgoogleanalyticstracker.getConstructor(new Class[]
651 { String.class, String.class, String.class }).newInstance(
655 (vrs = jalview.bin.Cache.getProperty("VERSION")
657 + jalview.bin.Cache.getDefault("BUILD_DATE",
658 "unknown")), "UA-9060947-1" });
659 jgoogleanalyticstracker.getMethod("trackAsynchronously",
661 { trackerfocus }).invoke(tracker, new Object[]
662 { trackerfocus.getConstructor(new Class[]
663 { String.class }).newInstance(new Object[]
664 { "Application Started." }) });
665 } catch (RuntimeException e)
668 } catch (Exception e)
675 if (re != null || ex != null || err != null)
680 log.debug("Caught runtime exception in googletracker init:", re);
683 "Failed to initialise GoogleTracker for Jalview Desktop with version "
687 "Whilst initing GoogleTracker for Jalview Desktop version "
695 .println("Debug: Caught runtime exception in googletracker init:"
697 re.printStackTrace();
702 .println("Warning: Failed to initialise GoogleTracker for Jalview Desktop with version "
704 ex.printStackTrace();
710 .println("ERROR: Whilst initing GoogleTracker for Jalview Desktop version "
712 err.printStackTrace();
718 log.debug("Successfully initialised tracker.");
724 * get the user's default colour if available
729 public static Color getDefaultColour(String property, Color defcolour)
731 String colprop = getProperty(property);
735 Color col = jalview.schemes.ColourSchemeProperty.getAWTColorFromName(colprop);
739 col = new jalview.schemes.UserColourScheme(colprop).findColour('A');
740 } catch (Exception ex)
742 log.warn("Couldn't parse '"+colprop+"' as a colour for "+property);
746 return (col==null) ? defcolour: col;
750 * store a colour as a Jalview user default property
754 public static void setColourProperty(String property, Color colour)
756 setProperty(property, jalview.util.Format
757 .getHexString(colour));
760 public static final DateFormat date_format = SimpleDateFormat.getDateTimeInstance();
763 * store a date in a jalview property
767 public static void setDateProperty(String property, Date time)
769 setProperty(property, date_format.format(time));
772 * read a date stored in a jalview property
774 * @return valid date as stored by setDateProperty, or null
777 public static Date getDateProperty(String property)
779 String val = getProperty(property);
783 return date_format.parse(val);
784 } catch (Exception ex)
786 System.err.println("Invalid or corrupt date in property '"+property+"' : value was '"+val+"'");
793 * get and parse a property as an integer. send any parsing problems to System.err
795 * @return null or Integer
797 public static Integer getIntegerProperty(String property)
799 String val=getProperty(property);
800 if (val!=null && (val=val.trim()).length()>0)
803 return Integer.valueOf(val);
804 } catch (NumberFormatException x)
806 System.err.println("Invalid integer in property '"+property+"' (value was '"+val+"')");
812 private static DasSourceRegistryI sourceRegistry=null;
815 * @return instance of the das source registry
817 public static DasSourceRegistryI getDasSourceRegistry()
819 if (sourceRegistry==null)
821 sourceRegistry = new DasSourceRegistry();
823 return sourceRegistry;