Commit 1f9f25e2 authored by Mathieu Courcelles's avatar Mathieu Courcelles

-Added my first test

-Fix bug in modifications for pLink and xQuest
parent 9a136ade
......@@ -50,7 +50,7 @@ class DatasetProcessing:
for fe in instance.clpeptidefilter.clpeptidefilterparam_set.all():
d = dict()
d[fe.field + '__' + fe.field_lookup] = fe.value
d['__'.join([fe.field, fe.field_lookup])] = fe.value
if fe.method == 'filter':
clpeptide_set = clpeptide_set.filter(**d)
......@@ -107,9 +107,9 @@ class DatasetProcessing:
msrun = 'Dataset'
# Skip peptide if already seen
print unique_key
#print unique_key
key = clpep.uniqueKey(unique_key)
print key
#print key
if msrun in unique_msrun_pep and key in unique_msrun_pep[msrun]:
continue
......
......@@ -389,8 +389,6 @@ class ProcessedDatasetAdmin(admin.ModelAdmin):
def save_model(self, request, obj, form, change):
# Need to save m2m before launching the processing
# Advice from http://makkalot-opensource.blogspot.ca/2009/01/django-admin-manytomany-behaviour.html
super(ProcessedDatasetAdmin, self).save_model(request, obj, form, change)
form.save_m2m()
obj.save()
......
......@@ -36,6 +36,13 @@ class AdminURLMixin(object):
"""
def formated_url(self):
"""
Returns HTML link for the admin panel.
"""
return '<a href="%s">%s</a><br />' % (self.get_admin_url(), self)
def get_admin_url(self):
content_type = ContentType \
.objects \
......@@ -108,19 +115,13 @@ class SearchAlgorithm(models.Model):
ordering = ['name']
class Project(models.Model, AdminURLMixin):
class Project(AdminURLMixin, models.Model):
"""
This class groups datasets.
"""
name = models.CharField(max_length=250, unique=True)
def formated_url(self):
"""
Returns HTML link for the admin panel.
"""
return '<a href="%s">%s</a><br />' % (self.get_admin_url(), self)
def __unicode__(self):
return ('[%s] %s') % (self.pk, self.name)
......@@ -128,7 +129,7 @@ class Project(models.Model, AdminURLMixin):
class Dataset(models.Model, AdminURLMixin):
class Dataset(AdminURLMixin, models.Model):
"""
This class holds dataset information of cross-linked peptides.
"""
......@@ -331,7 +332,7 @@ class CLPeptide(models.Model):
Convert the string value stored in the field to a boolean type.
"""
if self.autovalidated == 'true':
if str(self.autovalidated).lower() == 'true':
self.autovalidated = True
else:
self.autovalidated = False
......@@ -386,36 +387,36 @@ class CLPeptide(models.Model):
if params.has_key('sequence'):
seq_list = [self.peptide_wo_mod1, self.peptide_wo_mod2]
seq_list.sort()
key += seq_list
key.extend(seq_list)
if params.has_key('sequenceMods'):
seq_list = [self.peptide1, self.peptide2]
seq_list.sort()
key += seq_list
key.extend(seq_list)
if params.has_key('sequenceCpos'):
seq_list = [self.peptide_wo_mod1 + '-' + self.pep1_link_pos,
self.peptide_wo_mod2 + '-' + self.pep2_link_pos ]
seq_list = ['-'.join([self.peptide_wo_mod1, str(self.pep1_link_pos)]),
'-'.join([self.peptide_wo_mod2, str(self.pep2_link_pos)])
]
seq_list.sort()
key += seq_list
key.extend(seq_list)
if params.has_key('proteinPpos'):
seq_list = [self.peptide_wo_mod1 + '-' + self.pep1_link_pos,
self.peptide_wo_mod2 + '-' + self.pep2_link_pos ]
seq_list = ['-'.join([self.peptide_wo_mod1, str(self.pep1_link_pos)]),
'-'.join([self.peptide_wo_mod2, str(self.pep2_link_pos)])
]
seq_list.sort()
key += seq_list
key.extend(seq_list)
if params.has_key('charge'):
key += self.precursor_charge
key.extend(self.precursor_charge)
print key
return '-'.join(key)
class CLPeptideFilter(models.Model, AdminURLMixin):
class CLPeptideFilter(AdminURLMixin, models.Model):
"""
This class holds pre-defined filters for cross-linked peptides.
"""
......@@ -458,12 +459,6 @@ class CLPeptideFilter(models.Model, AdminURLMixin):
blank=True, null=True)
def formated_url(self):
"""
Returns HTML link for the admin panel.
"""
return '<a href="%s">%s</a><br />' % (self.get_admin_url(), self)
def __unicode__(self):
......
......@@ -49,8 +49,8 @@ class XiParser:
header_file = '"' + '","'.join(name for name in reader.fieldnames) + '",'
if header_template != header_file:
print header_template
print header_file
#print header_template
#print header_file
raise InvalidFileFormatException('Uploaded file is not\
recognized as a Xi results file (bad file header)')
......@@ -58,7 +58,7 @@ class XiParser:
# Iterate through lines and create CLPeptide
#count = 0
for row in reader:
print row
#print row
# Create the CLPeptide object
row['total_fragment_matches'] = int(float(row['total_fragment_matches']))
......
......@@ -25,7 +25,7 @@ class pLinkParser:
This method transform peptide modification from pLink format to Xi
format.
"""
peptide = re.sub("/^C/", "Cm", peptide)
peptide = re.sub('C', 'Cm', peptide)
# Convert the fixed modification of cysteine to Xi format
return peptide
......
......@@ -28,10 +28,10 @@ class xQuestParser:
This method transforms peptide modification fron xQuest format to Xi
format.
"""
peptide = re.sub("/^Z/", "", peptide) # Remove Z amino acid
peptide = re.sub("/^C/", "Cm", peptide)
peptide = re.sub('^Z', '', peptide) # Remove Z amino acid
peptide = re.sub('C', 'Cm', peptide)
# Convert the fixed modification of cysteine to Xi format
peptide = re.sub("/^X/", "Mox", peptide)
peptide = re.sub('X', 'Mox', peptide)
# Convert variable modification of methionine to Xi format
return peptide
......
"""
This file demonstrates writing tests using the unittest module. These will pass
when you run "manage.py test".
Replace this with more appropriate tests for your application.
"""
from django.test import TestCase
class SimpleTest(TestCase):
def test_basic_addition(self):
"""
Tests that 1 + 1 always equals 2.
"""
self.assertEqual(1 + 1, 2)
from test_forms import *
from test_models import *
from test_views import *
from test_parser import *
\ No newline at end of file
from django.test import TestCase
\ No newline at end of file
# # Copyright 2013 Mathieu Courcelles
# # Mike Tyers's lab / IRIC / Universite de Montreal
# Import standard libraries
# Import Django related libraries
from django.test import TestCase
# Import project libraries
from ..models import CLPeptide
from ..models import RawDataset
from ..models import upload_path_handler
from ..models import remove_CLPeptideRD
class SimpleTest(TestCase):
def test_basic_addition(self):
"""
Tests that 1 + 1 always equals 2.
"""
self.assertEqual(1 + 1, 2)
class ModelTestCase(TestCase):
fixtures = ['testdata.json']
def test_CLPeptide(self):
# fixAutovalidated() test
clpep = CLPeptide.objects.all()[0]
clpep.autovalidated = 'true'
clpep.fixAutovalidated()
self.assertEqual(clpep.autovalidated, True)
clpep.autovalidated = 'false'
clpep.fixAutovalidated()
self.assertEqual(clpep.autovalidated, False)
# guessLinkType() test
clpep.peptide_wo_mod1 = 'A'
clpep.peptide_wo_mod2 = 'A'
clpep.guessLinkType()
self.assertEqual(clpep.link_type, 'Inter-protein')
self.assertEqual(clpep.cross_link, True)
clpep.peptide_wo_mod2 = 'B'
clpep.display_protein1 = 'A'
clpep.display_protein2 = 'B'
clpep.guessLinkType()
self.assertEqual(clpep.link_type, 'Inter-protein')
self.assertEqual(clpep.cross_link, True)
clpep.peptide_wo_mod2 = 'B'
clpep.display_protein1 = 'A'
clpep.display_protein2 = 'A'
clpep.guessLinkType()
self.assertEqual(clpep.link_type, 'Intra-protein')
self.assertEqual(clpep.cross_link, True)
clpep.pep2_link_pos = -1
clpep.display_protein2 = ''
clpep.guessLinkType()
self.assertEqual(clpep.link_type, 'Dead-end')
self.assertEqual(clpep.cross_link, False)
clpep.pep2_link_pos = 1
clpep.peptide_wo_mod2 = '-'
clpep.guessLinkType()
self.assertEqual(clpep.link_type, 'Intra-peptide')
self.assertEqual(clpep.cross_link, False)
# isDecoy() test
clpep.display_protein1 = 'DECOY'
clpep.isDecoy()
self.assertEqual(clpep.not_decoy, False)
clpep.display_protein2 = 'DECOY'
clpep.isDecoy()
self.assertEqual(clpep.not_decoy, False)
clpep.display_protein1 = ''
clpep.isDecoy()
self.assertEqual(clpep.not_decoy, False)
clpep.display_protein2 = ''
clpep.isDecoy()
self.assertEqual(clpep.not_decoy, True)
# uniqueKey test
clpep.peptide_wo_mod1 = 'A'
clpep.peptide_wo_mod2 = 'B'
params = dict()
params['sequence'] = 1
self.assertEqual(len(clpep.uniqueKey(params).split('-')), 2)
params['sequenceMods'] = 1
self.assertEqual(len(clpep.uniqueKey(params).split('-')), 4)
params['sequenceCpos'] = 1
self.assertEqual(len(clpep.uniqueKey(params).split('-')), 8)
params['proteinPpos'] = 1
self.assertEqual(len(clpep.uniqueKey(params).split('-')), 12)
params['charge'] = 1
self.assertEqual(len(clpep.uniqueKey(params).split('-')), 13)
def test_RawDataset(self):
d1 = RawDataset.objects.all()[0]
self.assertEqual(upload_path_handler(d1, d1.file), 'dataset/%s-%s' % (d1.pk, d1.file))
self.assertEqual(d1.get_admin_url(), '/admin/CLMSpipeline_app/rawdataset/%s/' % d1.pk)
self.assertEqual(d1.formated_url(), '<a href="/admin/CLMSpipeline_app/rawdataset/%s/">%s</a><br />' % (d1.pk, d1))
self.assertEqual(d1.formated_url_short(), '<a href="/admin/CLMSpipeline_app/rawdataset/%s/">[%s]</a><br />' % (d1.pk, d1.pk))
# Check removal of cross-linked peptides
v1 = len(d1.clpeptide_set.all())
v2 = 0
for clpep in d1.clpeptide_set.all():
if clpep.dataset.count() == 1:
v2 += 1
remove_CLPeptideRD(None, d1)
v3 = len(d1.clpeptide_set.all())
self.assertEqual(v3, v1 - v2)
#self.assertEqual(, '')
#self.assertEqual(, '')
\ No newline at end of file
# # Copyright 2013 Mathieu Courcelles
# # Mike Tyers's lab / IRIC / Universite de Montreal
# Import standard libraries
# Import Django related libraries
from django.test import TestCase
# Import project libraries
from ..parser.pLinkParser import pLinkParser
from ..parser.xQuestParser import xQuestParser
class PaserTestCase(TestCase):
def test_pLink(self):
# formatPeptideSequence(peptide) test
self.assertEqual(pLinkParser.formatPeptideSequence('TTTXTTT'), 'TTTXTTT')
self.assertEqual(pLinkParser.formatPeptideSequence('TTTCTTT'), 'TTTCmTTT')
self.assertEqual(pLinkParser.formatPeptideSequence('TTTCTTCT'), 'TTTCmTTCmT')
def test_xQuest(self):
# formatPeptideSequence(peptide) test
self.assertEqual(xQuestParser.formatPeptideSequence('ZTTTTT'), 'TTTTT')
self.assertEqual(xQuestParser.formatPeptideSequence('TTTCTTT'), 'TTTCmTTT')
self.assertEqual(xQuestParser.formatPeptideSequence('TTTCTTCT'), 'TTTCmTTCmT')
self.assertEqual(xQuestParser.formatPeptideSequence('TTTXTTCT'), 'TTTMoxTTCmT')
\ No newline at end of file
from django.test import TestCase
\ No newline at end of file
......@@ -5,13 +5,10 @@
import os
# Import Django related libraries
from django.conf import settings
from django.conf.urls import patterns, include, url
from django.contrib import admin
from django.conf import settings
for x in range(1,1000):
print settings.MEDIA_ROOT
admin.autodiscover()
......
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