[project @ Prototype Web-based Eland Config generator]
authorBrandon King <kingb@caltech.edu>
Mon, 15 Oct 2007 22:36:48 +0000 (22:36 +0000)
committerBrandon King <kingb@caltech.edu>
Mon, 15 Oct 2007 22:36:48 +0000 (22:36 +0000)
 * Functional, but hard coded elandifier setting.py (needs updating before use).
 * Using Django SVN (will be Django 0.97).
 * Form currently returns to browser, will change in future.

elandifier/__init__.py [new file with mode: 0644]
elandifier/eland_config/__init__.py [new file with mode: 0644]
elandifier/eland_config/forms.py [new file with mode: 0644]
elandifier/eland_config/models.py [new file with mode: 0644]
elandifier/eland_config/urls.py [new file with mode: 0644]
elandifier/eland_config/views.py [new file with mode: 0644]
elandifier/manage.py [new file with mode: 0644]
elandifier/settings.py [new file with mode: 0644]
elandifier/urls.py [new file with mode: 0644]
templates/config_form.html [new file with mode: 0644]

diff --git a/elandifier/__init__.py b/elandifier/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/elandifier/eland_config/__init__.py b/elandifier/eland_config/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/elandifier/eland_config/forms.py b/elandifier/eland_config/forms.py
new file mode 100644 (file)
index 0000000..2488359
--- /dev/null
@@ -0,0 +1,163 @@
+from django import newforms as forms
+from django.newforms.util import ErrorList
+
+
+SPECIES_LIST = [#('--choose--', '--Choose--'),
+                ('hg18', 'Homo sapiens (Hg18)'),
+                ('Mm8', 'Mus musculus (Mm8)'),
+                ('arabv6', 'Arabadopsis Thaliana v6'),
+                ('other', 'Other species (Include in description)')]
+
+
+class DivErrorList(ErrorList):
+  def __unicode__(self):
+    return self.as_divs()
+  
+  def as_divs(self):
+    if not self: return u''
+    return u'<div class="errorlist">%s</div>' % (''.join([u'<div class="error">%s</div>' % e for e in self]))
+
+
+
+class ConfigForm(forms.Form):
+  
+  flow_cell_number = forms.CharField(min_length=2)
+  run_date = forms.DateTimeField()
+  advanced_run = forms.BooleanField(required=False)
+  read_length = forms.IntegerField(min_value=1, initial=32)
+  #eland_repeat = forms.BooleanField()
+  
+  #needs a for loop or something to allow for n configurations
+  #analysis_type = forms.ChoiceField(choices=[('eland','eland')])
+  lane1_species = forms.ChoiceField(choices=SPECIES_LIST)
+  lane1_description = forms.CharField(widget=forms.TextInput(attrs={'size':'60'}))
+  
+  lane2_species = forms.ChoiceField(choices=SPECIES_LIST)
+  lane2_description = forms.CharField(widget=forms.TextInput(attrs={'size':'60'}))
+  
+  lane3_species = forms.ChoiceField(choices=SPECIES_LIST)
+  lane3_description = forms.CharField(widget=forms.TextInput(attrs={'size':'60'}))
+  
+  lane4_species = forms.ChoiceField(choices=SPECIES_LIST)
+  lane4_description = forms.CharField(widget=forms.TextInput(attrs={'size':'60'}))
+  
+  lane5_species = forms.ChoiceField(choices=SPECIES_LIST)
+  lane5_description = forms.CharField(widget=forms.TextInput(attrs={'size':'60'}))
+  
+  lane6_species = forms.ChoiceField(choices=SPECIES_LIST)
+  lane6_description = forms.CharField(widget=forms.TextInput(attrs={'size':'60'}))
+  
+  lane7_species = forms.ChoiceField(choices=SPECIES_LIST)
+  lane7_description = forms.CharField(widget=forms.TextInput(attrs={'size':'60'}))
+  
+  lane8_species = forms.ChoiceField(choices=SPECIES_LIST)
+  lane8_description = forms.CharField(widget=forms.TextInput(attrs={'size':'60'}))
+  
+  notes = forms.CharField(widget=forms.Textarea(attrs={'cols':'70'}), required=False)
+  
+  #lane_specific_read_length = forms.IntegerField(min_value=1)
+  
+  #eland_genome_lanes = forms.MultipleChoiceField(choices=[('lane1','1'),
+  #                                              ('lane2','2'),
+  #                                              ('lane3','3'),
+  #                                              ('lane4','4'),
+  #                                              ('lane5','5'),
+  #                                              ('lane6','6'),
+  #                                              ('lane7','7'),
+  #                                              ('lane8','8') ])
+  
+  #eland_genome = forms.ChoiceField(choices=)
+  
+  #use_bases_lanes = forms.MultipleChoiceField(choices=[('lane1','1'),
+  #                                              ('lane2','2'),
+  #                                              ('lane3','3'),
+  #                                              ('lane4','4'),
+  #                                              ('lane5','5'),
+  #                                              ('lane6','6'),
+  #                                              ('lane7','7'),
+  #                                              ('lane8','8') ])
+  
+  #use_bases_mask = forms.CharField()
+  
+  #sequence_format = forms.ChoiceField(choices=[('scarf', 'scarf')])
+  
+  
+  
+  #subject = forms.CharField(max_length=100)
+  #message = forms.CharField()
+  #sender = forms.EmailField()
+  #cc_myself = forms.BooleanField()
+  
+  def as_custom(self):
+    """
+    Displays customized html output
+    """
+    html = []
+    
+    fcn = self['flow_cell_number']
+    
+    html.append(fcn.label_tag() + ': ' + str(fcn) + str(fcn.errors) + '<br />')
+    
+    run_date = self['run_date']
+    html.append(run_date.label_tag() + ': ' + str(run_date) + str(run_date.errors) + '<br />')
+    
+    arun = self['advanced_run']
+    html.append(arun.label_tag() + ': ' + str(arun) + str(arun.errors) + '<br />')
+    
+    rl = self['read_length']
+    html.append(rl.label_tag() + ': ' + str(rl) + str(rl.errors) + '<br /><br />')
+    
+    html.append('<table border="0">')
+    html.append(' <tr><td>%s</td><td>%s</td><td>%s</td></tr>' \
+                % ('Lane', 'Species', 'Description'))
+    
+    l1s = self['lane1_species']
+    l1d = self['lane1_description']
+    html.append(' <tr><td>%s</td><td>%s %s</td><td>%s %s</td></tr>' \
+                % ('1', str(l1s), str(l1s.errors), str(l1d), str(l1d.errors)))
+    
+    l2s = self['lane2_species']
+    l2d = self['lane2_description']
+    html.append(' <tr><td>%s</td><td>%s %s</td><td>%s %s</td></tr>' \
+                % ('2', str(l2s), str(l2s.errors), str(l2d), str(l2d.errors)))
+    
+    l3s = self['lane3_species']
+    l3d = self['lane3_description']
+    html.append(' <tr><td>%s</td><td>%s %s</td><td>%s %s</td></tr>' \
+                % ('3', str(l3s), str(l3s.errors), str(l3d), str(l3d.errors)))
+    
+    l4s = self['lane4_species']
+    l4d = self['lane4_description']
+    html.append(' <tr><td>%s</td><td>%s %s</td><td>%s %s</td></tr>' \
+                % ('4', str(l4s), str(l4s.errors), str(l4d), str(l4d.errors)))
+    
+    l5s = self['lane5_species']
+    l5d = self['lane5_description']
+    html.append(' <tr><td>%s</td><td>%s %s</td><td>%s %s</td></tr>' \
+                % ('5', str(l5s), str(l5s.errors), str(l5d), str(l5d.errors)))
+    
+    l6s = self['lane6_species']
+    l6d = self['lane6_description']
+    html.append(' <tr><td>%s</td><td>%s %s</td><td>%s %s</td></tr>' \
+                % ('6', str(l6s), str(l6s.errors), str(l6d), str(l6d.errors)))
+    
+    l7s = self['lane7_species']
+    l7d = self['lane7_description']
+    html.append(' <tr><td>%s</td><td>%s %s</td><td>%s %s</td></tr>' \
+                % ('7', str(l7s), str(l7s.errors), str(l7d), str(l7d.errors)))
+    
+    l8s = self['lane8_species']
+    l8d = self['lane8_description']
+    html.append(' <tr><td>%s</td><td>%s %s</td><td>%s %s</td></tr>' \
+                % ('8', str(l8s), str(l8s.errors), str(l8d), str(l8d.errors)))
+    
+    html.append('</table><br />')
+    
+    notes = self['notes']
+    html.append('<p>Notes:</p>')
+    html.append(' %s<br />' % (str(notes)))
+    
+    return '\n'.join(html)
+    
+    
+    
\ No newline at end of file
diff --git a/elandifier/eland_config/models.py b/elandifier/eland_config/models.py
new file mode 100644 (file)
index 0000000..71a8362
--- /dev/null
@@ -0,0 +1,3 @@
+from django.db import models
+
+# Create your models here.
diff --git a/elandifier/eland_config/urls.py b/elandifier/eland_config/urls.py
new file mode 100644 (file)
index 0000000..e6bda81
--- /dev/null
@@ -0,0 +1,7 @@
+from django.conf.urls.defaults import *
+
+urlpatterns = patterns('',
+    # Example:
+    (r'', 'elandifier.eland_config.views.index'),
+
+)
diff --git a/elandifier/eland_config/views.py b/elandifier/eland_config/views.py
new file mode 100644 (file)
index 0000000..6af3632
--- /dev/null
@@ -0,0 +1,117 @@
+from django.http import HttpResponse
+from django.shortcuts import render_to_response
+from elandifier.eland_config import forms
+
+import os
+# Create your views here.
+
+
+#def contact(request):
+#    if request.method == 'POST':
+#        form = ContactForm(request.POST)
+#        if form.is_valid():
+#            # Do form processing here...
+#            return HttpResponseRedirect('/url/on_success/')
+#    else:
+#        form = ContactForm()
+#    return
+
+
+def generateElandConfig(form):
+  data = []
+  
+  form = form.cleaned_data
+  
+  BASE_DIR = '/data-store01/compbio/genomes'
+  
+  notes = form['notes'].replace('\r\n', '\n').replace('\r', '\n')
+  notes = notes.replace('\n', '\n#  ')
+  data.append("# NOTES:")
+  data.append("#  %s\n#" % (notes))
+  
+  #Convert all newline conventions to unix style
+  l1d = form['lane1_description'].replace('\r\n', '\n').replace('\r', '\n')
+  l2d = form['lane2_description'].replace('\r\n', '\n').replace('\r', '\n')
+  l3d = form['lane3_description'].replace('\r\n', '\n').replace('\r', '\n')
+  l4d = form['lane4_description'].replace('\r\n', '\n').replace('\r', '\n')
+  l5d = form['lane5_description'].replace('\r\n', '\n').replace('\r', '\n')
+  l6d = form['lane6_description'].replace('\r\n', '\n').replace('\r', '\n')
+  l7d = form['lane7_description'].replace('\r\n', '\n').replace('\r', '\n')
+  l8d = form['lane8_description'].replace('\r\n', '\n').replace('\r', '\n')
+  
+  # Turn new lines into indented commented newlines
+  l1d = l1d.replace('\n', '\n#  ')
+  l2d = l2d.replace('\n', '\n#  ')
+  l3d = l3d.replace('\n', '\n#  ')
+  l4d = l4d.replace('\n', '\n#  ')
+  l5d = l5d.replace('\n', '\n#  ')
+  l6d = l6d.replace('\n', '\n#  ')
+  l7d = l7d.replace('\n', '\n#  ')
+  l8d = l8d.replace('\n', '\n#  ')
+  
+  data.append("# Lane1: %s" % (l1d))
+  data.append("# Lane2: %s" % (l2d))
+  data.append("# Lane3: %s" % (l3d))
+  data.append("# Lane4: %s" % (l4d))
+  data.append("# Lane5: %s" % (l5d))
+  data.append("# Lane6: %s" % (l6d))
+  data.append("# Lane7: %s" % (l7d))
+  data.append("# Lane8: %s" % (l8d))
+  
+  #data.append("GENOME_DIR %s" % (BASE_DIR))
+  #data.append("CONTAM_DIR %s" % (BASE_DIR))
+  read_length = form['read_length']
+  data.append("READ_LENGTH %d" % (read_length))
+  #data.append("ELAND_REPEAT")
+  data.append("ELAND_MULTIPLE_INSTANCES 8")
+  
+  #Construct genome dictionary to figure out what lanes to put
+  # in the config file.
+  genome_dict = {}
+  l1s = form['lane1_species']
+  genome_dict.setdefault(l1s, []).append('1')
+  l2s = form['lane2_species']
+  genome_dict.setdefault(l2s, []).append('2')
+  l3s = form['lane3_species']
+  genome_dict.setdefault(l3s, []).append('3')
+  l4s = form['lane4_species']
+  genome_dict.setdefault(l4s, []).append('4')
+  l5s = form['lane5_species']
+  genome_dict.setdefault(l5s, []).append('5')
+  l6s = form['lane6_species']
+  genome_dict.setdefault(l6s, []).append('6')
+  l7s = form['lane7_species']
+  genome_dict.setdefault(l7s, []).append('7')
+  l8s = form['lane8_species']
+  genome_dict.setdefault(l8s, []).append('8')
+  
+  genome_list = genome_dict.keys()
+  genome_list.sort()
+  
+  #Loop through and create entries for each species.
+  for genome in genome_list:
+    lanes = ''.join(genome_dict[genome])
+    data.append('%s:ANALYSIS eland' % (lanes))
+    data.append('%s:READ_LENGTH %s' % (lanes, read_length))
+    data.append('%s:ELAND_GENOME %s' % (lanes, os.path.join(BASE_DIR, genome)))
+    data.append('%s:USE_BASES %s' % (lanes, 'Y'*int(read_length)))
+    
+  data.append('SEQUENCE_FORMAT --scarf')
+  
+  return '\n'.join(data)
+
+
+def index(request):
+  """
+  """
+  if request.method == 'POST':
+    form = forms.ConfigForm(request.POST, error_class=forms.DivErrorList)
+    if form.is_valid():
+      cfg = generateElandConfig(form)
+      return HttpResponse(cfg, mimetype="text/plain")
+    else:
+      return render_to_response('config_form.html', {'form': form })
+  
+  else:   
+    fm = forms.ConfigForm(error_class=forms.DivErrorList)
+    return render_to_response('config_form.html', {'form': fm })
diff --git a/elandifier/manage.py b/elandifier/manage.py
new file mode 100644 (file)
index 0000000..5e78ea9
--- /dev/null
@@ -0,0 +1,11 @@
+#!/usr/bin/env python
+from django.core.management import execute_manager
+try:
+    import settings # Assumed to be in the same directory.
+except ImportError:
+    import sys
+    sys.stderr.write("Error: Can't find the file 'settings.py' in the directory containing %r. It appears you've customized things.\nYou'll have to run django-admin.py, passing it your settings module.\n(If the file settings.py does indeed exist, it's causing an ImportError somehow.)\n" % __file__)
+    sys.exit(1)
+
+if __name__ == "__main__":
+    execute_manager(settings)
diff --git a/elandifier/settings.py b/elandifier/settings.py
new file mode 100644 (file)
index 0000000..5aebce5
--- /dev/null
@@ -0,0 +1,83 @@
+# Django settings for elandifier project.
+
+DEBUG = True
+TEMPLATE_DEBUG = DEBUG
+
+ADMINS = (
+    # ('Your Name', 'your_email@domain.com'),
+)
+
+MANAGERS = ADMINS
+
+DATABASE_ENGINE = 'sqlite3'           # 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'ado_mssql'.
+DATABASE_NAME = '/home/king/proj/solexa/elandifier/ifier.db'             # Or path to database file if using sqlite3.
+DATABASE_USER = ''             # Not used with sqlite3.
+DATABASE_PASSWORD = ''         # Not used with sqlite3.
+DATABASE_HOST = ''             # Set to empty string for localhost. Not used with sqlite3.
+DATABASE_PORT = ''             # Set to empty string for default. Not used with sqlite3.
+
+# Local time zone for this installation. Choices can be found here:
+# http://www.postgresql.org/docs/8.1/static/datetime-keywords.html#DATETIME-TIMEZONE-SET-TABLE
+# although not all variations may be possible on all operating systems.
+# If running in a Windows environment this must be set to the same as your
+# system time zone.
+TIME_ZONE = 'America/Los_Angeles'
+
+# Language code for this installation. All choices can be found here:
+# http://www.w3.org/TR/REC-html40/struct/dirlang.html#langcodes
+# http://blogs.law.harvard.edu/tech/stories/storyReader$15
+LANGUAGE_CODE = 'en-us'
+
+SITE_ID = 1
+
+# If you set this to False, Django will make some optimizations so as not
+# to load the internationalization machinery.
+USE_I18N = True
+
+# Absolute path to the directory that holds media.
+# Example: "/home/media/media.lawrence.com/"
+MEDIA_ROOT = ''
+
+# URL that handles the media served from MEDIA_ROOT.
+# Example: "http://media.lawrence.com"
+MEDIA_URL = ''
+
+# URL prefix for admin media -- CSS, JavaScript and images. Make sure to use a
+# trailing slash.
+# Examples: "http://foo.com/media/", "/media/".
+ADMIN_MEDIA_PREFIX = '/media/'
+
+# Make this unique, and don't share it with anybody.
+SECRET_KEY = '(ekv^=gf(j9f(x25@a7r+8)hqlz%&_1!tw^75l%^041#vi=@4n'
+
+# List of callables that know how to import templates from various sources.
+TEMPLATE_LOADERS = (
+    'django.template.loaders.filesystem.load_template_source',
+    'django.template.loaders.app_directories.load_template_source',
+#     'django.template.loaders.eggs.load_template_source',
+)
+
+MIDDLEWARE_CLASSES = (
+    'django.middleware.common.CommonMiddleware',
+    'django.contrib.sessions.middleware.SessionMiddleware',
+    'django.contrib.auth.middleware.AuthenticationMiddleware',
+    'django.middleware.doc.XViewMiddleware',
+)
+
+ROOT_URLCONF = 'elandifier.urls'
+
+TEMPLATE_DIRS = (
+    # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
+    # Always use forward slashes, even on Windows.
+    # Don't forget to use absolute paths, not relative paths.
+    "/home/king/proj/solexa/elandifier/templates"
+)
+
+INSTALLED_APPS = (
+    'django.contrib.admin',
+    'django.contrib.auth',
+    'django.contrib.contenttypes',
+    'django.contrib.sessions',
+    'django.contrib.sites',
+    'elandifier.eland_config'
+)
diff --git a/elandifier/urls.py b/elandifier/urls.py
new file mode 100644 (file)
index 0000000..6e8b3b6
--- /dev/null
@@ -0,0 +1,9 @@
+from django.conf.urls.defaults import *
+
+urlpatterns = patterns('',
+    # Example:
+    (r'^elandifier/', include('elandifier.eland_config.urls')),
+
+    # Uncomment this for admin:
+     (r'^admin/', include('django.contrib.admin.urls')),
+)
diff --git a/templates/config_form.html b/templates/config_form.html
new file mode 100644 (file)
index 0000000..3fbbbee
--- /dev/null
@@ -0,0 +1,17 @@
+<html>
+  <head>
+    <title>Test Config Form</title>
+    <!--
+    <link rel="stylesheet" type="text/css" href="ext-all.css"/>
+    <script type="text/javascript" src="ext.js"></script>
+    <script type="text/javascript" src="elandifier.js"></script>
+    -->
+  </head>
+  <body>
+    <form method="post" action="">
+     <table>{{ form.as_custom }}</table>
+     <input type="submit" />
+   </form>    
+  </body>
+</html>
+  
\ No newline at end of file