com.hfg.bio.seq.alignment.PairwiseSettings 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 pairwise 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 PairwiseSettings implements Cloneable
{
private SubstitutionMatrix mMatrix;
private Integer mMaxLocalAlignmentResults = sDefaultMaxLocalAlignmentResults;
private Integer mMinLocalAlignmentLength = sDefaultMinLocalAlignmentLength;
private Integer mMinQueryMatchLength = sDefaultMinQueryMatchLength;
private Map mGapPenaltyMap = new HashMap<>(2);
private SparseMatrix mTerminalPenaltyMatrix = new SparseMatrix<>();
private PairwiseAlignmentType mQueryAlignmentType = sDefaultAlignmentType;
private PairwiseAlignmentType mSubjectAlignmentType = sDefaultAlignmentType;
private int mMinNumOfBackgroundCycles = sDefaultMinNumOfBackgroundCycles;
private Integer mMinRawScore = sDefaultMinRawScore;
private boolean mCaseInsensitive = false;
private boolean mSubjectTemplateMode = false;
private boolean mCalculateStatisticalScores = false;
private boolean mDumpMatrices = false;
private static Integer sDefaultMaxLocalAlignmentResults = 10;
private static Integer sDefaultMinLocalAlignmentLength = 4;
private static Integer sDefaultMinQueryMatchLength = 4;
private static Integer sDefaultMinRawScore = 1;
private static int sDefaultMinNumOfBackgroundCycles = 50;
private static GapPenalties sDefaultGapPenalties = new GapPenalties().setOpenPenalty(-5f).setExtensionPenalty(-2f);
private static Map sDefaultMatrixMap = new HashMap<>(2);
private static PairwiseAlignmentType sDefaultAlignmentType = PairwiseAlignmentType.LOCAL;
static
{
sDefaultMatrixMap.put(BioSequenceType.PROTEIN, SubstitutionMatrix.BLOSUM62);
sDefaultMatrixMap.put(BioSequenceType.NUCLEIC_ACID, SubstitutionMatrix.NUCLEOTIDE);
}
//###########################################################################
// CONSTRUCTORS
//###########################################################################
//---------------------------------------------------------------------------
public PairwiseSettings()
{
init();
}
//---------------------------------------------------------------------------
private void init()
{
setGapPenalties(sDefaultGapPenalties);
setPenalizeTerminalGaps(true);
}
//###########################################################################
// PUBLIC METHODS
//###########################################################################
//---------------------------------------------------------------------------
public PairwiseSettings 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;
}
//---------------------------------------------------------------------------
public PairwiseSettings setMaxLocalAlignmentResults(Integer inValue)
{
mMaxLocalAlignmentResults = inValue;
return this;
}
//---------------------------------------------------------------------------
public Integer getMaxLocalAlignmentResults()
{
return mMaxLocalAlignmentResults;
}
//---------------------------------------------------------------------------
public PairwiseSettings setMinLocalAlignmentLength(Integer inValue)
{
mMinLocalAlignmentLength = inValue;
return this;
}
//---------------------------------------------------------------------------
public Integer getMinLocalAlignmentLength()
{
return mMinLocalAlignmentLength;
}
//---------------------------------------------------------------------------
/**
Specifies the minimum number of non-gap characters for the query in the alignment.
@param inValue the minimum number of non-gap characters for the query in the alignment
@return this settings object to facilitate method chaining
*/
public PairwiseSettings setMinQueryMatchLength(Integer inValue)
{
mMinQueryMatchLength = inValue;
return this;
}
//---------------------------------------------------------------------------
public Integer getMinQueryMatchLength()
{
return mMinQueryMatchLength;
}
//---------------------------------------------------------------------------
public PairwiseSettings setMinRawScore(Integer inValue)
{
mMinRawScore = inValue;
return this;
}
//---------------------------------------------------------------------------
public Integer getMinRawScore()
{
return mMinRawScore;
}
//---------------------------------------------------------------------------
/**
If specified as true, query gaps are not penalized if they exist in the subject.
@param inValue whether or not to apply subject template mode scoring
@return this settings object (for possible method chaining)
*/
public PairwiseSettings setSubjectTemplateMode(boolean inValue)
{
mSubjectTemplateMode = inValue;
return this;
}
//---------------------------------------------------------------------------
public boolean getSubjectTemplateMode()
{
return mSubjectTemplateMode;
}
//---------------------------------------------------------------------------
/**
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 PairwiseSettings 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 PairwiseSettings setGapPenalties(GapPenalties inValue)
{
setGapPenalties(PairwiseSeqType.QUERY, inValue.clone());
setGapPenalties(PairwiseSeqType.SUBJECT, inValue.clone());
return this;
}
//---------------------------------------------------------------------------
public PairwiseSettings setGapPenalties(PairwiseSeqType inPairwiseSeqType, GapPenalties inValue)
{
mGapPenaltyMap.put(inPairwiseSeqType, inValue);
return this;
}
//---------------------------------------------------------------------------
public GapPenalties getGapPenalties(PairwiseSeqType inPairwiseSeqType)
{
return mGapPenaltyMap.get(inPairwiseSeqType);
}
//---------------------------------------------------------------------------
public PairwiseSettings setPenalizeTerminalGaps(boolean inValue)
{
setPenalizeTerminalGaps(PairwiseSeqType.QUERY, inValue);
setPenalizeTerminalGaps(PairwiseSeqType.SUBJECT, inValue);
return this;
}
//---------------------------------------------------------------------------
public PairwiseSettings setPenalizeTerminalGaps(PairwiseSeqType inPairwiseSeqType, boolean inValue)
{
setPenalizeTerminalGaps(inPairwiseSeqType, PairwiseSeqTerminus.LEFT, inValue);
setPenalizeTerminalGaps(inPairwiseSeqType, PairwiseSeqTerminus.RIGHT, inValue);
return this;
}
//---------------------------------------------------------------------------
public PairwiseSettings 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);
}
//---------------------------------------------------------------------------
public PairwiseSettings setAlignmentType(PairwiseAlignmentType inValue)
{
setQueryAlignmentType(inValue);
setSubjectAlignmentType(inValue);
return this;
}
//---------------------------------------------------------------------------
public PairwiseSettings setQueryAlignmentType(PairwiseAlignmentType inValue)
{
mQueryAlignmentType = inValue;
return this;
}
//---------------------------------------------------------------------------
public PairwiseAlignmentType getQueryAlignmentType()
{
return mQueryAlignmentType;
}
//---------------------------------------------------------------------------
public PairwiseSettings setSubjectAlignmentType(PairwiseAlignmentType inValue)
{
mSubjectAlignmentType = inValue;
return this;
}
//---------------------------------------------------------------------------
public PairwiseAlignmentType getSubjectAlignmentType()
{
return mSubjectAlignmentType;
}
//---------------------------------------------------------------------------
public PairwiseSettings setMinNumOfBackgroundCycles(int inValue)
{
mMinNumOfBackgroundCycles = inValue;
return this;
}
//---------------------------------------------------------------------------
public int getMinNumOfBackgroundCycles()
{
return mMinNumOfBackgroundCycles;
}
//---------------------------------------------------------------------------
/**
Specifies whether or not to calculate an E-value, P-value, and Z score by
generating background alignments.
@param inValue whether or not to calculate statistical measures for the alignment
@return this settings object (for possible method chaining)
*/
public PairwiseSettings setCalculateStatisticalScores(boolean inValue)
{
mCalculateStatisticalScores = inValue;
return this;
}
//---------------------------------------------------------------------------
public boolean getCalculateStatisticalScores()
{
return mCalculateStatisticalScores;
}
//---------------------------------------------------------------------------
public PairwiseSettings setDumpMatrices(boolean inValue)
{
mDumpMatrices = inValue;
return this;
}
//---------------------------------------------------------------------------
public boolean getDumpMatrices()
{
return mDumpMatrices;
}
//---------------------------------------------------------------------------
@Override
public PairwiseSettings clone()
{
PairwiseSettings cloneObj;
try
{
cloneObj = (PairwiseSettings) super.clone();
}
catch (CloneNotSupportedException e)
{
throw new ProgrammingException(e);
}
return cloneObj;
}
}