Commit 0ac4482b authored by Mathieu Courcelles's avatar Mathieu Courcelles

Migrates to Python 3.6

parent 54011a34
Pipeline #14896858 passed with stage
in 2 minutes and 11 seconds
......@@ -8,13 +8,13 @@ Act as the GUI to interact with the pipeline.
# Import standard libraries
from random import randint
import pickle
from textwrap import wrap
import urllib.request
# Import Django related libraries
from django import forms
from django.contrib import admin
from django.core.cache import caches
from django.core.paginator import Paginator
from django.db import connection
from django.db.models.signals import post_save
......@@ -25,6 +25,9 @@ from django.http import HttpResponse
from django.shortcuts import render
from django.utils.functional import cached_property
# Import project libraries
from .DatasetProcessing import DatasetProcessing
import CLMSVault.CLMSVault_app.export as export
......@@ -379,7 +382,8 @@ class CLPeptideAdmin(admin.ModelAdmin):
# Restore queryset
queryset = CLPeptide.objects.all()
random = request.POST.get('random')
queryset.query = pickle.loads(request.session.get('query_%s' % random))
cache = caches['default']
queryset.query = cache.get('query_%s' % random)
clpeptide_set, alignments = compute_cl_distance(queryset,
pdb,
......@@ -394,7 +398,8 @@ class CLPeptideAdmin(admin.ModelAdmin):
if not form:
# Store queryset query
random = randint(1, 1000000)
request.session['query_%s' % random] = pickle.dumps(queryset.query)
cache = caches['default']
cache.set(f'query_{random}', queryset.query, 300)
selected_action = request.POST.getlist(admin.ACTION_CHECKBOX_NAME)[0]
form = PDBSelectionForm(initial={'_selected_action': selected_action})
......@@ -437,7 +442,8 @@ class CLPeptideAdmin(admin.ModelAdmin):
# Restore queryset
random = request.POST.get('random')
queryset = CLPeptide.objects.all()
queryset.query = pickle.loads(request.session.get('query_%s' % random))
cache = caches['default']
queryset.query = cache.get('query_%s' % random)
clpeptide_set = queryset
protein_set = clpeptide_set_2_protein_set(clpeptide_set)
......@@ -450,7 +456,9 @@ class CLPeptideAdmin(admin.ModelAdmin):
if not form:
# Store queryset query
random = randint(1, 1000000)
request.session['query_%s' % random] = pickle.dumps(queryset.query)
cache = caches['default']
cache.set(f'query_{random}', queryset.query, 300)
selected_action = request.POST.getlist(admin.ACTION_CHECKBOX_NAME)[0]
form = PDBQuantForm(initial={'quant_pk': quant_pk,
......@@ -480,7 +488,8 @@ class CLPeptideAdmin(admin.ModelAdmin):
# Restore queryset
queryset = CLPeptide.objects.all()
random = request.POST.get('random')
queryset.query = pickle.loads(request.session.get('query_%s' % random))
cache = caches['default']
queryset.query = cache.get('query_%s' % random)
return xiNET_view(request, queryset, form)
......@@ -488,7 +497,8 @@ class CLPeptideAdmin(admin.ModelAdmin):
if not form:
# Store queryset query
random = randint(1, 1000000)
request.session['query_%s' % random] = pickle.dumps(queryset.query)
cache = caches['default']
cache.set(f'query_{random}', queryset.query, 300)
selected_action = request.POST.getlist(admin.ACTION_CHECKBOX_NAME)[0]
......@@ -810,7 +820,8 @@ class DatasetAdminMixin(object):
# Restore queryset
queryset = Dataset.objects.all()
random = request.POST.get('random')
queryset.query = pickle.loads(request.session.get('query_%s' % random))
cache = caches['default']
queryset.query = cache.get('query_%s' % random)
return DatasetProcessing.run_Percolator(self, request, queryset, form)
......@@ -818,7 +829,8 @@ class DatasetAdminMixin(object):
if not form:
# Store queryset query
random = randint(1, 1000000)
request.session['query_%s' % random] = pickle.dumps(queryset.query)
cache = caches['default']
cache.set(f'query_{random}', queryset.query, 300)
selected_action = request.POST.getlist(admin.ACTION_CHECKBOX_NAME)[0]
......@@ -916,7 +928,8 @@ class DatasetAdminMixin(object):
# Restore queryset
queryset = Dataset.objects.all()
random = request.POST.get('random')
queryset.query = pickle.loads(request.session.get('query_%s' % random))
cache = caches['default']
queryset.query = cache.get(f'query_{random}')
return xiNET_view(request, dataset_set_2_clpeptide_set(queryset), form)
......@@ -924,12 +937,11 @@ class DatasetAdminMixin(object):
if not form:
# Store queryset query
random = randint(1, 1000000)
request.session['query_%s' % random] = pickle.dumps(queryset.query)
cache = caches['default']
cache.set(f'query_{random}', queryset.query, 300)
selected_action = request.POST.getlist(admin.ACTION_CHECKBOX_NAME)[0]
quant_pk = clpeptide_set_2_quantificationPkString(dataset_set_2_clpeptide_set(queryset))
form = xiNETForm(initial={'quant_pk': quant_pk,
'_selected_action': selected_action,
})
......
......@@ -13,7 +13,7 @@ from numpy import linalg as LA
# Import Django related libraries
from django.http import HttpResponse
from django.template import loader, Context
from django.template import loader
# Import project libraries
from .parser.exception import InvalidFileFormatException
......@@ -79,12 +79,14 @@ def compareRunIds_csv(self, request, queryset, form, tableName):
# Iterates through datasets
for dataset in queryset:
header_list[dataset.__unicode__()] = ''
header_list[str(dataset)] = ''
# Iterates over Clpeptides
for clpep in dataset.clpeptide_set.all():
dataset_run_name = dataset.__unicode__() + '__' + clpep.run_name
dataset_str = str(dataset)
dataset_run_name = dataset_str + '__' + clpep.run_name
header_list[dataset_run_name] = ''
......@@ -93,12 +95,12 @@ def compareRunIds_csv(self, request, queryset, form, tableName):
if not unique_key in uniquePep_dict:
uniquePep_dict[unique_key] = dict()
if not dataset.__unicode__() in uniquePep_dict[unique_key]:
uniquePep_dict[unique_key][dataset.__unicode__()] = [clpep, 0]
elif uniquePep_dict[unique_key][dataset.__unicode__()][0].match_score < clpep.match_score:
uniquePep_dict[unique_key][dataset.__unicode__()][0] = clpep
if not dataset_str in uniquePep_dict[unique_key]:
uniquePep_dict[unique_key][dataset_str] = [clpep, 0]
elif uniquePep_dict[unique_key][dataset_str][0].match_score < clpep.match_score:
uniquePep_dict[unique_key][dataset_str][0] = clpep
uniquePep_dict[unique_key][dataset.__unicode__()][1] += 1
uniquePep_dict[unique_key][dataset_str][1] += 1
if not dataset_run_name in uniquePep_dict[unique_key]:
uniquePep_dict[unique_key][dataset_run_name] = [clpep, 0]
......@@ -114,7 +116,7 @@ def compareRunIds_csv(self, request, queryset, form, tableName):
uniquePep_dict[unique_key]['pep'] = clpep
# Write header
header_fields = header_list.keys()
header_fields = list(header_list.keys())
clpep_fields = clpep_header()
header_fields.extend(clpep_fields)
writer.writerow(header_fields)
......@@ -130,7 +132,7 @@ def compareRunIds_csv(self, request, queryset, form, tableName):
tmp_dict = header_list.copy()
tmp_dict['Unique Key'] = uniquePep_key
for dataset_run_name in tmp_dict.keys()[1:]:
for dataset_run_name in list(tmp_dict.keys())[1:]:
if dataset_run_name in uniquePep_dict[uniquePep_key]:
if form.cleaned_data['peptide_count']:
......@@ -155,7 +157,7 @@ def compareRunIds_csv(self, request, queryset, form, tableName):
except:
columns.append('') ## capture 'None' fields
values = tmp_dict.values()
values = list(tmp_dict.values())
values.extend(columns)
writer.writerow(values)
......@@ -219,7 +221,7 @@ def dataset_stats_csv(self, request, queryset, tableName):
# Iterates over Clpeptides
for clpep in dataset.clpeptide_set.all():
if not fields_dict.has_key(clpep.run_name):
if not clpep.run_name in fields_dict:
fields_dict[clpep.run_name] = fields.copy()
fields_dict[clpep.run_name]['Dataset'] = '[%s] %s' % (dataset.pk,
dataset.name)
......@@ -803,10 +805,10 @@ def make_xlink_analyzer_csv(self, request, queryset, table_name, form):
try:
clpeptide_set, alignments = compute_cl_distance(queryset,
pdb,
form.cleaned_data['protein_identity'],
form.cleaned_data['peptide_identity'],
unique_key=ukey)
pdb,
form.cleaned_data['protein_identity'],
form.cleaned_data['peptide_identity'],
unique_key=ukey)
except InvalidFileFormatException as e:
return HttpResponse('<h1>%s</h1>' % e)
......@@ -989,11 +991,11 @@ def psi_mi_xml25(self, request, queryset, tableName):
protein_pairs[key][3].append(clpep.pk)
t = loader.get_template('psi-mi_25.xml')
c = Context({'expShortDescription': expShortDescription,
'expFullDescription': expFullDescription,
'proteins': proteins,
'protein_pairs': protein_pairs,
'pCounter': 0})
c = {'expShortDescription': expShortDescription,
'expFullDescription': expFullDescription,
'proteins': proteins,
'protein_pairs': protein_pairs,
'pCounter': 0}
response = HttpResponse(t.render(c), content_type='text/xml')
response['Content-Disposition'] = ('attachment; filename=' + tableName +
......
This diff is collapsed.
......@@ -3,9 +3,10 @@
# Import standard libraries
from .parser.exception import InvalidFileFormatException
import logging
import os
from .parser.exception import InvalidFileFormatException
import pickle
import random
from unipath import Path
import urllib.request
......@@ -609,6 +610,9 @@ def randomDistance(pdb, random_dist, size):
residues_1_list = pdb.residues_list
residues_2_list = pdb.residues_list
residues_1_list = list(residues_1_list)
residues_2_list = list(residues_2_list)
# Avoid infinite loop
if len(residues_1_list) <= 1 or len(residues_2_list) <= 1:
return random_distance_list
......
# # Copyright 2013-2014 Mathieu Courcelles
# # Mike Tyers's lab / IRIC / Universite de Montreal
# Import standard libraries
# Import Django related libraries
......@@ -32,7 +29,7 @@ def clpeptide_set_2_protein_set(clpeptide_set):
def clpeptide_set_2_protein_sequences(clpeptide_set):
"""
Converts a clpeptide queryset to a protein sequences dictionnary.
Converts a clpeptide queryset to a protein sequences dictionary.
Key: protein.id
Value: protein.sequence
"""
......
......@@ -4,7 +4,6 @@
{% block content %}
{% if protein_set|length != 0 %}
{% include 'grappelli_collapse_js.html' %}
<form action="" method="post">
......@@ -40,17 +39,6 @@
</form>
<br /><br />
<strong>BLAST protein sequence against PDB</strong><br />
{% for protein in protein_set %}
<a href='http://www.ncbi.nlm.nih.gov/blast/Blast.cgi?QUERY={{protein.sequence}}&db=protein&QUERY_FROM=&QUERY_TO=&GENETIC_CODE=1&JOB_TITLE=&SUBJECTS=&stype=protein&SUBJECTS_FROM=&SUBJECTS_TO=&DATABASE=pdb&EQ_MENU=&NUM_ORG=1&EQ_TEXT=&BLAST_PROGRAMS=blastp&PHI_PATTERN=&MAX_NUM_SEQ=100&SHORT_QUERY_ADJUST=on&EXPECT=10&WORD_SIZE=3&HSP_RANGE_MAX=0&MATRIX_NAME=BLOSUM62&MATCH_SCORES=1,-2&GAPCOSTS=11 1&COMPOSITION_BASED_STATISTICS=2&REPEATS=5755&TEMPLATE_LENGTH=0&TEMPLATE_TYPE=0&I_THRESH=&DI_THRESH=&PSI_PSEUDOCOUNT=&SHOW_OVERVIEW=on&SHOW_LINKOUT=on&GET_SEQUENCE=on&FORMAT_OBJECT=Alignment&FORMAT_TYPE=HTML&ALIGNMENT_VIEW=Pairwise&MASK_CHAR=2&MASK_COLOR=1&DESCRIPTIONS=100&ALIGNMENTS=100&LINE_LENGTH=60&NEW_VIEW=on&OLD_BLAST=false&OLD_VIEW=false&NCBI_GI=&SHOW_CDS_FEATURE=&NUM_OVERVIEW=100&FORMAT_EQ_TEXT=&FORMAT_ORGANISM=&EXPECT_LOW=&EXPECT_HIGH=&PERC_IDENT_LOW=&PERC_IDENT_HIGH=&QUERY_INDEX=0&FORMAT_NUM_ORG=1&CONFIG_DESCR=2,3,4,5,6,7,8&CLIENT=web&SERVICE=plain&CMD=request&PAGE=Proteins&PROGRAM=blastp&MEGABLAST=&RUN_PSIBLAST=&WWW_BLAST_TYPE=&TWO_HITS=&CDD_SEARCH=on&ID_FOR_PSSM=&SAVED_PSSM=&SELECTED_PROG_TYPE=blastp&SAVED_SEARCH=&BLAST_SPEC=&MIXED_DATABASE=&QUERY_BELIEVE_DEFLINE=&DB_DIR_PREFIX=&USER_DATABASE=&USER_WORD_SIZE=&USER_MATCH_SCORES=&USER_FORMAT_DEFAULTS=&NO_COMMON=&NUM_DIFFS=1&NUM_OPTS_DIFFS=0&UNIQ_DEFAULTS_NAME=&PAGE_TYPE=BlastSearch&USER_DEFAULT_PROG_TYPE=blastp&USER_DEFAULT_MATRIX=4' target="_blank">{{protein.identifier}}</a><br />
{% endfor %}
{% else %}
<br /><br />
<strong>Protein set is empty. Hit back and select an other dataset.</strong>
{% endif %}
{% endblock %}
\ No newline at end of file
{% load static %}
{%if bin_values|length != 0 %}
{%if all_bin_values|length != 0 %}
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<script type="text/javascript">
......
......@@ -20,8 +20,12 @@ from Bio.PDB.PDBParser import PDBParser
# Import project libraries
from .parser.exception import InvalidFileFormatException
from .parser.mgf_parser import MGFParser
from .queryset_operation import clpeptide_set_2_protein_set
from .models import CLPeptide
from .models import (CLPeptide,
FastaDb_Sequence,
PeakList,
QuantificationFC)
from .pdb_structure import (compute_cl_distance,
randomDistance,
)
......@@ -361,7 +365,7 @@ def jsmol_view(request, clpeptide_set, form=None):
2))
# Replace fasta_id with identifier
for key, value in alignments.items():
for key in list(alignments.keys()):
seq = FastaDb_Sequence.objects.filter(pk=key)
identifier = seq[0].identifier
alignments[identifier] = alignments.pop(key)
......
......@@ -212,4 +212,11 @@ PIWIK_URL = os.getenv('PIWIK_URL')
SETTINGS_EXPORT = [
'PIWIK_SITEID',
'PIWIK_URL',
]
\ No newline at end of file
]
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
'LOCATION': 'unique-snowflake',
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment