Error Codes in Snakemake
1
0
Entering edit mode
26 days ago
888pea ▴ 10

Hello, I'm sorry if this is poorly written, it's my first time writing code with Snakemake, and my professor has given no instructions on how to deal with troubleshooting! I haven't found much help online because we're writing in Python, not Bash. I am getting an error code Expecting rule keyword, comment or docstrings inside a rule definition with the line genotypes= pd.read_table(str(input)) that my professor wrote! Any help would be appreciated

import pandas as pd

PEOPLE = ["X", "M"] 
rule all:
    input: expand("snaketest/{person}_homozygous.txt", person=PEOPLE)

rule create_genotype_counts:
    input: "/local-scratch/course_files/MBB110/fixed_genotypes/{person}_genotypes.txt"
    output: "snaketest/{person}_counts.txt"
    run: 
    genotypes= pd.read_table(str(input)) |
    [genotypes.chromosome.isin(["X", "Y", "MT"])] |
    [genotypes.genotype.isin(["--"])] |
    table1=genotypes.genotype.value_counts()
    out = open(str(output),"w")
    out.write(table1)
    out.close()
python snakemake • 472 views
ADD COMMENT
1
Entering edit mode

I believe you want genotypes= pd.read_table(str({input})), perhaps? The curly brackets mean to take the Snakemake directive setting in that context. Without that curly bracket, it would use what Python has as the input object. In a pure Python context input is a function to get user input from the command line. (Probably, a similar things for a later line involving out =. ) Your professor may have been hurriedly writing that and just forgot. (Or there is more instruction that you aren't sharing here as in that is a sketch of pseudocode and you are meant to make it work.) In the future, consult with your professor. You'll be programming with no safety net soon enough. For now take advantage of the resources you have to help you learn. "my professor has given no instructions on how to deal with troubleshooting! " usually means they assume you'll be consulting with them to troubleshoot.

ADD REPLY
0
Entering edit mode

my professor says " We are using python now, so instead of using the "shell:" part of the pipeline, we will be using "run:" . NOTE: when you use "run:", you do not have to use the curly brackets ({ and }) around input and output, BUT we do have a weird issue with snakemake in that we have to convert out input and output filenames to strings. I have provided the first line for this rule that shows you how to do this:"

Then, it's the example in my file! I don't see any examples like this here, lecture material, or in the documentation, so I am very confused about what to do! Unfortunately, my professor is unavailable until this is due (they are very absent from this course, and we only have limited time to talk with the TA)! If you point me to some non-bash resources, I would be very grateful!

ADD REPLY
2
Entering edit mode
25 days ago
genotypes= pd.read_table(str(input))

This is fine although I would prefer to give a name to input file and use that in the run directive:

rule create_genotype_counts:
    input: 
        gt="/local-scratch/course_files/MBB110/fixed_genotypes/{person}_genotypes.txt"
    output: 
        "snaketest/{person}_counts.txt"
    run: 
        genotypes= pd.read_table(input.gt)

More important, you seem to use the | operator as if it were a bash script and that won't work.


EDIT: Expecting rule keyword, comment or docstrings inside a rule definition this is because your run block is not indented.

ADD COMMENT
1
Entering edit mode

Thank you so much! My teacher must have used a different indentation from me so rewriting it solved my problem! Have a great day

ADD REPLY

Login before adding your answer.

Traffic: 2478 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