예제 #1
0
    return _validate_makefiles(config, makefiles)


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))


# Valid names for prefixes
_VALID_PREFIX_NAME = \
    And(_alphanum_check(whitelist="._-*"),
        Not(StringIn(["Options"] + [(s + "Reads") for s in _READ_TYPES])))

# Valid paths for prefixes; avoids some problems with e.g. Bowtie2
_VALID_PREFIX_PATH = \
    And(IsStr(), Not(ValuesIntersect("\\:?\"<>|() \t\n\v\f\r")),
        default=REQUIRED_VALUE)

# Valid strings for targets / samples / libraries / lanes
_VALID_TARGET_NAME = \
    And(_alphanum_check(whitelist="._-"),
        ValueGE(2, key=len, description="at least two characters long"))

_VALID_FEATURES_DICT = {
    "Coverage":
    IsBoolean(default=True),
    "Depths":
예제 #2
0

def _alphanum_check(whitelist, min_len=1):
    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(min_len=min_len),
               ValuesSubsetOf(whitelist, description=description))


# Valid names for prefixes
_VALID_PREFIX_NAME = And(
    _alphanum_check(whitelist="._-*"),
    Not(StringIn(["Options"] + [(s + "Reads") for s in _READ_TYPES])),
)

# Valid paths for prefixes; avoids some problems with e.g. Bowtie2
_VALID_PREFIX_PATH = And(IsStr(),
                         Not(ValuesIntersect('\\:?"<>|() \t\n\v\f\r')),
                         default=REQUIRED_VALUE)

# Valid strings for targets / samples / libraries / lanes
_VALID_TARGET_NAME = _alphanum_check(whitelist="._-", min_len=2)

_VALID_FEATURES_DICT = {
    "Coverage": IsBoolean(default=True),
    "Depths": IsBoolean(default=True),
    "DuplicateHist": RemovedOption(),
    "RawBAM": RemovedOption(),
예제 #3
0
        msa[key] = fill_dict(msa.get(key, {}), defaults)

    unknown_regions = set(msa) - set(mkfile["Project"]["Regions"])
    if unknown_regions:
        raise MakefileError("Unknown Regions of Interest in Genotyping: %s" \
                            % (", ".join(unknown_regions),))


# Recursive definition of sample tree
_VALIDATION_SUBSAMPLE_KEY = And(StringStartsWith("<"),
                                StringEndsWith(">"))
_VALIDATION_SAMPLES_KEY = And(IsStr, Not(_VALIDATION_SUBSAMPLE_KEY))
_VALIDATION_SAMPLES = {
    _VALIDATION_SAMPLES_KEY: {
        "GenotypingMethod": StringIn(("reference sequence",
                                      "random sampling",
                                      "samtools"),
                                     default="samtools"),
        "SpeciesName": IsStr,  # Not used; left for backwards compatibility
        "CommonName": IsStr,   # Not used; left for backwards compatibility
        "Sex": IsStr(),
        "Gender": IsStr(),
    }
}
_VALIDATION_SAMPLES[_VALIDATION_SUBSAMPLE_KEY] = _VALIDATION_SAMPLES

# Genotyping settings; note that explicit lists must not be used here, to allow
# proper inheritance of default values. Use IsListOf instead.
_VALIDATION_GENOTYPES = {
    "Padding": IsUnsignedInt,
    "GenotypeEntirePrefix": IsBoolean(default=False),
    "MPileup": {
예제 #4
0
def test_string_in__default_set__must_meet_spec():
    with pytest.raises(ValueError):
        StringIn("ABCDEFGH", default="i")
예제 #5
0
def test_string_in__handles_types(value):
    spec = StringIn("ABC")
    with pytest.raises(MakefileError,
                       match="Expected value: one of 'A', 'B', or 'C'"):
        spec(_DUMMY_PATH, value)
예제 #6
0
def test_string_in__default_not_set():
    spec = StringIn("ABCDEFGH")
    assert spec.default is DEFAULT_NOT_SET
예제 #7
0
def test_string_in__default_set__valid_value():
    spec = StringIn("ABCDEFGH", default="e")
    assert spec.default == "e"
예제 #8
0
def test_string_in__case_insensitive__mixed_string__string_found():
    spec = StringIn(("A", "c", "B", 1, 2, 3))
    spec(_DUMMY_PATH, "a")
예제 #9
0
def test_string_in__case_insensitive__value_not_set():
    spec = StringIn(("Abc", "bCe", "cdE"))
    with pytest.raises(MakefileError):
        spec(_DUMMY_PATH, "ABce")
예제 #10
0
def test_string_in__case_insensitive__value_in_set():
    spec = StringIn(("Abc", "bCe", "cdE"))
    spec(_DUMMY_PATH, "Bce")
예제 #11
0
_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):
        spec(_DUMMY_PATH, value)


###############################################################################
###############################################################################
예제 #12
0
# proper inheritance of default values. Use IsListOf instead.
_VALIDATION_GENOTYPES = {
    "Padding": IsUnsignedInt,
    "GenotypeEntirePrefix": IsBoolean(default=False),
    "MPileup": {
        StringStartsWith("-"): Or(IsInt, IsStr, IsNone)
    },
    "BCFTools": {
        StringStartsWith("-"): Or(IsInt, IsStr, IsNone)
    },
    "Random": {
        "--min-distance-to-indels": IsUnsignedInt
    },
    "VCF_Filter": {
        "MaxReadDepth":
        Or(IsUnsignedInt, IsDictOf(IsStr, IsUnsignedInt), StringIn(
            ("auto", ))),
        "--keep-ambigious-genotypes":
        IsNone,
        "--min-quality":
        IsUnsignedInt,
        "--min-allele-frequency":
        RemovedOption,
        "--min-mapping-quality":
        IsUnsignedInt,
        "--min-read-depth":
        IsUnsignedInt,
        "--max-read-depth":
        IsUnsignedInt,
        "--min-num-alt-bases":
        IsUnsignedInt,
        "--min-distance-to-indels":