This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Rstudio server in Snakemake

Hello, I am new to using Snakemake and I am running a test script calling an R script. I work on a restricted server and I have access to a docker R studio server to run everything. However, it seems I am not able to connect the Snakemake to the Rstudio docker. Is that possible? Or do I need to install R?

This is my R script:

args = commandArgs(trailingOnly = TRUE)

num_cells = args[[1]]

write.table("Cells: 1000", num_cells)

This is the Snakemake script (Snakemake_Test1_PS.txt):

rule test_file:
    output:
        num_cells="all_cells.txt"
    shell:
        "Rstudio --no_environ Scripts/testing_snakemake.R {output.num_cells}"

Output:

$ snakemake -s Snakemake_Test1_PS.txt
Building DAG of jobs...
Using shell: /usr/bin/bash
Provided cores: 88
Rules claiming more threads will be scaled down.
Job counts:
        count   jobs
        1       read_file
        1

[Tue Jul 18 12:38:20 2023]
rule read_file:
    output: all_cells.txt
    jobid: 0

/usr/bin/bash: Rstudio: command not found
[Tue Jul 18 12:38:20 2023]
Error in rule read_file:
    jobid: 0
    output: all_cells.txt
    shell:
        Rstudio --no_environ Scripts/testing_snakemake.R all_cells.txt
        (one of the commands exited with non-zero exit code; note that snakemake uses bash strict mode!)

Thank you!!

server rstudio snakemake

Why do you run Rstudio and not simply R?

I would like to run it in the R studio server environment I have. But either way just R doesn't work either. I get the exact same error

So do you run the script inside the docker? Do you run this specific part in the docker?

No, it doesn't work inside the docker because Snakemake isnt recognized. I run the docker using:

sudo docker exec -it rstudio_server4.2 bash

but mostly I use the Rstudio webpage interface linked to the docker

  1. You should avoid running anything with sudo, there is a way to run docker without a sudo, see here.
  2. You should tell snakemake in which environment it should run the rule. See here , you should add a docker: label to your rule.

Unfortunately I cannot do that. Although I have sudo access I wasn't given the docker account password. I understand that doesn't really make sense.

Running this:

rule test_file:
    output:
        num_cells="all_cells.txt"
    container:
        "docker://joseespinosa/docker-r-ggplot2"
    script:
        "Scripts/testing_snakemake.R"

Gives me this error

SyntaxError in line 4 of /redacted/Snakemake_Test1_PS.txt:
Unexpected keyword container in rule definition (Snakemake_Test1_PS.txt, line 4)

What version of snakemake are you using?

It is version 5.9.1

container support was introduced in 4.8.0 so it should work, but your version is quite old. I recommend updating to the latest version and giving it another try.

How do you normally use R/Rsudio on the server? It would appear that it is not installed / available. On our server, R is not available by default and requires running module load R to make it available. If it is not available at all you will need to install R and Rstudio for these commands to run.

I think thats my issue. I don't know how to have the console access the docker while still using the usual bash interface where Snakemake is. Or if that is even possible

1 answer

There are several ways you could do, I would suggest you make use of the container keyword in the test_file rule (see here Snakemake container). Generally it's also a good idea to use script instead of shell if you call R scripts (see here R script).

Log in to answer this question.