Snakemake issue
0
0
Entering edit mode
2.9 years ago
brunobsouzaa ▴ 830

Hi everyone,

So, I'm trying to build a Snakefile that executes Illumina's basespace app to list all my projects and then ask the user which project he wants to download. If the project is on the list, the user just needs to provide the file extension that he wants, else he will be prompted to log into the right account. In the first case, depending on the file extension, a different script will be executed for each analysis, which can be a whole germline pipeline (CNV, SNP, Indel, and ACMG classification) or just a standard VEP annotation from basespace VCF file. Scrips is as follows:

import os
import yaml
import subprocess

# load in the config file which contains all the information needed for the workflow

with open("/home/idengene/snakemake-tutorial/config.yaml") as f:
config = yaml.safe_load(f)

### PROGRAMS AND FOLDERS USED

bam=config["BAM_OUT"]
read=config["READS"]
vcf_out=config["VCF_FOLDER"]
basespace=config["BASESPACE"]

rule proj_download:
output:
    vcf=directory(vcf_out),
    reads=directory(read)
script:
    bs=basespace
run:
    ("{script.bs} project list")
    answer = input("Is your project on the list? 'Yes' or 'No' [Y/N]: ").lower()
    if answer == "yes" or answer == "y":
        ext = input("Give me the extension you want [fastq|VCF]: ").lower()
        prj = input("Give me the project name: ")
        if answer == "yes" or answer == "y" and extension == "vcf":
            subprocess.call(['rm -rf {output.vcf}/*_ds.*/}'])
            subprocess.call(['rm {output.vcf}/VCFs/*'])
                {script.bs} download project --name prj --extension ext -o {output.vcf}
                        CALL VEP_annot.sh
                elif answer == 'yes' or answer == 'y' and extension == 'fastq':
                subprocess.call(['rm -rf {output.reads}/*_ds.*/}'])
                subprocess.call(['rm {output.reads}/reads/*}'])
                subprocess.call(['rm {output.bam}/*.*}'])
                    {script.bs} download project --name prj --extension ext -o {output.reads}
                CALL Script Germline.sh.sh
            else:
            print(f'{ext} is not a valid extension!')
    else:
        print("Need to authenticate on the right account")
        {script.bs} auth --force

So, the issue here is that I'm having the following error:

SyntaxError in line 22 of /home/idengene/snakemake-tutorial/Snakefile:
Multiple run or shell keywords in rule proj_download. (Snakefile, line 22)

Already tried including shell statement before all executable commands but the error persists. Also tried to use shell: instead of run: on line 22 but the error keeps the same.

Verified config file and everything is ok. It's working for the other parts of the pipeline (SNP call, indel call, CNV call, annotation, etc...)

Appreciate any help. Thanks.

EDIT: Having issues with formatting in this post!

Snakemake python • 1.6k views
ADD COMMENT
3
Entering edit mode

When script is provided, you can't declare run or shell because the external script is meant to replace shell or any inline code in run. https://snakemake.readthedocs.io/en/stable/snakefiles/rules.html#external-scripts . It reads like your script is better suited as an input.

rule:
    input:
        bs=basespace

As Jeremy mentioned, input is reserved inside run, so you would need to bind the function to a different name. For example,

user_input = input

rule:
    run:
        answer = user_input("Is your project on the list? 'Yes' or 'No' [Y/N]: ").lower()
ADD REPLY
1
Entering edit mode

Using that bind to avoid clashing of reserved words handy approach to know.
In case it helps someone else, I made a simple example Snakefile that uses the binding of Python's input to allow collecting text from the user as a Snakemake rule runs. It is here. The example pipeline just makes a few files, each with content the user provides at the prompt.
Snakemake is already installed and the snakefile will be pulled in automatically in MyBinder.org-served Jupyter sessions launched via this link. After the session spins up, click on the Jupyter logo in the upper right to go to JupyterLab if you prefer that interface instead of the classic. Both interfaces have terminals where you can run the snakefile; note the snakefile is in sub-directory named after the gist SHA.

ADD REPLY
1
Entering edit mode

input is a reserved word inside a python run block (it is the input files)

ADD REPLY
0
Entering edit mode

So input is being used to ask the user to provide an answer for a specific condition... Tried using input: statement but also it's not working!

ADD REPLY
0
Entering edit mode

@brunobsouzaa Could you edit the title of your post to be much more specific?
Keep in mind the person you help find it six months from now may just be yourself.

ADD REPLY

Login before adding your answer.

Traffic: 1922 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6