com.hfg.bio.seq.alignment.blast.BLAST_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.blast;
import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import com.hfg.setting.*;
import com.hfg.util.StringUtil;
import com.hfg.util.collection.CollectionUtil;
import com.hfg.xml.XMLTag;
//==============================================================================
/**
Settings used for BLAST search execution.
@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]
//==============================================================================
// http://www.ncbi.nlm.nih.gov/books/NBK279675/
public class BLAST_Settings extends Settings implements Cloneable
{
public static final String EXECUTABLE_DIR = "executable_dir";
public static final String BLAST_PROGRAM = "blast_program";
public static final String BLAST_DATABASE = "blast_db";
public static final String OUTPUT_FILENAME = "output_filename";
public static final String NUM_DESCRIPTIONS = "num_descriptions";
public static final String NUM_ALIGNMENTS = "num_alignments";
public static final String NUM_THREADS = "num_threads";
public static final String EVALUE = "evalue";
public static final String HTML = "html";
public static final String WORD_SIZE = "word_size";
public static final String SOFT_MASKING = "soft_masking";
public static final String COMMAND_LINE_PARAMS = "command_line_params";
//###########################################################################
// CONSTRUCTORS
//###########################################################################
//---------------------------------------------------------------------------
public BLAST_Settings()
{
super();
}
public BLAST_Settings(XMLTag inXMLTag)
{
super(inXMLTag);
}
//---------------------------------------------------------------------------
@Override
protected void init()
{
add(new StringSetting(EXECUTABLE_DIR));
add(new StringSetting(BLAST_PROGRAM));
add(new StringSetting(OUTPUT_FILENAME));
add(new StringListSetting(BLAST_DATABASE));
add(new IntSetting(NUM_DESCRIPTIONS));
add(new IntSetting(NUM_ALIGNMENTS));
add(new IntSetting(NUM_THREADS));
add(new IntSetting(WORD_SIZE));
add(new FloatSetting(EVALUE));
add(new BooleanSetting(HTML));
add(new BooleanSetting(SOFT_MASKING));
add(new StringSetting(COMMAND_LINE_PARAMS));
}
//###########################################################################
// PUBLIC METHODS
//###########################################################################
//---------------------------------------------------------------------------
public File getExecutableDir()
{
File executableDir = null;
String stringValue = get(EXECUTABLE_DIR).getStringValue();
if (StringUtil.isSet(stringValue))
{
executableDir = new File(stringValue);
}
return executableDir;
}
//---------------------------------------------------------------------------
@SuppressWarnings("unchecked")
public BLAST_Settings setExecutableDir(File inValue)
{
get(EXECUTABLE_DIR).setValue(inValue != null ? inValue.getAbsolutePath() : null);
return this;
}
//---------------------------------------------------------------------------
public BLAST_Program getBLAST_Program()
{
BLAST_Program program = null;
String stringValue = get(BLAST_PROGRAM).getStringValue();
if (StringUtil.isSet(stringValue))
{
program = BLAST_Program.valueOf(stringValue);
}
return program;
}
//---------------------------------------------------------------------------
@SuppressWarnings("unchecked")
public BLAST_Settings setBLAST_Program(BLAST_Program inValue)
{
get(BLAST_PROGRAM).setValue(inValue != null ? inValue.name() : null);
return this;
}
//---------------------------------------------------------------------------
public List getBLAST_Databases()
{
List dbs = null;
List stringList = (List) get(BLAST_DATABASE).getValue();
if (CollectionUtil.hasValues(stringList))
{
dbs = new ArrayList<>(stringList.size());
for (String dbString : stringList)
{
dbs.add(new BLAST_Database(dbString));
}
}
return dbs;
}
//---------------------------------------------------------------------------
@SuppressWarnings("unchecked")
public BLAST_Settings addBLAST_Database(BLAST_Database inValue)
{
if (inValue != null)
{
List dbs = getBLAST_Databases();
if (null == dbs)
{
dbs = new ArrayList<>(1);
}
if (! dbs.contains(inValue))
{
dbs.add(inValue);
}
setBLAST_Databases(dbs);
}
return this;
}
//---------------------------------------------------------------------------
@SuppressWarnings("unchecked")
public BLAST_Settings setBLAST_Databases(Collection inValues)
{
List stringList = null;
if (CollectionUtil.hasValues(inValues))
{
stringList = new ArrayList<>(inValues.size());
for (BLAST_Database db : inValues)
{
stringList.add(db.getAbsolutePath());
}
}
get(BLAST_DATABASE).setValue(stringList);
return this;
}
//---------------------------------------------------------------------------
public File getOutputFile()
{
File file = null;
String stringValue = get(OUTPUT_FILENAME).getStringValue();
if (StringUtil.isSet(stringValue))
{
file = new File(stringValue);
}
return file;
}
//---------------------------------------------------------------------------
@SuppressWarnings("unchecked")
public BLAST_Settings setOutputFile(File inValue)
{
get(OUTPUT_FILENAME).setValue(inValue != null ? inValue.getAbsolutePath() : null);
return this;
}
//---------------------------------------------------------------------------
public Integer getNumDescriptions()
{
return (Integer) get(NUM_DESCRIPTIONS).getValue();
}
//---------------------------------------------------------------------------
/**
Show one-line descriptions for this number of database sequences.
@param inValue the number of description lines
@return this Settings object to enable chaining
*/
@SuppressWarnings("unchecked")
public BLAST_Settings setNumDescriptions(Integer inValue)
{
get(NUM_DESCRIPTIONS).setValue(inValue);
return this;
}
//---------------------------------------------------------------------------
public Integer getNumAlignments()
{
return (Integer) get(NUM_ALIGNMENTS).getValue();
}
//---------------------------------------------------------------------------
/**
Show alignments for this number of database sequences.
@param inValue the number of alignments to show
@return this Settings object to enable chaining
*/
@SuppressWarnings("unchecked")
public BLAST_Settings setNumAlignments(Integer inValue)
{
get(NUM_ALIGNMENTS).setValue(inValue);
return this;
}
//---------------------------------------------------------------------------
public Integer getWordSize()
{
return (Integer) get(WORD_SIZE).getValue();
}
//---------------------------------------------------------------------------
/**
From the BLAST documentation:
"BLAST is a heuristic that works by finding word-matches between the query and database sequences.
One may think of this process as finding "hot-spots" that BLAST can then use to initiate extensions
that might eventually lead to full-blown alignments. For nucleotide-nucleotide searches (i.e., "blastn")
an exact match of the entire word is required before an extension is initiated, so that one normally
regulates the sensitivity and speed of the search by increasing or decreasing the word-size.
For other BLAST searches non-exact word matches are taken into account based upon the similarity between words."
@param inValue the word size to use
@return this Settings object to enable chaining
*/
@SuppressWarnings("unchecked")
public BLAST_Settings setWordSize(Integer inValue)
{
get(WORD_SIZE).setValue(inValue);
return this;
}
//---------------------------------------------------------------------------
public Integer getNumThreads()
{
return (Integer) get(NUM_THREADS).getValue();
}
//---------------------------------------------------------------------------
/**
Number of threads (CPUs) to use in the BLAST search.
@param inValue the number of threads
@return this Settings object to enable chaining
*/
@SuppressWarnings("unchecked")
public BLAST_Settings setNumThreads(Integer inValue)
{
get(NUM_THREADS).setValue(inValue);
return this;
}
//---------------------------------------------------------------------------
public Float getEValue()
{
return (Float) get(EVALUE).getValue();
}
//---------------------------------------------------------------------------
/**
Expect value (E) for saving hits.
@param inValue the e-value threshold
@return this Settings object to enable chaining
*/
@SuppressWarnings("unchecked")
public BLAST_Settings setEValue(Float inValue)
{
get(EVALUE).setValue(inValue);
return this;
}
//---------------------------------------------------------------------------
public Boolean htmlOutput()
{
return (Boolean) get(HTML).getValue();
}
//---------------------------------------------------------------------------
/**
Produce HTML output.
@param inValue whether to produce HTML output or not
@return this Settings object to enable chaining
*/
@SuppressWarnings("unchecked")
public BLAST_Settings setHTMLOutput(Boolean inValue)
{
get(HTML).setValue(inValue);
return this;
}
//---------------------------------------------------------------------------
public Boolean getSoftMasking()
{
return (Boolean) get(SOFT_MASKING).getValue();
}
//---------------------------------------------------------------------------
/**
Apply filtering locations as soft masks.
@param inValue whether to apply filtering locations as soft masks or not
@return this Settings object to enable chaining
*/
@SuppressWarnings("unchecked")
public BLAST_Settings setSoftMasking(Boolean inValue)
{
get(SOFT_MASKING).setValue(inValue);
return this;
}
//---------------------------------------------------------------------------
public String getCommandLineParams()
{
return (String) get(COMMAND_LINE_PARAMS).getValue();
}
//---------------------------------------------------------------------------
/**
Additional (optional) command line parameters for the end of the BLAST command
@param inValue the additional command line parameters to be appended to the end of the command
@return this Settings object to enable chaining
*/
@SuppressWarnings("unchecked")
public BLAST_Settings setCommandLineParams(String inValue)
{
get(COMMAND_LINE_PARAMS).setValue(inValue);
return this;
}
}