All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.hfg.bio.DigestSettings Maven / Gradle / Ivy

There is a newer version: 20240423
Show newest version
package com.hfg.bio;


import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import com.hfg.setting.FloatSetting;
import com.hfg.setting.IntSetting;
import com.hfg.setting.Settings;
import com.hfg.setting.StringListSetting;
import com.hfg.setting.StringSetting;
import com.hfg.util.StringUtil;
import com.hfg.util.collection.CollectionUtil;

//------------------------------------------------------------------------------
/**
 Settings for protein digestion via protease(s).
 
@author J. Alex Taylor, hairyfatguy.com
*/ //------------------------------------------------------------------------------ // com.hfg XML/HTML Coding Library // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 2.1 of the License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // // J. Alex Taylor, President, Founder, CEO, COO, CFO, OOPS hairyfatguy.com // [email protected] //------------------------------------------------------------------------------ public class DigestSettings extends Settings implements Cloneable { public static final String PROTEASE = "protease"; public static final String MAX_MISSED_CLEAVAGES = "maxMissedCleavages"; public static final String MIN_FRAG_LENGTH = "minFragLength"; public static final String MAX_FRAG_LENGTH = "maxFragLength"; public static final String MIN_FRAG_MASS = "minFragMass"; public static final String MAX_FRAG_MASS = "maxFragMass"; public static final String ALKYLATED_CYS = "alkylatedCys"; private static int sDefaultMaxMissedCleavages = 0; private static int sDefaultMinFragmentLength = 1; //########################################################################### // CONSTRUCTORS //########################################################################### //--------------------------------------------------------------------------- public DigestSettings() { super(); init(); } //--------------------------------------------------------------------------- @Override protected void init() { add(new StringListSetting(PROTEASE)); add(new IntSetting(MAX_MISSED_CLEAVAGES, sDefaultMaxMissedCleavages)); add(new IntSetting(MIN_FRAG_LENGTH, sDefaultMinFragmentLength)); add(new IntSetting(MAX_FRAG_LENGTH)); add(new FloatSetting(MIN_FRAG_MASS)); add(new FloatSetting(MAX_FRAG_MASS)); add(new StringSetting(ALKYLATED_CYS)); } //########################################################################### // PUBLIC METHODS //########################################################################### //--------------------------------------------------------------------------- @SuppressWarnings("unchecked") public DigestSettings setProtease(Protease inValue) { List list = new ArrayList<>(1); list.add(inValue); return setProteases(list); } //--------------------------------------------------------------------------- @SuppressWarnings("unchecked") public DigestSettings setProteases(Collection inValues) { List stringListValue = null; if (CollectionUtil.hasValues(inValues)) { stringListValue = new ArrayList<>(inValues.size()); for (Protease protease : inValues) { stringListValue.add(protease.name()); } } get(PROTEASE).setValue(stringListValue); return this; } //--------------------------------------------------------------------------- @SuppressWarnings("unchecked") public Set getProteases() { Set proteases = null; List proteaseNames = (List) get(PROTEASE).getValue(); if (CollectionUtil.hasValues(proteaseNames)) { proteases = new HashSet<>(proteaseNames.size()); for (String proteaseName : proteaseNames) { proteases.add(Protease.valueOf(proteaseName)); } } return proteases; } //--------------------------------------------------------------------------- @SuppressWarnings("unchecked") public DigestSettings setMaxMissedCleavages(int inValue) { get(MAX_MISSED_CLEAVAGES).setValue(inValue); return this; } //--------------------------------------------------------------------------- public Integer getMaxMissedCleavages() { return (Integer) get(MAX_MISSED_CLEAVAGES).getValue(); } //--------------------------------------------------------------------------- @SuppressWarnings("unchecked") public DigestSettings setMinFragmentLength(Integer inValue) { get(MIN_FRAG_LENGTH).setValue(inValue); return this; } //--------------------------------------------------------------------------- public Integer getMinFragmentLength() { return (Integer) get(MIN_FRAG_LENGTH).getValue(); } //--------------------------------------------------------------------------- @SuppressWarnings("unchecked") public DigestSettings setMaxFragmentLength(Integer inValue) { get(MAX_FRAG_LENGTH).setValue(inValue); return this; } //--------------------------------------------------------------------------- public Integer getMaxFragmentLength() { return (Integer) get(MAX_FRAG_LENGTH).getValue(); } //--------------------------------------------------------------------------- @SuppressWarnings("unchecked") public DigestSettings setMinFragmentMass(Float inValue) { get(MIN_FRAG_MASS).setValue(inValue); return this; } //--------------------------------------------------------------------------- public Float getMinFragmentMass() { return (Float) get(MIN_FRAG_MASS).getValue(); } //--------------------------------------------------------------------------- @SuppressWarnings("unchecked") public DigestSettings setMaxFragmentMass(Float inValue) { get(MAX_FRAG_MASS).setValue(inValue); return this; } //--------------------------------------------------------------------------- public Float getMaxFragmentMass() { return (Float) get(MAX_FRAG_MASS).getValue(); } //--------------------------------------------------------------------------- /** By specifying a modified cysteine a "virtual reduction" will be performed on the protein before digestion. @param inValue AminoAcid to substitute for x-linked or free cysteines @return this DigestSettings object to enable method chaining */ public DigestSettings setAlkylatedCys(AminoAcid inValue) { get(ALKYLATED_CYS).setValue(inValue != null ? inValue.name() : null); return this; } //--------------------------------------------------------------------------- public AminoAcid getAlkylatedCys() { AminoAcid aa = null; String stringValue = (String) get(ALKYLATED_CYS).getValue(); if (StringUtil.isSet(stringValue)) { aa = AminoAcid.valueOf(stringValue); } return aa; } //--------------------------------------------------------------------------- /** Returns whether the specified DigestFragment meets criteria for inclusion. @param inFrag the DigestFragment to test for inclusion @return whether the specified DigestFragment meets criteria for inclusion */ public boolean meetsCriteria(DigestFragment inFrag) { boolean result = true; if ( (getMinFragmentLength() != null && inFrag.length() < getMinFragmentLength()) || (getMinFragmentMass() != null && inFrag.getMonoisotopicMass() < getMinFragmentMass()) || (getMaxFragmentLength() != null && inFrag.length() > getMaxFragmentLength()) || (getMaxFragmentMass() != null && inFrag.getMonoisotopicMass() > getMaxFragmentMass())) { result = false; } return result; } //--------------------------------------------------------------------------- @Override public DigestSettings clone() { DigestSettings copy; try { copy = (DigestSettings) super.clone(); } catch (CloneNotSupportedException e) { throw new RuntimeException(e); } return copy; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy