001package com.hfg.bio;
002
003
004import java.util.ArrayList;
005import java.util.Collection;
006import java.util.HashSet;
007import java.util.List;
008import java.util.Set;
009
010import com.hfg.setting.FloatSetting;
011import com.hfg.setting.IntSetting;
012import com.hfg.setting.Settings;
013import com.hfg.setting.StringListSetting;
014import com.hfg.setting.StringSetting;
015import com.hfg.util.StringUtil;
016import com.hfg.util.collection.CollectionUtil;
017
018//------------------------------------------------------------------------------
019/**
020 Settings for protein digestion via protease(s).
021 <div>
022  @author J. Alex Taylor, hairyfatguy.com
023 </div>
024 */
025//------------------------------------------------------------------------------
026// com.hfg XML/HTML Coding Library
027//
028// This library is free software; you can redistribute it and/or
029// modify it under the terms of the GNU Lesser General Public
030// License as published by the Free Software Foundation; either
031// version 2.1 of the License, or (at your option) any later version.
032//
033// This library is distributed in the hope that it will be useful,
034// but WITHOUT ANY WARRANTY; without even the implied warranty of
035// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
036// Lesser General Public License for more details.
037//
038// You should have received a copy of the GNU Lesser General Public
039// License along with this library; if not, write to the Free Software
040// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
041//
042// J. Alex Taylor, President, Founder, CEO, COO, CFO, OOPS hairyfatguy.com
043// jataylor@hairyfatguy.com
044//------------------------------------------------------------------------------
045
046public class DigestSettings extends Settings implements Cloneable
047{
048   public static final String PROTEASE             = "protease";
049   public static final String MAX_MISSED_CLEAVAGES = "maxMissedCleavages";
050   public static final String MIN_FRAG_LENGTH      = "minFragLength";
051   public static final String MAX_FRAG_LENGTH      = "maxFragLength";
052   public static final String MIN_FRAG_MASS        = "minFragMass";
053   public static final String MAX_FRAG_MASS        = "maxFragMass";
054   public static final String ALKYLATED_CYS        = "alkylatedCys";
055
056   private static int  sDefaultMaxMissedCleavages = 0;
057   private static int  sDefaultMinFragmentLength  = 1;
058
059
060
061   //###########################################################################
062   // CONSTRUCTORS
063   //###########################################################################
064
065   //---------------------------------------------------------------------------
066   public DigestSettings()
067   {
068      super();
069      init();
070   }
071
072   //---------------------------------------------------------------------------
073   @Override
074   protected void init()
075   {
076      add(new StringListSetting(PROTEASE));
077      add(new IntSetting(MAX_MISSED_CLEAVAGES, sDefaultMaxMissedCleavages));
078      add(new IntSetting(MIN_FRAG_LENGTH, sDefaultMinFragmentLength));
079      add(new IntSetting(MAX_FRAG_LENGTH));
080      add(new FloatSetting(MIN_FRAG_MASS));
081      add(new FloatSetting(MAX_FRAG_MASS));
082      add(new StringSetting(ALKYLATED_CYS));
083   }
084
085   //###########################################################################
086   // PUBLIC METHODS
087   //###########################################################################
088
089   //---------------------------------------------------------------------------
090   @SuppressWarnings("unchecked")
091   public DigestSettings setProtease(Protease inValue)
092   {
093      List<Protease> list = new ArrayList<>(1);
094      list.add(inValue);
095      return setProteases(list);
096   }
097
098   //---------------------------------------------------------------------------
099   @SuppressWarnings("unchecked")
100   public DigestSettings setProteases(Collection<Protease> inValues)
101   {
102      List<String> stringListValue = null;
103      if (CollectionUtil.hasValues(inValues))
104      {
105         stringListValue = new ArrayList<>(inValues.size());
106         for (Protease protease : inValues)
107         {
108            stringListValue.add(protease.name());
109         }
110      }
111
112      get(PROTEASE).setValue(stringListValue);
113      return this;
114   }
115
116   //---------------------------------------------------------------------------
117   @SuppressWarnings("unchecked")
118   public Set<Protease> getProteases()
119   {
120      Set<Protease> proteases = null;
121
122      List<String> proteaseNames = (List<String>) get(PROTEASE).getValue();
123      if (CollectionUtil.hasValues(proteaseNames))
124      {
125         proteases = new HashSet<>(proteaseNames.size());
126         for (String proteaseName : proteaseNames)
127         {
128            proteases.add(Protease.valueOf(proteaseName));
129         }
130      }
131
132      return proteases;
133   }
134
135   //---------------------------------------------------------------------------
136   @SuppressWarnings("unchecked")
137   public DigestSettings setMaxMissedCleavages(int inValue)
138   {
139      get(MAX_MISSED_CLEAVAGES).setValue(inValue);
140      return this;
141   }
142
143   //---------------------------------------------------------------------------
144   public Integer getMaxMissedCleavages()
145   {
146      return (Integer) get(MAX_MISSED_CLEAVAGES).getValue();
147   }
148
149
150   //---------------------------------------------------------------------------
151   @SuppressWarnings("unchecked")
152   public DigestSettings setMinFragmentLength(Integer inValue)
153   {
154      get(MIN_FRAG_LENGTH).setValue(inValue);
155      return this;
156   }
157
158   //---------------------------------------------------------------------------
159   public Integer getMinFragmentLength()
160   {
161      return (Integer) get(MIN_FRAG_LENGTH).getValue();
162   }
163
164
165   //---------------------------------------------------------------------------
166   @SuppressWarnings("unchecked")
167   public DigestSettings setMaxFragmentLength(Integer inValue)
168   {
169      get(MAX_FRAG_LENGTH).setValue(inValue);
170      return this;
171   }
172
173   //---------------------------------------------------------------------------
174   public Integer getMaxFragmentLength()
175   {
176      return (Integer) get(MAX_FRAG_LENGTH).getValue();
177   }
178
179
180   //---------------------------------------------------------------------------
181   @SuppressWarnings("unchecked")
182   public DigestSettings setMinFragmentMass(Float inValue)
183   {
184      get(MIN_FRAG_MASS).setValue(inValue);
185      return this;
186   }
187
188   //---------------------------------------------------------------------------
189   public Float getMinFragmentMass()
190   {
191      return (Float) get(MIN_FRAG_MASS).getValue();
192   }
193
194   //---------------------------------------------------------------------------
195   @SuppressWarnings("unchecked")
196   public DigestSettings setMaxFragmentMass(Float inValue)
197   {
198      get(MAX_FRAG_MASS).setValue(inValue);
199      return this;
200   }
201
202   //---------------------------------------------------------------------------
203   public Float getMaxFragmentMass()
204   {
205      return (Float) get(MAX_FRAG_MASS).getValue();
206   }
207
208
209   //---------------------------------------------------------------------------
210   /**
211    By specifying a modified cysteine a "virtual reduction" will be performed on
212    the protein before digestion.
213    @param inValue AminoAcid to substitute for x-linked or free cysteines
214    @return this DigestSettings object to enable method chaining
215    */
216   public DigestSettings setAlkylatedCys(AminoAcid inValue)
217   {
218      get(ALKYLATED_CYS).setValue(inValue != null ? inValue.name() : null);
219      return this;
220   }
221
222   //---------------------------------------------------------------------------
223   public AminoAcid getAlkylatedCys()
224   {
225      AminoAcid aa = null;
226      String stringValue = (String) get(ALKYLATED_CYS).getValue();
227      if (StringUtil.isSet(stringValue))
228      {
229         aa = AminoAcid.valueOf(stringValue);
230      }
231
232      return aa;
233   }
234
235   //---------------------------------------------------------------------------
236   /**
237    Returns whether the specified DigestFragment meets criteria for inclusion.
238    @param inFrag the DigestFragment to test for inclusion
239    @return whether the specified DigestFragment meets criteria for inclusion
240    */
241   public boolean meetsCriteria(DigestFragment inFrag)
242   {
243      boolean result = true;
244
245      if (   (getMinFragmentLength() != null && inFrag.length() < getMinFragmentLength())
246          || (getMinFragmentMass()   != null && inFrag.getMonoisotopicMass() < getMinFragmentMass())
247          || (getMaxFragmentLength() != null && inFrag.length() > getMaxFragmentLength())
248          || (getMaxFragmentMass()   != null && inFrag.getMonoisotopicMass() > getMaxFragmentMass()))
249      {
250         result = false;
251      }
252
253      return result;
254   }
255
256   //---------------------------------------------------------------------------
257   @Override
258   public DigestSettings clone()
259   {
260      return (DigestSettings) super.clone();
261   }
262}
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322