Set Seurat enviroment through Anaconda

I’m using the computional cluster to run R enviroment. But I haven’t got the access to the root or sudoers.
Usually, I will choose Docker to set up a totally independent enviroment. This doesn’t work right now, because to launch a docker daemon, you have to get the permission to access root.

I use linuxbrew to set up the enviroment at first. But sometimes it won’t work as well when it comes to the library dependencies.
The mainly reason is that linuxbrew just installs some softwares into the user’s directory, but we still depend on some system libraries and so on. For example, I found that the version of libstdc++ does not meet a software.
I installed all version of gcc and tried to substitute all correlated library to these system ones. However, even vim refuse to work right now.

Good news are that I recently Anaconda can support building a R enviroment friendly.
First of all, download the Anaconda3-2018.12-Linux-x86_64.sh according your operating system.
Then install softwares, I need library Seurat, so some softwares are needed:

1
2
3
4
5
6
7
sh Anaconda3-2018.12-Linux-x86_64.sh
cd Anaconda3
source bin/activate
conda create -n r_env r-essentials r-base
conda activate r_env
conda install hdf5
conda install -c r r-git2r

Then install all library you need inner R

1
2
3
4
5
6
7
install.packages("hdf5r")
install.packages("Seurat")
install.packages(c("WriteXLS", "devtools", "urltools", "pheatmap", "shinythemes","BiocManager"))
libraray(devtools)
install_github("ggjlab/scMCA")
BiocManager::install("clusterProfiler", version = "3.8")
BiocManager::install("piano", version = "3.8")

rmarkdown generate pdf

It is easy to generate html using through knit. However, sometimes pdf generating will be an obstacle. The most common advise is Pandoc.
However, when I try to generate pdfs, I found all format good in html became really unacceptable. After some search, I decided to generate PDF through webshot library in R. The installation step is as follows:

1
2
install.packages("webshot")
webshot::install_phantomjs()

Now you can generate pdf through Rscript:

1
2
library(webshot)
webshot("x.html", "y.pdf")

Problems emerged when opened the pdf file due to the pages. Because webshot generates pdf with a huge page without break, it is hard for pdf viewer to load a page. So I had to find anothe software. html-pdf can solve the pages problem, to install:

1
2
conda install nodejs
npm install -g html-pdf

Estar egg: knitter script for Rmd to generate html or pdfs

I just improve a script from stackoverflow

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/bin/sh

### Test usage; if incorrect, output correct usage and exit
if [ "$#" -gt 2 -o "$#" -lt 2 ]; then
echo "********************************************************************"
echo "* Knitter version 1.0 *"
echo "********************************************************************"
echo -e "The 'knitter' script converts Rmd files into HTML or PDFs. \n"
echo -e "usage: knitter file.Rmd file.{pdf,html} \n"
echo -e "Spaces in the filename or directory name may cause failure. \n"
exit
fi
# Stem and extension of file
extension1=`echo $1 | cut -f2 -d.`
extension2=`echo $2 | cut -f2 -d.`
name_without_ext=`echo $1 | cut -f1 -d.`
out_without_ext=`echo $2 | cut -f1 -d.`

### Test if file exist
if [[ ! -r $1 ]]; then
echo -e "\n File does not exist, or option mispecified \n"
exit
fi

### Test file extension
if [[ $extension1 != Rmd ]]; then
echo -e "\n Invalid input file, must be a Rmd-file \n"
exit
fi

# Create temporary script
# Use user-defined 'TMPDIR' if possible; else, use /tmp
if [[ -n $TMPDIR ]]; then
pathy=$TMPDIR
else
pathy=/tmp
fi
# Tempfile for the script
tempscript=`mktemp $pathy/tempscript.XXXXXX` || exit 1
if [[ $extension2 == "pdf" ]]; then
echo "library(rmarkdown);rmarkdown::render('"${1}"', 'html_document');" >> $tempscript
Rscript $tempscript
html-pdf "${name_without_ext}".html "${2}"
rm ${name_without_ext}.html
echo generate "${2}"
fi

if [[ $extension2 == "html" ]]; then
echo "library(rmarkdown); rmarkdown::render('"${1}"', 'html_document')" >> $tempscript
Rscript $tempscript
mv ${name_without_ext}.html ${2}
echo generate "${2}"
fi

if [[ $extension2 == "both" ]]; then
echo "library(rmarkdown);rmarkdown::render('"${1}"', 'html_document');" >> $tempscript
Rscript $tempscript
html-pdf "${name_without_ext}".html ${out_without_ext}.pdf
mv ${name_without_ext}.html ${out_without_ext}.html
echo generate "${out_without_ext}".html and "${out_without_ext}".pdf
fi