Search code examples
pythonsnakemake

Snakemake: error when using split command?


I'm getting an error when I use the Unix split command in the shell part of my Snakemake rule:

rule split:
    input:
            "test_file.txt"
    output:
            directory("split_test_file")
    shell:
            '''
            mkdir {output}
            split -1 3 {input} split_
            mv split_* {output}
            '''

This is the error:

Error in rule split:
jobid: 0
output: split_test_file
shell:
    
    mkdir split_test_file
    split -1 3 test_file.txt split_
    mv split_* split_test_file
    
    (one of the commands exited with non-zero exit code; note that snakemake uses bash strict mode!)

I think the error occurs in the mv split_* split_test_file line because when I run only the first 2 lines there is no error. I can't seem to find why I can't move all the files that resulted from splitting test_file.txt into the output directory? Thank you so much!


Solution

    1. There is a typo in split command, where -1 needs to be letter -l.
    2. Your mv command would result in error mv: cannot move ‘split_test_file’ to a subdirectory of itself, ‘split_test_file/split_test_file’. Both the files to be moved and the destination directory begin with same string split_, which leads to this error. Modifying either of them would fix this issue.