From: Brandon King Date: Tue, 20 Nov 2007 18:48:21 +0000 (+0000) Subject: [project @ Moved ga_frontend to gaworkflow.frontend package.] X-Git-Tag: 0.1.0~55 X-Git-Url: http://woldlab.caltech.edu/gitweb/?p=htsworkflow.git;a=commitdiff_plain;h=8a5bc0aa3e00f05fd0e56e07386b820fd20f13e3 [project @ Moved ga_frontend to gaworkflow.frontend package.] * All the modules in the front end have been updated to be located in gaworkflow.frontend. * Requires that PYTHONPATH include top level directory or for the package to be installed as gaworkflow/frontend/manage.py only adds frontend/ to the python path, and therefore it will fail. * Changed the hard coded paths to be more like os.path.abspath('../../fctracker.db') so, the code should just work if the main package is available on the python path. (Good defaults are nice!) --- diff --git a/ga_frontend/__init__.py b/ga_frontend/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/ga_frontend/eland_config/__init__.py b/ga_frontend/eland_config/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/ga_frontend/eland_config/forms.py b/ga_frontend/eland_config/forms.py deleted file mode 100644 index 2488359..0000000 --- a/ga_frontend/eland_config/forms.py +++ /dev/null @@ -1,163 +0,0 @@ -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'
%s
' % (''.join([u'
%s
' % 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) + '
') - - run_date = self['run_date'] - html.append(run_date.label_tag() + ': ' + str(run_date) + str(run_date.errors) + '
') - - arun = self['advanced_run'] - html.append(arun.label_tag() + ': ' + str(arun) + str(arun.errors) + '
') - - rl = self['read_length'] - html.append(rl.label_tag() + ': ' + str(rl) + str(rl.errors) + '

') - - html.append('') - html.append(' ' \ - % ('Lane', 'Species', 'Description')) - - l1s = self['lane1_species'] - l1d = self['lane1_description'] - html.append(' ' \ - % ('1', str(l1s), str(l1s.errors), str(l1d), str(l1d.errors))) - - l2s = self['lane2_species'] - l2d = self['lane2_description'] - html.append(' ' \ - % ('2', str(l2s), str(l2s.errors), str(l2d), str(l2d.errors))) - - l3s = self['lane3_species'] - l3d = self['lane3_description'] - html.append(' ' \ - % ('3', str(l3s), str(l3s.errors), str(l3d), str(l3d.errors))) - - l4s = self['lane4_species'] - l4d = self['lane4_description'] - html.append(' ' \ - % ('4', str(l4s), str(l4s.errors), str(l4d), str(l4d.errors))) - - l5s = self['lane5_species'] - l5d = self['lane5_description'] - html.append(' ' \ - % ('5', str(l5s), str(l5s.errors), str(l5d), str(l5d.errors))) - - l6s = self['lane6_species'] - l6d = self['lane6_description'] - html.append(' ' \ - % ('6', str(l6s), str(l6s.errors), str(l6d), str(l6d.errors))) - - l7s = self['lane7_species'] - l7d = self['lane7_description'] - html.append(' ' \ - % ('7', str(l7s), str(l7s.errors), str(l7d), str(l7d.errors))) - - l8s = self['lane8_species'] - l8d = self['lane8_description'] - html.append(' ' \ - % ('8', str(l8s), str(l8s.errors), str(l8d), str(l8d.errors))) - - html.append('
%s%s%s
%s%s %s%s %s
%s%s %s%s %s
%s%s %s%s %s
%s%s %s%s %s
%s%s %s%s %s
%s%s %s%s %s
%s%s %s%s %s
%s%s %s%s %s

') - - notes = self['notes'] - html.append('

Notes:

