def test_specs__path_is_displayed_in_exception(): def _path_is_displayed_in_exception(spec, value): assert_raises_regexp(MakefileError, _DUMMY_PATH_STR, spec, _DUMMY_PATH, value) yield _path_is_displayed_in_exception, IsInt(), "foo" yield _path_is_displayed_in_exception, IsUnsignedInt(), -1 yield _path_is_displayed_in_exception, IsFloat(), "abc" yield _path_is_displayed_in_exception, IsBoolean(), 1 yield _path_is_displayed_in_exception, IsStr(), 1 yield _path_is_displayed_in_exception, IsNone(), 1 yield _path_is_displayed_in_exception, ValueLT(0), 1 yield _path_is_displayed_in_exception, ValueLE(0), 1 yield _path_is_displayed_in_exception, ValueGE(0), -1 yield _path_is_displayed_in_exception, ValueGT(0), -1 yield _path_is_displayed_in_exception, ValueIn([1]), 2 yield _path_is_displayed_in_exception, ValuesIntersect([1]), [2] yield _path_is_displayed_in_exception, ValuesSubsetOf([1]), [2] yield _path_is_displayed_in_exception, ValueMissing(), True yield _path_is_displayed_in_exception, And(IsStr), 1 yield _path_is_displayed_in_exception, Or(IsStr), 1 yield _path_is_displayed_in_exception, Xor(IsStr, IsInt), True yield _path_is_displayed_in_exception, Not(IsInt), 1 yield _path_is_displayed_in_exception, StringIn("abc"), 1 yield _path_is_displayed_in_exception, StringsIntersect("abc"), [1] yield _path_is_displayed_in_exception, StringsSubsetOf("abc"), [1] yield _path_is_displayed_in_exception, StringIsUppercase(), 1 yield _path_is_displayed_in_exception, StringStartsWith("FOO"), 1 yield _path_is_displayed_in_exception, StringEndsWith("FOO"), 1 yield _path_is_displayed_in_exception, IsListOf(IsInt), "foo" yield _path_is_displayed_in_exception, IsDictOf(IsInt, IsInt), 1
def test_process_makefile__missing_list_default_value(): current = {"A": 1} expected = {"A": 1, "B": [1, 2, 3]} specs = {"A": IsInt, "B": IsListOf(IsInt, default=[1, 2, 3])} result = process_makefile(current, specs) assert_equal(result, expected)
def test_is_list_of__default_set__valid_value(): spec = IsListOf(IsInt, default=range(5)) assert_equal(spec.default, range(5))
def test_is_list_of__non_list_rejected(): spec = IsListOf(IsInt) assert_raises(MakefileError, spec, _DUMMY_PATH, {1: 2})
def test_is_list_of__default_not_set(): spec = IsListOf(IsInt) assert_is(spec.default, DEFAULT_NOT_SET)
def test_is_list_of__mixed_list_rejected(): spec = IsListOf(IsInt) assert_raises(MakefileError, spec, _DUMMY_PATH, [1, 'b', 3])
def test_is_list_of__default_description(): spec = IsListOf(IsInt, IsFloat) assert_equal(spec.description, "[(an integer) or (a float), ...]")
def test_is_list_of__list_of_ints_accepted(): spec = IsListOf(IsInt) spec(_DUMMY_PATH, [1, 2, 3])
def test_is_list_of__list_of_non_ints_rejected(): spec = IsListOf(IsInt) assert_raises(MakefileError, spec, _DUMMY_PATH, ['a', 'b', 'c'])
def test_is_list_of__empty_list_always_ok(): spec = IsListOf(IsInt) spec(_DUMMY_PATH, [])
CLI_PARAMETERS, }, } _VALIDATION = { "Project": { "Title": IsStr(default="Untitled"), "Samples": _VALIDATION_SAMPLES, "RegionsOfInterest": { IsStr: { "Prefix": IsStr(default=REQUIRED_VALUE), "Realigned": IsBoolean(default=False), "ProteinCoding": IsBoolean(default=False), "IncludeIndels": IsBoolean(default=True), "HomozygousContigs": { IsStr: Or(IsNone, IsListOf(IsStr)) }, }, }, "FilterSingletons": { IsStr: [IsStr], }, }, "Genotyping": { "Defaults": _VALIDATION_GENOTYPES, IsStr: _VALIDATION_GENOTYPES, }, "MultipleSequenceAlignment": { "Defaults": _VALIDATION_MSA, IsStr: _VALIDATION_MSA, },
_VALID_TARGET_NAME = \ And(_alphanum_check(whitelist="._-"), ValueGE(2, key=len, description="at least two characters long")) _VALIDATION_OPTIONS = { # Sequencing platform, used to tag read-groups. "Platform": StringIn(("CAPILLARY", "LS454", "ILLUMINA", "SOLID", "HELICOS", "IONTORRENT", "PACBIO"), default="ILLUMINA"), # Offset for quality scores in FASTQ files. "QualityOffset": ValueIn((33, 64, "Solexa"), default=33), # Split a lane into multiple entries, one for each (pair of) file(s) "SplitLanesByFilenames": Or(IsBoolean, IsListOf(IsStr), default=True), # Format to use when compressing FASTQ files ("gz" or "bz2") "CompressionFormat": ValueIn(("gz", "bz2"), default="bz2"), "AdapterRemoval": { "Version": ValueIn(("v1.4", "v1.5+"), default="v1.5+"), "--pcr1": IsStr, "--pcr2": IsStr, "--adapter1": IsStr, "--adapter2": IsStr, "--maxns": IsUnsignedInt, "--minquality": IsUnsignedInt, "--trimns": Or(IsNone, IsBoolean), "--trimqualities": Or(IsNone, IsBoolean), "--collapse": Or(IsNone, IsBoolean, default=True), "--mm": Or(IsFloat, IsUnsignedInt, default=3),
}, }, } _VALIDATION = { "Project" : { "Title" : IsStr, "Taxa" : _validate_taxa, "Intervals" : { IsStr : { "Genome" : IsStr, "Protein coding" : IsBoolean, "Orthology map" : IsStr, "Homozygous Contigs" : { IsStr : IsListOf(IsStr), }, }, }, "Filter Singletons" : { IsStr : IsListOf(IsStr), }, }, "Genotyping" : { "Default" : OneOf("random", "samtools", case_sensitive = False), "Padding" : IsInt, "Indels" : IsBoolean, AnyOf("MPileup", "BCFTools", "Random") : { IsStrWithPrefix("-") : CLI_PARAMETERS, }, "VCF_Filter" : {
from pypeline.common.makefile import \ read_makefile, \ IsUnsignedInt, \ IsFloat, \ IsStr, \ IsBoolean, \ And, \ Or, \ ValueIn, \ IsNone, \ StringIn, \ ValueGE, \ ValuesSubsetOf, \ IsListOf EXCLUDEBED = Or(IsListOf(IsStr), IsStr, IsNone, default=None) 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_BED_NAME = _VALID_TARGET_NAME = \ And(_alphanum_check(whitelist=".-"), ValueGE(2, key=len, description="at least two characters long"))