Güngör Budak's Blog

Bioinformatics, web programming, coding in general

Configuring Mezzanine for Apache server & mod_wsgi in AWS

Install Mezzanine, Apache server and mod_wsgi:

sudo apt-get install libapache2-mod-wsgi
sudo a2enmod wsgi

Set up a MySQL database for your Mezzanine project

Read my post on how to set up a MySQL database for a Mezzanine project

Collect static files:

python manage.py collectstatic

Configure your Apache server configuration for the project like following:

WSGIPythonPath /home/ubuntu/www/mezzanine-project

<VirtualHost *:80>
    #ServerName example.com
    ServerAdmin admin@example.com
    DocumentRoot /home/ubuntu/www/mezzanine-project
    WSGIScriptAlias / /home/ubuntu/www/mezzanine-project/wsgi.py
    Alias /static /home/ubuntu/www/mezzanine-project/static/

    <Directory /home/ubuntu/www/mezzanine-project>
        Order allow,deny
        Allow from all
        Require all granted
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Note: Replace mezzanine-project with the name of your project

Configure wsgi.py (I don’t know why but it needs this fix - complete script):

from __future__ import unicode_literals
import os
import sys

PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))
sys.path.append(os.path.join(PROJECT_ROOT, ".."))
settings_module = "%s.settings" % PROJECT_ROOT.split(os.sep)[-1]
os.environ["DJANGO_SETTINGS_MODULE"] = settings_module

from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

Enable the site and restart the server:

sudo a2ensite mezzanine-project.conf
sudo service apache2 restart

Now, when you navigate to your AWS public DNS, your Mezzanine project should be running.

Source: Vimmaniac

How to Set Up a MySQL Database for a Mezzanine Project

Install MySQL server and python-mysqldb package:

sudo apt-get install mysql-server
sudo apt-get install python-mysqldb

Run MySQL:

mysql -u root -p

Create a database:

mysql> create database mezzanine_project;

Confirm it:

mysql> show databases;

Exit:

mysql> exit

Configure local_settings.py:

cd path/to/your/mezzanine/projectnano local_settings.py

Like following:

DATABASES = {
    "default": {
        "ENGINE": "django.db.backends.mysql",
        "NAME": "mezzanine_project",
        "USER": "root",
        "PASSWORD": "123456",
        "HOST": "",
        "PORT": "",
        }
    }

Note: Replace your password

Setting Up Mezzanine Projects in AWS

Go to EC2 management console, Security groups and add a Custom TCP inbound rule with port 8000. Select “Anywhere” from the list.

Then follow this to install Mezzanine

Above tutorial is also explains setting up a site record. Mezzanine default site record is 127.0.0.1:8000 which should be 0.0.0.0:8000 in our case. So, enter 0.0.0.0:8000 when you’re asked to enter a site record when you ru

python manage.py createdb

Also, you might still need to provide this site record while running the development server:

python manage.py runserver 0.0.0.0:8000

Next, visit following URL:

http://http://ec2-XX-XX-XX-XX.us-west-2.compute.amazonaws.com:8000

You’ll see the server running in this URL.

Note: The URL is your public DNS given in the instance page.

Getting Started with Your AWS Instance and Installing and Setting Up an Apache Server

Update and upgrade packages:

sudo apt-get update
sudo apt-get upgrade

Install Apache server:

sudo apt-get install apache2

Set up a root folder in home folder and create an index file for testing:

mkdir ~/www
echo ‘Hello, World!’ > ~/www/index.html

Set up your virtual host:

sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/000-www.conf
sudo nano /etc/apache2/sites-available/000-www.conf

Modify DocumentRoot to point your “www” folder in home folder (e.g. /home/ubuntu/www)

And add following lines after DocumentRoot line:

<Directory "/home/ubuntu/www">
    Order allow,deny
    Allow from all
    Require all granted
</Directory>

Enable ”www” site and restart Apache:

sudo a2ensite 000-www
sudo service apache2 restart

Finally, go to your public DNS, something like:

http://ec2-XX-XX-XXX-XX.us-west-2.compute.amazonaws.com/

Sources: SO, DO Community

AWS Start an Instance and Connect to it

Go to EC2 management console

Create a new key-pair if necessary and download it

Launch an instance

Add HTTP security group for web applications over HTTP

Get public DNS

Change permissions on key-pair file:

chmod 400 path/to/your/file.pem

Connect:

ssh -i path/to/your/file.pem ubuntu@PUBLIC_DNS

Note: ubuntu is for connecting an Ubuntu 64 bit instance. It’s different for others

