User:Lindenb/Notebook/UMR915/2012/04/02: Difference between revisions
Line 397: | Line 397: | ||
)</pre> | )</pre> | ||
Edit TEMPLATE_DIRS in settings.py | |||
<pre>TEMPLATE_DIRS = ( | |||
'/home/lindenb/tmp/DJANGO/gene2pubmed/templates' | |||
)</pre> | |||
and create a template in /home/lindenb/tmp/DJANGO/templates | |||
<pre><html><body><div> | |||
<h1>Pubmed</h1> | |||
<table> | |||
<tr> | |||
<th>PMID</th> | |||
<th>Year</th> | |||
<th>Title</th> | |||
</tr> | |||
{% for article in papers %} | |||
<tr> | |||
<td>{{article.id}}</td> | |||
<td>{{article.year}}</td> | |||
<td>{{article.title}}</td> | |||
</tr> | |||
{% endfor %} | |||
</div></body></html></pre> | |||
Add an article into the sqliteDB: | |||
<pre>sqlite> insert into articles_article(id,year,title) values (999,2012,'another great paper');</pre> | |||
__NOTOC__ | __NOTOC__ |
Revision as of 07:51, 2 April 2012
Project name | <html><img src="/images/9/94/Report.png" border="0" /></html> Main project page <html><img src="/images/c/c3/Resultset_previous.png" border="0" /></html>Previous entry<html> </html>Next entry<html><img src="/images/5/5c/Resultset_next.png" border="0" /></html> |
Dailyvariant_effect_predictor.plFix for proxyreplace unless(getstore($url, $target_file) == 200) by my $status = system("/usr/bin/curl --proxy 'http://proxy:3128' -o '$target_file' -L '$url'"); (...) my $status2 = system("/usr/bin/curl --proxy 'http://proxy:3128' -o '$target_file' -L --create-dirs '$BIOPERL_URL,'");
in the directory 'Bio': Align AlignIO Annotation Assembly Biblio bioperl-1.2.3 Cluster ClusterIO Coordinate Das DB EnsEMBL Event Expression Factory Graphics Index LiveSeq Location Map MapIO Matrix Ontology OntologyIO Phenotype Root Search SearchIO Seq SeqFeature SeqIO Structure Symbol Taxonomy tmp Tools Tree TreeIO Variation
Runperl variant_effect_predictor.pl --regulatory --sift=b --polyphen=b --regulatory --input_file 20120327.rs.vcf.gz --format vcf -o 20120402.vcf --vcf
|
DJANGO
install ubuntu:
sudo apt-get install python-django
start a new project
$ django-admin startproject gene2pubmed
$ find gene2pubmed/ gene2pubmed/ gene2pubmed/urls.py gene2pubmed/__init__.py gene2pubmed/manage.py gene2pubmed/settings.py
Edit gene2pubmed/settings.py and set the default db to sqlite3:
DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'. 'NAME': 'gene2pubmed.sqlite3', # Or path to database file if using sqlite3. 'USER': '', # Not used with sqlite3. 'PASSWORD': '', # Not used with sqlite3. 'HOST': '', # Set to empty string for localhost. Not used with sqlite3. 'PORT': '', # Set to empty string for default. Not used with sqlite3. } }
set the local time in gene2pubmed/settings.py
TIME_ZONE = 'Europe/Paris'
synchronize installation for sessions, messages, etc...
python manage.py syncdb $ python manage.py syncdb Creating tables ... Creating table auth_permission Creating table auth_group_permissions Creating table auth_group Creating table auth_user_user_permissions Creating table auth_user_groups Creating table auth_user Creating table auth_message Creating table django_content_type Creating table django_session Creating table django_site You just installed Django's auth system, which means you don't have any superusers defined. Would you like to create one now? (yes/no): y Please enter either "yes" or "no": yes Username (Leave blank to use 'lindenb'): E-mail address: xxxx@xxxx.xxx Password: Password (again): Superuser created successfully. Installing custom SQL ... Installing indexes ... No fixtures found.
check the databases created:
$ sqlite3 gene2pubmed.sqlite3 SQLite version 3.7.7 2011-06-23 19:49:22 Enter ".help" for instructions Enter SQL statements terminated with a ";" sqlite> .schema CREATE TABLE "auth_group" ( "id" integer NOT NULL PRIMARY KEY, "name" varchar(80) NOT NULL UNIQUE ); CREATE TABLE "auth_group_permissions" ( "id" integer NOT NULL PRIMARY KEY, "group_id" integer NOT NULL, "permission_id" integer NOT NULL REFERENCES "auth_permission" ("id"), UNIQUE ("group_id", "permission_id") ); CREATE TABLE "auth_message" ( "id" integer NOT NULL PRIMARY KEY, "user_id" integer NOT NULL REFERENCES "auth_user" ("id"), "message" text NOT NULL ); CREATE TABLE "auth_permission" ( "id" integer NOT NULL PRIMARY KEY, "name" varchar(50) NOT NULL, "content_type_id" integer NOT NULL, "codename" varchar(100) NOT NULL, UNIQUE ("content_type_id", "codename") ); CREATE TABLE "auth_user" ( "id" integer NOT NULL PRIMARY KEY, "username" varchar(30) NOT NULL UNIQUE, "first_name" varchar(30) NOT NULL, "last_name" varchar(30) NOT NULL, "email" varchar(75) NOT NULL, "password" varchar(128) NOT NULL, "is_staff" bool NOT NULL, "is_active" bool NOT NULL, "is_superuser" bool NOT NULL, "last_login" datetime NOT NULL, "date_joined" datetime NOT NULL ); CREATE TABLE "auth_user_groups" ( "id" integer NOT NULL PRIMARY KEY, "user_id" integer NOT NULL, "group_id" integer NOT NULL REFERENCES "auth_group" ("id"), UNIQUE ("user_id", "group_id") ); CREATE TABLE "auth_user_user_permissions" ( "id" integer NOT NULL PRIMARY KEY, "user_id" integer NOT NULL, "permission_id" integer NOT NULL REFERENCES "auth_permission" ("id"), UNIQUE ("user_id", "permission_id") ); CREATE TABLE "django_content_type" ( "id" integer NOT NULL PRIMARY KEY, "name" varchar(100) NOT NULL, "app_label" varchar(100) NOT NULL, "model" varchar(100) NOT NULL, UNIQUE ("app_label", "model") ); CREATE TABLE "django_session" ( "session_key" varchar(40) NOT NULL PRIMARY KEY, "session_data" text NOT NULL, "expire_date" datetime NOT NULL ); CREATE TABLE "django_site" ( "id" integer NOT NULL PRIMARY KEY, "domain" varchar(100) NOT NULL, "name" varchar(50) NOT NULL ); CREATE INDEX "auth_group_permissions_1e014c8f" ON "auth_group_permissions" ("permission_id"); CREATE INDEX "auth_group_permissions_425ae3c4" ON "auth_group_permissions" ("group_id"); CREATE INDEX "auth_message_403f60f" ON "auth_message" ("user_id"); CREATE INDEX "auth_permission_1bb8f392" ON "auth_permission" ("content_type_id"); CREATE INDEX "auth_user_groups_403f60f" ON "auth_user_groups" ("user_id"); CREATE INDEX "auth_user_groups_425ae3c4" ON "auth_user_groups" ("group_id"); CREATE INDEX "auth_user_user_permissions_1e014c8f" ON "auth_user_user_permissions" ("permission_id"); CREATE INDEX "auth_user_user_permissions_403f60f" ON "auth_user_user_permissions" ("user_id"); CREATE INDEX "django_session_3da3d3d8" ON "django_session" ("expire_date");
testing the development server:
$ python gene2pubmed/manage.py runserver Validating models... 0 errors found Django version 1.3, using settings 'gene2pubmed.settings' Development server is running at http://127.0.0.1:8000/ Quit the server with CONTROL-C. [02/Apr/2012 07:57:11] "GET / HTTP/1.1" 200 2061
It worked!
Congratulations on your first Django-powered page.
Of course, you haven't actually done any work yet. Here's what to do next:
- If you plan to use a database, edit the
DATABASES
setting ingene2pubmed/settings.py
. - Start your first app by running
python gene2pubmed/manage.py startapp [appname]
.
You're seeing this message because you have DEBUG = True
in your
Django settings file and you haven't configured any URLs. Get to work!
creating model
$ python manage.py startapp articles $ find . . ./urls.py ./__init__.py ./urls.pyc ./settings.pyc ./articles ./articles/__init__.py ./articles/models.py ./articles/tests.py ./articles/views.py ./manage.py ./settings.py ./gene2pubmed.sqlite3 ./__init__.pyc
$ cat articles/models.py from django.db import models # Create your models here.
change to:
d$ cat articles/models.py from django.db import models # Create your models here. class Article(models.Model): year = models.IntegerField() title = models.TextField()
Add articles in 'settings.py' /INSTALLED_APPS
INSTALLED_APPS = ( 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', 'django.contrib.messages', 'django.contrib.staticfiles', 'articles'
tell dgango about this new table:
$ python manage.py sql articles $ python manage.py sql articles BEGIN; CREATE TABLE "articles_article" ( "id" integer NOT NULL PRIMARY KEY, "year" integer NOT NULL, "title" text NOT NULL ) ; COMMIT; COMMIT;
Now, run syncdb again to create those model tables in your database:
$ python manage.py syncdb Creating tables ... Creating table articles_article Installing custom SQL ... Installing indexes ... No fixtures found.
Activate the admin site
Add "django.contrib.admin" to the INSTALLED_APPS setting
and run
$python manage.py syncdb Creating tables ... Creating table django_admin_log Installing custom SQL ... Installing indexes ... No fixtures found.
edit urls.py and uncomment the lines for administration:
from django.conf.urls.defaults import patterns, include, url # Uncomment the next two lines to enable the admin: from django.contrib import admin admin.autodiscover() urlpatterns = patterns('', # Examples: # url(r'^$', 'gene2pubmed.views.home', name='home'), # url(r'^gene2pubmed/', include('gene2pubmed.foo.urls')), # Uncomment the admin/doc line below to enable admin documentation: # url(r'^admin/doc/', include('django.contrib.admindocs.urls')), # Uncomment the next line to enable the admin: url(r'^admin/', include(admin.site.urls)), )
Make the articles app modifiable in the admin :
Create a file ./articles/admin.py
:
from articles.models import Article from django.contrib import admin admin.site.register(Article)
restart the server:
d$ python manage.py runserver Validating models... 0 errors found Django version 1.3, using settings 'gene2pubmed.settings' Development server is running at http://127.0.0.1:8000/ Quit the server with CONTROL-C. [02/Apr/2012 16:03:45] "GET /admin HTTP/1.1" 301 0
see http://127.0.0.1:8000/admin/
Django administration Username:____ Password:____
after logging, you'll get the admin screen and an interface to the Article DB:
Add a view
edit urls, and add path to articles
(...) url(r'^articles/','articles.views.list'), url(r'^admin/', include(admin.site.urls)), )
Edit TEMPLATE_DIRS in settings.py
TEMPLATE_DIRS = ( '/home/lindenb/tmp/DJANGO/gene2pubmed/templates' )
and create a template in /home/lindenb/tmp/DJANGO/templates
<html><body><div> <h1>Pubmed</h1> <table> <tr> <th>PMID</th> <th>Year</th> <th>Title</th> </tr> {% for article in papers %} <tr> <td>{{article.id}}</td> <td>{{article.year}}</td> <td>{{article.title}}</td> </tr> {% endfor %} </div></body></html>
Add an article into the sqliteDB:
sqlite> insert into articles_article(id,year,title) values (999,2012,'another great paper');