Skip to content

Commit

Permalink
Update docs: add dev_w_docker.md and include dev_w_docker.md in the d…
Browse files Browse the repository at this point in the history
…ocuments
  • Loading branch information
xies4 committed May 1, 2024
1 parent ca5fc24 commit e26ca06
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 1 deletion.
57 changes: 57 additions & 0 deletions docs/dev_w_docker.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
To develop R scripts for single cell sequencing data, docker container can be used. In the docker container, development can be finished using jupyter-lab.

If the goal is to develop an R script named `sc_singleR.prod.R`, we create two files:
```
sc_seurat_opt.R
sc_singleR.ipynb
```

1. Record the script path:

```
script_path = getwd() # %exclude_jupyterlab%
script_path # %exclude_jupyterlab%
```

2. Invoke `sc_singleR_opt.R` for command line options

Inside the notebook, we use the cell below to utilize `sc_seurat_opt.R` to read the command line options and save the information in an RDS file named `opt.rds`.

```
system(paste0('Rscript ', script_path, # %exclude_jupyterlab%
'/sc_singleR_opt.R --genome="hg38" --markerList="/Volumes/ccrsf-ifx/Software/scripts/bin/currentsnake/single_cell/gene_lists/human_gene_list.csv" --outdir="/Volumes/ccrsf-static/Analysis/xies4/github_repos/pipeline_dev_test/singleR" --rds="/Volumes/ccrsf-static/Analysis/xies4/github_repos/pipeline_dev_test/test_dir/seur_10x_cluster_object.rds"'), # %exclude_jupyterlab%
intern = T) # %exclude_jupyterlab%
```

3. Write the main code

First, read the options using readRDS:

```
opt = readRDS("/Volumes/ccrsf-static/Analysis/xies4/github_repos/pipeline_dev_test/singleR/opt.rds") # %exclude_jupyterlab%
```

Then include the code to accomplish the task.

4. Generate production script: `sc_singleR.prod.R`

The code below will first convert the `ipynb` file to a script file and combine the script for option `sc_singleR_opt.R` and `sc_singleR.r` (output file of `jupyter nbconvert -`) with exclusion of the lines with "exclude_jupyterlab".

```
notebook_prefix = "sc_singleR" # %exclude_jupyterlab%
notebook_name = paste0(notebook_prefix, ".ipynb") # %exclude_jupyterlab%
notebook_r = paste0(script_path, "/", paste0(notebook_prefix, ".r")) # %exclude_jupyterlab%
notebook_path = paste0(script_path, "/", notebook_name) # %exclude_jupyterlab%
opt_name = paste0(script_path, "/", sub(".ipynb", "_opt.R", notebook_name)) # %exclude_jupyterlab%
output = paste0(script_path, "/", sub(".ipynb", ".prod.R", notebook_name)) # %exclude_jupyterlab%
cmd1 = paste0("jupyter nbconvert --to script --output ", # %exclude_jupyterlab%
notebook_prefix, ' ', notebook_path, "> /dev/null 2>&1 ") # %exclude_jupyterlab%
cmd1 # %exclude_jupyterlab%
system(cmd1, intern = TRUE) # %exclude_jupyterlab%
cmd2 = paste0('cat ', opt_name, ' ', notebook_r, # %exclude_jupyterlab%
' |grep -v exclude_jupyterlab > ', output, ' 2>&1') # %exclude_jupyterlab%
cmd2 # %exclude_jupyterlab%
system(cmd2, intern = T) # %exclude_jupyterlab%
system(paste0("rm ", notebook_r)) # %exclude_jupyterlab%
```

2 changes: 1 addition & 1 deletion mkdocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ nav:
- Containerization for Snakemake pipeline:
- Build Snakemake pipeline with Singularity: pipeline_containerization.md
- Snakemake options for containerization: snakemake_opt4singularity.md

- Develop R scripts in the container: dev_w_docker.md
- FAQ:
- General Questions: general-questions.md
- Troubleshooting: troubleshooting.md
Expand Down

0 comments on commit e26ca06

Please sign in to comment.