How to Get (or Load) NCBI GEO Microarray Data into R using GEOquery Package from Bioconductor

R, especially with lots of Bioconductor packages, provides nice tools to load, manage and analyze microarray data. If you are trying to load NCBI GEO data into R, use GEOquery package. Here, I’ll describe how to start with it and probably in my future posts I’ll mention more.

Installation

source("http://bioconductor.org/biocLite.R")
biocLite("GEOquery")

Usage

library(GEOquery)
gds <- getGEO("GDS5072")

or

library(GEOquery)
gds <- getGEO(filename="path/to/GDS5072.soft.gz")

getGEO function return a complex class type GDS object which contains the complete dataset. For example to obtain sample organism information:

organism <- gds@header$sample_organism
print(organism)
[1] "Homo sapiens"

Obtain sample IDs:

sample <- gds@dataTable@columns$sample
print(sample)
[1] GSM1095883 GSM1095886 GSM1095877 GSM1095878 GSM1095879 GSM1095880
[7] GSM1095881 GSM1095882 GSM1095884 GSM1095885 GSM1095876
11 Levels: GSM1095876 GSM1095877 GSM1095878 GSM1095879 ... GSM1095886

Obtain gene IDs:

genes <- gds@dataTable@table$IDENTIFIER
head(genes)
[1] DDR1   RFC2   HSPA6  PAX8   GUCA1A UBA7
31596 Levels: ADAM32 AFG3L1P AK9 ALG10 ARMCX4 ATP6V1E2 ...

Obtain levels for the first sample:

sample_1 <- gds@dataTable@table$GSM1095883
head(sample_1)
[1] "3362.6" "400"    "70.9"   "362.8"  "5"      "849"

GEOquery loads all parts of the data in a good format so that you can start your analysis directly. For more information visit package’s GitHub vignettes.

How to Install Mezzanine on Ubuntu/Linux Mint [Complete Guide]

Mezzanine is a CMS application built on Django web framework. The installation steps are easy but your environment may not just suitable enough for it work without a problem. So, here I’m going to describe complete installation from scratch on a virtual environment.

First of all, install virtualenv:

$ sudo apt-get install python-virtualenv

Then, create a virtual environment:

$ virtualenv testenv

And, activate it: $ cd testenv $ source bin/activate

Now, we have our environment set and it only has python and pip installed. Next, we are going to install some necessary packages:

(testenv)$ sudo apt-get install python-pip python-dev python-setuptools python-imaging build-essential

Finally, we can install Mezzanine:

(testenv)$ pip install mezzanine

To start your first Mezzanine project: (testenv)$ mezzanine-project mytest

And create DB and run:

(testenv)$ cd mytest
(testenv)$ python manage.py createdb
(testenv)$ python manage.py runserver

Note that you’ll be asked to create a super user when you’re creating DB, do that.

After you ran your project, go to: http://127.0.0.1:8000/. You’ll visit your first Mezzanine project on your favorite browser. 

How to Clear (or Drop) DB Table of A Django App

Let’s say you created a Django app and ran python manage.py syncdb and created its table. Everytime you make a change in the table, you’ll need to drop that table and run python manage.py syncdb again to update. And how you drop a table of a Django app:

$ python manage.py sqlclear app_name | python manage.py dbshell

Drop tables of an app with migrations (Django >= 1.8):

$ python manage.py migrate appname zero

Recreate all the tables:

$ python manage.py syncdb

Easy!

Taken from SO

Salmonella - Host Interaction Network - A Detailed, Better Visualization

We’re almost done with the analyses and we’re making the final visualization of the network. As I previously posted, the network was clustered and visualized by time points. After that, we have done several more analyses and here I report how we visualized them. I’m going to post more about how we did the analyses separately.

First, the nodes are grouped into experimental and not experimental (PCSF nodes). This can easily be done by parsing experimental network output and network outputs of PCSF. Second, using Salmonella human host interactome is used to find out proteins that are host proteins in Salmonella infection. These are imported as network tables into Cytoscape and visualized as shown below.

Next, another set of analyses (not visualized yet) has been done to find out “the most important” proteins in the network. Four features are used: path damaging percentages, in degree centralities, out degree centralities and betweenness centralities. I used Python package NetworkX again for computing these features. After I obtained a value for each feature for each protein, I also imported them as a network table into Cytoscape.

Here is how I visualized each feature:

Salmonella network annotations

For time points, a protein has all four colors when it’s seen at all time points. Colors change according to time point(s) proteins are seen at.

Below, there is a subgraph of newly visualized network:

Salmonella network subgraph

The features that are not visualized yet will also be done and reported soon.