JAL-3253 jalview.bin.Instance streamlining
[jalview.git] / src / jalview / structure / StructureImportSettings.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3  * Copyright (C) $$Year-Rel$$ The Jalview Authors
4  * 
5  * This file is part of Jalview.
6  * 
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.
11  *  
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.
16  * 
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.
20  */
21 package jalview.structure;
22
23 import jalview.bin.Instance;
24 import jalview.datamodel.PDBEntry;
25 import jalview.datamodel.PDBEntry.Type;
26
27 /**
28  * bean holding settings for structure IO. TODO: tests for validation of values
29  * TODO: tests for race conditions (all fields are static, is that correct ?)
30  * 
31  * @author tcofoegbu
32  *
33  */
34 public class StructureImportSettings
35 {
36
37   private StructureImportSettings()
38   {
39     // private singleton
40   }
41
42   private static StructureImportSettings getInstance()
43   {
44     Instance j = Instance.getInstance();
45     return (j.structureImportSettings == null
46             ? j.structureImportSettings = new StructureImportSettings()
47             : j.structureImportSettings);
48   }
49
50   /**
51    * set to true to add derived sequence annotations (temp factor read from
52    * file, or computed secondary structure) to the alignment
53    */
54   private boolean visibleChainAnnotation = false;
55
56   /**
57    * Set true to predict secondary structure (using JMol for protein, Annotate3D
58    * for RNA)
59    */
60   private boolean processSecStr = false;
61
62   /**
63    * Set true (with predictSecondaryStructure=true) to predict secondary
64    * structure using an external service (currently Annotate3D for RNA only)
65    */
66   private boolean externalSecondaryStructure = false;
67
68   private boolean showSeqFeatures = true;
69
70   public enum StructureParser
71   {
72     JMOL_PARSER, JALVIEW_PARSER
73   }
74
75   /**
76    * Determines the default file format for structure files to be downloaded
77    * from the PDB sequence fetcher. Possible options include: PDB|mmCIF
78    */
79   private PDBEntry.Type defaultStructureFileFormat = Type.PDB;
80
81   /**
82    * Determines the parser used for parsing PDB format file. Possible options
83    * are : JMolParser|JalveiwParser
84    */
85   private StructureParser defaultPDBFileParser = StructureParser.JMOL_PARSER;
86
87   public static void addSettings(boolean addAlignmentAnnotations,
88           boolean processSecStr, boolean externalSecStr)
89   {
90     StructureImportSettings s = getInstance();
91     s.visibleChainAnnotation = addAlignmentAnnotations;
92     s.processSecStr = processSecStr;
93     s.externalSecondaryStructure = externalSecStr;
94     s.showSeqFeatures = true;
95   }
96
97   public static boolean isVisibleChainAnnotation()
98   {
99     return getInstance().visibleChainAnnotation;
100   }
101
102   public static void setVisibleChainAnnotation(
103           boolean visibleChainAnnotation)
104   {
105     getInstance().visibleChainAnnotation = visibleChainAnnotation;
106   }
107
108   public static boolean isProcessSecondaryStructure()
109   {
110     return getInstance().processSecStr;
111   }
112
113   public static void setProcessSecondaryStructure(
114           boolean processSecondaryStructure)
115   {
116     getInstance().processSecStr = processSecondaryStructure;
117   }
118
119   public static boolean isExternalSecondaryStructure()
120   {
121     return getInstance().externalSecondaryStructure;
122   }
123
124   public static void setExternalSecondaryStructure(
125           boolean externalSecondaryStructure)
126   {
127     getInstance().externalSecondaryStructure = externalSecondaryStructure;
128   }
129
130   public static boolean isShowSeqFeatures()
131   {
132     return getInstance().showSeqFeatures;
133   }
134
135   public static void setShowSeqFeatures(boolean showSeqFeatures)
136   {
137     getInstance().showSeqFeatures = showSeqFeatures;
138   }
139
140   public static PDBEntry.Type getDefaultStructureFileFormat()
141   {
142     return getInstance().defaultStructureFileFormat;
143   }
144
145   public static void setDefaultStructureFileFormat(
146           String defaultStructureFileFormat)
147   {
148     getInstance().defaultStructureFileFormat = PDBEntry.Type
149             .valueOf(defaultStructureFileFormat.toUpperCase());
150   }
151
152   public static String getDefaultPDBFileParser()
153   {
154     return getInstance().defaultPDBFileParser.toString();
155   }
156
157   public static void setDefaultPDBFileParser(
158           StructureParser defaultPDBFileParser)
159   {
160     getInstance().defaultPDBFileParser = defaultPDBFileParser;
161   }
162
163   public static void setDefaultPDBFileParser(String defaultPDBFileParser)
164   {
165     getInstance().defaultPDBFileParser = StructureParser
166             .valueOf(defaultPDBFileParser.toUpperCase());
167   }
168
169 }