') - html.append(' %s
' % (str(notes))) - - return '\n'.join(html) - - - \ No newline at end of file diff --git a/ga_frontend/eland_config/models.py b/ga_frontend/eland_config/models.py deleted file mode 100644 index 71a8362..0000000 --- a/ga_frontend/eland_config/models.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.db import models - -# Create your models here. diff --git a/ga_frontend/eland_config/urls.py b/ga_frontend/eland_config/urls.py deleted file mode 100644 index 13d659b..0000000 --- a/ga_frontend/eland_config/urls.py +++ /dev/null @@ -1,10 +0,0 @@ -from django.conf.urls.defaults import * - -urlpatterns = patterns('', - # Example: - - (r'^(?PFC\d+)/$', 'ga_frontend.eland_config.views.config'), - (r'^$', 'ga_frontend.eland_config.views.config'), - #(r'^$', 'ga_frontend.eland_config.views.index') - -) diff --git a/ga_frontend/eland_config/views.py b/ga_frontend/eland_config/views.py deleted file mode 100644 index 596e0ff..0000000 --- a/ga_frontend/eland_config/views.py +++ /dev/null @@ -1,413 +0,0 @@ -from django.http import HttpResponse -from django.shortcuts import render_to_response -from django.core.exceptions import ObjectDoesNotExist - -from ga_frontend.eland_config import forms -from ga_frontend import settings -from ga_frontend.fctracker import models - -import os -import glob -# Create your views here. - - -def _validate_input(data): - #if data.find('..') == -1 or data.find('/') == -1 or data.find('\\') == -1: - return data.replace('..', '').replace('/', '_').replace('\\', '_') - -#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 _saveConfigFile(form): -# """ -# Given a valid form, save eland config to file based on flowcell number. -# """ -# assert form.is_valid() -# -# clean_data = form.cleaned_data -# flowcell = clean_data['flow_cell_number'].replace('/','_').replace('..', '__') -# -# file_path = os.path.join(settings.UPLOADTO_CONFIG_FILE, flowcell) -# -# f = open(file_path, 'w') -# cfg = generateElandConfig(form) -# f.write(cfg) -# f.close() -# -# -#def _saveToDb(form): -# """ -# Save info to the database. -# """ -# clean_data = form.cleaned_data -# -# fc_id = clean_data['flow_cell_number'] -# -# try: -# fc = models.FlowCell.objects.get(flowcell_id=fc_id) -# except models.FlowCell.DoesNotExist: -# fc = models.FlowCell() -# -# fc.flowcell_id = fc_id -# fc.run_date = clean_data['run_date'] -# -# #LANE 1 -# fc.lane1_sample = clean_data['lane1_description'] -# species_name = clean_data['lane1_species'] -# try: -# specie = models.Specie.objects.get(scientific_name=species_name) -# except models.Specie.DoesNotExist: -# specie = models.Specie(scientific_name=species_name) -# specie.save() -# fc.lane1_species = specie -# -# #LANE 2 -# fc.lane2_sample = clean_data['lane2_description'] -# species_name = clean_data['lane2_species'] -# try: -# specie = models.Specie.objects.get(scientific_name=species_name) -# except models.Specie.DoesNotExist: -# specie = models.Specie(scientific_name=species_name) -# specie.save() -# fc.lane2_species = specie -# -# #LANE 3 -# fc.lane3_sample = clean_data['lane3_description'] -# species_name = clean_data['lane3_species'] -# try: -# specie = models.Specie.objects.get(scientific_name=species_name) -# except models.Specie.DoesNotExist: -# specie = models.Specie(scientific_name=species_name) -# specie.save() -# fc.lane3_species = specie -# -# #LANE 4 -# fc.lane4_sample = clean_data['lane4_description'] -# species_name = clean_data['lane4_species'] -# try: -# specie = models.Specie.objects.get(scientific_name=species_name) -# except models.Specie.DoesNotExist: -# specie = models.Specie(scientific_name=species_name) -# specie.save() -# fc.lane4_species = specie -# -# #LANE 5 -# fc.lane5_sample = clean_data['lane5_description'] -# species_name = clean_data['lane5_species'] -# try: -# specie = models.Specie.objects.get(scientific_name=species_name) -# except models.Specie.DoesNotExist: -# specie = models.Specie(scientific_name=species_name) -# specie.save() -# fc.lane5_species = specie -# -# #LANE 6 -# fc.lane6_sample = clean_data['lane6_description'] -# species_name = clean_data['lane6_species'] -# try: -# specie = models.Specie.objects.get(scientific_name=species_name) -# except models.Specie.DoesNotExist: -# specie = models.Specie(scientific_name=species_name) -# specie.save() -# fc.lane6_species = specie -# -# #LANE 7 -# fc.lane7_sample = clean_data['lane7_description'] -# species_name = clean_data['lane7_species'] -# try: -# specie = models.Specie.objects.get(scientific_name=species_name) -# except models.Specie.DoesNotExist: -# specie = models.Specie(scientific_name=species_name) -# specie.save() -# fc.lane7_species = specie -# -# #LANE 8 -# fc.lane8_sample = clean_data['lane8_description'] -# species_name = clean_data['lane8_species'] -# try: -# specie = models.Specie.objects.get(scientific_name=species_name) -# except models.Specie.DoesNotExist: -# specie = models.Specie(scientific_name=species_name) -# specie.save() -# fc.lane8_species = specie -# -# fc.notes = clean_data['notes'] -# -# fc.save() -# -# return fc -# -# -#def generateElandConfig(form): -# data = [] -# -# form = form.cleaned_data -# -# BASE_DIR = '/data-store01/compbio/genomes' -# -# data.append("# FLOWCELL: %s" % (form['flow_cell_number'])) -# data.append("#") -# -# 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 getElandConfig(flowcell, regenerate=False): - - file_path = os.path.join(settings.UPLOADTO_CONFIG_FILE, flowcell) - - #If we are regenerating the config file, skip - # reading of existing file. If the file doesn't - # exist, try to generate it form the DB. - if not regenerate and os.path.isfile(file_path): - f = open(file_path, 'r') - data = f.read() - f.close() - return data - - try: - fcObj = models.FlowCell.objects.get(flowcell_id=flowcell) - except ObjectDoesNotExist: - return None - - data = [] - - #form = form.cleaned_data - - BASE_DIR = '/data-store01/compbio/genomes' - - data.append("# FLOWCELL: %s" % (fcObj.flowcell_id)) - data.append("#") - - notes = fcObj.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 = str(fcObj.lane_1_library.library_id) + '|' \ - + fcObj.lane_1_library.library_name.replace('\r\n', '\n').replace('\r', '\n') - l2d = str(fcObj.lane_2_library.library_id) + '|' \ - + fcObj.lane_2_library.library_name.replace('\r\n', '\n').replace('\r', '\n') - l3d = str(fcObj.lane_3_library.library_id) + '|' \ - + fcObj.lane_3_library.library_name.replace('\r\n', '\n').replace('\r', '\n') - l4d = str(fcObj.lane_4_library.library_id) + '|' \ - + fcObj.lane_4_library.library_name.replace('\r\n', '\n').replace('\r', '\n') - - l5d = str(fcObj.lane_5_library.library_id) + '|' \ - + fcObj.lane_5_library.library_name.replace('\r\n', '\n').replace('\r', '\n') - l6d = str(fcObj.lane_6_library.library_id) + '|' \ - + fcObj.lane_6_library.library_name.replace('\r\n', '\n').replace('\r', '\n') - l7d = str(fcObj.lane_7_library.library_id) + '|' \ - + fcObj.lane_7_library.library_name.replace('\r\n', '\n').replace('\r', '\n') - l8d = str(fcObj.lane_8_library.library_id) + '|' \ - + fcObj.lane_8_library.library_name.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 = fcObj.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'] - l1s = fcObj.lane_1_library.library_species.scientific_name + '|' + \ - fcObj.lane_1_library.library_species.use_genome_build - genome_dict.setdefault(l1s, []).append('1') - l2s = fcObj.lane_2_library.library_species.scientific_name + '|' + \ - fcObj.lane_2_library.library_species.use_genome_build - genome_dict.setdefault(l2s, []).append('2') - l3s = fcObj.lane_3_library.library_species.scientific_name + '|' + \ - fcObj.lane_3_library.library_species.use_genome_build - genome_dict.setdefault(l3s, []).append('3') - l4s = fcObj.lane_4_library.library_species.scientific_name + '|' + \ - fcObj.lane_4_library.library_species.use_genome_build - genome_dict.setdefault(l4s, []).append('4') - l5s = fcObj.lane_5_library.library_species.scientific_name + '|' + \ - fcObj.lane_5_library.library_species.use_genome_build - genome_dict.setdefault(l5s, []).append('5') - l6s = fcObj.lane_6_library.library_species.scientific_name + '|' + \ - fcObj.lane_6_library.library_species.use_genome_build - genome_dict.setdefault(l6s, []).append('6') - l7s = fcObj.lane_7_library.library_species.scientific_name + '|' + \ - fcObj.lane_7_library.library_species.use_genome_build - genome_dict.setdefault(l7s, []).append('7') - l8s = fcObj.lane_8_library.library_species.scientific_name + '|' + \ - fcObj.lane_8_library.library_species.use_genome_build - 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, '%%(%s)s' % (genome))) - data.append('%s:USE_BASES %s' % (lanes, 'Y'*int(read_length))) - - data.append('SEQUENCE_FORMAT --scarf') - - data = '\n'.join(data) - - f = open(file_path, 'w') - f.write(data) - f.close() - - return data - - - -def config(request, flowcell=None): - """ - Returns eland config file for a given flowcell number, - or returns a list of available flowcell numbers. - """ - - # Provide INDEX of available Flowcell config files. - if flowcell is None: - #Find all FC* config files and report an index html file - #fc_list = [ os.path.split(file_path)[1] for file_path in glob.glob(os.path.join(settings.UPLOADTO_CONFIG_FILE, 'FC*')) ] - fc_list = [ fc.flowcell_id for fc in models.FlowCell.objects.all() ] - - #Convert FC* list to html links - fc_html = [ '%s' % (fc_name, fc_name) for fc_name in fc_list ] - - return HttpResponse('
'.join(fc_html)) - - #FIXME: Should validate flowcell input before using. - flowcell = _validate_input(flowcell) - cfg = getElandConfig(flowcell, regenerate=True) - - if not cfg: - return HttpResponse("Hmm, config file for %s does not seem to exist." % (flowcell)) - - - return HttpResponse(cfg, mimetype="text/plain") - - - - -#def index(request): -# """ -# Return a form for filling out information about the flowcell -# """ -# if request.method == 'POST': -# form = forms.ConfigForm(request.POST, error_class=forms.DivErrorList) -# if form.is_valid(): -# #cfg = generateElandConfig(form) -# _saveConfigFile(form) -# _saveToDb(form) -# return HttpResponse("Eland Config Saved!", 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/ga_frontend/fctracker/__init__.py b/ga_frontend/fctracker/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/ga_frontend/fctracker/models.py b/ga_frontend/fctracker/models.py deleted file mode 100644 index 013f36b..0000000 --- a/ga_frontend/fctracker/models.py +++ /dev/null @@ -1,147 +0,0 @@ -from django.db import models -from ga_frontend import settings - -# Create your models here. - -class Species(models.Model): - - scientific_name = models.CharField(max_length=256, unique=True, db_index=True, core=True) - common_name = models.CharField(max_length=256, blank=True) - use_genome_build = models.CharField(max_length=100, blank=False, null=False) - - def __str__(self): - return '%s (%s)|%s' % (self.scientific_name, self.common_name, self.use_genome_build) - - class Meta: - verbose_name_plural = "species" - ordering = ["scientific_name"] - - class Admin: - fields = ( - (None, { - 'fields': (('scientific_name', 'common_name'), ('use_genome_build')) - }), - ) - -class Library(models.Model): - - library_id = models.IntegerField(primary_key=True, db_index=True, core=True) - library_name = models.CharField(max_length=100, unique=True, core=True) - library_species = models.ForeignKey(Species, core=True) - #use_genome_build = models.CharField(max_length=100, blank=False, null=False) - RNAseq = models.BooleanField() - - made_by = models.CharField(max_length=50, blank=True, default="Lorian") - creation_date = models.DateField(blank=True, null=True) - made_for = models.CharField(max_length=50, blank=True) - - PROTOCOL_END_POINTS = ( - ('?', 'Unknown'), - ('Sample', 'Raw sample'), - ('Gel', 'Ran gel'), - ('1A', 'Gel purification'), - ('2A', '2nd PCR'), - ('Progress', 'In progress'), - ) - stopping_point = models.CharField(max_length=50, choices=PROTOCOL_END_POINTS) - amplified_from_sample = models.ForeignKey('self', blank=True, null=True) - - undiluted_concentration = models.DecimalField(max_digits=5, decimal_places=2, blank=True, null=True) - ten_nM_dilution = models.BooleanField() - successful_pM = models.IntegerField(blank=True, null=True) - - notes = models.TextField(blank=True) - - def __str__(self): - return '#%s: %s' % (self.library_id, self.library_name) - - class Meta: - verbose_name_plural = "libraries" - ordering = ["-library_id"] - - class Admin: - date_hierarchy = "creation_date" - save_as = True - save_on_top = True - search_fields = ['library_name'] - list_display = ('library_id', 'library_name', 'made_for', 'creation_date', 'ten_nM_dilution', 'stopping_point', 'successful_pM') - list_display_links = ('library_id', 'library_name') - list_filter = ('stopping_point', 'ten_nM_dilution', 'library_species', 'made_for', 'made_by') - fields = ( - (None, { - 'fields': (('library_id', 'library_name'), ('library_species', 'RNAseq'),) - }), - ('Creation Information:', { - 'fields' : (('made_for', 'made_by', 'creation_date'), ('stopping_point', 'amplified_from_sample'), ('undiluted_concentration', 'ten_nM_dilution', 'successful_pM'), 'notes',) - }), - ) - -class FlowCell(models.Model): - - flowcell_id = models.CharField(max_length=20, unique=True, db_index=True, core=True) - run_date = models.DateTimeField(core=True) - advanced_run = models.BooleanField(default=False) - read_length = models.IntegerField(default=32) - - lane_1_library = models.ForeignKey(Library, related_name="lane_1_library") - lane_2_library = models.ForeignKey(Library, related_name="lane_2_library") - lane_3_library = models.ForeignKey(Library, related_name="lane_3_library") - lane_4_library = models.ForeignKey(Library, related_name="lane_4_library") - lane_5_library = models.ForeignKey(Library, related_name="lane_5_library") - lane_6_library = models.ForeignKey(Library, related_name="lane_6_library") - lane_7_library = models.ForeignKey(Library, related_name="lane_7_library") - lane_8_library = models.ForeignKey(Library, related_name="lane_8_library") - - lane_1_pM = models.IntegerField(default=4) - lane_2_pM = models.IntegerField(default=4) - lane_3_pM = models.IntegerField(default=4) - lane_4_pM = models.IntegerField(default=4) - lane_5_pM = models.IntegerField(default=4) - lane_6_pM = models.IntegerField(default=4) - lane_7_pM = models.IntegerField(default=4) - lane_8_pM = models.IntegerField(default=4) - - lane_1_cluster_estimate = models.IntegerField(blank=True, null=True) - lane_2_cluster_estimate = models.IntegerField(blank=True, null=True) - lane_3_cluster_estimate = models.IntegerField(blank=True, null=True) - lane_4_cluster_estimate = models.IntegerField(blank=True, null=True) - lane_5_cluster_estimate = models.IntegerField(blank=True, null=True) - lane_6_cluster_estimate = models.IntegerField(blank=True, null=True) - lane_7_cluster_estimate = models.IntegerField(blank=True, null=True) - lane_8_cluster_estimate = models.IntegerField(blank=True, null=True) - - notes = models.TextField(blank=True) - - def __str__(self): - return '%s (%s)' % (self.flowcell_id, self.run_date) - - class Meta: - ordering = ["run_date"] - - class Admin: - date_hierarchy = "run_date" - save_on_top = True - search_fields = ['lane_1_library', 'lane_2_library', 'lane_3_library', 'lane_4_library', 'lane_5_library', 'lane_6_library', 'lane_7_library', 'lane_8_library'] - list_display = ('flowcell_id', 'run_date', 'lane_1_library', 'lane_2_library', 'lane_3_library', 'lane_4_library', 'lane_5_library', 'lane_6_library', 'lane_7_library', 'lane_8_library') - fields = ( - (None, { - 'fields': ('run_date', 'flowcell_id', ('read_length', 'advanced_run'),) - }), - ('Lanes:', { - 'fields' : (('lane_1_library', 'lane_1_pM', 'lane_1_cluster_estimate'), ('lane_2_library', 'lane_2_pM', 'lane_2_cluster_estimate'), ('lane_3_library', 'lane_3_pM', 'lane_3_cluster_estimate'), ('lane_4_library', 'lane_4_pM', 'lane_4_cluster_estimate'), ('lane_5_library', 'lane_5_pM', 'lane_5_cluster_estimate'), ('lane_6_library', 'lane_6_pM', 'lane_6_cluster_estimate'), ('lane_7_library', 'lane_7_pM', 'lane_7_cluster_estimate'), ('lane_8_library', 'lane_8_pM', 'lane_8_cluster_estimate'),) - }), - (None, { - 'fields' : ('notes',) - }), - ) - -class ElandResult(models.Model): - - class Admin: pass - - flow_cell = models.ForeignKey(FlowCell) - config_file = models.FileField(upload_to=settings.UPLOADTO_CONFIG_FILE) - eland_result_pack = models.FileField(upload_to=settings.UPLOADTO_ELAND_RESULT_PACKS) - bed_file_pack = models.FileField(upload_to=settings.UPLOADTO_BED_PACKS) - - notes = models.TextField(blank=True) diff --git a/ga_frontend/fctracker/views.py b/ga_frontend/fctracker/views.py deleted file mode 100644 index 60f00ef..0000000 --- a/ga_frontend/fctracker/views.py +++ /dev/null @@ -1 +0,0 @@ -# Create your views here. diff --git a/ga_frontend/manage.py b/ga_frontend/manage.py deleted file mode 100644 index 5e78ea9..0000000 --- a/ga_frontend/manage.py +++ /dev/null @@ -1,11 +0,0 @@ -#!/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/ga_frontend/settings.py b/ga_frontend/settings.py deleted file mode 100644 index 65dbab3..0000000 --- a/ga_frontend/settings.py +++ /dev/null @@ -1,94 +0,0 @@ -import os - -# 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/ga_frontend/elandifier.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 = 'ga_frontend.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/ga_frontend/templates" -) - -INSTALLED_APPS = ( - 'django.contrib.admin', - 'django.contrib.auth', - 'django.contrib.contenttypes', - 'django.contrib.sessions', - 'django.contrib.sites', - 'ga_frontend.eland_config', - 'ga_frontend.fctracker', - 'django.contrib.databrowse', -) - -# Project specific settings -UPLOADTO_HOME = '/home/king/proj/ga_frontend/uploads' -UPLOADTO_CONFIG_FILE = os.path.join(UPLOADTO_HOME, 'eland_config') -UPLOADTO_ELAND_RESULT_PACKS = os.path.join(UPLOADTO_HOME, 'eland_results') -UPLOADTO_BED_PACKS = os.path.join(UPLOADTO_HOME, 'bed_packs') - diff --git a/ga_frontend/urls.py b/ga_frontend/urls.py deleted file mode 100644 index 44f8121..0000000 --- a/ga_frontend/urls.py +++ /dev/null @@ -1,16 +0,0 @@ -from django.conf.urls.defaults import * - -# Databrowser: -from django.contrib import databrowse -from fctracker.models import Library, FlowCell -databrowse.site.register(Library) -databrowse.site.register(FlowCell) - -urlpatterns = patterns('', - # Base: - (r'^eland_config/', include('ga_frontend.eland_config.urls')), - # Admin: - (r'^admin/', include('django.contrib.admin.urls')), - # Databrowser: - (r'^databrowse/(.*)', databrowse.site.root), -) diff --git a/gaworkflow/frontend/__init__.py b/gaworkflow/frontend/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/gaworkflow/frontend/eland_config/__init__.py b/gaworkflow/frontend/eland_config/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/gaworkflow/frontend/eland_config/forms.py b/gaworkflow/frontend/eland_config/forms.py new file mode 100644 index 0000000..2488359 --- /dev/null +++ b/gaworkflow/frontend/eland_config/forms.py @@ -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'
%s
' % (''.join([u'
%s
' % 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) + '
') + + run_date = self['run_date'] + html.append(run_date.label_tag() + ': ' + str(run_date) + str(run_date.errors) + '
') + + arun = self['advanced_run'] + html.append(arun.label_tag() + ': ' + str(arun) + str(arun.errors) + '
') + + rl = self['read_length'] + html.append(rl.label_tag() + ': ' + str(rl) + str(rl.errors) + '

