GBrowse2 installation
David Roquis - 24aug2013

Walkthrough to install GBrowse 2 (tested version was 2.54).
In this install, we used the Bio::DB::SeqFeature::Store adaptor (see GMOD wiki for more infos).

This install method was tested under Fedora 16, 17 and 18.

Under another linux system, replace "yum" par the command corresponding to your local package installer.

Command lines that must be typed in a terminal are displayed in italic. Replace text in red by your own values.
Almost all of these steps have to be performed as root.


Refer to this tutorial for explanations on how to setup basic functions of GBrowse2 once installed.

Error log is stored under /etc/httpd/logs/error (very useful for troubleshooting).


Table of contents
    1. Install GBrowse2 dependencies
    2. Installing missing perl modules through CPAN
    3. Installing GBrowse2
    4. Set online access to GBrowse2
    5. Running GBrowse2 under fastcgi

    6. Configuring the User Account Database
    7. Create and configure mySQL database
    8. Allow the creation of custom tracks (uploaded by users, and removable)
    9. Troubleshooting
        9.1. xyplot_wiggle bug fix

        9.2. Delete obsolete community tracks
        9.3. Database/user access denied


1. Install GBrowse2 dependencies

#install nedit as a text editor (optional)
yum install nedit

# build utilities
yum install make gcc gmp-devel

#Utilities to help with fetching components distributed in source code
yum install wget git

#apache2 and some plugins
yum install httpd mod_fcgid fcgi-perl

# various Perl modules. This modules can also be installed through the CPAN shell.
yum install perl-GD perl-Module-Build perl-CPAN perl-IO-String perl-Capture-Tiny perl-CGI-Session \
            perl-JSON perl-JSON-Any perl-libwww-perl perl-DBD-SQLite perl-File-NFSLock perl-Net-SMTP-SSL \
            perl-Crypt-SSLeay perl-Net-SSLeay perl-Template-Toolkit perl-Array-Compare.noarch\
            perl-GraphViz.noarch graphviz.x86_64 perl-Sort-Naturally.noarch perl-SOAP-Lite.noarch\
            perl-IO-String.noarch perl-Capture-Tiny.noarch perl-Digest-MD5.x86_64 perl-CGI-Session.noarch\
            perl-Statistics-Descriptive.noarch perl-Math-BigInt-GMP.x86_64 perl-Math-Pari.x86_64\
            perl-Crypt-SSLeay.x86_64 perl-Net-SMTP-SSL.noarch perl-Getopt-Long-Descriptive.noarch\
            perl-Getopt-GUI-Long.noarch perl-Digest-SHA.x86_64 perl-Authen-SASL.noarch

# bioperl
yum install perl-bioperl perl-Bio-Graphics

#Staden libraries
yum install staden-io_lib.x86_64 staden-io_lib-devel.x86_64

#LWP libraries
yum install lwp-devel.x86_64 lwp.x86_64

#Libpng libraries
yum install libpng.x86_64 libpng-devel.x86_64

#Freetype libraries
yum install freetype.x86_64 freetype-devel.x86_64

#Some mysql libraries
yum install mysql-devel.x86_64 libnss-mysql.x86_64

#Curses library
yum install ncurses-devel ncurses

#Samtools libraries
yum install samtools samtools-devel.x86_64 samtools-libs.x86_64 samtools.x86_64

#optionally... (but I strongly suggest you install them)
yum install mysql-server mysql-libs perl-DBD-MySQL
yum install phpMyAdmin.noarch
yum install postgresql postgresql-server perl-DBD-Pg
yum install inkscape
yum install perl-GD-SVG


2. Installing missing perl modules through CPAN

#Some modules cannot be installed through yum and have to be installed using the CPAN shell.
#Modules installed through CPAN MUST be recompiled manually if PERL version is updated.
cpan
Upgrade CPAN
install Algorithm::Munkres
install Math::Random
install Storable
install File::Temp
install Math::BigInt::Pari
install Math::BigInt
install Net::OpenID::Consumer
install Bio::Phylo
install Math::BigInt::Pari
install Net::OpenID::Consumer
#Stay under the CPAN shell for the next step. You can leave it by typing "exit".


3. Installing GBrowse2

#under CPAN shell
install Bio::Graphics::Browser2
#Select all defaults parameters during the install; but avoid to register (tends to crash).
#Make sure you accept the setting to allow fastcgi.
#Note the install path of the CGI-BIN folder, this will define the URL to access GBrowse.

