Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ networks:
front-tier:
driver: bridge
back-tier:
driver: bridge
driver: bridge
8 changes: 6 additions & 2 deletions pgd/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
import os
PROJECT_ROOT = os.path.dirname(os.path.abspath(os.path.dirname(__file__)))

DEBUG = config('DEBUG', default=False, cast=bool)
DEBUG = True
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ease of debugging

TEMPLATE_DEBUG = DEBUG


ADMINS = (
# ('Your Name', 'your_email@domain.com'),
)
Expand Down Expand Up @@ -122,6 +123,7 @@
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django_pdb.middleware.PdbMiddleware',
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ease of debugging

)

ROOT_URLCONF = config('ROOT_URLCONF', default='pgd.urls')
Expand All @@ -130,11 +132,12 @@
WSGI_APPLICATION = 'pgd.wsgi.application'

TEMPLATE_DIRS = (
'%s/templates' % DOC_ROOT
'%s/templates' % DOC_ROOT,
)

INSTALLED_APPS = (
'django.contrib.auth',
'django_pdb',
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ease of debugging

'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
Expand Down Expand Up @@ -175,6 +178,7 @@
}
}

DJANGO_SETTINGS_MODULE = 'pgd.settings'
# PGD Specific settings
QUERY_LIMIT = config('QUERY_LIMIT', default=50000000, cast=int)
SEGMENT_SIZE = config('SEGMENT_SIZE', default=10, cast=int)
Expand Down
6 changes: 4 additions & 2 deletions pgd/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
from django.core.urlresolvers import reverse_lazy
from views import ReferencesView, ContactUsView, NewsView, WelcomeView
admin.autodiscover()
import pgd_search.urls
import pgd_core.urls

#from pgd import VERSION
#from pgd_splicer.models import pdb_select_settings
Expand All @@ -20,9 +22,9 @@
# Uncomment the next line to enable the admin:
#(r'^admin/', include(admin.site.urls)),

url(r'^search/', include('pgd_search.urls'), name='pgd_search'),
url(r'^search/', include(pgd_search.urls), name='pgd_search'),

url(r'^accounts/', include('pgd_core.urls')),
url(r'^accounts/', include(pgd_core.urls)),

# Static pages:
(r'^references/$', ReferencesView.as_view()),
Expand Down
5 changes: 4 additions & 1 deletion pgd/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@

