示例#1
0
def renderToPNG(request):
    if request.method == 'POST':  # If the form has been submitted
        form = PlotForm(request.POST)  # A form bound to the POST data
        if form.is_valid():  # All validation rules pass
            data = form.cleaned_data
            width = data['width']
            height = data['height']
            svg, x, x1, xBin, y, y1, yBin = drawGraph(
                request, height, width, data['x'], data['y'], data['x1'],
                data['y1'], data['attribute'], data['xProperty'],
                data['yProperty'], data['reference'], int(data['sigmaVal']),
                int(data['residue_attribute']), int(data['residue_xproperty']),
                int(data['residue_yproperty']), data['xBin'], data['yBin'],
                data['background_color'], data['graph_color'],
                data['text_color'], data['plot_hue'], data['hash_color'])

    else:
        form = PlotForm()  # An unbound form
        svg, x, x1, xBin, y, y1, yBin = drawGraph(request)
        width = 560
        height = 480

    response = HttpResponse(mimetype="image/png")
    response['Content-Disposition'] = 'attachment; filename="plot.png"'
    svg.render_png(response, width, height + 30)

    return response
def renderToSVG(request):
    """
    render conf dist plot using jquery.svg
    """
    try:
        form = PlotForm(request.POST) # A form bound to the POST data
        if form.is_valid(): # All validation rules pass
            data = form.cleaned_data
            svg,x,x1,xBin,y,y1,yBin = drawGraph(
                                                request,
                                                int(data['height']),
                                                int(data['width']),
                                                data['x'],
                                                data['y'],
                                                data['x1'],
                                                data['y1'],
                                                data['attribute'],
                                                data['xProperty'],
                                                data['yProperty'],
                                                data['reference'],
                                                int(data['sigmaVal']),
                                                int(data['residue_attribute']),
                                                int(data['residue_xproperty']),
                                                int(data['residue_yproperty']),
                                                data['xBin'],
                                                data['yBin'],
                                                data['background_color'],
                                                data['graph_color'],
                                                data['text_color'],
                                                data['plot_hue'],
                                                data['hash_color'])
            _json = json.dumps({'svg':svg.to_dict(), \
                                        'x':x, 'x1':x1, 'xBin':xBin, \
                                        'y':y, 'y1':y1, 'yBin':yBin})
            return HttpResponse(_json)

        else:
            """
            Errors in the form - repackage the error list as a list of errors
            This list can then be json serialized and processed by the javascript
            on the plot page
            """
            errors = []
            for k, v in form.errors.items():
                for error in v:
                    errors.append([k, error._proxy____args[0]])

            return HttpResponse(json.dumps({'errors':errors}))
    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)
        return HttpResponse("-1")
def renderToPNG(request):
    if request.method == 'POST': # If the form has been submitted
        form = PlotForm(request.POST) # A form bound to the POST data
        if form.is_valid(): # All validation rules pass
            data = form.cleaned_data
            width = data['width']
            height = data['height']
            svg, x,x1,xBin,y,y1,yBin = drawGraph(
                        request,
                        height,
                        width,
                        data['x'],
                        data['y'],
                        data['x1'],
                        data['y1'],
                        data['attribute'],
                        data['xProperty'],
                        data['yProperty'],
                        data['reference'],
                        int(data['sigmaVal']),
                        int(data['residue_attribute']),
                        int(data['residue_xproperty']),
                        int(data['residue_yproperty']),
                        data['xBin'],
                        data['yBin'],
                        data['background_color'],
                        data['graph_color'],
                        data['text_color'],
                        data['plot_hue'],
                        data['hash_color'])

    else:
        form = PlotForm() # An unbound form
        svg,x,x1,xBin,y,y1,yBin = drawGraph(request)
        width = 560
        height = 480

    response = HttpResponse(content_type="image/png")
    response['Content-Disposition'] = 'attachment; filename="plot.png"'
    svg.render_png(response, width, height+30)

    return response
