Commit f0e3a902 authored by Mathieu Courcelles's avatar Mathieu Courcelles

Adds export for Xlink Analyzer

parent bc535df4
This diff is collapsed.
# # Copyright 2013-2015 Mathieu Courcelles
# # Mike Tyers's lab / IRIC / Universite de Montreal
# Copyright 2013-2017 Mathieu Courcelles
# Mike Tyers's lab / IRIC / Universite de Montreal
"""
This module contains methods to export dataset to various
......@@ -16,9 +16,8 @@ from django.http import HttpResponse
from django.template import loader, Context
# Import project libraries
from queryset_operation import (dataset_set_2_clpeptide_set,
)
from pdb_structure import compute_cl_distance
from queryset_operation import dataset_set_2_clpeptide_set
def clpep_header():
......@@ -54,7 +53,6 @@ def clpep_header():
return fields
def compareRunIds_csv(self, request, queryset, form, tableName):
"""
Compares cross-linked peptides across MS runs and datasets.
......@@ -136,11 +134,11 @@ def compareRunIds_csv(self, request, queryset, form, tableName):
if dataset_run_name in uniquePep_dict[uniquePep_key]:
if form.cleaned_data['peptide_count']:
tmp_dict[dataset_run_name] = '%.2f (%s)' % (
uniquePep_dict[uniquePep_key][dataset_run_name][0].match_score,
uniquePep_dict[uniquePep_key][dataset_run_name][1])
uniquePep_dict[uniquePep_key][dataset_run_name][0].match_score,
uniquePep_dict[uniquePep_key][dataset_run_name][1])
else:
tmp_dict[dataset_run_name] = '%.2f' % (
uniquePep_dict[uniquePep_key][dataset_run_name][0].match_score)
uniquePep_dict[uniquePep_key][dataset_run_name][0].match_score)
count_dict[dataset_run_name] += 1
sum_dict[dataset_run_name] += uniquePep_dict[uniquePep_key][dataset_run_name][0].match_score
......@@ -171,7 +169,6 @@ def compareRunIds_csv(self, request, queryset, form, tableName):
return response
def dataset_stats_csv(self, request, queryset, tableName):
"""
Write dataset statistics about cross-linked peptides to CSV file.
......@@ -292,7 +289,6 @@ def dataset_stats_csv(self, request, queryset, tableName):
return response
def make_Percolator_tsv(self, request, clpeptide_set, tableName, fh=None, nv=False):
"""
Export selected objects as TSV file
......@@ -356,7 +352,6 @@ def make_Percolator_tsv(self, request, clpeptide_set, tableName, fh=None, nv=Fal
return response
def make_Xi_csv(self, request, queryset, tableName, clpep_distances=False):
"""
Export selected objects as CSV file
......@@ -398,7 +393,6 @@ def make_Xi_csv(self, request, queryset, tableName, clpep_distances=False):
return response
def interaction_matrix(self, request, clpeptide_set, tableName):
"""
Export selected objects to protein interactions matrix
......@@ -472,7 +466,6 @@ def interaction_matrix(self, request, clpeptide_set, tableName):
return response
# def make_XiNET_csv(self, request, queryset, tableName):
# """
# Export selected objects as XiNET CSV file
......@@ -619,7 +612,6 @@ def make_ProteoProfile_csv(self, request, queryset, tableName):
return response
def make_xTract_csv(self, request, queryset, tableName):
"""
Export selected objects as xTract CSV file
......@@ -641,7 +633,6 @@ def make_xTract_csv(self, request, queryset, tableName):
if obj.fs_prot1_id is None or obj.fs_prot2_id is None:
continue
columns = []
scan = '%s.c.%s.%s.%s' % (obj.run_name, obj.scan_number,
......@@ -681,8 +672,6 @@ def make_xTract_csv(self, request, queryset, tableName):
pos += 1
beta = {
'sequence': obj.peptide_wo_mod2,
'protein': obj.fs_prot2_id.identifier,
......@@ -716,8 +705,6 @@ def make_xTract_csv(self, request, queryset, tableName):
pos += 1
swap = False
if len(beta['sequence']) > len(alpha['sequence']):
......@@ -739,8 +726,7 @@ def make_xTract_csv(self, request, queryset, tableName):
columns.append(seq)
prot = '%s:%s' %(alpha['protein'], beta['protein'])
prot = '%s:%s' % (alpha['protein'], beta['protein'])
columns.append(prot)
......@@ -755,18 +741,15 @@ def make_xTract_csv(self, request, queryset, tableName):
}
for mod in alpha['mod_list']:
mod_fix = mod_dict[mod[1]]
mod_str = '%s-a=%s' % (mod[0], mod_fix)
combined_mods.append(mod_str)
for mod in beta['mod_list']:
mod_fix = mod_dict[mod[1]]
mod_str = '%s-b=%s' % (mod[0], mod_fix)
combined_mods.append(mod_str)
columns.append(':'.join(combined_mods))
columns.append(obj.match_score)
......@@ -784,14 +767,101 @@ def make_xTract_csv(self, request, queryset, tableName):
columns.append(uxid)
columns.append('')
writer.writerow(columns)
return response
def make_xlink_analyzer_csv(self, request, queryset, table_name, form):
"""
Export selected objects as XlinkAnalyzer CSV file
:param self: Self
:param request: Django request object
:param queryset: CLPeptide queryset
:param table_name: String
:param form: PDBSelectionForm
:return: HttpResponse
"""
writer.writerow(columns)
response = HttpResponse(content_type='text/csv')
response['Content-Disposition'] = ('attachment; filename=XlinkAnalyzer_'
+ table_name + '_'
+ request.META['QUERY_STRING'] + '.csv')
return response
# Write header
writer = csv.writer(response)
fields = ['Id', 'Protein1', 'Protein2', 'AbsPos1', 'AbsPos2', 'score']
writer.writerow(fields)
max_score = None
pdb = form.get_PDB()
ukey = dict()
ukey['proteinPpos'] = True
clpeptide_set, alignments = compute_cl_distance(queryset,
pdb,
form.cleaned_data['protein_identity'],
form.cleaned_data['peptide_identity'],
unique_key=ukey)
for clpep in clpeptide_set:
if clpep.fs_prot1_id is None or clpep.fs_prot2_id is None:
continue
alpha = {
'sequence': clpep.peptide_wo_mod1,
'protein': clpep.fs_prot1_id.identifier,
'link_pos': clpep.pep1_link_pos,
'peptide_pos': clpep.peptide_position1,
}
beta = {
'sequence': clpep.peptide_wo_mod2,
'protein': clpep.fs_prot2_id.identifier,
'link_pos': clpep.pep2_link_pos,
'peptide_pos': clpep.peptide_position2,
}
swap = False
if len(beta['sequence']) > len(alpha['sequence']):
swap = True
elif len(beta['sequence']) == len(alpha['sequence']):
sorted_peptides = sorted([alpha['sequence'], beta['sequence']])
if sorted_peptides[0] != alpha['sequence']:
swap = True
if swap:
alpha, beta = beta, alpha
seq = '%s-%s-a%s-b%s' % (alpha['sequence'], beta['sequence'],
alpha['link_pos'], beta['link_pos'])
if max_score is None:
max_score = clpep.match_score
for cldistance in clpep.distances:
if swap:
cldistance.residue_1_str, cldistance.residue_2_str = cldistance.residue_2_str, cldistance.residue_1_str
columns = list()
columns.append(seq)
columns.append(cldistance.residue_1.get_parent().get_id())
columns.append(cldistance.residue_2.get_parent().get_id())
columns.append(cldistance.residue_1.get_id()[1])
columns.append(cldistance.residue_2.get_id()[1])
columns.append(int(clpep.match_score / max_score * 100))
writer.writerow(columns)
return response
def psi_mi_tab25(self, request, clpeptide_set, tableName):
......@@ -874,7 +944,6 @@ def psi_mi_tab25(self, request, clpeptide_set, tableName):
return response
def psi_mi_xml25(self, request, queryset, tableName):
"""
Export selected objects to PSI-MI XML 2.5
......
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