Thursday, February 27, 2014

Merging RNA-seq replicates from Tophat

Sometimes, you might want to present your replicates as one consensus sequencing track on viewers like IGV or IGB.

To merge bam files : Use samtools merge.
To merge junctions.bed files : Use the tbedjuncs and combineJuncs scripts at seqscripts
cat junctions_file1.bed junction_file_2.bed junction_file_3.bed | tbed2juncs | combineJuncs > combined.junctions.bed

Ref: http://seqanswers.com/forums/showthread.php?t=3381

Wednesday, February 26, 2014

Converting BAM files to BigWig format

One of the reasons to convert bam to BigWig is to get a normalized coverage in viewers such as IGB.

Tools needed

samtools (if your bam file is not sorted by position), bedtools and ucsc's bedGraphToBigWig in the ucsc command line utilities

Procedure

samtools sort input.bam input.sorted
mysql --user=genome --host=genome-mysql.cse.ucsc.edu -A -e "select chrom, size from hg19.chromInfo" > hg19.genome
bedtools genomecov -ibam input.sorted.bam -bg hg19.genome > input.sorted.bedGraph
bedGraphToBigWig input.sorted.bedGraph hg19.genome input.sorted.bigwig

Unfortunately we can't pipe genomecoverage directly into bedGraphToBigWig because bedGraphToBigWig does a few passes over the file (for improved speed).