"""
import os
import sys
from django.core.wsgi import get_wsgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "pgd.settings")

#os.environ.setdefault("DJANGO_SETTINGS_MODULE", "pgd.settings")
os.environ['DJANGO_SETTINGS_MODULE'] = 'pgd.settings'
# This application object is used by any WSGI server configured to use this
# file. This includes Django's development server, if the WSGI_APPLICATION
# setting points here.
Expand Down
21 changes: 16 additions & 5 deletions pgd_search/plot/ConfDistFuncs.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@
from django.db import connections
from django.db.backends.mysql.compiler import SQLCompiler

from django.db.models import Count, Avg, StdDev
from django.db.models import Count, Avg, StdDev, FloatField

from pgd_constants import *
from pgd_core.models import *
from pgd_search.models import *
from pgd_search.statistics.aggregates import DirectionalAvg, DirectionalStdDev, BinSort
from pgd_search.statistics.aggregates import DirectionalAvg, DirectionalStdDev, BinSort, PGDAggregate, BinSortSQL
from pgd_splicer.sidechain import sidechain_length_relationship_list, sidechain_angle_relationship_list
from svg import *

import sys
ANGLES = ('ome', 'phi', 'psi', 'chi1','chi2','chi3','chi4','chi5','zeta')
NON_FIELDS = ('Observations', 'all')

Expand Down Expand Up @@ -311,7 +312,7 @@ def query_bins(self):
annotations[avg] = Avg(field[1])
annotations[stddev] = StdDev(field[1])
annotated_query = querySet.annotate(**annotations)

# sort and group by bins using an aggregate function that calculates
# bin index based on bin size (in field units ie. degrees) and bin count.
#
Expand All @@ -324,14 +325,24 @@ def query_bins(self):
# XXX in Django 1.2+ aggregates were changed to require connection and
# SQLCompiler objects to generate sql. We must initialize this all
# manually to be able to grab the SQL for just our aggregate.

sortx = BinSort(self.xTextString, offset=x, bincount=xbin, max=x1)
sorty = BinSort(self.yTextString, offset=y, bincount=ybin, max=y1)

annotated_query.annotate(x=sortx, y=sorty)

cn = connections['default']
qn = SQLCompiler(annotated_query.query, cn, 'default').quote_name_unless_alias
sortx_sql = sortx.aggregate.as_sql(qn, cn)[0]
sorty_sql = sorty.aggregate.as_sql(qn, cn)[0]

#Hack : Using the BinSortSQL class directly instead of BinSort
#this overrides l:329 and l:330
sortx = BinSortSQL(('pgd_core_residue', 'psi'), offset=x, bincount=xbin, max=x1)
sorty = BinSortSQL(('pgd_core_residue', 'phi'), offset=y, bincount=ybin, max=y1)

sortx_sql = sortx.as_sql(qn, cn)[0]
sorty_sql = sorty.as_sql(qn, cn)[0]



annotated_query = annotated_query.extra(select={'x':sortx_sql, 'y':sorty_sql})
annotated_query = annotated_query.order_by('x','y')
Expand Down
42 changes: 24 additions & 18 deletions pgd_search/plot/PlotForm.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from pgd_search.views import RESIDUE_INDEXES

#choice for occurence of property
ATTRIBUTE_CHOICES = [
ATTRIBUTE_CHOICES = (
("Observations",'Observations'),
("L1",u'C<sup>-1</sup>N'),
("L2",u'NC<sup>&alpha;</sup>'),
Expand All @@ -28,10 +28,10 @@
("psi",u'&psi;'),
('zeta',u'&zeta;'),
#('h_bond_energy','H Bond'),
]
)

# choices for properties mapped to axis
PROPERTY_CHOICES = [
PROPERTY_CHOICES = (
("L1",u'C<sup>-1</sup>N'),
("L2",u'NC<sup>&alpha;</sup>'),
("L3",u'C<sup>&alpha;</sup>C<sup>&beta;</sup>'),
Expand All @@ -55,50 +55,50 @@
("psi",u'&psi;'),
('zeta',u'&zeta;'),
#('h_bond_energy','H Bond'),
]
)


PROPERTY_CHOICES_DICT = {}
for prop, label in PROPERTY_CHOICES:
PROPERTY_CHOICES_DICT[prop] = label


BACKGROUND_CHOICES = [
BACKGROUND_CHOICES = (
('#ffffff','White'),
('#000000','Black'),
('#666666','Gray'),
('#222222','Dark Gray'),
(None,'Transparent'),
]
)

GRAPH_CHOICES = [
GRAPH_CHOICES = (
('#222222','Dark Gray'),
('#666666','Gray'),
('#000000','Black'),
('#ffffff','White'),
(None,'Transparent'),
]
)

TEXT_CHOICES = [
TEXT_CHOICES = (
('#000000','Black'),
('#ffffff','White'),
('#666666','Gray'),
('#222222','Dark Gray'),
]
)

HUE_CHOICES = [
HUE_CHOICES = (
('green','Green'),
('blue','Blue'),
('red','Red'),
('black','Black/White'),
]
)

HASH_CHOICES = [
HASH_CHOICES = (
('#666666','Gray'),
('#222222','Dark Gray'),
('#000000','Black'),
('#ffffff','White'),
]
)


"""
Expand Down Expand Up @@ -147,11 +147,11 @@ class PlotForm(forms.Form):
widget=forms.TextInput(attrs={'size':4}))

