def test_builder__finalize__calls_atomiccmd(): was_called = [] class _AtomicCmdMock: def __init__(self, *args, **kwargs): assert_equal(args, (["echo", "-out", "%(OUT_FILE)s", "%(IN_FILE)s"],)) assert_equal(kwargs, {"IN_FILE": "/in/file", "OUT_FILE": "/out/file", "set_cwd": True}) was_called.append(True) with Monkeypatch("paleomix.atomiccmd.builder.AtomicCmd", _AtomicCmdMock): builder = AtomicCmdBuilder("echo", set_cwd=True) builder.add_option("-out", "%(OUT_FILE)s") builder.add_value("%(IN_FILE)s") builder.set_kwargs(OUT_FILE="/out/file", IN_FILE="/in/file") builder.finalize() assert was_called
def test_builder__add_option__overwrite(): builder = AtomicCmdBuilder("find") builder.add_option("-name", "*.txt") builder.add_option("-or") builder.add_option("-name", "*.bat") assert_equal(builder.call, ["find", "-name", "*.txt", "-or", "-name", "*.bat"])
def test_builder__finalize__calls_atomiccmd(): was_called = [] class _AtomicCmdMock(object): def __init__(self, *args, **kwargs): assert_equal(args, (["echo", "-out", "%(OUT_FILE)s", "%(IN_FILE)s"], )) assert_equal(kwargs, { "IN_FILE": "/in/file", "OUT_FILE": "/out/file", "set_cwd": True }) was_called.append(True) with Monkeypatch("paleomix.atomiccmd.builder.AtomicCmd", _AtomicCmdMock): builder = AtomicCmdBuilder("echo", set_cwd=True) builder.add_option("-out", "%(OUT_FILE)s") builder.add_value("%(IN_FILE)s") builder.set_kwargs(OUT_FILE="/out/file", IN_FILE="/in/file") builder.finalize() assert was_called
def __init__( self, reference, infile, bedfile, outfile, mpileup_options={}, bcftools_options={}, dependencies=(), ): mpileup = AtomicCmdBuilder( ("bcftools", "mpileup", "%(IN_BAMFILE)s"), IN_BAMFILE=infile, IN_INTERVALS=bedfile, OUT_STDOUT=AtomicCmd.PIPE, CHECK_VERSION=BCFTOOLS_VERSION, ) # Ignore read-groups for pileup mpileup.add_option("--ignore-RG") # Reference sequence (FASTA) mpileup.add_option("--fasta-ref", reference) # Output compressed VCF mpileup.add_option("--output-type", "u") if bedfile: mpileup.set_option("--regions-file", "%(IN_INTERVALS)s") apply_options(mpileup, mpileup_options) genotype = AtomicCmdBuilder( ("bcftools", "call", "-"), IN_STDIN=mpileup, IN_BAMFILE=infile, OUT_STDOUT=outfile, CHECK_VERSION=BCFTOOLS_VERSION, ) genotype.set_option("--output-type", "z") apply_options(genotype, bcftools_options) CommandNode.__init__( self, description="<GenotypeRegions: '%s' -> '%s'>" % ( infile, outfile, ), command=ParallelCmds([mpileup.finalize(), genotype.finalize()]), dependencies=dependencies, )
def test_builder__pop_option__last_option(): builder = AtomicCmdBuilder("find") builder.add_option("-size", "0", fixed=False) builder.add_option("-size", "1", fixed=False) builder.pop_option("-size") assert_equal(builder.call, ["find", "-size", "0"])