Browse files

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...
1 parent 3340812 commit 4cad6b96d6ad85d8bee41e735191255e8afc5f88 @nmsutton nmsutton committed with etal Mar 11, 2013
Showing with 12 additions and 10 deletions.
  1. +12 −10 Bio/Phylo/Applications/_Fasttree.py
View
22 Bio/Phylo/Applications/_Fasttree.py
@@ -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.
@@ -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 = [
@@ -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'],
@@ -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'],
@@ -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'],

0 comments on commit 4cad6b9

Please sign in to comment.