Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Changed float and decimal type safety
The is_decimal function is now used and allows the data type to be
any number including but not limited to float or decimal.
  • Loading branch information
nmsutton authored and etal committed Mar 11, 2013
1 parent 3340812 commit 4cad6b9
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions Bio/Phylo/Applications/_Fasttree.py
Expand Up @@ -6,7 +6,6 @@
__docformat__ = "restructuredtext en"

from Bio.Application import _Option, _Switch, _Argument, AbstractCommandline
from decimal import *

class FastTreeCommandline(AbstractCommandline):
"""Command-line wrapper for FastTree.
Expand Down Expand Up @@ -39,6 +38,13 @@ class FastTreeCommandline(AbstractCommandline):
from the command line use 'fasttree.exe -help' or 'fasttree.exe -expert' for more explanation of usage options
"""

def is_numeric(self, x):
try:
float(str(x))
return True
except ValueError:
return False

def __init__(self, cmd='fasttree', **kwargs):
self.parameters = [
Expand Down Expand Up @@ -356,18 +362,16 @@ def __init__(self, cmd='fasttree', **kwargs):
top 2*m hits of a 'close' neighbor, where close is
defined as d(seed,close) < 0.75 * d(seed, hit of rank 2*m),
and updates the top-hits as joins proceed""",
checker_function=(lambda x:
isinstance(x, float) or isinstance(x, Decimal)),
equate=False,
checker_function=(lambda x: FastTreeCommandline.is_numeric(self, x)),
equate=False,
),
_Option(['-close', 'close'],
"""Modify the close heuristic for the top-hit list
Top-hit heuristics:
By default, FastTree uses a top-hit list to speed up search
-close 0.75 -- modify the close heuristic, lower is more conservative""",
checker_function=(lambda x:
isinstance(x, float) or isinstance(x, Decimal)),
checker_function=(lambda x: FastTreeCommandline.is_numeric(self, x)),
equate=False,
),
_Option(['-refresh', 'refresh'],
Expand All @@ -378,8 +382,7 @@ def __init__(self, cmd='fasttree', **kwargs):
-refresh 0.8 -- compare a joined node to all other nodes if its
top-hit list is less than 80% of the desired length,
or if the age of the top-hit list is log2(m) or greater""",
checker_function=(lambda x:
isinstance(x, float) or isinstance(x, Decimal)),
checker_function=(lambda x: FastTreeCommandline.is_numeric(self, x)),
equate=False,
),
_Option(['-matrix', 'matrix'],
Expand Down Expand Up @@ -434,8 +437,7 @@ def __init__(self, cmd='fasttree', **kwargs):
-constraintWeight -- how strongly to weight the constraints. A value of 1
means a penalty of 1 in tree length for violating a constraint
Default: 100.0""",
checker_function=(lambda x:
isinstance(x, float) or isinstance(x, Decimal)),
checker_function=(lambda x: FastTreeCommandline.is_numeric(self, x)),
equate=False,
),
_Option(['-log', 'log'],
Expand Down

0 comments on commit 4cad6b9

Please sign in to comment.