') + + html.append('') + html.append(' ' \ + % ('Lane', 'Species', 'Description')) + + l1s = self['lane1_species'] + l1d = self['lane1_description'] + html.append(' ' \ + % ('1', str(l1s), str(l1s.errors), str(l1d), str(l1d.errors))) + + l2s = self['lane2_species'] + l2d = self['lane2_description'] + html.append(' ' \ + % ('2', str(l2s), str(l2s.errors), str(l2d), str(l2d.errors))) + + l3s = self['lane3_species'] + l3d = self['lane3_description'] + html.append(' ' \ + % ('3', str(l3s), str(l3s.errors), str(l3d), str(l3d.errors))) + + l4s = self['lane4_species'] + l4d = self['lane4_description'] + html.append(' ' \ + % ('4', str(l4s), str(l4s.errors), str(l4d), str(l4d.errors))) + + l5s = self['lane5_species'] + l5d = self['lane5_description'] + html.append(' ' \ + % ('5', str(l5s), str(l5s.errors), str(l5d), str(l5d.errors))) + + l6s = self['lane6_species'] + l6d = self['lane6_description'] + html.append(' ' \ + % ('6', str(l6s), str(l6s.errors), str(l6d), str(l6d.errors))) + + l7s = self['lane7_species'] + l7d = self['lane7_description'] + html.append(' ' \ + % ('7', str(l7s), str(l7s.errors), str(l7d), str(l7d.errors))) + + l8s = self['lane8_species'] + l8d = self['lane8_description'] + html.append(' ' \ + % ('8', str(l8s), str(l8s.errors), str(l8d), str(l8d.errors))) + + html.append('
%s%s%s
%s%s %s%s %s
%s%s %s%s %s
%s%s %s%s %s
%s%s %s%s %s
%s%s %s%s %s
%s%s %s%s %s
%s%s %s%s %s
%s%s %s%s %s

