I am trying to write a workflow in Snakemake for my MD studies. This is test as well as a learning experience. My workflow looks like this:
# This is to set the GMX workflow using SnakeMake workflow system
mdp_files = "/mnt/e2f3_dp2/mdp_files/"
em_files = "/mnt/e2f3_dp2/01_prep/"
rule nvt_prep:
input:
coordinate = em_files + "em.gro" ,
topology = em_files + "topol.top" ,
mdparam = mdp_files+ "03_nvt_amber_1ns.mdp" ,
checkpoint = em_files + "em.gro"
output:
outf = "nvt.tpr"
shell:
"
gmx grompp -f {input.mdparam} \
-c {input.coordinate} \
-r {input.checkpoint} \
-p {input.topology} \
-o {output.outf}
"
rule nvt:
input:
rules.nvt_prep.output
output:
multiext("nvt", "edr", "xtc", "log", "cpt")
shell:"""gmx mdrun -v -deffnm {input}""""
rule temp:
output: "nvt_temp.xvg"
input:
energy= "nvt.tpr.edr"
shell: "echo Temperature | gmx energy -f {input.energy} -o {output}"
rule npt_prep:
input:
coordinate= "nvt.gro",
topology= em_files + "topol.top",
md_param= mdp_files+ "03_npt_amber_1ns.mdp",
checkpoint= "nvt.gro"
output: "npt.tpr"
shell:
"gmx grompp -f {input.md_param} \
-c {input.coordinate} \
-r {input.checkpoint} \
-p {input.topology} \
-o {output} "
rule npt:
input:
rules.npt_prep.output
output:
"nvt.edr",
"nvt.gro",
"nvt.cpt",
"nvt.xtc"
shell:
"gmx mdrun -v -deffnm {input} -nb gpu -pin on -nt 12 -gpu_id 1 -pinoffset 24"
It keeps throwing this error:
SyntaxError in file /mnt/e2f3_dp2/md3/gmx_workflow.text, line 19:
unterminated string literal :
None
'''
I tried googling, but could not figure out the prob. Its been many days, but still could not figure out whats wrong with this.
Tried to change the shell line with:
f"""gmx grompp ... """
But it did not work, tried single quote, multiple quotes, none seemed to work out.
Anyone, please help me figure out the problem, many thanks.
I am not sure this will solve your issue, but I usually don't write anything after the marks of multiple code lines
"""
Try :
Thank you, I tried with 3 quotes, it gave me same error, however, I changed to singel quote and put the indentation as shown. With this modification, it gave me the same error but now the line number is 13 (some improvement).
I am writing this in vim, so I dont think that there is some hiddern charater causing this. Any other idea, please.
For indentation, I am single or double tabbing, if it matters.
Smell like an indentation issue for sure. Try to simplify your script as much as possible (echo something as output, remove your inputs).
I also remember having some issue with tabs and moving my files around from one text editor to another, some text editors translate 1 tab as 2 or 4 spaces. It gave me a lot of headaches. Try to use a fix number of spaces and not tabs (even if tabs should work in theory)
Thank you, let me simplify it first, then I will update you. I have changed all the tabs to spaces, (1 tab == 4 spaces), but it did not solve the prob. I wll add one rule at a time, and then see, where I am getting error.
I noticed that it is difficult to convey the indentation properly in the biostars code widget, which is a little odd because this is essentially python code and python is most used these days. However, indentation inside the quotes should not matter for shell code. The way Bastien shows should work fine.
I was wondering if snakemake has a specific interpretation of
"""
, on top of python usual interpretation, which is making multiple lines comments.If you have a multiple lines command in
shell
you should use 3 double quotes ("""
)I tried your code literally and I got no syntax error in a dry run. If it was an indentation error, you should see something like
IndentationError in file <string>, line 13: unindent does not match any outer indentation level:
Are you sure this is your complete code? Possibly, you have some unterminated quotes higher up in the file?
Also, I haven't been able to get the exact error message you got. The closest I got was:
By inserting
' "
in line 3. I would look for a non-matching pair of quotes and the like.Thank you for the help, I have uploaded the complete script, fom top to bottom. My error is not identation, but "unterminated string". After checking so many examples, I could not figure out where I am making mistake. The following is the command I am running (I copied from terminal):