Tuesday, May 27, 2014

Installing Shiny server

## Prepared by Diana Low
## https://github.com/dianalow
## $ cat /etc/*-release
## Red Hat Enterprise Linux Server release 6.5 (Santiago)
## $ uname -mrs
## Linux 2.6.32-431.11.2.el6.i686 i686
## Get Fedora EPEL
## Full guide here http://www.tecmint.com/how-to-enable-epel-repository-for-rhel-centos-6-5/
## Depends on your distro!
wget http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
rpm -ivh epel-release-6-8.noarch.rpm
## Verify repo
yum repolist
## Install R dependencies texinfo and texinfo-tex
## Check rpmfind for appropriate rpms
wget ftp://195.220.108.108/linux/centos/6.5/os/i386/Packages/texinfo-4.13a-8.el6.i686.rpm
wget ftp://195.220.108.108/linux/centos/6.5/os/i386/Packages/texinfo-tex-4.13a-8.el6.i686.rpm
rpm -ivh texinfo-4.13a-8.el6.i686.rpm
rpm -ivh texinfo-tex-4.13a-8.el6.i686.rpm
## Full instructions here: http://www.rstudio.com/shiny/server/install-opensource
## Install R
sudo yum install R
## Install Shiny package
sudo su - \
-c "R -e \"install.packages('shiny', repos='http://cran.rstudio.com/')\""
## Unfortunately the institute personal server is 32bit, so I have to compile Shiny server from source
## If yours is 64bit, just grab the rpm
## Full instructions here : https://github.com/rstudio/shiny-server/wiki/Building-Shiny-Server-from-Source
## Shiny dependencies
## cmake
wget http://www.cmake.org/files/v2.8/cmake-2.8.11.2.tar.gz
tar xzf cmake-2.8.11.2.tar.gz
cd cmake-2.8.11.2
./configure
make
sudo make install
## get the shiny-server pack!
# Clone the repository from GitHub
git clone https://github.com/rstudio/shiny-server.git
# Get into a temporary directory in which we'll build the project
cd shiny-server
mkdir tmp
cd tmp
# Add the bin directory to the path so we can reference node
DIR=`pwd`
PATH=$PATH:$DIR/../bin/
# See the "Python" section below if your default python version is not 2.6 or 2.7.
PYTHON=`which python`
# Check the version of Python. If it's not 2.6.x or 2.7.x, see the Python section below.
$PYTHON --version
# Use cmake to prepare the make step. Modify the "--DCMAKE_INSTALL_PREFIX"
# if you wish the install the software at a different location.
cmake -DCMAKE_INSTALL_PREFIX=/usr/local -DPYTHON="$PYTHON" ../
# Get an error here? Check the "How do I set the cmake Python version?" question below
# Recompile the npm modules included in the project
make
mkdir ../build
(cd .. && bin/npm --python="$PYTHON" rebuild)
# Need to rebuild our gyp bindings since 'npm rebuild' won't run gyp for us.
(cd .. && ext/node/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js --python="$PYTHON" rebuild)
# Install the software at the predefined location
sudo make install
# Place a shortcut to the shiny-server executable in /usr/bin
sudo ln -s /usr/local/shiny-server/bin/shiny-server /usr/bin/shiny-server
#Create shiny user. On some systems, you may need to specify the full path to 'useradd'
sudo useradd -r -m shiny
# Create log, config, and application directories
sudo mkdir -p /var/log/shiny-server
sudo mkdir -p /srv/shiny-server
sudo mkdir -p /var/lib/shiny-server
sudo chown shiny /var/log/shiny-server
sudo mkdir -p /etc/shiny-server
## Self compiled shiny-server did not auto create .conf file,
## so make your own at /etc/shiny-server/shiny-server.conf
## If not running pro version, be sure to comment out the pro-only commands in the .conf file
sudo /usr/local/shiny-server/bin/deploy-example default

Monday, May 26, 2014

Coursera course review : Interactive Python Programming

An Introduction to Interactive Programming in Python

Although it says "introduction in the title", do not be misled to think that it is an introduction to Python programming, rather, it is introducing *interactive* Python programming. Reading through the course forum, many beginners found it hard to grasp concepts fast enough to be able to do the weekly coding mini-projects (my background : I use Python everyday at work for years. I would say that if you are not completely clueless about programming, and have at least some encounter with coding concepts, this course is manageable). Having said that, the forum is a great resource and there are lots of people willing to help you out with coding problems and point you in the right direction.

You write and execute your code on CodeSkulptor (made by Scott, one of the course instructors). Great tool to eliminate the need for installs and there are custom modules created to take away the nitty gritty parts of graphical programming - and that helps lessens the frustration of potentially dealing with more technical issues.

What attracted me most to this course is the application of the concepts learned. Each week, students will code a game. You start text-based, and at the end you code a graphical game with sound and animation!

This course is a good example of applied coding skills, and the course instructors were very good in presenting concepts and helping with framing the projects, and kick-starting the enthusiasm to complete them every week.

Verdict: Highly recommended, and lots of fun.

Wednesday, May 21, 2014

Useful Javascript functions!

Personal list of useful functions:

Converting a Javascript array to a function arguments list 
Very important for writing short code when passing values to another function (exploding the list).

Tuesday, May 6, 2014

Adding column entries to DataFrame objects

The DataFrame class comes from the IRanges package and is used by several other packages (eg. Rsamtools) to read in bam files.

Simply cbind-ing a column to the DataFrame object will change it to the more conventional data.frame class.

So, instead of 
cbind(object1,newcolumn)

do:
cbind(object1,DataFrame(newcolumn))

to ensure that the result is still in the DataFrame class.

Monday, May 5, 2014

Subsetting/ extracting reads from bam files

1. Regions (make an index first, then select your regions)
samtools index bam_file 
samtools view -b file.bam chr1 > file_chr1.bam 
samtools view -b file.bam chr1:1-10000 > file_chr1_1_10000.bam 

2. Regions given in bed file
samtools view -bL regions.bed file.bam > file_regions.bam 

3. First n reads
samtools view -h file.bam | head -n 10000 | samtools view -bS - > file_n10000.bam