') + + notes = self['notes'] + html.append('

Notes:

') + html.append(' %s
' % (str(notes))) + + return '\n'.join(html) + + + \ No newline at end of file diff --git a/gaworkflow/frontend/eland_config/models.py b/gaworkflow/frontend/eland_config/models.py new file mode 100644 index 0000000..71a8362 --- /dev/null +++ b/gaworkflow/frontend/eland_config/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/gaworkflow/frontend/eland_config/urls.py b/gaworkflow/frontend/eland_config/urls.py new file mode 100644 index 0000000..c5292ab --- /dev/null +++ b/gaworkflow/frontend/eland_config/urls.py @@ -0,0 +1,10 @@ +from django.conf.urls.defaults import * + +urlpatterns = patterns('', + # Example: + + (r'^(?PFC\d+)/$', 'gaworkflow.frontend.eland_config.views.config'), + (r'^$', 'gaworkflow.frontend.eland_config.views.config'), + #(r'^$', 'gaworkflow.frontend.eland_config.views.index') + +) diff --git a/gaworkflow/frontend/eland_config/views.py b/gaworkflow/frontend/eland_config/views.py new file mode 100644 index 0000000..994062a --- /dev/null +++ b/gaworkflow/frontend/eland_config/views.py @@ -0,0 +1,413 @@ +from django.http import HttpResponse +from django.shortcuts import render_to_response +from django.core.exceptions import ObjectDoesNotExist + +from gaworkflow.frontend.eland_config import forms +from gaworkflow.frontend import settings +from gaworkflow.frontend.fctracker import models + +import os +import glob +# Create your views here. + + +def _validate_input(data): + #if data.find('..') == -1 or data.find('/') == -1 or data.find('\\') == -1: + return data.replace('..', '').replace('/', '_').replace('\\', '_') + +#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 _saveConfigFile(form): +# """ +# Given a valid form, save eland config to file based on flowcell number. +# """ +# assert form.is_valid() +# +# clean_data = form.cleaned_data +# flowcell = clean_data['flow_cell_number'].replace('/','_').replace('..', '__') +# +# file_path = os.path.join(settings.UPLOADTO_CONFIG_FILE, flowcell) +# +# f = open(file_path, 'w') +# cfg = generateElandConfig(form) +# f.write(cfg) +# f.close() +# +# +#def _saveToDb(form): +# """ +# Save info to the database. +# """ +# clean_data = form.cleaned_data +# +# fc_id = clean_data['flow_cell_number'] +# +# try: +# fc = models.FlowCell.objects.get(flowcell_id=fc_id) +# except models.FlowCell.DoesNotExist: +# fc = models.FlowCell() +# +# fc.flowcell_id = fc_id +# fc.run_date = clean_data['run_date'] +# +# #LANE 1 +# fc.lane1_sample = clean_data['lane1_description'] +# species_name = clean_data['lane1_species'] +# try: +# specie = models.Specie.objects.get(scientific_name=species_name) +# except models.Specie.DoesNotExist: +# specie = models.Specie(scientific_name=species_name) +# specie.save() +# fc.lane1_species = specie +# +# #LANE 2 +# fc.lane2_sample = clean_data['lane2_description'] +# species_name = clean_data['lane2_species'] +# try: +# specie = models.Specie.objects.get(scientific_name=species_name) +# except models.Specie.DoesNotExist: +# specie = models.Specie(scientific_name=species_name) +# specie.save() +# fc.lane2_species = specie +# +# #LANE 3 +# fc.lane3_sample = clean_data['lane3_description'] +# species_name = clean_data['lane3_species'] +# try: +# specie = models.Specie.objects.get(scientific_name=species_name) +# except models.Specie.DoesNotExist: +# specie = models.Specie(scientific_name=species_name) +# specie.save() +# fc.lane3_species = specie +# +# #LANE 4 +# fc.lane4_sample = clean_data['lane4_description'] +# species_name = clean_data['lane4_species'] +# try: +# specie = models.Specie.objects.get(scientific_name=species_name) +# except models.Specie.DoesNotExist: +# specie = models.Specie(scientific_name=species_name) +# specie.save() +# fc.lane4_species = specie +# +# #LANE 5 +# fc.lane5_sample = clean_data['lane5_description'] +# species_name = clean_data['lane5_species'] +# try: +# specie = models.Specie.objects.get(scientific_name=species_name) +# except models.Specie.DoesNotExist: +# specie = models.Specie(scientific_name=species_name) +# specie.save() +# fc.lane5_species = specie +# +# #LANE 6 +# fc.lane6_sample = clean_data['lane6_description'] +# species_name = clean_data['lane6_species'] +# try: +# specie = models.Specie.objects.get(scientific_name=species_name) +# except models.Specie.DoesNotExist: +# specie = models.Specie(scientific_name=species_name) +# specie.save() +# fc.lane6_species = specie +# +# #LANE 7 +# fc.lane7_sample = clean_data['lane7_description'] +# species_name = clean_data['lane7_species'] +# try: +# specie = models.Specie.objects.get(scientific_name=species_name) +# except models.Specie.DoesNotExist: +# specie = models.Specie(scientific_name=species_name) +# specie.save() +# fc.lane7_species = specie +# +# #LANE 8 +# fc.lane8_sample = clean_data['lane8_description'] +# species_name = clean_data['lane8_species'] +# try: +# specie = models.Specie.objects.get(scientific_name=species_name) +# except models.Specie.DoesNotExist: +# specie = models.Specie(scientific_name=species_name) +# specie.save() +# fc.lane8_species = specie +# +# fc.notes = clean_data['notes'] +# +# fc.save() +# +# return fc +# +# +#def generateElandConfig(form): +# data = [] +# +# form = form.cleaned_data +# +# BASE_DIR = '/data-store01/compbio/genomes' +# +# data.append("# FLOWCELL: %s" % (form['flow_cell_number'])) +# data.append("#") +# +# 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 getElandConfig(flowcell, regenerate=False): + + file_path = os.path.join(settings.UPLOADTO_CONFIG_FILE, flowcell) + + #If we are regenerating the config file, skip + # reading of existing file. If the file doesn't + # exist, try to generate it form the DB. + if not regenerate and os.path.isfile(file_path): + f = open(file_path, 'r') + data = f.read() + f.close() + return data + + try: + fcObj = models.FlowCell.objects.get(flowcell_id=flowcell) + except ObjectDoesNotExist: + return None + + data = [] + + #form = form.cleaned_data + + BASE_DIR = '/data-store01/compbio/genomes' + + data.append("# FLOWCELL: %s" % (fcObj.flowcell_id)) + data.append("#") + + notes = fcObj.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 = str(fcObj.lane_1_library.library_id) + '|' \ + + fcObj.lane_1_library.library_name.replace('\r\n', '\n').replace('\r', '\n') + l2d = str(fcObj.lane_2_library.library_id) + '|' \ + + fcObj.lane_2_library.library_name.replace('\r\n', '\n').replace('\r', '\n') + l3d = str(fcObj.lane_3_library.library_id) + '|' \ + + fcObj.lane_3_library.library_name.replace('\r\n', '\n').replace('\r', '\n') + l4d = str(fcObj.lane_4_library.library_id) + '|' \ + + fcObj.lane_4_library.library_name.replace('\r\n', '\n').replace('\r', '\n') + + l5d = str(fcObj.lane_5_library.library_id) + '|' \ + + fcObj.lane_5_library.library_name.replace('\r\n', '\n').replace('\r', '\n') + l6d = str(fcObj.lane_6_library.library_id) + '|' \ + + fcObj.lane_6_library.library_name.replace('\r\n', '\n').replace('\r', '\n') + l7d = str(fcObj.lane_7_library.library_id) + '|' \ + + fcObj.lane_7_library.library_name.replace('\r\n', '\n').replace('\r', '\n') + l8d = str(fcObj.lane_8_library.library_id) + '|' \ + + fcObj.lane_8_library.library_name.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 = fcObj.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'] + l1s = fcObj.lane_1_library.library_species.scientific_name + '|' + \ + fcObj.lane_1_library.library_species.use_genome_build + genome_dict.setdefault(l1s, []).append('1') + l2s = fcObj.lane_2_library.library_species.scientific_name + '|' + \ + fcObj.lane_2_library.library_species.use_genome_build + genome_dict.setdefault(l2s, []).append('2') + l3s = fcObj.lane_3_library.library_species.scientific_name + '|' + \ + fcObj.lane_3_library.library_species.use_genome_build + genome_dict.setdefault(l3s, []).append('3') + l4s = fcObj.lane_4_library.library_species.scientific_name + '|' + \ + fcObj.lane_4_library.library_species.use_genome_build + genome_dict.setdefault(l4s, []).append('4') + l5s = fcObj.lane_5_library.library_species.scientific_name + '|' + \ + fcObj.lane_5_library.library_species.use_genome_build + genome_dict.setdefault(l5s, []).append('5') + l6s = fcObj.lane_6_library.library_species.scientific_name + '|' + \ + fcObj.lane_6_library.library_species.use_genome_build + genome_dict.setdefault(l6s, []).append('6') + l7s = fcObj.lane_7_library.library_species.scientific_name + '|' + \ + fcObj.lane_7_library.library_species.use_genome_build + genome_dict.setdefault(l7s, []).append('7') + l8s = fcObj.lane_8_library.library_species.scientific_name + '|' + \ + fcObj.lane_8_library.library_species.use_genome_build + 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, '%%(%s)s' % (genome))) + data.append('%s:USE_BASES %s' % (lanes, 'Y'*int(read_length))) + + data.append('SEQUENCE_FORMAT --scarf') + + data = '\n'.join(data) + + f = open(file_path, 'w') + f.write(data) + f.close() + + return data + + + +def config(request, flowcell=None): + """ + Returns eland config file for a given flowcell number, + or returns a list of available flowcell numbers. + """ + + # Provide INDEX of available Flowcell config files. + if flowcell is None: + #Find all FC* config files and report an index html file + #fc_list = [ os.path.split(file_path)[1] for file_path in glob.glob(os.path.join(settings.UPLOADTO_CONFIG_FILE, 'FC*')) ] + fc_list = [ fc.flowcell_id for fc in models.FlowCell.objects.all() ] + + #Convert FC* list to html links + fc_html = [ '%s' % (fc_name, fc_name) for fc_name in fc_list ] + + return HttpResponse('
'.join(fc_html)) + + #FIXME: Should validate flowcell input before using. + flowcell = _validate_input(flowcell) + cfg = getElandConfig(flowcell, regenerate=True) + + if not cfg: + return HttpResponse("Hmm, config file for %s does not seem to exist." % (flowcell)) + + + return HttpResponse(cfg, mimetype="text/plain") + + + + +#def index(request): +# """ +# Return a form for filling out information about the flowcell +# """ +# if request.method == 'POST': +# form = forms.ConfigForm(request.POST, error_class=forms.DivErrorList) +# if form.is_valid(): +# #cfg = generateElandConfig(form) +# _saveConfigFile(form) +# _saveToDb(form) +# return HttpResponse("Eland Config Saved!", 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/gaworkflow/frontend/fctracker/__init__.py b/gaworkflow/frontend/fctracker/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/gaworkflow/frontend/fctracker/models.py b/gaworkflow/frontend/fctracker/models.py new file mode 100644 index 0000000..a995462 --- /dev/null +++ b/gaworkflow/frontend/fctracker/models.py @@ -0,0 +1,147 @@ +from django.db import models +from gaworkflow.frontend import settings + +# Create your models here. + +class Species(models.Model): + + scientific_name = models.CharField(max_length=256, unique=True, db_index=True, core=True) + common_name = models.CharField(max_length=256, blank=True) + use_genome_build = models.CharField(max_length=100, blank=False, null=False) + + def __str__(self): + return '%s (%s)|%s' % (self.scientific_name, self.common_name, self.use_genome_build) + + class Meta: + verbose_name_plural = "species" + ordering = ["scientific_name"] + + class Admin: + fields = ( + (None, { + 'fields': (('scientific_name', 'common_name'), ('use_genome_build')) + }), + ) + +class Library(models.Model): + + library_id = models.IntegerField(primary_key=True, db_index=True, core=True) + library_name = models.CharField(max_length=100, unique=True, core=True) + library_species = models.ForeignKey(Species, core=True) + #use_genome_build = models.CharField(max_length=100, blank=False, null=False) + RNAseq = models.BooleanField() + + made_by = models.CharField(max_length=50, blank=True, default="Lorian") + creation_date = models.DateField(blank=True, null=True) + made_for = models.CharField(max_length=50, blank=True) + + PROTOCOL_END_POINTS = ( + ('?', 'Unknown'), + ('Sample', 'Raw sample'), + ('Gel', 'Ran gel'), + ('1A', 'Gel purification'), + ('2A', '2nd PCR'), + ('Progress', 'In progress'), + ) + stopping_point = models.CharField(max_length=50, choices=PROTOCOL_END_POINTS) + amplified_from_sample = models.ForeignKey('self', blank=True, null=True) + + undiluted_concentration = models.DecimalField(max_digits=5, decimal_places=2, blank=True, null=True) + ten_nM_dilution = models.BooleanField() + successful_pM = models.IntegerField(blank=True, null=True) + + notes = models.TextField(blank=True) + + def __str__(self): + return '#%s: %s' % (self.library_id, self.library_name) + + class Meta: + verbose_name_plural = "libraries" + ordering = ["-library_id"] + + class Admin: + date_hierarchy = "creation_date" + save_as = True + save_on_top = True + search_fields = ['library_name'] + list_display = ('library_id', 'library_name', 'made_for', 'creation_date', 'ten_nM_dilution', 'stopping_point', 'successful_pM') + list_display_links = ('library_id', 'library_name') + list_filter = ('stopping_point', 'ten_nM_dilution', 'library_species', 'made_for', 'made_by') + fields = ( + (None, { + 'fields': (('library_id', 'library_name'), ('library_species', 'RNAseq'),) + }), + ('Creation Information:', { + 'fields' : (('made_for', 'made_by', 'creation_date'), ('stopping_point', 'amplified_from_sample'), ('undiluted_concentration', 'ten_nM_dilution', 'successful_pM'), 'notes',) + }), + ) + +class FlowCell(models.Model): + + flowcell_id = models.CharField(max_length=20, unique=True, db_index=True, core=True) + run_date = models.DateTimeField(core=True) + advanced_run = models.BooleanField(default=False) + read_length = models.IntegerField(default=32) + + lane_1_library = models.ForeignKey(Library, related_name="lane_1_library") + lane_2_library = models.ForeignKey(Library, related_name="lane_2_library") + lane_3_library = models.ForeignKey(Library, related_name="lane_3_library") + lane_4_library = models.ForeignKey(Library, related_name="lane_4_library") + lane_5_library = models.ForeignKey(Library, related_name="lane_5_library") + lane_6_library = models.ForeignKey(Library, related_name="lane_6_library") + lane_7_library = models.ForeignKey(Library, related_name="lane_7_library") + lane_8_library = models.ForeignKey(Library, related_name="lane_8_library") + + lane_1_pM = models.IntegerField(default=4) + lane_2_pM = models.IntegerField(default=4) + lane_3_pM = models.IntegerField(default=4) + lane_4_pM = models.IntegerField(default=4) + lane_5_pM = models.IntegerField(default=4) + lane_6_pM = models.IntegerField(default=4) + lane_7_pM = models.IntegerField(default=4) + lane_8_pM = models.IntegerField(default=4) + + lane_1_cluster_estimate = models.IntegerField(blank=True, null=True) + lane_2_cluster_estimate = models.IntegerField(blank=True, null=True) + lane_3_cluster_estimate = models.IntegerField(blank=True, null=True) + lane_4_cluster_estimate = models.IntegerField(blank=True, null=True) + lane_5_cluster_estimate = models.IntegerField(blank=True, null=True) + lane_6_cluster_estimate = models.IntegerField(blank=True, null=True) + lane_7_cluster_estimate = models.IntegerField(blank=True, null=True) + lane_8_cluster_estimate = models.IntegerField(blank=True, null=True) + + notes = models.TextField(blank=True) + + def __str__(self): + return '%s (%s)' % (self.flowcell_id, self.run_date) + + class Meta: + ordering = ["run_date"] + + class Admin: + date_hierarchy = "run_date" + save_on_top = True + search_fields = ['lane_1_library', 'lane_2_library', 'lane_3_library', 'lane_4_library', 'lane_5_library', 'lane_6_library', 'lane_7_library', 'lane_8_library'] + list_display = ('flowcell_id', 'run_date', 'lane_1_library', 'lane_2_library', 'lane_3_library', 'lane_4_library', 'lane_5_library', 'lane_6_library', 'lane_7_library', 'lane_8_library') + fields = ( + (None, { + 'fields': ('run_date', 'flowcell_id', ('read_length', 'advanced_run'),) + }), + ('Lanes:', { + 'fields' : (('lane_1_library', 'lane_1_pM', 'lane_1_cluster_estimate'), ('lane_2_library', 'lane_2_pM', 'lane_2_cluster_estimate'), ('lane_3_library', 'lane_3_pM', 'lane_3_cluster_estimate'), ('lane_4_library', 'lane_4_pM', 'lane_4_cluster_estimate'), ('lane_5_library', 'lane_5_pM', 'lane_5_cluster_estimate'), ('lane_6_library', 'lane_6_pM', 'lane_6_cluster_estimate'), ('lane_7_library', 'lane_7_pM', 'lane_7_cluster_estimate'), ('lane_8_library', 'lane_8_pM', 'lane_8_cluster_estimate'),) + }), + (None, { + 'fields' : ('notes',) + }), + ) + +class ElandResult(models.Model): + + class Admin: pass + + flow_cell = models.ForeignKey(FlowCell) + config_file = models.FileField(upload_to=settings.UPLOADTO_CONFIG_FILE) + eland_result_pack = models.FileField(upload_to=settings.UPLOADTO_ELAND_RESULT_PACKS) + bed_file_pack = models.FileField(upload_to=settings.UPLOADTO_BED_PACKS) + + notes = models.TextField(blank=True) diff --git a/gaworkflow/frontend/fctracker/views.py b/gaworkflow/frontend/fctracker/views.py new file mode 100644 index 0000000..60f00ef --- /dev/null +++ b/gaworkflow/frontend/fctracker/views.py @@ -0,0 +1 @@ +# Create your views here. diff --git a/gaworkflow/frontend/manage.py b/gaworkflow/frontend/manage.py new file mode 100644 index 0000000..5e78ea9 --- /dev/null +++ b/gaworkflow/frontend/manage.py @@ -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/gaworkflow/frontend/settings.py b/gaworkflow/frontend/settings.py new file mode 100644 index 0000000..fc79fb2 --- /dev/null +++ b/gaworkflow/frontend/settings.py @@ -0,0 +1,94 @@ +import os + +# 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 = os.path.abspath('../../fctracker.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 = 'gaworkflow.frontend.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. + os.path.abspath("../../templates") +) + +INSTALLED_APPS = ( + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.sites', + 'gaworkflow.frontend.eland_config', + 'gaworkflow.frontend.fctracker', + 'django.contrib.databrowse', +) + +# Project specific settings +UPLOADTO_HOME = os.path.abspath('../../uploads') +UPLOADTO_CONFIG_FILE = os.path.join(UPLOADTO_HOME, 'eland_config') +UPLOADTO_ELAND_RESULT_PACKS = os.path.join(UPLOADTO_HOME, 'eland_results') +UPLOADTO_BED_PACKS = os.path.join(UPLOADTO_HOME, 'bed_packs') + diff --git a/gaworkflow/frontend/urls.py b/gaworkflow/frontend/urls.py new file mode 100644 index 0000000..0c67015 --- /dev/null +++ b/gaworkflow/frontend/urls.py @@ -0,0 +1,16 @@ +from django.conf.urls.defaults import * + +# Databrowser: +from django.contrib import databrowse +from fctracker.models import Library, FlowCell +databrowse.site.register(Library) +databrowse.site.register(FlowCell) + +urlpatterns = patterns('', + # Base: + (r'^eland_config/', include('gaworkflow.frontend.eland_config.urls')), + # Admin: + (r'^admin/', include('django.contrib.admin.urls')), + # Databrowser: + (r'^databrowse/(.*)', databrowse.site.root), +)