com.hfg.bio.seq.alignment.MSA_Settings Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of com_hfg Show documentation
Show all versions of com_hfg Show documentation
com.hfg xml, html, svg, and bioinformatics utility library
package com.hfg.bio.seq.alignment;
import java.util.HashMap;
import java.util.Map;
import com.hfg.bio.seq.BioSequenceType;
import com.hfg.bio.seq.alignment.matrix.SubstitutionMatrix;
import com.hfg.exception.ProgrammingException;
import com.hfg.util.collection.SparseMatrix;
//------------------------------------------------------------------------------
/**
Container for multiple sequence alignment settings.
@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 MSA_Settings implements Cloneable
{
private SubstitutionMatrix mMatrix;
private boolean mCaseInsensitive = false;
private int mKMerSize = sDefaultKMerSize;
private Map mGapPenaltyMap = new HashMap<>(2);
private SparseMatrix mTerminalPenaltyMatrix = new SparseMatrix<>();
private static int sDefaultKMerSize = 3;
private static GapPenalties sDefaultGapPenalties = new GapPenalties().setOpenPenalty(-5f).setExtensionPenalty(-2f);
private static Map sDefaultMatrixMap = new HashMap<>(2);
static
{
sDefaultMatrixMap.put(BioSequenceType.PROTEIN, SubstitutionMatrix.BLOSUM62);
sDefaultMatrixMap.put(BioSequenceType.NUCLEIC_ACID, SubstitutionMatrix.NUCLEOTIDE);
}
//###########################################################################
// CONSTRUCTORS
//###########################################################################
//---------------------------------------------------------------------------
public MSA_Settings()
{
init();
}
//---------------------------------------------------------------------------
private void init()
{
setGapPenalties(sDefaultGapPenalties);
setPenalizeTerminalGaps(true);
}
//###########################################################################
// PUBLIC METHODS
//###########################################################################
//---------------------------------------------------------------------------
public MSA_Settings setKMerSize(int inValue)
{
mKMerSize = inValue;
return this;
}
//---------------------------------------------------------------------------
public int getKMerSize()
{
return mKMerSize;
}
//---------------------------------------------------------------------------
public MSA_Settings setSubstitutionMatrix(SubstitutionMatrix inValue)
{
mMatrix = inValue;
return this;
}
//---------------------------------------------------------------------------
public SubstitutionMatrix getSubstitutionMatrix(BioSequenceType inSeqType)
{
if (null == mMatrix)
{
mMatrix = sDefaultMatrixMap.get(inSeqType != null ? inSeqType : BioSequenceType.NUCLEIC_ACID);
}
return mMatrix;
}
//---------------------------------------------------------------------------
/**
If specified as true, the scoring matrix's scoreCaseInsensitive() method is used.
@param inValue whether or not scoring is case insensitive
@return this settings object (for possible method chaining)
*/
public MSA_Settings setScoreCaseInsensitive(boolean inValue)
{
mCaseInsensitive = inValue;
return this;
}
//---------------------------------------------------------------------------
public boolean getScoreCaseInsensitive()
{
return mCaseInsensitive;
}
//---------------------------------------------------------------------------
/**
Sets the specified gap penalties for both the query and subject.
@param inValue GapPenalties to apply
@return this settings object (for possible method chaining)
*/
public MSA_Settings setGapPenalties(GapPenalties inValue)
{
setGapPenalties(PairwiseSeqType.QUERY, inValue.clone());
setGapPenalties(PairwiseSeqType.SUBJECT, inValue.clone());
return this;
}
//---------------------------------------------------------------------------
public MSA_Settings setGapPenalties(PairwiseSeqType inPairwiseSeqType, GapPenalties inValue)
{
mGapPenaltyMap.put(inPairwiseSeqType, inValue);
return this;
}
//---------------------------------------------------------------------------
public GapPenalties getGapPenalties(PairwiseSeqType inPairwiseSeqType)
{
return mGapPenaltyMap.get(inPairwiseSeqType);
}
//---------------------------------------------------------------------------
public MSA_Settings setPenalizeTerminalGaps(boolean inValue)
{
setPenalizeTerminalGaps(PairwiseSeqType.QUERY, inValue);
setPenalizeTerminalGaps(PairwiseSeqType.SUBJECT, inValue);
return this;
}
//---------------------------------------------------------------------------
public MSA_Settings setPenalizeTerminalGaps(PairwiseSeqType inPairwiseSeqType, boolean inValue)
{
setPenalizeTerminalGaps(inPairwiseSeqType, PairwiseSeqTerminus.LEFT, inValue);
setPenalizeTerminalGaps(inPairwiseSeqType, PairwiseSeqTerminus.RIGHT, inValue);
return this;
}
//---------------------------------------------------------------------------
public MSA_Settings setPenalizeTerminalGaps(PairwiseSeqType inPairwiseSeqType, PairwiseSeqTerminus inPairwiseSeqTerminus, boolean inValue)
{
mTerminalPenaltyMatrix.put(inPairwiseSeqType, inPairwiseSeqTerminus, inValue);
return this;
}
//---------------------------------------------------------------------------
public Boolean getPenalizeTerminalGaps(PairwiseSeqType inPairwiseSeqType, PairwiseSeqTerminus inPairwiseSeqTerminus)
{
return mTerminalPenaltyMatrix.get(inPairwiseSeqType, inPairwiseSeqTerminus);
}
//---------------------------------------------------------------------------
@Override
public MSA_Settings clone()
{
MSA_Settings cloneObj;
try
{
cloneObj = (MSA_Settings) super.clone();
}
catch (CloneNotSupportedException e)
{
throw new ProgrammingException(e);
}
return cloneObj;
}
}