#custom plot properties
background_color= forms.ChoiceField(choices=BACKGROUND_CHOICES)
graph_color = forms.ChoiceField(choices=GRAPH_CHOICES)
text_color = forms.ChoiceField(choices=TEXT_CHOICES)
background_color= forms.ChoiceField(required=False, choices=BACKGROUND_CHOICES)
graph_color = forms.ChoiceField(required=False, choices=GRAPH_CHOICES)
text_color = forms.ChoiceField(required=False, choices=TEXT_CHOICES)
plot_hue = forms.ChoiceField(choices=HUE_CHOICES)
hash_color = forms.ChoiceField(choices=HASH_CHOICES)
hash_color = forms.ChoiceField(required=False, choices=HASH_CHOICES)
height = forms.IntegerField(initial=470,
widget=forms.TextInput(attrs={'size':4}))
width = forms.IntegerField(initial=560,
Expand All @@ -165,4 +165,10 @@ def clean(self):
data['attribute'] = data['attribute'].replace('-','_')
except KeyError:
pass
if not data['graph_color'] :
data['graph_color'] = '#222222'
if not data['hash_color'] :
data['hash_color'] = '#666666'
if not data['text_color'] :
data['text_color'] = '#000000'
return data
5 changes: 1 addition & 4 deletions pgd_search/plot/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
from django.conf import settings
from django.shortcuts import render_to_response
import json

from PlotForm import PlotForm, ATTRIBUTE_CHOICES, PROPERTY_CHOICES
from ConfDistFuncs import *
from pgd_constants import AA_CHOICES
from pgd_search.views import settings_processor
from pgd_splicer.sidechain import sidechain_string_dict


AA_CHOICES = [aa[1].upper() for aa in filter(lambda x: x[1].upper() in sidechain_string_dict, AA_CHOICES)]

def drawGraph(request, height=470, width=560, xStart=None, yStart=None, xEnd=None, yEnd=None, attribute='Observations', xProperty='phi', yProperty='psi', reference=None, sigmaVal=3, residue_attribute=None, residue_xproperty=None, residue_yproperty=None, xBin=None, yBin=None, background_color='#ffffff',graph_color='#222222',text_color='#000000', hue='green', hash_color='666666'):
Expand Down Expand Up @@ -74,15 +74,12 @@ def drawGraph(request, height=470, width=560, xStart=None, yStart=None, xEnd=Non
text_color,
hash_color
)

svg = cdp.Plot()
except Exception, e:
print 'exception', e
import traceback, sys
exceptionType, exceptionValue, exceptionTraceback = sys.exc_info()
print "*** print_tb:"
traceback.print_tb(exceptionTraceback, limit=10, file=sys.stdout)

raise e
return (svg, xStart, xEnd, xBin, yStart, yEnd, yBin)

Expand Down
8 changes: 3 additions & 5 deletions pgd_search/search/views.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import math
import re
import pickle

from django.http import HttpResponse, HttpResponseRedirect
from django.template import RequestContext
from django.shortcuts import render_to_response, redirect
from django.conf import settings
from django.forms.util import ErrorList
from django.forms.utils import ErrorList
from django.core.paginator import Paginator, InvalidPage, EmptyPage
import json
from datetime import datetime
Expand All @@ -24,7 +23,6 @@
json_sidechain_angles_lookup = json.dumps(bond_angles_string_dict)



def search(request):
"""
Handler for search form.
Expand All @@ -43,10 +41,10 @@ def search(request):
#at least for now limit the size of the result set
count = search_object.querySet().count()
if count > settings.QUERY_LIMIT:
form._errors['Result Size'] = ErrorList(['Your query returned more than 20,000 records, refine your search'])
form.error['Result Size'] = ErrorList(['Your query returned more than 20,000 records, refine your search'])

elif count == 0 and False:
form._errors['Result Size'] = ErrorList(['Your query returned no results'])
form.error['Result Size'] = ErrorList(['Your query returned no results'])

else:
#store search in session
Expand Down
8 changes: 6 additions & 2 deletions pgd_search/statistics/aggregates.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class PGDAggregate(Aggregate):
Modified to allow Aggregate functions outside of the Django module
"""


def add_to_query(self, query, alias, col, source, is_summary):
"""Add the aggregate to the nominated query.

Expand All @@ -24,13 +25,15 @@ def add_to_query(self, query, alias, col, source, is_summary):
* is_summary is a boolean that is set True if the aggregate is a
summary value rather than an annotation.
"""
self.queryObj = query
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will be removed, had it for debugging purpose

klass = globals()['%sSQL' % self.name]
aggregate = klass(col, source=source, is_summary=is_summary, **self.extra)

# Validate that the backend has a fully supported, correct
# implementation of this aggregate
self.aggr = aggregate
query.aggregates[alias] = aggregate
self.aggregate = aggregate



class DirectionalStdDev(PGDAggregate):
Expand Down Expand Up @@ -63,3 +66,4 @@ class BinSort(PGDAggregate):
class BinSortSQL(SQLAggregate):
sql_function = ''
sql_template = '%(function)sFLOOR((IF(%(field)s<%(offset).16f,360,0)+%(field)s-%(offset).16f)/%(bincount).16f)-IF(%(field)s=%(max).16f,1,0)'

Loading