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 java.awt.Color;
22 import java.text.DateFormat;
23 import java.text.SimpleDateFormat;
26 import org.apache.log4j.*;
27 import org.biojava.dasobert.dasregistry.Das1Source;
30 * Stores and retrieves Jalview Application Properties Lists and fields within
31 * list entries are separated by '|' symbols unless otherwise stated (|) clauses
32 * are alternative values for a tag. <br>
34 * Current properties include:
37 * logs.Axis.Level - one of the stringified Levels for log4j controlling the
38 * logging level for axis (used for web services) <br>
40 * <li>logs.Castor.Level - one of the stringified Levels for log4j controlling
41 * the logging level for castor (used for serialization) <br>
43 * <li>logs.Jalview.Level - Cache.log stringified level. <br>
45 * <li>SCREEN_WIDTH</li>
46 * <li>SCREEN_HEIGHT</li>
47 * <li>SCREEN_Y=285</li>
48 * <li>SCREEN_X=371</li>
49 * <li>SHOW_FULLSCREEN boolean</li>
50 * <li>FONT_NAME java font name for alignment text display</li>
51 * <li>FONT_SIZE size of displayed alignment text</li>
52 * <li>FONT_STYLE style of font displayed (sequence labels are always italic)</li>
53 * <li>GAP_SYMBOL character to treat as gap symbol (usually -,.,' ')</li>
54 * <li>LAST_DIRECTORY last directory for browsing alignment</li>
55 * <li>USER_DEFINED_COLOURS list of user defined colour scheme files</li>
56 * <li>SHOW_FULL_ID show id with '/start-end' numbers appended</li>
57 * <li>SHOW_IDENTITY show percentage identity annotation</li>
58 * <li>SHOW_QUALITY show alignment quality annotation</li>
59 * <li>SHOW_ANNOTATIONS show alignment annotation rows</li>
60 * <li>SHOW_CONSERVATION show alignment conservation annotation</li>
61 * <li>CENTRE_COLUMN_LABELS centre the labels at each column in a displayed
63 * <li>DEFAULT_COLOUR default colour scheme to apply for a new alignment</li>
64 * <li>DEFAULT_FILE_FORMAT file format used to save</li>
65 * <li>STARTUP_FILE file loaded on startup (may be a fully qualified url)</li>
66 * <li>SHOW_STARTUP_FILE flag to control loading of startup file</li>
67 * <li>VERSION the version of the jalview build</li>
68 * <li>BUILD_DATE date of this build</li>
69 * <li>LATEST_VERSION the latest jalview version advertised on the
70 * www.jalview.org</li>
71 * <li>PIR_MODELLER boolean indicating if PIR files are written with MODELLER
73 * <li>(FASTA,MSF,PILEUP,CLUSTAL,BLC,PIR,PFAM)_JVSUFFIX boolean for adding jv
75 * <li>RECENT_URL list of recently retrieved URLs</li>
76 * <li>RECENT_FILE list of recently opened files</li>
77 * <li>USE_PROXY flag for whether a http proxy is to be used</li>
78 * <li>PROXY_SERVER the proxy</li>
80 * <li>NOQUESTIONNAIRES true to prevent jalview from checking the questionnaire
82 * <li>QUESTIONNAIRE last questionnaire:responder id string from questionnaire
84 * <li>USAGESTATS (false - user prompted) Enable google analytics tracker for
85 * collecting usage statistics</li>
86 * <li>DAS_LOCAL_SOURCE list of local das sources</li>
87 * <li>SHOW_OVERVIEW boolean for overview window display</li>
88 * <li>ANTI_ALIAS boolean for smooth fonts</li>
89 * <li>RIGHT_ALIGN_IDS boolean</li>
90 * <li>AUTO_CALC_CONSENSUS boolean for automatic recalculation of consensus</li>
91 * <li>PAD_GAPS boolean</li>
92 * <li>ID_ITALICS boolean</li>
93 * <li>SHOW_JV_SUFFIX</li>
94 * <li>WRAP_ALIGNMENT</li>
95 * <li>EPS_RENDERING (Prompt each time|Lineart|Text) default for EPS rendering
97 * <li>SORT_ALIGNMENT (No sort|Id|Pairwise Identity)</li>
98 * <li>SEQUENCE_LINKS list of name|URL pairs for opening a url with
100 * <li>GROUP_LINKS list of name|URL[|<separator>] tuples - see
101 * jalview.utils.GroupURLLink for more info</li>
102 * <li>DAS_REGISTRY_URL the registry to query</li>
103 * <li>DEFAULT_BROWSER for unix</li>
104 * <li>DAS_ACTIVE_SOURCE list of active sources</li>
105 * <li>SHOW_MEMUSAGE boolean show memory usage and warning indicator on desktop
107 * <li>VERSION_CHECK (true) check for the latest release version from
108 * www.jalview.org (or the alias given by the www.jalview.org property)</li>
109 * <li>SHOW_NPFEATS_TOOLTIP (true) show non-positional features in the Sequence
111 * <li>SHOW_DBREFS_TOOLTIP (true) show Database Cross References in the Sequence
113 * <li>SHOW_UNCONSERVED (false) only render unconserved residues - conserved
114 * displayed as '.'</li>
115 * <li>SORT_BY_TREE (false) sort the current alignment view according to the
116 * order of a newly displayed tree</li>
117 * <li>DBFETCH_USEPICR (false) use PICR to recover valid DB references from
118 * sequence ID strings before attempting retrieval from any datasource</li>
119 * <li>SHOW_GROUP_CONSENSUS (false) Show consensus annotation for groups in the
121 * <li>SHOW_GROUP_CONSERVATION (false) Show conservation annotation for groups
122 * in the alignment.</li>
123 * <li>SHOW_CONSENSUS_HISTOGRAM (false) Show consensus annotation row's
125 * <li>SHOW_CONSENSUS_LOGO (false) Show consensus annotation row's sequence
127 * <li>NORMALISE_CONSENSUS_LOGO (false) Show consensus annotation row's sequence
128 * logo normalised to row height rather than histogram height.</li>
129 * <li>FOLLOW_SELECTIONS (true) Controls whether a new alignment view should
130 * respond to selections made in other alignments containing the same sequences.
132 * <li>SHOW_WSDISCOVERY_ERRORS (true) Controls if the web service URL discovery
133 * warning dialog box is displayed.</li>
134 * <li>ANNOTATIONCOLOUR_MIN (orange) Shade used for minimum value of annotation when shading by annotation</li>
135 * <li>ANNOTATIONCOLOUR_MAX (red) Shade used for maximum value of annotation when shading by annotation</li>
136 * <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>
141 * Deprecated settings:
143 * * <li>DISCOVERY_START - Boolean - controls if discovery services are queried on
144 * startup (JWS1 services only)</li>
145 * <li>DISCOVERY_URLS - comma separated list of Discovery Service endpoints. (JWS1 services only)</li>
146 * <li>SHOW_JWS1_SERVICES (true) enable or disable the original Jalview 2 services in the desktop GUI</li>
147 * <li>ENABLE_RSBS_EDITOR (false for 2.7 release) enable or disable RSBS editing panel in web service preferences</li>
150 * @version $Revision$
155 * property giving log4j level for CASTOR loggers
157 public static final String CASTORLOGLEVEL = "logs.Castor.level";
160 * property giving log4j level for AXIS loggers
162 public static final String AXISLOGLEVEL = "logs.Axis.level";
165 * property giving log4j level for Jalview Log
167 public static final String JALVIEWLOGLEVEL = "logs.Jalview.level";
169 public static final String DAS_LOCAL_SOURCE = "DAS_LOCAL_SOURCE";
171 public static final String DAS_REGISTRY_URL = "DAS_REGISTRY_URL";
173 public static final String DAS_ACTIVE_SOURCE = "DAS_ACTIVE_SOURCE";
176 * Initialises the Jalview Application Log
178 public static Logger log;
180 /** Jalview Properties */
181 public static Properties applicationProperties = new Properties();
183 /** Default file is ~/.jalview_properties */
184 static String propertiesFile;
186 private static boolean propsAreReadOnly=false;
188 public static void initLogger()
196 // TODO: redirect stdout and stderr here in order to grab the output of
199 ConsoleAppender ap = new ConsoleAppender(new SimpleLayout(),
201 ap.setName("JalviewLogger");
202 org.apache.log4j.Logger.getRootLogger().addAppender(ap); // catch all for
204 Logger laxis = Logger.getLogger("org.apache.axis");
205 Logger lcastor = Logger.getLogger("org.exolab.castor");
206 jalview.bin.Cache.log = Logger.getLogger("jalview.bin.Jalview");
208 laxis.setLevel(Level.toLevel(Cache.getDefault("logs.Axis.Level",
209 Level.INFO.toString())));
210 lcastor.setLevel(Level.toLevel(Cache.getDefault("logs.Castor.Level",
211 Level.INFO.toString())));
212 lcastor = Logger.getLogger("org.exolab.castor.xml");
213 lcastor.setLevel(Level.toLevel(Cache.getDefault("logs.Castor.Level",
214 Level.INFO.toString())));
215 // lcastor = Logger.getLogger("org.exolab.castor.xml.Marshaller");
216 // lcastor.setLevel(Level.toLevel(Cache.getDefault("logs.Castor.Level",
217 // Level.INFO.toString())));
218 jalview.bin.Cache.log.setLevel(Level.toLevel(Cache.getDefault(
219 "logs.Jalview.level", Level.INFO.toString())));
220 // laxis.addAppender(ap);
221 // lcastor.addAppender(ap);
222 // jalview.bin.Cache.log.addAppender(ap);
223 // Tell the user that debug is enabled
224 jalview.bin.Cache.log.debug("Jalview Debugging Output Follows.");
225 } catch (Exception ex)
227 System.err.println("Problems initializing the log4j system\n");
228 ex.printStackTrace(System.err);
232 /** Called when Jalview is started */
233 public static void loadProperties(String propsFile)
235 propertiesFile = propsFile;
236 if (propsFile == null)
238 propertiesFile = System.getProperty("user.home") + File.separatorChar
239 + ".jalview_properties";
241 // don't corrupt the file we've been given.
242 propsAreReadOnly = true;
250 fis = new java.net.URL(propertiesFile).openStream();
251 System.out.println("Loading jalview properties from : "
254 .println("Disabling Jalview writing to user's local properties file.");
255 propsAreReadOnly = true;
257 } catch (Exception ex)
263 fis = new FileInputStream(propertiesFile);
265 applicationProperties.load(fis);
266 applicationProperties.remove("LATEST_VERSION");
267 applicationProperties.remove("VERSION");
269 } catch (Exception ex)
271 System.out.println("Error reading properties file: " + ex);
274 if (getDefault("USE_PROXY", false))
276 System.out.println("Using proxyServer: "
277 + getDefault("PROXY_SERVER", null) + " proxyPort: "
278 + getDefault("PROXY_PORT", null));
279 System.setProperty("http.proxyHost", getDefault("PROXY_SERVER", null));
280 System.setProperty("http.proxyPort", getDefault("PROXY_PORT", null));
283 // LOAD THE AUTHORS FROM THE authors.props file
286 String authorDetails = "jar:".concat(Cache.class.getProtectionDomain()
287 .getCodeSource().getLocation().toString()
288 .concat("!/authors.props"));
290 java.net.URL localJarFileURL = new java.net.URL(authorDetails);
292 InputStream in = localJarFileURL.openStream();
293 applicationProperties.load(in);
295 } catch (Exception ex)
297 System.out.println("Error reading author details: " + ex);
298 applicationProperties.remove("AUTHORS");
299 applicationProperties.remove("AUTHORFNAMES");
300 applicationProperties.remove("YEAR");
303 // FIND THE VERSION NUMBER AND BUILD DATE FROM jalview.jar
304 // MUST FOLLOW READING OF LOCAL PROPERTIES FILE AS THE
305 // VERSION MAY HAVE CHANGED SINCE LAST USING JALVIEW
308 String buildDetails = "jar:".concat(Cache.class.getProtectionDomain()
309 .getCodeSource().getLocation().toString()
310 .concat("!/.build_properties"));
312 java.net.URL localJarFileURL = new java.net.URL(buildDetails);
314 InputStream in = localJarFileURL.openStream();
315 applicationProperties.load(in);
317 } catch (Exception ex)
319 System.out.println("Error reading build details: " + ex);
320 applicationProperties.remove("VERSION");
323 String jnlpVersion = System.getProperty("jalview.version");
324 String codeVersion = getProperty("VERSION");
326 if (codeVersion == null)
328 // THIS SHOULD ONLY BE THE CASE WHEN TESTING!!
329 codeVersion = "Test";
330 jnlpVersion = "Test";
333 System.out.println("Jalview Version: " + codeVersion);
335 // jnlpVersion will be null if we're using InstallAnywhere
336 // Dont do this check if running in headless mode
337 if (jnlpVersion == null
338 && getDefault("VERSION_CHECK", true)
339 && (System.getProperty("java.awt.headless") == null || System
340 .getProperty("java.awt.headless").equals("false")))
343 class VersionChecker extends Thread
347 String orgtimeout = System
348 .getProperty("sun.net.client.defaultConnectTimeout");
349 if (orgtimeout == null)
352 System.out.println("# INFO: Setting default net timeout to "
353 + orgtimeout + " seconds.");
355 String jnlpVersion = null;
358 System.setProperty("sun.net.client.defaultConnectTimeout",
360 java.net.URL url = new java.net.URL(
361 Cache.getDefault("www.jalview.org", "http://www.jalview.org")+"/webstart/jalview.jnlp");
362 BufferedReader in = new BufferedReader(new InputStreamReader(
365 while ((line = in.readLine()) != null)
367 if (line.indexOf("jalview.version") == -1)
372 line = line.substring(line.indexOf("value=") + 7);
373 line = line.substring(0, line.lastIndexOf("\""));
377 } catch (Exception ex)
380 .println("Non-fatal exceptions when checking version at www.jalview.org :");
381 System.out.println(ex);
382 jnlpVersion = getProperty("VERSION");
384 System.setProperty("sun.net.client.defaultConnectTimeout",
387 setProperty("LATEST_VERSION", jnlpVersion);
391 VersionChecker vc = new VersionChecker();
396 if (jnlpVersion != null)
398 setProperty("LATEST_VERSION", jnlpVersion);
402 applicationProperties.remove("LATEST_VERSION");
406 setProperty("VERSION", codeVersion);
408 // LOAD USERDEFINED COLOURS
409 jalview.gui.UserDefinedColours
410 .initUserColourSchemes(getProperty("USER_DEFINED_COLOURS"));
411 jalview.io.PIRFile.useModellerOutput = Cache.getDefault("PIR_MODELLER",
416 * Gets Jalview application property of given key. Returns null if key not
422 * @return Property value
424 public static String getProperty(String key)
426 return applicationProperties.getProperty(key);
430 * These methods are used when checking if the saved preference is different
431 * to the default setting
434 public static boolean getDefault(String property, boolean def)
436 String string = getProperty(property);
439 def = Boolean.valueOf(string).booleanValue();
446 * These methods are used when checking if the saved preference is different
447 * to the default setting
449 public static String getDefault(String property, String def)
451 String string = getProperty(property);
461 * Stores property in the file "HOME_DIR/.jalview_properties"
466 * String value of property
468 * @return String value of property
470 public static String setProperty(String key, String obj)
475 applicationProperties.setProperty(key, obj);
476 if (!propsAreReadOnly)
478 FileOutputStream out = new FileOutputStream(propertiesFile);
479 applicationProperties.store(out, "---JalviewX Properties File---");
482 } catch (Exception ex)
484 System.out.println("Error setting property: " + key + " " + obj
491 * remove the specified property from the jalview properties file
495 public static void removeProperty(String string)
497 applicationProperties.remove(string);
502 * save the properties to the jalview properties path
504 public static void saveProperties()
506 if (!propsAreReadOnly)
510 FileOutputStream out = new FileOutputStream(propertiesFile);
511 applicationProperties.store(out, "---JalviewX Properties File---");
513 } catch (Exception ex)
515 System.out.println("Error saving properties: " + ex);
521 * internal vamsas class discovery state
523 private static int vamsasJarsArePresent = -1;
526 * Searches for vamsas client classes on class path.
528 * @return true if vamsas client is present on classpath
530 public static boolean vamsasJarsPresent()
532 if (vamsasJarsArePresent == -1)
536 if (jalview.jbgui.GDesktop.class.getClassLoader().loadClass(
537 "uk.ac.vamsas.client.VorbaId") != null)
539 jalview.bin.Cache.log
540 .debug("Found Vamsas Classes (uk.ac..vamsas.client.VorbaId can be loaded)");
541 vamsasJarsArePresent = 1;
542 Logger lvclient = Logger.getLogger("uk.ac.vamsas");
543 lvclient.setLevel(Level.toLevel(Cache.getDefault(
544 "logs.Vamsas.Level", Level.INFO.toString())));
546 lvclient.addAppender(log.getAppender("JalviewLogger"));
547 // Tell the user that debug is enabled
548 lvclient.debug("Jalview Vamsas Client Debugging Output Follows.");
550 } catch (Exception e)
552 vamsasJarsArePresent = 0;
553 jalview.bin.Cache.log.debug("Vamsas Classes are not present");
556 return (vamsasJarsArePresent > 0);
560 * internal vamsas class discovery state
562 private static int groovyJarsArePresent = -1;
565 * Searches for vamsas client classes on class path.
567 * @return true if vamsas client is present on classpath
569 public static boolean groovyJarsPresent()
571 if (groovyJarsArePresent == -1)
575 if (Cache.class.getClassLoader().loadClass(
576 "groovy.lang.GroovyObject") != null)
578 jalview.bin.Cache.log
579 .debug("Found Groovy (groovy.lang.GroovyObject can be loaded)");
580 groovyJarsArePresent = 1;
581 Logger lgclient = Logger.getLogger("groovy");
582 lgclient.setLevel(Level.toLevel(Cache.getDefault(
583 "logs.Groovy.Level", Level.INFO.toString())));
585 lgclient.addAppender(log.getAppender("JalviewLogger"));
586 // Tell the user that debug is enabled
587 lgclient.debug("Jalview Groovy Client Debugging Output Follows.");
591 groovyJarsArePresent = 0;
592 jalview.bin.Cache.log.debug("Groovy Classes are not present", e);
593 } catch (Exception e)
595 groovyJarsArePresent = 0;
596 jalview.bin.Cache.log.debug("Groovy Classes are not present");
599 return (groovyJarsArePresent > 0);
603 * generate Das1Sources from the local das source list
605 * @return Vector of Das1Sources
607 public static Vector getLocalDasSources()
609 Vector localSources = new Vector();
610 String local = jalview.bin.Cache.getProperty("DAS_LOCAL_SOURCE");
613 StringTokenizer st = new StringTokenizer(local, "\t");
614 while (st.hasMoreTokens())
616 String token = st.nextToken();
617 int bar = token.indexOf("|");
618 Das1Source source = new Das1Source();
619 source.setUrl(token.substring(bar + 1));
620 if (source.getUrl().startsWith("sequence:"))
622 source.setUrl(source.getUrl().substring(9));
623 // this source also serves sequences as well as features
624 source.setCapabilities(new String[]
625 { "sequence", "features" });
629 // default is that all user added sources serve features
630 source.setCapabilities(new String[]
634 source.setNickname(token.substring(0, bar));
636 localSources.addElement(source);
643 * GA tracker object - actually JGoogleAnalyticsTracker null if tracking not
646 protected static Object tracker = null;
648 protected static Class trackerfocus = null;
650 protected static Class jgoogleanalyticstracker = null;
653 * Initialise the google tracker if it is not done already.
655 public static void initGoogleTracker()
659 if (jgoogleanalyticstracker == null)
661 // try to get the tracker class
664 jgoogleanalyticstracker = Cache.class
667 "com.boxysystems.jgoogleanalytics.JGoogleAnalyticsTracker");
668 trackerfocus = Cache.class.getClassLoader().loadClass(
669 "com.boxysystems.jgoogleanalytics.FocusPoint");
670 } catch (Exception e)
672 log.debug("com.boxysystems.jgoogleanalytics package is not present - tracking not enabled.");
674 jgoogleanalyticstracker = null;
679 // now initialise tracker
680 Exception re = null, ex = null;
682 String vrs = "No Version Accessible";
685 // Google analytics tracking code for Library Finder
686 tracker = jgoogleanalyticstracker.getConstructor(new Class[]
687 { String.class, String.class, String.class }).newInstance(
691 (vrs = jalview.bin.Cache.getProperty("VERSION")
693 + jalview.bin.Cache.getDefault("BUILD_DATE",
694 "unknown")), "UA-9060947-1" });
695 jgoogleanalyticstracker.getMethod("trackAsynchronously",
697 { trackerfocus }).invoke(tracker, new Object[]
698 { trackerfocus.getConstructor(new Class[]
699 { String.class }).newInstance(new Object[]
700 { "Application Started." }) });
701 } catch (RuntimeException e)
704 } catch (Exception e)
711 if (re != null || ex != null || err != null)
716 log.debug("Caught runtime exception in googletracker init:", re);
719 "Failed to initialise GoogleTracker for Jalview Desktop with version "
723 "Whilst initing GoogleTracker for Jalview Desktop version "
731 .println("Debug: Caught runtime exception in googletracker init:"
733 re.printStackTrace();
738 .println("Warning: Failed to initialise GoogleTracker for Jalview Desktop with version "
740 ex.printStackTrace();
746 .println("ERROR: Whilst initing GoogleTracker for Jalview Desktop version "
748 err.printStackTrace();
754 log.debug("Successfully initialised tracker.");
760 * get the user's default colour if available
765 public static Color getDefaultColour(String property, Color defcolour)
767 String colprop = getProperty(property);
771 Color col = jalview.schemes.ColourSchemeProperty.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 "+property);
782 return (col==null) ? defcolour: col;
786 * store a colour as a Jalview user default property
790 public static void setColourProperty(String property, Color colour)
792 setProperty(property, jalview.util.Format
793 .getHexString(colour));
796 public static final DateFormat date_format = SimpleDateFormat.getDateTimeInstance();
799 * store a date in a jalview property
803 public static void setDateProperty(String property, Date time)
805 setProperty(property, date_format.format(time));
808 * read a date stored in a jalview property
810 * @return valid date as stored by setDateProperty, or null
813 public static Date getDateProperty(String property)
815 String val = getProperty(property);
819 return date_format.parse(val);
820 } catch (Exception ex)
822 System.err.println("Invalid or corrupt date in property '"+property+"' : value was '"+val+"'");