示例#4
0
def renderToSVG(request):
    """
    render conf dist plot using jquery.svg
    """
    print "hhel"
    try:
        form = PlotForm(request.POST)  # A form bound to the POST data
        if form.is_valid():  # All validation rules pass
            data = form.cleaned_data
            svg, x, x1, xBin, y, y1, yBin = drawGraph(
                request, int(data['height']), int(data['width']), data['x'],
                data['y'], data['x1'], data['y1'], data['attribute'],
                data['xProperty'], data['yProperty'], data['reference'],
                int(data['sigmaVal']), int(data['residue_attribute']),
                int(data['residue_xproperty']), int(data['residue_yproperty']),
                data['xBin'], data['yBin'], data['background_color'],
                data['graph_color'], data['text_color'], data['plot_hue'],
                data['hash_color'])
            _json = json.dumps({'svg':svg.to_dict(), \
                                        'x':x, 'x1':x1, 'xBin':xBin, \
                                        'y':y, 'y1':y1, 'yBin':yBin})
            return HttpResponse(_json)

        else:
            """
            Errors in the form - repackage the error list as a list of errors
            This list can then be json serialized and processed by the javascript
            on the plot page
            """
            errors = []
            for k, v in form.errors.items():
                for error in v:
                    errors.append([k, error._proxy____args[0]])

            return HttpResponse(json.dumps({'errors': errors}))
    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)
        return HttpResponse("-1")
def plotDump(request):
    """
    render the results of the search as a TSV (tab separated file)
    and return it to the user as a download
    """
    if request.method == 'POST': # If the form has been submitted
        form = PlotForm(request.POST) # A form bound to the POST data
        if form.is_valid(): # All validation rules pass
            data = form.cleaned_data

            cdp = ConfDistPlot(
                360,               #height
                360,               #width
                data['x'],         #Xstart
                data['x1'],        #Xend
                data['y'],         #Ystart
                data['y1'],        #Yend
                data['xBin'],      #Xbin
                data['yBin'],      #Ybin
                data['xProperty'], #X property
                data['yProperty'], #Y property
                #data['attribute'],#property
                'all',#property
                #data['reference'],
                int(data['sigmaVal']),
                int(data['residue_attribute']),
                int(data['residue_xproperty']),
                int(data['residue_yproperty']),
                pickle.loads(request.session['search']).querySet()
            )

            response = HttpResponse(content_type="text/tab-separated-values")
            response['Content-Disposition'] = 'attachment; filename="plot.tsv"'

            cdp.Plot()
            cdp.PrintDump(response)

            return response

    return HttpResponse('Error')
示例#6
0
def plotDump(request):
    """
    render the results of the search as a TSV (tab separated file)
    and return it to the user as a download
    """
    if request.method == 'POST':  # If the form has been submitted
        form = PlotForm(request.POST)  # A form bound to the POST data
        if form.is_valid():  # All validation rules pass
            data = form.cleaned_data

            cdp = ConfDistPlot(
                360,  #height
                360,  #width
                data['x'],  #Xstart
                data['x1'],  #Xend
                data['y'],  #Ystart
                data['y1'],  #Yend
                data['xBin'],  #Xbin
                data['yBin'],  #Ybin
                data['xProperty'],  #X property
                data['yProperty'],  #Y property
                #data['attribute'],#property
                'all',  #property
                #data['reference'],
                int(data['sigmaVal']),
                int(data['residue_attribute']),
                int(data['residue_xproperty']),
                int(data['residue_yproperty']),
                pickle.loads(request.session['search']).querySet())

            response = HttpResponse(mimetype="text/tab-separated-values")
            response['Content-Disposition'] = 'attachment; filename="plot.tsv"'

            cdp.Plot()
            cdp.PrintDump(response)

            return response

    return HttpResponse('Error')
示例#7
0
def plot(request):
    """
    Draws the plot page.  The plot page will rely on AJAX calls to 
    render the graph
    """
    form = PlotForm()  # An unbound form
    response_dict = {
        'defaults': json.dumps(RefDefaults()),
        'xProperty': form.fields['xProperty'].initial,
        'yProperty': form.fields['yProperty'].initial,
        'xBin': form.fields['xBin'].initial,
        'yBin': form.fields['yBin'].initial,
        'attribute': form.fields['attribute'].initial,
        'form': form,
        'attribute_choices': ATTRIBUTE_CHOICES,
        'property_choices': PROPERTY_CHOICES,
        'sidechain_angles': bond_angles_string_dict,
        'sidechain_lengths': bond_lengths_string_dict,
        'aa_choices': AA_CHOICES
    }
    return render_to_response('graph.html',
                              response_dict,
                              context_instance=RequestContext(
                                  request, processors=[settings_processor]))