001package com.hfg.bio.seq.alignment.muscle;
002
003
004import java.io.File;
005
006import com.hfg.setting.*;
007import com.hfg.util.StringUtil;
008import com.hfg.xml.XMLTag;
009
010//==============================================================================
011/**
012 Settings used for Muscle multiple sequence alignment execution.
013
014 @author J. Alex Taylor, hairyfatguy.com
015 */
016//==============================================================================
017// com.hfg XML/HTML Coding Library
018//
019// This library is free software; you can redistribute it and/or
020// modify it under the terms of the GNU Lesser General Public
021// License as published by the Free Software Foundation; either
022// version 2.1 of the License, or (at your option) any later version.
023//
024// This library is distributed in the hope that it will be useful,
025// but WITHOUT ANY WARRANTY; without even the implied warranty of
026// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
027// Lesser General Public License for more details.
028//
029// You should have received a copy of the GNU Lesser General Public
030// License along with this library; if not, write to the Free Software
031// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
032//
033// J. Alex Taylor, President, Founder, CEO, COO, CFO, OOPS hairyfatguy.com
034// jataylor@hairyfatguy.com
035//==============================================================================
036// http://www.drive5.com/muscle
037
038public class MuscleSettings extends Settings implements Cloneable
039{
040   public static final String EXECUTABLE_DIR      = "executable_dir";
041   public static final String EXECUTABLE          = "executable";
042   public static final String INPUT_FILENAME      = "input_filename";
043   public static final String OUTPUT_FILENAME     = "output_filename";
044   public static final String OUTPUT_FORMAT       = "output_format";
045
046   public static final String COMMAND_LINE_PARAMS = "command_line_params";
047
048
049   private static String sDefaultExecutableDir = "/usr/local/bin";
050   private static String sDefaultExecutable    = "muscle";
051
052   //###########################################################################
053   // CONSTRUCTORS
054   //###########################################################################
055
056   //---------------------------------------------------------------------------
057   public MuscleSettings()
058   {
059      super();
060   }
061
062   public MuscleSettings(XMLTag inXMLTag)
063   {
064      super(inXMLTag);
065   }
066
067   //---------------------------------------------------------------------------
068   @Override
069   protected void init()
070   {
071      add(new StringSetting(EXECUTABLE_DIR, sDefaultExecutableDir));
072      add(new StringSetting(EXECUTABLE, sDefaultExecutable));
073      add(new StringSetting(INPUT_FILENAME));
074      add(new StringSetting(OUTPUT_FILENAME));
075      add(new StringSetting(OUTPUT_FORMAT));
076
077      add(new StringSetting(COMMAND_LINE_PARAMS));
078   }
079
080   //###########################################################################
081   // PUBLIC METHODS
082   //###########################################################################
083
084   //---------------------------------------------------------------------------
085   public static void setDefaultExecutableDir(File inValue)
086   {
087      sDefaultExecutableDir = inValue.getPath();
088   }
089
090   //---------------------------------------------------------------------------
091   public static File getDefaultExecutableDir()
092   {
093      return new File(sDefaultExecutableDir);
094   }
095
096   //---------------------------------------------------------------------------
097   public static void setDefaultExecutable(String inValue)
098   {
099      sDefaultExecutable = inValue;
100   }
101
102   //---------------------------------------------------------------------------
103   public static String getDefaultExecutable()
104   {
105      return sDefaultExecutable;
106   }
107
108
109   //---------------------------------------------------------------------------
110   public File getExecutableDir()
111   {
112      File executableDir = null;
113
114      String stringValue = get(EXECUTABLE_DIR).getStringValue();
115      if (StringUtil.isSet(stringValue))
116      {
117         executableDir = new File(stringValue);
118      }
119
120      return executableDir;
121   }
122
123   //---------------------------------------------------------------------------
124   @SuppressWarnings("unchecked")
125   public MuscleSettings setExecutableDir(File inValue)
126   {
127      get(EXECUTABLE_DIR).setValue(inValue != null ? inValue.getAbsolutePath() : null);
128      return this;
129   }
130
131   //---------------------------------------------------------------------------
132   public String getExecutable()
133   {
134      return get(EXECUTABLE).getStringValue();
135   }
136
137   //---------------------------------------------------------------------------
138   @SuppressWarnings("unchecked")
139   public MuscleSettings setExecutable(String inValue)
140   {
141      get(EXECUTABLE).setValue(inValue);
142      return this;
143   }
144
145   //---------------------------------------------------------------------------
146   public File getInputFile()
147   {
148      File file = null;
149
150      String stringValue = get(INPUT_FILENAME).getStringValue();
151      if (StringUtil.isSet(stringValue))
152      {
153         file = new File(stringValue);
154      }
155
156      return file;
157   }
158
159   //---------------------------------------------------------------------------
160   @SuppressWarnings("unchecked")
161   public MuscleSettings setInputFile(File inValue)
162   {
163      get(INPUT_FILENAME).setValue(inValue != null ? inValue.getAbsolutePath() : null);
164      return this;
165   }
166
167
168   //---------------------------------------------------------------------------
169   public File getOutputFile()
170   {
171      File file = null;
172
173      String stringValue = get(OUTPUT_FILENAME).getStringValue();
174      if (StringUtil.isSet(stringValue))
175      {
176         file = new File(stringValue);
177      }
178
179      return file;
180   }
181
182   //---------------------------------------------------------------------------
183   @SuppressWarnings("unchecked")
184   public MuscleSettings setOutputFile(File inValue)
185   {
186      get(OUTPUT_FILENAME).setValue(inValue != null ? inValue.getAbsolutePath() : null);
187      return this;
188   }
189
190   //---------------------------------------------------------------------------
191   public MuscleOutputFormat getOutputFormat()
192   {
193      MuscleOutputFormat value = null;
194
195      String stringValue = get(OUTPUT_FORMAT).getStringValue();
196      if (StringUtil.isSet(stringValue))
197      {
198         value = MuscleOutputFormat.valueOf(stringValue);
199      }
200
201      return value;
202   }
203
204   //---------------------------------------------------------------------------
205   @SuppressWarnings("unchecked")
206   public MuscleSettings setOutputFormat(MuscleOutputFormat inValue)
207   {
208      get(OUTPUT_FORMAT).setValue(inValue != null ? inValue.name() : null);
209      return this;
210   }
211
212
213   //---------------------------------------------------------------------------
214   public String getCommandLineParams()
215   {
216      return (String) get(COMMAND_LINE_PARAMS).getValue();
217   }
218
219   //---------------------------------------------------------------------------
220   /**
221    Additional (optional) command line parameters for the end of the Muscle command
222    @param inValue the additional command line parameters to be appended to the end of the command
223    @return this Settings object to enable chaining
224    */
225   @SuppressWarnings("unchecked")
226   public MuscleSettings setCommandLineParams(String inValue)
227   {
228      get(COMMAND_LINE_PARAMS).setValue(inValue);
229      return this;
230   }
231
232}