<commit_before>from django.shortcuts import render, render_to_response, get_object_or_404, HttpResponseRedirect
from news.models import News, Faq
from docking.models import Receptor, Docking
from docking.adddocking import adddocking
from docking.forms import SubmitDocking
from docking.math import getroc, getEnrichment, AUC, tresholdstable, resultstable
from json import dumps
import pybel
import string
import random

def home(request):
    allnews = News.objects.all()
    allreceptors = Receptor.objects.all()
    return render(request, 'index.html', {'allnews':allnews, 'allreceptors':allreceptors})

def get_faq(request):
    allfaq = Faq.objects.all()
    allreceptors = Receptor.objects.all()
    return render(request, 'faq.html', {'allfaq':allfaq, 'allreceptors':allreceptors})

def prediction(request):
    """
    Form for submitting user calculations
    """
    allreceptors = Receptor.objects.all()
    
    
    if 'submitdocking' in request.POST:
        form = SubmitDocking(request.POST)
        form.is_valid()
        smiles = str(form.cleaned_data['smiles'])
        name = form.cleaned_data['name']
        
        error = []
        try:
            pybel.readstring("smi", str(smiles))
        except:
            error.append("Error in SMILES")
        if not error:
            uniquestring = ''.join(random.choice(string.ascii_lowercase) for x in range(10))
            dockid = adddocking(uniquestring,smiles,name)
            return HttpResponseRedirect('/docking/%s/' % uniquestring)
        else:
            form = SubmitDocking()
            return render(request, 'prediction.html', {'form':form, 'error':error, 'allreceptors':allreceptors})
    else:
        form = SubmitDocking()
        return render(request, 'prediction.html', {'form':form, 'allreceptors':allreceptors})

def receptors(request):
    allreceptors = Receptor.objects.all()
    return render(request, 'receptors.html', {'allreceptors':allreceptors})

def receptor(request, idnum):
    allreceptors = Receptor.objects.all()
    #Views for individual receptors
    try:
        offset = int(idnum)
    except ValueError:
        raise Http404()
    rec = get_object_or_404(Receptor, pk=idnum)
    
    xdata, ydata = getroc(rec.roc.split('\\n')[:-1]) #returns Se data and 1-Sp data
    rocdata = dumps(zip(xdata, ydata)) #makes nested list in JSON format to plot ROC with Flot
    auc = round(AUC(xdata, ydata), 4) #takes Se data and 1-Sp data and returns auc of ROC
    enric = getEnrichment(rec.roc.split('\\n')[:-1], 1) #calculates enrichment factor, where sec arg is procent number
    tresholds = tresholdstable(rec.treshold1)
    if rec.roc_an != "":<commit_msg>Docking error<commit_after>from django.shortcuts import render, render_to_response, get_object_or_404, HttpResponseRedirect
from news.models import News, Faq
from docking.models import Receptor, Docking
from docking.adddocking import adddocking
from docking.forms import SubmitDocking
from docking.math import getroc, getEnrichment, AUC, tresholdstable, resultstable
from json import dumps
import pybel
import string
import random

def home(request):
    allnews = News.objects.all()
    allreceptors = Receptor.objects.all()
    return render(request, 'index.html', {'allnews':allnews, 'allreceptors':allreceptors})

def get_faq(request):
    allfaq = Faq.objects.all()
    allreceptors = Receptor.objects.all()
    return render(request, 'faq.html', {'allfaq':allfaq, 'allreceptors':allreceptors})

def prediction(request):
    """
    Form for submitting user calculations
    """
    allreceptors = Receptor.objects.all()
    
    
    if 'submitdocking' in request.POST:
        form = SubmitDocking(request.POST)
        form.is_valid()
        smiles = str(form.cleaned_data['smiles'])
        name = form.cleaned_data['name']
        
        error = []
        try:
            pybel.readstring("smi", str(smiles))
        except:
            error.append("Error in SMILES or compound molecular weight too big")
        if not error:
            uniquestring = ''.join(random.choice(string.ascii_lowercase) for x in range(10))
            dockid = adddocking(uniquestring,smiles,name)
            return HttpResponseRedirect('/docking/%s/' % uniquestring)
        else:
            form = SubmitDocking()
            return render(request, 'prediction.html', {'form':form, 'error':error, 'allreceptors':allreceptors})
    else:
        form = SubmitDocking()
        return render(request, 'prediction.html', {'form':form, 'allreceptors':allreceptors})

def receptors(request):
    allreceptors = Receptor.objects.all()
    return render(request, 'receptors.html', {'allreceptors':allreceptors})

def receptor(request, idnum):
    allreceptors = Receptor.objects.all()
    #Views for individual receptors
    try:
        offset = int(idnum)
    except ValueError:
        raise Http404()
    rec = get_object_or_404(Receptor, pk=idnum)
    
    xdata, ydata = getroc(rec.roc.split('\\n')[:-1]) #returns Se data and 1-Sp data
    rocdata = dumps(zip(xdata, ydata)) #makes nested list in JSON format to plot ROC with Flot
    auc = round(AUC(xdata, ydata), 4) #takes Se data and 1-Sp data and returns auc of ROC
    enric = getEnrichment(rec.roc.split('\\n')[:-1], 1) #calculates enrichment factor, where sec arg is procent number
    tresholds = tresholdstable(rec.treshold1)
    if rec.roc_an != "":
{'fraction_non_alphanumeric': 0.1144768630366103, 'fraction_numerical': 0.006690206281360342, 'mean_word_length': 3.4479338842975205, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6906942', 'n_tokens_mistral': 1758, 'n_tokens_neox': 1655, 'n_words': 417}