This is the API backend for ConnecTF. The instructions for the for the react server should be followed after these instructions.
Following instructions are using conda
# On linux
curl -O https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
sh Miniconda3-latest-Linux-x86_64.sh
conda config --add channels defaults
conda config --add channels bioconda
conda config --add channels conda-forge
conda create -n connectf
conda activate connectf
conda install python
conda install nodejs
sudo apt-get install build-essential
A MySQL database instance is required.
sudo apt install mariadb-server
sudo apt install mariadb-client
sudo apt-get install libmariadbclient-dev
#TODO: confirm the following are required
#sudo apt-get install gcc
#pip install mysql-connector-python
sudo system mysql start
sudo mysql_secure_installation
# set a password for user root on mysql
Now create database with username and password that will be accessed for connectf.
Details of the database should be configured in the config.yaml
file in the ./connectf/
folder, alongside settings.py
. You can edit settings.py
directly if you are more comfortable in configuring a Django project.
- db_name=connectf
- db_username=connectfuser
- db_passwd=connectfpwd
sudo mysqladmin create connectf
sudo mysql -u root
grant all privileges on connectf.* to 'connectfuser'@'localhost' identified by 'connectfpwd';
flush privileges;
pip install -r requirements.txt
Create a config.yaml
in the ./connectf
folder, alongside the ./connectf/settings.py
file.
To set up data files for the server to read from, it is recommended you create a ./data
folder at the top level of the project. Put required data files within the ./data
folder and edit config.yaml
to reflect the changes.
A MySQL database instance is required. Details of the database should be configured in the config.yaml
file. You can edit settings.py
directly if you are more comfortable in
configuring a Django project.
python manage.py migrate
Import data before starting the server.
python manage.py import_annotation -i annotation.csv # import gene annotations
python manage.py import_data data.csv metadata.txt # import data/metadata
python manage.py import_edges additional_edges.txt # import additional edges
Sample files can be found at:
A sample config.yaml
file:
N.B. If the file does not exist, create a new config.yaml
in the same folder as connectf/settings.py
, with the contents similar to the one seen in the sample.
SECRET_KEY: 'django_secret_key' # see https://docs.djangoproject.com/en/2.2/ref/settings/#secret-key
DEBUG: True
DATABASE:
NAME: 'db_name'
USER: 'db_username'
PASSWORD: 'db_password'
HOST: 'localhost'
MOTIF_ANNOTATION: '/path/to/file' # path to cluster motif file motifs.csv.gz
MOTIF_TF_ANNOTATION: '/path/to/file' # path to tf motif file motifs_indv.csv.gz
MOTIF_CLUSTER_INFO: '/path/to/file' # path to cluster_info.csv.gz
GENE_LISTS: '/path/to/folder' # optional gene list folder
TARGET_NETWORKS: '/path/to/folder' # optional target network folder
python manage.py runserver 8000
Deploy using Gunicorn
pip install gunicorn
gunicorn --workers 5 --timeout 200 --bind unix:connectf_backend.sock -m 007 connectf.wsgi
# use "nohup gunicorn [OPTIONS] &" to run in background
This binds the server to a unix socket, which can then be connected to from a reverse proxy such as nginx.
This listens to an HTTPS connection. Remember to include certificates and private keys in the configuration, or use an HTTP configuration instead.
server {
listen [::]:443 ssl http2;
listen 443 ssl http2;
server_name example.com;
ssl_certificate /path/to/cert.cer;
ssl_certificate_key /path/to/private_key.pem;
ssl_protocols TLSv1.2;
ssl_ciphers HIGH:!aNULL:!MD5;
add_header Strict-Transport-Security "max-age=86400; includeSubDomains" always;
client_max_body_size 100M; # ensure file size is big enough for user upload
root /var/www/html; # path to html files
index index.html;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri /index.html;
}
location ~* ^/(api|queryapp)/ {
# include proxy_params;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_connect_timeout 3600;
proxy_send_timeout 3600;
proxy_read_timeout 3600;
send_timeout 3600;
proxy_pass http://unix:/path/to/connectf_backend.sock;
}
}
The front end of this project is built with ReactJS. You can find it at connectf_react.
All data for this project can be found at https://connectf.s3.amazonaws.com/connectf_data_release_v1.tar.gz