Other things to consider:
1) Scaling : setting a scale factor (within bedtools) would normalize your bedgraph/bigwig files (the default=1, no scaling). I generally scale all files to say, 10 million reads (get total reads from eg. samtools flagstat output) so that they can be consistently used throughout different comparisons.
2) -split option should be used for RNA-seq to properly represent spliced reads.
3) -strand option in theory would give you strand-specific files (meaning you'll have a +ve and -ve set) but for my paired-end directional reads, it seems to only work for the first in read pair. I've left out this option until I figure out a solution.

Wednesday, February 19, 2014

R Shiny + qPCR calculator

The problem with R (and many other platform that involves some level of coding/commands for execution) for biologists is : how do I run/use a package? How do we, as developers, "package" them for mass consumption? Several years ago, I started with creating GUI interfaces to provide a point and click platform for my scripts in R, but this also requires the user to install R, have the relevant libraries installed.

Shiny takes care of that, putting your scripts on the web, and most importantly, frees the user from having to install anything.

As an exercise on building apps, I've created a simple qPCR calculator and plot generator.


More good things to come.

Monday, February 17, 2014

VNC (remote desktop) on Ubuntu

Server-side setup

Official Ubuntu help on VNC here : https://help.ubuntu.com/community/VNC/Servers

There are many flavours of VNC (server-side) in Linux, and the default one used by Ubuntu's Remote Desktop is vino (get it here https://apps.ubuntu.com/cat/applications/precise/vino/ if it is not installed)




Another option would be x11vnc, which offers more customizable options, if you need any.
sudo apt-get install x11vnc
x11vnc -usepw

Which will then give you the port to connect to on the client side.
e2@e2-ubuntu:~$ x11vnc -usepw
18/02/2014 08:55:41 -usepw: found /home/e2/.vnc/passwd
18/02/2014 08:55:41 x11vnc version: 0.9.12 lastmod: 2010-09-09  pid: 37014
18/02/2014 08:55:41 Using X display :0
18/02/2014 08:55:41 rootwin: 0x150 reswin: 0x5200001 dpy: 0x1641590
18/02/2014 08:55:41 
18/02/2014 08:55:41 ------------------ USEFUL INFORMATION ------------------
18/02/2014 08:55:41 X DAMAGE available on display, using it for polling hints.
18/02/2014 08:55:41   To disable this behavior use: '-noxdamage'
18/02/2014 08:55:41 
18/02/2014 08:55:41   Most compositing window managers like 'compiz' or 'beryl'
18/02/2014 08:55:41   cause X DAMAGE to fail, and so you may not see any screen
18/02/2014 08:55:41   updates via VNC.  Either disable 'compiz' (recommended) or
18/02/2014 08:55:41   supply the x11vnc '-noxdamage' command line option.
18/02/2014 08:55:41 
18/02/2014 08:55:41 Wireframing: -wireframe mode is in effect for window moves.
18/02/2014 08:55:41   If this yields undesired behavior (poor response, painting
18/02/2014 08:55:41   errors, etc) it may be disabled:
18/02/2014 08:55:41    - use '-nowf' to disable wireframing completely.
18/02/2014 08:55:41    - use '-nowcr' to disable the Copy Rectangle after the
18/02/2014 08:55:41      moved window is released in the new position.
18/02/2014 08:55:41   Also see the -help entry for tuning parameters.
18/02/2014 08:55:41   You can press 3 Alt_L's (Left "Alt" key) in a row to 
18/02/2014 08:55:41   repaint the screen, also see the -fixscreen option for
18/02/2014 08:55:41   periodic repaints.
18/02/2014 08:55:41 
18/02/2014 08:55:41 XFIXES available on display, resetting cursor mode
18/02/2014 08:55:41   to: '-cursor most'.
18/02/2014 08:55:41   to disable this behavior use: '-cursor arrow'
18/02/2014 08:55:41   or '-noxfixes'.
18/02/2014 08:55:41 using XFIXES for cursor drawing.
18/02/2014 08:55:41 GrabServer control via XTEST.
18/02/2014 08:55:41 
18/02/2014 08:55:41 Scroll Detection: -scrollcopyrect mode is in effect to
18/02/2014 08:55:41   use RECORD extension to try to detect scrolling windows
18/02/2014 08:55:41   (induced by either user keystroke or mouse input).
18/02/2014 08:55:41   If this yields undesired behavior (poor response, painting
18/02/2014 08:55:41   errors, etc) it may be disabled via: '-noscr'
18/02/2014 08:55:41   Also see the -help entry for tuning parameters.
18/02/2014 08:55:41   You can press 3 Alt_L's (Left "Alt" key) in a row to 
18/02/2014 08:55:41   repaint the screen, also see the -fixscreen option for
18/02/2014 08:55:41   periodic repaints.
18/02/2014 08:55:41 
18/02/2014 08:55:41 XKEYBOARD: number of keysyms per keycode 7 is greater
18/02/2014 08:55:41   than 4 and 51 keysyms are mapped above 4.
18/02/2014 08:55:41   Automatically switching to -xkb mode.
18/02/2014 08:55:41   If this makes the key mapping worse you can
18/02/2014 08:55:41   disable it with the "-noxkb" option.
18/02/2014 08:55:41   Also, remember "-remap DEAD" for accenting characters.
18/02/2014 08:55:41 
18/02/2014 08:55:41 X FBPM extension not supported.
18/02/2014 08:55:41 X display is capable of DPMS.
18/02/2014 08:55:41 --------------------------------------------------------
18/02/2014 08:55:41 
18/02/2014 08:55:41 Default visual ID: 0x21
18/02/2014 08:55:41 Read initial data from X display into framebuffer.
18/02/2014 08:55:41 initialize_screen: fb_depth/fb_bpp/fb_Bpl 24/32/7680
18/02/2014 08:55:41 
18/02/2014 08:55:41 X display :0 is 32bpp depth=24 true color
18/02/2014 08:55:41 
18/02/2014 08:55:41 Autoprobing TCP port 
18/02/2014 08:55:41 Autoprobing selected port 5903
18/02/2014 08:55:41 Listening also on IPv6 port 5903 (socket 11)
18/02/2014 08:55:41 
18/02/2014 08:55:41 Xinerama is present and active (e.g. multi-head).
18/02/2014 08:55:41 Xinerama: number of sub-screens: 1
18/02/2014 08:55:41 Xinerama: no blackouts needed (only one sub-screen)
18/02/2014 08:55:41 
18/02/2014 08:55:42 fb read rate: 64 MB/sec
18/02/2014 08:55:42 The X server says there are 16 mouse buttons.
18/02/2014 08:55:42 screen setup finished.
18/02/2014 08:55:42 

The VNC desktop is:      e2-ubuntu:3
PORT=5903

Client-side setup


to be continued

Thursday, February 13, 2014

Setting up GNomEx on a Synology NAS

GNomEx is data management and repository catered toward genomics (microarray, high thoughput sequencing, etc) which I found very useful during my collaborations with the Huntsman Cancer Institute in Utah.

I figured it would also be useful for our lab and collabs albeit on a much smaller scale. We have a Synology-based NAS setup here, which is useful since it supports easy installation for most of the needed applications.

GnomEx version installed : 5.16.9

Packages needed on Synology:
  1. Java (as of this post, Synology handles auto-installation of ver 1.6.0_38)
  2. phpMyAdmin (you'ld also need to enable MySQL through Control Panel - Web Services)
The Apache Tomcat package on Synology is still on version 6, so I installed 7 manually. *update* the latest DSM upgrade now offers Tomcat 7, so you don't have to do a manual installation.

You should be able to access the Tomcat page at the default http://yourserver:8080

To ensure Tomcat starts up automatically with your Synology box, create a script for autostart according to your Synology model (this one is for DS2413+).
The rest of the GnomEx instructions at http://hci-scrum.hci.utah.edu/gnomexdoc/?page_id=102 are pretty straightforward. Notes below on what I did differently.
  • JDBC driver (jar file) was copied into $CATALINA_HOME/lib/
  • All mySQL setup was done through phpMyAdmin.
    • As admin, create both users (gnomex and gnomexGuest)
    • Log out  and login as gnomex
    • Create a database called gnomex
    • Paste SQL and execute SQL code from gnomex_db_ddl.sql and then gnomex_db_populate.sql.
  • Only GnomEx "Super Admin" seems to be able to edit dictionaries once you enter the interface, so I kept the original admin account and changed the password.