#When "Done!" is displayed, hit "return/enter" on keyboard to complete installation.

#To enable PDF generation (useful!!!), please enter the directory "/usr/share/httpd" and run the commands:
sudo mkdir -p .config/inkscape .gnome2
sudo chown apache .config/inkscape .gnome2


4. Set online access to GBrowse2

#Set SE linux as permissive. Be careful with this setting and ask to your network administrator
#if it does not cause security threat (shouldn't, but better be safe than sorry).
nedit /etc/selinux/config
#replace SELINUX=enforcing by SELINUX=permissive
#reboot


#edit /etc/hosts using the IP and the hostname of the machine (ifconfig
#to get the IP, hostnames to get the hostnames (duh!)
#if the hostname is someserver1.host-name.net and the ip is 192.1.0.123
::1 localhost.someserver1.host-name.net localhost
127.0.0.1 localhost.someserver1.host-name.net localhost
192.1.0.123 someserver1.host-name.net someserver1
192.1.0.123 someserver1.host-name.net

#Start apache and start it at login
su -lc 'service httpd start'
su -lc 'chkconfig httpd on'

#In /etc/httpd/conf/httpd.conf, replace
<Directory />
    AllowOverride none
    Require all denied
</Directory>
#by
<Directory "/var/tmp/gbrowse2/images/nameofyourdatabase/">
    Options All
    AllowOverride All
    Require all granted
</Directory>

#Start mySQL and start it at login
su -lc 'service mysqld start'
su -lc 'chkconfig mysqld on'

#in firewall, choose persistent configuration and open TCP ports 80 and 443

#access GBrowse at http:/localhost/cgi-bin/gb2/gbrowse/ or http:/ipofyourmachine/cgi-bin/gb2/gbrowse/
#Path might be a bit different depending where you installed gbrowse cgi-bin files.


5. Running GBrowse2 under fastcgi

#This setting will greatly improve the display speed.
yum install libtool httpd-devel apr-devel apr
#if config during gbrowse installation was done accepting using fastCGI,
#all done! Else, ./build apache_conf from the GBrowse distribution directory.


6. Configuring the User Account Database

# If no authentication plugin is defined, and  "user_accounts" is true, then GBrowse
# will attempt to use its internal user accounts database to authenticate and/or register users.
#Change this setting in /etc/gbrowse2/gbrowse.conf
user_accounts               = 1
user_accounts_registration  = 1
user_accounts_openid        = 1

#Create the gbrowse_login database (run as root)
gbrowse_metadb_config.pl


#In /etc/gbrowse2/GBrowse.conf
# For MySQL
user_account_db        = DBI:mysql:gbrowse_login;user=gbrowse;password=gbrowse

#To create user accounts
gbrowse_create_account.pl -pass <password> -fullname <fullname> <username>


7. Create and configure mySQL database

#Start mySQL
service mysqld start

#Automatically start mySQL at startup
systemctl enable mysqld.service

#Create your first database
mysqladmin -u root password
yourpassword

mysql --user=root --password=yourpassword -e 'create database yourdatabasename'
mysql --user=root --password=yourpassword -e 'grant all privileges on yourdatabasename'.* to you@localhost'
mysql --user=root --password=yourpassword -e'grant file on *.* to you@@localhost'
mysql --user=root --password=yourpassword -e 'grant select on yourdatabasename'.* to nobody@localhost'
mysql --user=root --password=yourpassword -e 'grant all privileges on yourdatabasename'.* to gbrowse@localhost'
mysql --user=root --password=yourpassword -e "grant all privileges on yourdatabasename'.* to 'www-data'@localhost identified by 'theIDyouchose'
'"
#Do the same 6 previous steps for each new database you want to create.

#Load reference genome using
Bio::DB::SeqFeature::Store adaptor
cd /var/lib/gbrowse2/databases/yourdatabasename
bp_seqfeature_load.pl -u root -p yourpassword -d 'dbi:mysql:yourdatabasename' -c -f yourfastafile.fa yourannotationfile.gff3
#You can add more tracks to the same database by using the same command line, but ommiting  -c parameter (use to create the database schema for the first import)

#in /etc/gbrowse2/GBrowse.conf
    # for mysql
    upload_db_adaptor = DBI::mysql
    upload_db_host    = localhost
    upload_db_user    = www-data
    upload_db_pass    =
