Commit b360309b authored by Mathieu Courcelles's avatar Mathieu Courcelles

-Added Quantification filter

-Added support for a new quantification file format with File name, Scan number format.
parent cc59845e
......@@ -6,7 +6,7 @@
<key>DJANGO_MANAGE_LOCATION</key>
<value>manage.py</value>
<key>DJANGO_SETTINGS_MODULE</key>
<value>CLMSVault.settings.production</value>
<value>CLMSVault.settings.local</value>
</pydev_variables_property>
<pydev_pathproperty name="org.python.pydev.PROJECT_SOURCE_PATH">
<path>/CLMSVault</path>
......
"CLPeptideId","FoldChange",'
"1","10",'
"8","100",'
"10","25",'
"11","-100",'
"13","-20",'
\ No newline at end of file
No preview for this file type
......@@ -4,9 +4,13 @@
# Import standard librariesdjang
# Import Django related libraries
from django.db.models import Q
# Import project libraries
from .models import CLPeptide, ProcessedDataset
from .models import (CLPeptide,
ProcessedDataset,
QuantificationFC,
)
class DatasetProcessing:
......@@ -55,6 +59,33 @@ class DatasetProcessing:
datasets_list = list(datasets.values_list('pk', flat=True))
clpeptide_set = CLPeptide.objects.filter(dataset__in=datasets_list)
# Filter for quantification
if instance.clpeptidefilter.quantification_experiment is not None:
qfcs = QuantificationFC.objects.filter(quantification_id=instance.clpeptidefilter.quantification_experiment)
fc = dict()
if instance.clpeptidefilter.quantification_value_1 is not None:
fc['__'.join(['fold_change', instance.clpeptidefilter.quantification_operator_1])] = instance.clpeptidefilter.quantification_value_1
if instance.clpeptidefilter.quantification_value_2 is not None:
fc['__'.join(['fold_change', instance.clpeptidefilter.quantification_operator_2])] = instance.clpeptidefilter.quantification_value_2
if len(fc) == 1:
qfcs = qfcs.filter(**fc)
if len(fc) == 2:
keys = fc.keys()
if instance.clpeptidefilter.quantification_logic == '|':
qfcs = qfcs.filter(Q( **{keys[0]: fc[keys[0]]}) | Q(**{keys[1]: fc[keys[1]]}) )
elif instance.clpeptidefilter.quantification_logic == '&':
qfcs = qfcs.filter(Q( **{keys[0]: fc[keys[0]]}) & Q(**{keys[1]: fc[keys[1]]}) )
quant_clpeptide_pk_list = list(qfcs.values_list('clpeptide', flat=True))
clpeptide_set = clpeptide_set.filter(pk__in=quant_clpeptide_pk_list)
# Apply/prepare filter/exclude to CLPeptides
fp_msrun = dict()
......
......@@ -72,7 +72,7 @@ class quantificationForm(forms.Form):
quant_pk = ''
if 'initial' in kwargs:
quant_pk = kwargs['initial']['quant_pk']
quant_pk = kwargs['initial']['quant_pk'].split(',')
self.fields['quantification'] = forms.ModelChoiceField(queryset = Quantification.objects.filter(pk__in=quant_pk),
required=False)
......
This diff is collapsed.
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
class Migration(migrations.Migration):
dependencies = [
('CLMSVault_app', '0001_initial'),
]
operations = [
migrations.AddField(
model_name='quantification',
name='file_header',
field=models.CharField(max_length=20, null=True, choices=[(b'CF', b'"CLPeptideId","FoldChange",'), (b'FSF', b'"File","ScanNumber","FoldChange",')]),
preserve_default=True,
),
]
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
class Migration(migrations.Migration):
dependencies = [
('CLMSVault_app', '0002_quantification_file_header'),
]
operations = [
migrations.AddField(
model_name='clpeptidefilter',
name='quantification_experiment',
field=models.ForeignKey(blank=True, to='CLMSVault_app.Quantification', null=True),
preserve_default=True,
),
migrations.AddField(
model_name='clpeptidefilter',
name='quantification_max_operator',
field=models.CharField(blank=True, max_length=3, null=True, choices=[(b'gt', b'Greater than'), (b'gte', b'Greater than or equal to'), (b'lt', b'Less than'), (b'lte', b'Less than or equal to')]),
preserve_default=True,
),
migrations.AddField(
model_name='clpeptidefilter',
name='quantification_max_value',
field=models.FloatField(null=True, blank=True),
preserve_default=True,
),
migrations.AddField(
model_name='clpeptidefilter',
name='quantification_min_operator',
field=models.CharField(blank=True, max_length=3, null=True, choices=[(b'gt', b'Greater than'), (b'gte', b'Greater than or equal to'), (b'lt', b'Less than'), (b'lte', b'Less than or equal to')]),
preserve_default=True,
),
migrations.AddField(
model_name='clpeptidefilter',
name='quantification_min_value',
field=models.FloatField(null=True, blank=True),
preserve_default=True,
),
]
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
class Migration(migrations.Migration):
dependencies = [
('CLMSVault_app', '0003_auto_20150303_1203'),
]
operations = [
migrations.RenameField(
model_name='clpeptidefilter',
old_name='quantification_min_operator',
new_name='quantification_operator_1',
),
migrations.RenameField(
model_name='clpeptidefilter',
old_name='quantification_max_operator',
new_name='quantification_operator_2',
),
migrations.RenameField(
model_name='clpeptidefilter',
old_name='quantification_min_value',
new_name='quantification_value_1',
),
migrations.RenameField(
model_name='clpeptidefilter',
old_name='quantification_max_value',
new_name='quantification_value_2',
),
migrations.AddField(
model_name='clpeptidefilter',
name='quantification_logic',
field=models.CharField(blank=True, max_length=1, null=True, choices=[(b'&', b'AND'), (b'|', b'OR')]),
preserve_default=True,
),
]
......@@ -595,7 +595,51 @@ class CLPeptide(AdminURLMixin, models.Model):
return separator.join(key)
class Quantification(models.Model):
"""
This class Quantification experiment.
"""
creation_date = models.DateTimeField(auto_now_add=True)
name = models.CharField(max_length=100)
TYPE_CHOICES = (
('FC', 'Fold change'),
('FClog2', 'Fold change log2'),
('FClog10', 'Fold change log10'),
)
quantification_type = models.CharField(max_length=20, choices=TYPE_CHOICES)
parsing_status = models.BooleanField(default=False)
parsing_log = models.CharField(max_length=1000, blank=True, null=True)
HEADER_CHOICES= (
('CF','"CLPeptideId","FoldChange",'),
('FSF','"File","ScanNumber","FoldChange",')
)
file_header =models.CharField(max_length=20, choices=HEADER_CHOICES, null=True)
file = models.FileField(upload_to=upload_path_handler,
max_length=255,
help_text='Select quantification file.')
def __unicode__(self):
return '%s - %s' % (self.pk, self.name)
class QuantificationFC(models.Model):
quantification = models.ForeignKey(Quantification)
clpeptide = models.ForeignKey(CLPeptide)
fold_change = models.FloatField()
class CLPeptideFilter(AdminURLMixin, models.Model):
"""
......@@ -638,7 +682,43 @@ class CLPeptideFilter(AdminURLMixin, models.Model):
unique_key = models.CharField('Unique peptide key', max_length=20,
choices=UKEY_CHOICES,
blank=True, null=True)
OPERATOR_CHOICES = (
('gt', 'Greater than'),
('gte', 'Greater than or equal to'),
('lt', 'Less than'),
('lte', 'Less than or equal to'),
)
LOGIC_CHOICES = (
('|', 'OR'),
('&', 'AND'),
)
quantification_experiment = models.ForeignKey(Quantification, null=True,
blank=True)
quantification_value_1 = models.FloatField(null=True, blank=True)
quantification_operator_1 = models.CharField(max_length=3,
choices=OPERATOR_CHOICES,
null=True, blank=True)
quantification_logic = models.CharField(max_length=1,
choices=LOGIC_CHOICES,
null=True, blank=True)
quantification_value_2 = models.FloatField(null=True, blank=True)
quantification_operator_2 = models.CharField(max_length=3,
choices=OPERATOR_CHOICES,
null=True, blank=True)
def __unicode__(self):
return ('[%s] %s') % (self.pk, self.name)
......@@ -742,41 +822,6 @@ class PDB(models.Model):
class Quantification(models.Model):
"""
This class Quantification experiment.
"""
creation_date = models.DateTimeField(auto_now_add=True)
name = models.CharField(max_length=100)
TYPE_CHOICES = (
('FC', 'Fold change'),
('FClog2', 'Fold change log2'),
('FClog10', 'Fold change log10'),
)
quantification_type = models.CharField(max_length=20, choices=TYPE_CHOICES)
parsing_status = models.BooleanField(default=False)
parsing_log = models.CharField(max_length=1000, blank=True, null=True)
file = models.FileField(upload_to=upload_path_handler,
max_length=255,
help_text='Select quantification file.')
def __unicode__(self):
return '%s - %s' % (self.pk, self.name)
class QuantificationFC(models.Model):
quantification = models.ForeignKey(Quantification)
clpeptide = models.ForeignKey(CLPeptide)
fold_change = models.FloatField()
\ No newline at end of file
# # Copyright 2013 Mathieu Courcelles
# # Copyright 2013-2015 Mathieu Courcelles
# # Mike Tyers's lab / IRIC / Universite de Montreal
......@@ -42,28 +42,57 @@ class QuantFC_Parser:
reader = csv.DictReader(f)
# Check header to validate file format
header_template = ('"CLPeptideId","FoldChange",')
header_template = ''
if quantification.file_header == 'CF':
header_template = ('"CLPeptideId","FoldChange",')
else:
header_template = ('"File","ScanNumber","FoldChange",')
header_file = '"' + '","'.join(name for name in reader.fieldnames) + '",'
if header_template != header_file:
if header_template == header_file:
raise InvalidFileFormatException(header_file +
'Uploaded extra file is not recognized as a '
'Quantification fold change results file (bad file header)')
id_no_match = ''
# Iterate through lines and create QuantificationFC
for row in reader:
# Split CLPeptideId
clpeptides_id = row['CLPeptideId'].split('-')
for clpep_id in clpeptides_id:
# Iterate through lines and create QuantificationFC
if quantification.file_header == 'CF':
for row in reader:
# Split CLPeptideId
clpeptides_id = row['CLPeptideId'].split('-')
for clpep_id in clpeptides_id:
# Match clpep_id to database
queryset = CLPeptide.objects.filter(pk=clpep_id)
if len(queryset):
# Create the QuantificationFC object
quantificationFC = QuantificationFC()
quantificationFC.quantification = quantification
quantificationFC.clpeptide = queryset[0]
quantificationFC.fold_change = row['FoldChange']
# Save object to db
quantificationFC.save()
else:
id_no_match += clpep_id + '-'
elif quantification.file_header == 'FSF':
for row in reader:
# Match clpep_id to database
queryset = CLPeptide.objects.filter(pk=clpep_id)
queryset = CLPeptide.objects.filter(run_name=row['File'],
scan_number=row['ScanNumber'])
if len(queryset):
......@@ -77,7 +106,8 @@ class QuantFC_Parser:
# Save object to db
quantificationFC.save()
else:
id_no_match += clpep_id + '-'
id_no_match += row['File'] + ':' + row['ScanNumber'] + '-'
if id_no_match == '':
id_no_match = 'Ok'
......
......@@ -101,15 +101,19 @@ def findPeptidePositionsInAligment(pep_seq, fasta_seq_aligned,
if identity >= peptide_identity:
# Assign cross-linked position by lower case
while (len(pdb_pep_seq) != 0 and
pdb_pep_seq[index] == '-'):
del(pdb_pep_seq[index])
if index == len(pdb_pep_seq):
index -= 1
else:
if len(pdb_pep_seq) != 0:
pdb_pep_seq[index] = pdb_pep_seq[index].lower()
pdb_pep_seq[index] = pdb_pep_seq[index].lower()
# while (len(pdb_pep_seq) != 0 and
# pdb_pep_seq[index] == '-'):
# del(pdb_pep_seq[index])
#
# if index == len(pdb_pep_seq):
# index -= 1
# else:
# if len(pdb_pep_seq) != 0:
# pdb_pep_seq[index] = pdb_pep_seq[index].lower()
# Remove gaps in the aligned PDB peptide sequence
......@@ -128,6 +132,7 @@ def findPeptidePositionsInAligment(pep_seq, fasta_seq_aligned,
hit['identity'] = identity
hit_positions.append(hit)
#Reset position for next search
pep_cursor = 0
......@@ -177,7 +182,7 @@ def crosslinkResidues(pep_seq, cl_position, alignments, pdb, peptide_identity):
for position in positions:
pdb_pep_seq_start = 0
pdb_pep_seq_linked = 0
pdb_pep_seq_linked = -1
pdb_seq_index = 0
pep_index = 0
chain_list = list(chain)
......@@ -209,8 +214,10 @@ def crosslinkResidues(pep_seq, cl_position, alignments, pdb, peptide_identity):
# Complete peptide sequence found
if pep_index == len(position['final_pep_seq']):
linked_residue = chain_list[pdb_pep_seq_linked]
linked_residues.append((linked_residue, position['identity']))
if pdb_pep_seq_linked != -1:
linked_residue = chain_list[pdb_pep_seq_linked]
linked_residues.append((linked_residue, position['identity']))
pdb_pep_seq_linked = -1
# Reset to see if peptide is present latter in sequence
pep_index = 0
......
......@@ -167,9 +167,7 @@
color_command = ''
if(scale_type == 'quant') {
match = position['pk'].match(/clpeptide\/\w+/);
clpeptideid = match[0].split('/')[1];
color_command = 'color measure [x' + scale(quant[clpeptideid]).substring(1) + ']; '
color_command = 'color measure [x' + scale(quant[position['pk']]).substring(1) + ']; '
}
else if(scale_type == 'score') {
color_command = 'color measure [x' + scale(position['score']).substring(1) + ']; '
......
"File","ScanNumber","FoldChange",
"BSA-DSS_2013-09-30_10uL_R1_131006223038","8226","10",
"BSA-DSS_2013-09-30_10uL_R1","9774","100",
"BSA-DSS_2013-09-30_10uL_R1","5424","25",
"BSA-DSS_2013-09-30_10uL_R1_131006223038","8350","-100",
"BSA-DSS_2013-09-30_10uL_R1_131006223038","8655","-20",
\ 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