Example #1
0
def _alphanum_check(whitelist):
    description = "characters a-z, A-Z, 0-9%s allowed"
    description %= (", and %r" % whitelist, ) if whitelist else ""

    whitelist += string.ascii_letters + string.digits

    return And(IsStr(), ValuesSubsetOf(whitelist, description=description))
Example #2
0
 "PhylogeneticInference": {
     IsStr: {
         # Which program to use; TODO: Add support for other programs
         "Program": StringIn(("examl",), default="examl"),
         # Exclude one or more samples from the phylogeny
         "ExcludeSamples": [IsStr],
         # Which samples to root the final trees on / or midpoint rooting
         "RootTreesOn": [IsStr],
         # Create a tree per gene, for each region of interest,
         # or create a supermatrix tree from all regions specified.
         "PerGeneTrees": IsBoolean(default=False),
         # Selection of regions of interest / settings per region
         "RegionsOfInterest": {
             IsStr: {
                 "Partitions": Or(And(IsStr,
                                      ValuesSubsetOf("123456789X")),
                                  ValueIn([False]),
                                  default=REQUIRED_VALUE),
                 "SubsetRegions": Or(IsStr, IsNone, default=None),
             },
         },
         "SubsetRegions": {
             IsStr: IsStr,
         },
         "ExaML": {
             "Bootstraps": IsUnsignedInt(default=100),
             "Replicates": IsUnsignedInt(default=1),
             "Model": StringIn(("GAMMA", "PSR"),
                               default="gamma"),
         }
     }
Example #3
0
def test_subset_of__handles_types(value):
    spec = ValuesSubsetOf(list(range(5)))
    with pytest.raises(MakefileError,
                       match="Expected value: subset of 0, 1, 2, 3, and 4"):
        spec(_DUMMY_PATH, value)
Example #4
0
def test_subset_of__default_set__must_meet_spec():
    with pytest.raises(ValueError):
        ValuesSubsetOf(list(range(5)), default=[4, 5])
Example #5
0
def test_subset_of__default_set__valid_value():
    spec = ValuesSubsetOf(list(range(5)), default=[3, 4])
    assert spec.default == [3, 4]
Example #6
0
def test_subset_of__default_not_set():
    spec = ValuesSubsetOf(list(range(5)))
    assert spec.default is DEFAULT_NOT_SET
Example #7
0
def test_subset_of__chars__case_sensitive__rejects_differences_in_case():
    spec = ValuesSubsetOf("abcdefghijkl ")
    with pytest.raises(MakefileError):
        spec(_DUMMY_PATH, "A big DEAL")
Example #8
0

###############################################################################
###############################################################################
# Path is displayed in exception

_PATH_IN_EXCEPTION_VALUES = (
    (IsInt(), "foo"),
    (IsUnsignedInt(), -1),
    (IsFloat(), "abc"),
    (IsBoolean(), 1),
    (IsStr(), 1),
    (IsNone(), 1),
    (ValueIn([1]), 2),
    (ValuesIntersect([1]), [2]),
    (ValuesSubsetOf([1]), [2]),
    (ValueMissing(), True),
    (And(IsStr), 1),
    (Or(IsStr), 1),
    (Not(IsInt), 1),
    (StringIn("abc"), 1),
    (StringStartsWith("FOO"), 1),
    (StringEndsWith("FOO"), 1),
    (IsListOf(IsInt), "foo"),
    (IsDictOf(IsInt, IsInt), 1),
)


@pytest.mark.parametrize("spec, value", _PATH_IN_EXCEPTION_VALUES)
def test_specs__path_is_displayed_in_exception(spec, value):
    with pytest.raises(MakefileError, match=_DUMMY_PATH_STR):
Example #9
0
def test_subset_of__case_sensitive__value_in_not_set():
    spec = ValuesSubsetOf(("Abc", "bCe", "cdE"))
    with pytest.raises(MakefileError):
        spec(_DUMMY_PATH, ["Bce"])
Example #10
0
def test_subset_of__case_sensitive__value_in_set():
    spec = ValuesSubsetOf(("Abc", "bCe", "cdE"))
    spec(_DUMMY_PATH, ["bCe"])
Example #11
0
def test_subset_of__empty_set():
    spec = ValuesSubsetOf(list(range(5)))
    spec(_DUMMY_PATH, [])
Example #12
0
def test_subset_of__multiple_values_not_in_set():
    spec = ValuesSubsetOf(list(range(5)))
    with pytest.raises(MakefileError):
        spec(_DUMMY_PATH, [4, 5])
Example #13
0
def test_subset_of__multiple_values_in_set():
    spec = ValuesSubsetOf(list(range(5)))
    spec(_DUMMY_PATH, [1, 4])
Example #14
0
def test_subset_of__single_value_in_set():
    spec = ValuesSubsetOf(list(range(5)))
    spec(_DUMMY_PATH, [1])
Example #15
0
    "DuplicateHist":
    IsBoolean(default=False),
    "RawBAM":
    IsBoolean(default=False),
    "RealignedBAM":
    IsBoolean(default=True),
    "Summary":
    IsBoolean(default=True),
    "mapDamage":
    Or(IsBoolean,
       StringIn(('rescale', 'model', 'plot', 'no', 'yes')),
       default=True)
}

_VALID_FEATURES_LIST = ValuesSubsetOf(
    ("Coverage", "Depths", "DuplicateHist", "mapDamage", "Raw BAM", "RawBAM",
     "Realigned BAM", "RealignedBAM", "Summary"))

_VALID_EXCLUDE_DICT = {
    "Single": IsBoolean(default=False),
    "Collapsed": IsBoolean(default=False),
    "CollapsedTruncated": IsBoolean(default=False),
    "Paired": IsBoolean(default=False),
    "Singleton": IsBoolean(default=False),
}

_VALID_EXCLUDE_LIST = ValuesSubsetOf(_READ_TYPES)


class BAMFeatures(PreProcessMakefile):
    """Makefile pre-processor that converts convert an old-style 'Features'
Example #16
0
def test_subset_of__chars__case_sensitive():
    spec = ValuesSubsetOf("abcdefghijkl ")
    spec(_DUMMY_PATH, "a big deal")
Example #17
0
 IsStr: {
     # Which program to use; TODO: Add support for other programs
     "Program": StringIn(("examl", ), default="examl"),
     # Exclude one or more samples from the phylogeny
     "ExcludeSamples": [IsStr],
     # Which samples to root the final trees on / or midpoint rooting
     "RootTreesOn": [IsStr],
     # Create a tree per gene, for each region of interest,
     # or create a supermatrix tree from all regions specified.
     "PerGeneTrees": IsBoolean(default=False),
     # Selection of regions of interest / settings per region
     "RegionsOfInterest": {
         IsStr: {
             "Partitions":
             Or(
                 And(IsStr, ValuesSubsetOf("123456789X")),
                 ValueIn([False]),
                 default=REQUIRED_VALUE,
             ),
             "SubsetRegions":
             Or(IsStr, IsNone, default=None),
         }
     },
     "SubsetRegions": {
         IsStr: IsStr
     },
     "ExaML": {
         "Bootstraps": IsUnsignedInt(default=100),
         "Replicates": IsUnsignedInt(default=1),
         "Model": StringIn(("GAMMA", "PSR"), default="gamma"),
     },