diff --git a/docs/dev_w_docker.md b/docs/dev_w_docker.md new file mode 100644 index 0000000..af02a80 --- /dev/null +++ b/docs/dev_w_docker.md @@ -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% +``` + diff --git a/mkdocs.yaml b/mkdocs.yaml index fe1d0b9..0cf965e 100644 --- a/mkdocs.yaml +++ b/mkdocs.yaml @@ -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