carpentries-incubator / snakemake-novice-bioinformatics

Introduction to Snakemake for Bioinformatics
https://carpentries-incubator.github.io/snakemake-novice-bioinformatics
Other
18 stars 9 forks source link

Another option for formatting multi-line shell commands #48

Open tbooth opened 1 year ago

tbooth commented 1 year ago

From @jdblischak

I know you recommend using r""" to make the quoting more robust, but personally I find this more readable:

 shell:
        """
        fastqc -o . {input}
        mv {wildcards.sample}_fastqc.html {output.html}
        mv {wildcards.sample}_fastqc.zip  {output.zip}
        """

compared to your recommendation:

shell:
       r"""fastqc -o . {input}
           mv {wildcards.sample}_fastqc.html {output.html}
           mv {wildcards.sample}_fastqc.zip  {output.zip}
        """

Especially since this example doesn't require robust quoting.

tbooth commented 1 year ago

I had a look at the standard for docstrings, which are a common Python example of multi-line strings (https://peps.python.org/pep-0257/) but that simply says putting a newline right after the opening quotes is optional. I used the format I tend to use myself with but I guess I'm not really fussed either way.

Regarding when to use robust quoting, my current approach in my real workflows is to use robust quoting consistently for everything, rather then looking at each case and adding the r only when necessary. So I taught it the way I do it. But then you might fairly point out that I'm not using r"..." for regular quotes, so this is inconsistent.

Given that none of the examples in the main workflow rely on the r, perhaps this should be relegated to chapter 13 after all. It does make the code more readable.

tbooth commented 1 year ago

I've removed mention of r-strings until ep13. Still on the fence about how to place the text within the quotes.