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

.

parent 86907e31
......@@ -6,8 +6,7 @@ This is the Admin module for the CLMSpipeline.
"""
# Import standard librariesdjang
from collections import OrderedDict
# Import standard libraries
# Import Django related libraries
#from django import forms
......@@ -31,32 +30,6 @@ class CLPeptideAdmin(admin.ModelAdmin):
actions = ['make_Xi_csv']
exportXiFields = OrderedDict( [('run_name', 'run_name'),
('scan_number', 'scan_number'),
('precursor_mz','precursor_mz'),
('precursor_charge','precursor_charge'),
('precursor_intensity','precursor_intensity'),
('rank','rank'),
('match_score','match_score'),
('spectrum_intensity_coverage','spectrum_intensity_coverage'),
('total_fragment_matches','total_fragment_matches'),
('delta','delta'),
('error','error'),
('peptide1','peptide1'),
('display_protein1','display_protein1'),
('peptide_position1','peptide_position1'),
('pep1_link_pos','pep1_link_pos'),
('peptide2','peptide2'),
('display_protein2','display_protein2'),
('peptide_position2','peptide_position2'),
('pep2_link_pos','pep2_link_pos'),
('autovalidated','autovalidated'),
('validated','validated'),
('rejected','rejected'),
('notes','notes'),
])
list_display = ('pk', 'getDataset', 'run_name', 'scan_number',
'precursor_mz_2d', 'precursor_charge',
'match_score_2d', 'error_2d', 'spectrum_intensity_coverage_2d',
......@@ -72,8 +45,7 @@ class CLPeptideAdmin(admin.ModelAdmin):
def make_Xi_csv(self, request, queryset):
return export.make_Xi_csv(self, request, queryset,
self.exportXiFields, 'CLPeptide')
return export.make_Xi_csv(self, request, queryset, 'CLPeptide')
make_Xi_csv.short_description = 'Export as Xi CSV'
......@@ -107,10 +79,28 @@ class CLPeptideAdmin(admin.ModelAdmin):
spectrum_intensity_coverage_2d.admin_order_field = 'spectrum_intensity_coverage'
class CLPeptideFilterAdminInline(admin.TabularInline):
extra = 1
model = CLMSpipelineModels.CLPeptideFilterParam
class CLPeptideFilterAdmin(admin.ModelAdmin):
inlines = [ CLPeptideFilterAdminInline ]
class DatasetAdmin(admin.ModelAdmin):
actions = ['make_Xi_csv']
date_hierarchy = 'creation_date'
list_display = ('name', 'prefix', 'file', 'cross_linker', 'instrument_name', 'fasta_db',
......@@ -123,12 +113,7 @@ class DatasetAdmin(admin.ModelAdmin):
search_fields = ('name', 'prefix', 'file', 'description')
@staticmethod
@receiver(post_save, sender=CLMSpipelineModels.Dataset)
def process_file(sender, instance, created, **kwargs):
if instance.parsing_status == False and created == False:
instance.parsing_log = parser_generic.parseResults(instance)
def get_readonly_fields(self, request, obj=None):
......@@ -147,6 +132,20 @@ class DatasetAdmin(admin.ModelAdmin):
return '<a href="/admin/CLMSpipeline_app/clpeptide/?dataset__id__exact=%s">See</a>' % (obj.pk)
get_CLPeptides_URL.allow_tags = True
get_CLPeptides_URL.short_description = 'CLPeptides'
def make_Xi_csv(self, request, queryset):
from itertools import chain
return export.make_Xi_csv(self, request, list(chain(*[d.clpeptide_set.all() for d in queryset])), 'Dataset_CLPeptide')
make_Xi_csv.short_description = 'Export as Xi CSV'
@staticmethod
@receiver(post_save, sender=CLMSpipelineModels.Dataset)
def process_file(sender, instance, created, **kwargs):
if instance.parsing_status == False and created == False:
instance.parsing_log = parser_generic.parseResults(instance)
......@@ -157,3 +156,4 @@ admin.site.register(CLMSpipelineModels.FastaDB)
admin.site.register(CLMSpipelineModels.Instrument)
admin.site.register(CLMSpipelineModels.CLPeptide, CLPeptideAdmin)
admin.site.register(CLMSpipelineModels.searchAlgorithm)
admin.site.register(CLMSpipelineModels.CLPeptideFilter, CLPeptideFilterAdmin)
......@@ -6,19 +6,50 @@ This module contains methods to export dataset to various
format.
"""
# Import standard libraries
from collections import OrderedDict
import csv
# Import Django related libraries
from django.http import HttpResponse
# Import project libraries
def make_Xi_csv(self, request, queryset, fields, tableName):
def make_Xi_csv(self, request, queryset, tableName):
"""
Export selected objects as CSV file
"""
fields = OrderedDict( [('run_name', 'run_name'),
('scan_number', 'scan_number'),
('precursor_mz','precursor_mz'),
('precursor_charge','precursor_charge'),
('precursor_intensity','precursor_intensity'),
('rank','rank'),
('match_score','match_score'),
('spectrum_intensity_coverage','spectrum_intensity_coverage'),
('total_fragment_matches','total_fragment_matches'),
('delta','delta'),
('error','error'),
('peptide1','peptide1'),
('display_protein1','display_protein1'),
('peptide_position1','peptide_position1'),
('pep1_link_pos','pep1_link_pos'),
('peptide2','peptide2'),
('display_protein2','display_protein2'),
('peptide_position2','peptide_position2'),
('pep2_link_pos','pep2_link_pos'),
('autovalidated','autovalidated'),
('validated','validated'),
('rejected','rejected'),
('notes','notes'),
])
response = HttpResponse(mimetype='text/csv')
response['Content-Disposition'] = 'attachment; filename=' + tableName + '.csv'
response['Content-Disposition'] = 'attachment; filename=' + tableName + '_' + request.META['QUERY_STRING'] + '.csv'
response.write('Filter: { ' + request.get_full_path() + ' }\n\n')
......
# -*- coding: utf-8 -*-
import datetime
from south.db import db
from south.v2 import SchemaMigration
from django.db import models
class Migration(SchemaMigration):
def forwards(self, orm):
# Adding model 'CLPeptideFilter'
db.create_table(u'CLMSpipeline_app_clpeptidefilter', (
(u'id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
('creation_date', self.gf('django.db.models.fields.DateTimeField')(auto_now_add=True, blank=True)),
('name', self.gf('django.db.models.fields.CharField')(max_length=100)),
('description', self.gf('django.db.models.fields.TextField')(blank=True)),
))
db.send_create_signal(u'CLMSpipeline_app', ['CLPeptideFilter'])
# Adding model 'CLPeptideFilterParam'
db.create_table(u'CLMSpipeline_app_clpeptidefilterparam', (
(u'id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
('clpeptidefilter', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['CLMSpipeline_app.CLPeptideFilter'])),
('method', self.gf('django.db.models.fields.CharField')(max_length=20)),
('field', self.gf('django.db.models.fields.CharField')(max_length=100)),
('field_lookup', self.gf('django.db.models.fields.CharField')(max_length=20)),
('value', self.gf('django.db.models.fields.CharField')(max_length=50)),
))
db.send_create_signal(u'CLMSpipeline_app', ['CLPeptideFilterParam'])
def backwards(self, orm):
# Deleting model 'CLPeptideFilter'
db.delete_table(u'CLMSpipeline_app_clpeptidefilter')
# Deleting model 'CLPeptideFilterParam'
db.delete_table(u'CLMSpipeline_app_clpeptidefilterparam')
models = {
u'CLMSpipeline_app.clpeptide': {
'Meta': {'ordering': "['-match_score']", 'object_name': 'CLPeptide'},
'autovalidated': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'cross_link': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'dataset': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['CLMSpipeline_app.Dataset']", 'symmetrical': 'False'}),
'delta': ('django.db.models.fields.FloatField', [], {}),
'display_protein1': ('django.db.models.fields.CharField', [], {'max_length': '250'}),
'display_protein2': ('django.db.models.fields.CharField', [], {'max_length': '250'}),
'error': ('django.db.models.fields.FloatField', [], {}),
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'link_type': ('django.db.models.fields.IntegerField', [], {}),
'match_score': ('django.db.models.fields.FloatField', [], {}),
'not_decoy': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'notes': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'pep1_link_pos': ('django.db.models.fields.IntegerField', [], {}),
'pep2_link_pos': ('django.db.models.fields.IntegerField', [], {}),
'peptide1': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'peptide2': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'peptide_position1': ('django.db.models.fields.IntegerField', [], {}),
'peptide_position2': ('django.db.models.fields.IntegerField', [], {}),
'peptide_wo_mod1': ('django.db.models.fields.CharField', [], {'max_length': '150'}),
'peptide_wo_mod2': ('django.db.models.fields.CharField', [], {'max_length': '150'}),
'precursor_charge': ('django.db.models.fields.CharField', [], {'max_length': '5'}),
'precursor_intensity': ('django.db.models.fields.FloatField', [], {}),
'precursor_mz': ('django.db.models.fields.FloatField', [], {}),
'rank': ('django.db.models.fields.IntegerField', [], {}),
'rejected': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'run_name': ('django.db.models.fields.CharField', [], {'max_length': '1000'}),
'scan_number': ('django.db.models.fields.IntegerField', [], {}),
'spectrum_intensity_coverage': ('django.db.models.fields.FloatField', [], {}),
'total_fragment_matches': ('django.db.models.fields.IntegerField', [], {}),
'validated': ('django.db.models.fields.CharField', [], {'max_length': '50'})
},
u'CLMSpipeline_app.clpeptidefilter': {
'Meta': {'object_name': 'CLPeptideFilter'},
'creation_date': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
'description': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
},
u'CLMSpipeline_app.clpeptidefilterparam': {
'Meta': {'object_name': 'CLPeptideFilterParam'},
'clpeptidefilter': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['CLMSpipeline_app.CLPeptideFilter']"}),
'field': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'field_lookup': ('django.db.models.fields.CharField', [], {'max_length': '20'}),
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'method': ('django.db.models.fields.CharField', [], {'max_length': '20'}),
'value': ('django.db.models.fields.CharField', [], {'max_length': '50'})
},
u'CLMSpipeline_app.crosslinker': {
'Meta': {'ordering': "['name']", 'object_name': 'CrossLinker'},
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '100'})
},
u'CLMSpipeline_app.dataset': {
'Meta': {'ordering': "['-creation_date']", 'object_name': 'Dataset'},
'creation_date': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
'cross_linker': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['CLMSpipeline_app.CrossLinker']"}),
'description': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
'extra_file': ('django.db.models.fields.files.FileField', [], {'max_length': '100', 'blank': 'True'}),
'fasta_db': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['CLMSpipeline_app.FastaDB']"}),
'file': ('django.db.models.fields.files.FileField', [], {'max_length': '100'}),
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'instrument_name': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['CLMSpipeline_app.Instrument']"}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'parsing_log': ('django.db.models.fields.CharField', [], {'max_length': '1000', 'null': 'True', 'blank': 'True'}),
'parsing_status': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'prefix': ('django.db.models.fields.CharField', [], {'max_length': '25'}),
'search_algorithm': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['CLMSpipeline_app.searchAlgorithm']"})
},
u'CLMSpipeline_app.fastadb': {
'Meta': {'ordering': "['name']", 'object_name': 'FastaDB'},
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '200'})
},
u'CLMSpipeline_app.instrument': {
'Meta': {'ordering': "['name']", 'object_name': 'Instrument'},
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '100'})
},
u'CLMSpipeline_app.searchalgorithm': {
'Meta': {'ordering': "['name']", 'object_name': 'searchAlgorithm'},
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '100'})
}
}
complete_apps = ['CLMSpipeline_app']
\ No newline at end of file
# -*- coding: utf-8 -*-
import datetime
from south.db import db
from south.v2 import SchemaMigration
from django.db import models
class Migration(SchemaMigration):
def forwards(self, orm):
# Changing field 'CLPeptideFilterParam.field_lookup'
db.alter_column(u'CLMSpipeline_app_clpeptidefilterparam', 'field_lookup', self.gf('django.db.models.fields.CharField')(max_length=50))
def backwards(self, orm):
# Changing field 'CLPeptideFilterParam.field_lookup'
db.alter_column(u'CLMSpipeline_app_clpeptidefilterparam', 'field_lookup', self.gf('django.db.models.fields.CharField')(max_length=20))
models = {
u'CLMSpipeline_app.clpeptide': {
'Meta': {'ordering': "['-match_score']", 'object_name': 'CLPeptide'},
'autovalidated': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'cross_link': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'dataset': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['CLMSpipeline_app.Dataset']", 'symmetrical': 'False'}),
'delta': ('django.db.models.fields.FloatField', [], {}),
'display_protein1': ('django.db.models.fields.CharField', [], {'max_length': '250'}),
'display_protein2': ('django.db.models.fields.CharField', [], {'max_length': '250'}),
'error': ('django.db.models.fields.FloatField', [], {}),
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'link_type': ('django.db.models.fields.IntegerField', [], {}),
'match_score': ('django.db.models.fields.FloatField', [], {}),
'not_decoy': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'notes': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'pep1_link_pos': ('django.db.models.fields.IntegerField', [], {}),
'pep2_link_pos': ('django.db.models.fields.IntegerField', [], {}),
'peptide1': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'peptide2': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'peptide_position1': ('django.db.models.fields.IntegerField', [], {}),
'peptide_position2': ('django.db.models.fields.IntegerField', [], {}),
'peptide_wo_mod1': ('django.db.models.fields.CharField', [], {'max_length': '150'}),
'peptide_wo_mod2': ('django.db.models.fields.CharField', [], {'max_length': '150'}),
'precursor_charge': ('django.db.models.fields.CharField', [], {'max_length': '5'}),
'precursor_intensity': ('django.db.models.fields.FloatField', [], {}),
'precursor_mz': ('django.db.models.fields.FloatField', [], {}),
'rank': ('django.db.models.fields.IntegerField', [], {}),
'rejected': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'run_name': ('django.db.models.fields.CharField', [], {'max_length': '1000'}),
'scan_number': ('django.db.models.fields.IntegerField', [], {}),
'spectrum_intensity_coverage': ('django.db.models.fields.FloatField', [], {}),
'total_fragment_matches': ('django.db.models.fields.IntegerField', [], {}),
'validated': ('django.db.models.fields.CharField', [], {'max_length': '50'})
},
u'CLMSpipeline_app.clpeptidefilter': {
'Meta': {'object_name': 'CLPeptideFilter'},
'creation_date': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
'description': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
},
u'CLMSpipeline_app.clpeptidefilterparam': {
'Meta': {'object_name': 'CLPeptideFilterParam'},
'clpeptidefilter': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['CLMSpipeline_app.CLPeptideFilter']"}),
'field': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'field_lookup': ('django.db.models.fields.CharField', [], {'max_length': '50'}),
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'method': ('django.db.models.fields.CharField', [], {'max_length': '20'}),
'value': ('django.db.models.fields.CharField', [], {'max_length': '50'})
},
u'CLMSpipeline_app.crosslinker': {
'Meta': {'ordering': "['name']", 'object_name': 'CrossLinker'},
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '100'})
},
u'CLMSpipeline_app.dataset': {
'Meta': {'ordering': "['-creation_date']", 'object_name': 'Dataset'},
'creation_date': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
'cross_linker': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['CLMSpipeline_app.CrossLinker']"}),
'description': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
'extra_file': ('django.db.models.fields.files.FileField', [], {'max_length': '100', 'blank': 'True'}),
'fasta_db': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['CLMSpipeline_app.FastaDB']"}),
'file': ('django.db.models.fields.files.FileField', [], {'max_length': '100'}),
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'instrument_name': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['CLMSpipeline_app.Instrument']"}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'parsing_log': ('django.db.models.fields.CharField', [], {'max_length': '1000', 'null': 'True', 'blank': 'True'}),
'parsing_status': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'prefix': ('django.db.models.fields.CharField', [], {'max_length': '25'}),
'search_algorithm': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['CLMSpipeline_app.searchAlgorithm']"})
},
u'CLMSpipeline_app.fastadb': {
'Meta': {'ordering': "['name']", 'object_name': 'FastaDB'},
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '200'})
},
u'CLMSpipeline_app.instrument': {
'Meta': {'ordering': "['name']", 'object_name': 'Instrument'},
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '100'})
},
u'CLMSpipeline_app.searchalgorithm': {
'Meta': {'ordering': "['name']", 'object_name': 'searchAlgorithm'},
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '100'})
}
}
complete_apps = ['CLMSpipeline_app']
\ No newline at end of file
......@@ -320,6 +320,53 @@ class CLPeptide(models.Model):
class CLPeptideFilter(models.Model):
"""
This class holds pre-defined filters for cross-linked peptides.
"""
creation_date = models.DateTimeField(auto_now_add=True)
name = models.CharField(max_length=100)
description = models.TextField('Detailed description', blank=True)
class CLPeptideFilterParam(models.Model):
clpeptidefilter = models.ForeignKey(CLPeptideFilter)
METHOD_CHOICES = (
('Exclude', 'Exclude'),
('Filter', 'Filter'),
)
method = models.CharField(max_length = 20, choices = METHOD_CHOICES)
field = models.CharField(max_length = 100, choices = [(field.name, field.name) for field in CLPeptide._meta.fields])
LOOKUP_CHOICES = (
('Exact match', 'exact'),
('Exact match case insentive', 'iexact'),
('Contains', 'contains'),
('Contains case insentive', 'contains'),
('Greater than', 'gt'),
('Greater than or equal to', 'gte'),
('Less than', 'lt'),
('Less than or equal to', 'lte'),
('Starts-with', 'startswith'),
('Starts-with case insensitive', 'istartswith'),
('Ends-with', 'endswith'),
('Ends-with case insensitive', 'iendswith'),
('Is null', 'isnull'),
('Regular expression match', 'regex'),
('Regular expression match case insensitive', 'iregex'),
)
field_lookup = models.CharField(max_length=50, choices=LOOKUP_CHOICES)
value = models.CharField(max_length = 50)
\ No newline at end of file
......@@ -125,7 +125,7 @@ class pLinkParser:
fields['pep2_link_pos'] = int(tmp_fields['NO1_XLink_Pos2']) + 1
fields['autovalidated'] = False
fields['validated'] = False
fields['validated'] = ''
fields['rejected'] = False
fields['notes'] = ''
fields['not_decoy'] = True
......
......@@ -134,7 +134,7 @@ class xQuestParser:
fields['display_protein2'] = row['Protein2']
fields['autovalidated'] = False
fields['validated'] = False
fields['validated'] = ''
fields['rejected'] = False
fields['notes'] = row['comment']
fields['not_decoy'] = not row['XLType'].startswith('decoy')
......
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