theIDyouchose
   
    #Datasource definition
    [yourdatabasename]
    description  = the description you want
    path         = configfileforyourdatabase.conf
#You have to create one .conf file for any browser you want to create. You can have references to several disctinct databases in the same .conf files
#Refer to this tutorial for more detailed explanations

#To backup the DB
 mysqldump -u root -p
yourpassword > /home/yourusername/mysql_backup.sql

 #To restore the DB
 mysql -u root -p
yourpassword < /home/yourusername/mysql_backup.sql


8. Allow the creation of custom tracks (uploaded by users, and removable)

#All these steps might have already been done automatically during gbrowse installation

#as root
mysql -u root -p -e 'create database gbrowse_login'
mysql -u root -p -e "grant all privileges on gbrowse_login.* to gbrowse@localhost identified by 'gbrowse'"

#Create tables for gbrowse_login databases
cd /usr/local/bin/
perl gbrowse_metadb_config.pl


9. Troubleshooting

#Some bugs we faced and how we fixed them.
#Refer to this tutorial for explanations on how to setup basic functions of GBrowse2 once installed

#Error log can be found in /etc/httpd/logs/error.log

    9.1. xyplot_wiggle bug fix

#If the tracks sets with the xyplot_wiggle glyph are not displayed properly
#The patch below seems to fix the problem (/Bio/Graphics/Glyph/xyplot.pm)

#remove lines with - and substitute with lines with +

--- xyplot.pm.bak       2013-05-09 17:17:35.945089675 +1000
+++ xyplot.pm   2013-05-09 17:17:59.349088690 +1000
@@ -107,8 +107,8 @@
 sub pad_top {
   my $self = shift;
   my $pad = $self->Bio::Graphics::Glyph::generic::pad_top(@_);
-  if ($pad < $self->font_height('gdTinyFont')+8) {
-      $pad = $self->font_height('gdTinyFont')+8;  # extra room for the scale
+  if ($pad < ($self->font('gdTinyFont')->height+8)) {
+    $pad = $self->font('gdTinyFont')->height+8;  # extra room for the scale
   }
   $pad;
 }
@@ -116,8 +116,8 @@
 sub pad_bottom {
   my $self = shift;
   my $pad  = $self->Bio::Graphics::Glyph::generic::pad_bottom(@_);
-  if ($pad < $self->font_height('gdTinyFont')/4) {
-      $pad = $self->font_height('gdTinyFont')/4;  # extra room for the scale
+  if ($pad < ($self->font('gdTinyFont')->height)/4) {
+    $pad = ($self->font('gdTinyFont')->height)/4;  # extra room for the scale
   }
   $pad;
 }

    9.2. Delete obsolete community tracks

#To remove community tracks from gbrowse (once the corresponding custom track has been removed).
#Delete files corresponding to this track in /car/lin/gbrowse2/userdata/sma/*hexadecimal-name-folder/*custom_track_name*
#Open phpmyadmin and go to the gbrowse_login database and the upload table. Remove corresponding entries
#Then go to the sharing table and remove corresponding entries.

    9.3. Database/user access denied

#If you get the following error message in the apache error log

Replacement list is longer than search list at /usr/share/perl5/vendor_perl/Bio/Range.pm line 251.
DBI connect('gbrowse_login;user=gbrowse;password=gbrowse','',...) failed: Access denied for user 'gbrowse'@'localhost' (using password: YES) at /usr/local/bin/gbrowse_metadb_config.pl line 550.
Could not log into gbrowse_login database, creating and/or fixing login permissions...
Please enter the MySQL administrator user [root] root
Please enter the MySQL administrator password []
Database created!
DBI connect('gbrowse_login;user=gbrowse;password=gbrowse','',...) failed: Access denied for user 'gbrowse'@'localhost' (using password: YES) at /usr/local/bin/gbrowse_metadb_config.pl line 77.
Error: Could not open users database, please check your credentials.
Access denied for user 'gbrowse'@'localhost' (using password: YES) at /usr/local/bin/gbrowse_metadb_config.pl line 77, <STDIN> line 2.

#Temp solution, in gbrowse.conf, replace all 1 by 0 in the following section
####### User Account Registration Database ######
# If no authentication plugin is defined, and
# "user_accounts" is true, then GBrowse
# will attempt to use its internal user accounts database
# to authenticate and/or register users.
user_accounts               = 1
user_accounts_registration  = 1
user_accounts_openid        = 1