com.hfg.bio.seq.pattern.ProteinPatternMatcher 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.pattern;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import com.hfg.bio.seq.Protein;
import com.hfg.util.collection.CollectionUtil;
//------------------------------------------------------------------------------
/**
Examines a query sequence to find instances of the specified patterns.
@author J. Alex Taylor, hairyfatguy.com
*/
//------------------------------------------------------------------------------
// com.hfg 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 ProteinPatternMatcher
{
private List mPatterns;
private boolean mIgnoreGaps = false;
//###########################################################################
// CONSTRUCTORS
//###########################################################################
//--------------------------------------------------------------------------
public ProteinPatternMatcher()
{
}
//--------------------------------------------------------------------------
public ProteinPatternMatcher(ProteinPattern inPattern)
{
addPattern(inPattern);
}
//###########################################################################
// PUBLIC METHODS
//###########################################################################
//--------------------------------------------------------------------------
public ProteinPatternMatcher addPattern(ProteinPattern inValue)
{
if (null == mPatterns)
{
mPatterns = new ArrayList<>(25);
}
mPatterns.add(inValue);
inValue.setIgnoreGaps(mIgnoreGaps);
return this;
}
//--------------------------------------------------------------------------
public ProteinPatternMatcher addPatterns(Collection inValues)
{
if (CollectionUtil.hasValues(inValues))
{
for (ProteinPattern pattern : inValues)
{
addPattern(pattern);
}
}
return this;
}
//--------------------------------------------------------------------------
public ProteinPatternMatcher setIgnoreGaps(boolean inValue)
{
mIgnoreGaps = inValue;
if (CollectionUtil.hasValues(mPatterns))
{
for (ProteinPattern pattern : mPatterns)
{
pattern.setIgnoreGaps(inValue);
}
}
return this;
}
//--------------------------------------------------------------------------
public List match(Protein inQuery)
{
List matches = new ArrayList<>(25);
for (ProteinPattern proteinPattern : mPatterns)
{
List chains = new ArrayList<>(5);
if (CollectionUtil.hasValues(inQuery.getChains()))
{
chains.addAll(inQuery.getChains());
}
else
{
chains.add(inQuery);
}
for (Protein chain : chains)
{
SeqPatternMatcher m = proteinPattern.matcher(chain);
List patternMatches = m.findAll();
if (CollectionUtil.hasValues(patternMatches))
{
matches.addAll(patternMatches);
}
}
}
return matches;
}
}