Commit 8b4af0cf authored by Mathieu Courcelles's avatar Mathieu Courcelles

First version of Xi parser

parent 8c68a78f
......@@ -26,5 +26,5 @@ import CLMSpipeline.CLMSpipeline_app.models as CLMSpipelineModels
admin.site.register(CLMSpipelineModels.Dataset)
admin.site.register(CLMSpipelineModels.FastaDB)
admin.site.register(CLMSpipelineModels.Instrument)
admin.site.register(CLMSpipelineModels.clPeptides)
admin.site.register(CLMSpipelineModels.CLPeptide)
admin.site.register(CLMSpipelineModels.searchAlgorithm)
# -*- 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):
# Deleting field 'CLPeptide.peptide_mod2'
db.delete_column(u'CLMSpipeline_app_clpeptide', 'peptide_mod2')
# Deleting field 'CLPeptide.peptide_mod1'
db.delete_column(u'CLMSpipeline_app_clpeptide', 'peptide_mod1')
# Adding field 'CLPeptide.peptide_wo_mod1'
db.add_column(u'CLMSpipeline_app_clpeptide', 'peptide_wo_mod1',
self.gf('django.db.models.fields.CharField')(default='', max_length=150),
keep_default=False)
# Adding field 'CLPeptide.peptide_wo_mod2'
db.add_column(u'CLMSpipeline_app_clpeptide', 'peptide_wo_mod2',
self.gf('django.db.models.fields.CharField')(default='', max_length=150),
keep_default=False)
def backwards(self, orm):
# User chose to not deal with backwards NULL issues for 'CLPeptide.peptide_mod2'
raise RuntimeError("Cannot reverse this migration. 'CLPeptide.peptide_mod2' and its values cannot be restored.")
# User chose to not deal with backwards NULL issues for 'CLPeptide.peptide_mod1'
raise RuntimeError("Cannot reverse this migration. 'CLPeptide.peptide_mod1' and its values cannot be restored.")
# Deleting field 'CLPeptide.peptide_wo_mod1'
db.delete_column(u'CLMSpipeline_app_clpeptide', 'peptide_wo_mod1')
# Deleting field 'CLPeptide.peptide_wo_mod2'
db.delete_column(u'CLMSpipeline_app_clpeptide', 'peptide_wo_mod2')
models = {
u'CLMSpipeline_app.clpeptide': {
'Meta': {'object_name': 'CLPeptide'},
'autovalidated': ('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'}),
'match_score': ('django.db.models.fields.FloatField', [], {}),
'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.FloatField', [], {}),
'validated': ('django.db.models.fields.CharField', [], {'max_length': '50'})
},
u'CLMSpipeline_app.dataset': {
'Meta': {'ordering': "['-experimentdate']", 'object_name': 'Dataset'},
'creation_date': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
'description': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
'experimentdate': ('django.db.models.fields.DateTimeField', [], {'null': 'True', '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'}),
'file_name': ('django.db.models.fields.CharField', [], {'max_length': '1000'}),
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'instrument_name': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['CLMSpipeline_app.Instrument']"}),
'search_agorithm': ('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):
# Deleting field 'Dataset.file_name'
#db.delete_column(u'CLMSpipeline_app_dataset', 'file_name')
# Adding field 'Dataset.name'
db.add_column(u'CLMSpipeline_app_dataset', 'name',
self.gf('django.db.models.fields.CharField')(default='', max_length=100),
keep_default=False)
# Adding field 'Dataset.prefix'
db.add_column(u'CLMSpipeline_app_dataset', 'prefix',
self.gf('django.db.models.fields.CharField')(default='', max_length=25),
keep_default=False)
def backwards(self, orm):
# User chose to not deal with backwards NULL issues for 'Dataset.file_name'
raise RuntimeError("Cannot reverse this migration. 'Dataset.file_name' and its values cannot be restored.")
# Deleting field 'Dataset.name'
db.delete_column(u'CLMSpipeline_app_dataset', 'name')
# Deleting field 'Dataset.prefix'
db.delete_column(u'CLMSpipeline_app_dataset', 'prefix')
models = {
u'CLMSpipeline_app.clpeptide': {
'Meta': {'object_name': 'CLPeptide'},
'autovalidated': ('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'}),
'match_score': ('django.db.models.fields.FloatField', [], {}),
'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.FloatField', [], {}),
'validated': ('django.db.models.fields.CharField', [], {'max_length': '50'})
},
u'CLMSpipeline_app.dataset': {
'Meta': {'ordering': "['-experimentdate']", 'object_name': 'Dataset'},
'creation_date': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
'description': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
'experimentdate': ('django.db.models.fields.DateTimeField', [], {'null': 'True', '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'}),
'prefix': ('django.db.models.fields.CharField', [], {'max_length': '25'}),
'search_agorithm': ('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):
# Adding field 'CLPeptide.link_type'
db.add_column(u'CLMSpipeline_app_clpeptide', 'link_type',
self.gf('django.db.models.fields.CharField')(default='', max_length=15),
keep_default=False)
def backwards(self, orm):
# Deleting field 'CLPeptide.link_type'
db.delete_column(u'CLMSpipeline_app_clpeptide', 'link_type')
models = {
u'CLMSpipeline_app.clpeptide': {
'Meta': {'object_name': 'CLPeptide'},
'autovalidated': ('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.CharField', [], {'max_length': '15'}),
'match_score': ('django.db.models.fields.FloatField', [], {}),
'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.FloatField', [], {}),
'validated': ('django.db.models.fields.CharField', [], {'max_length': '50'})
},
u'CLMSpipeline_app.dataset': {
'Meta': {'ordering': "['-experimentdate']", 'object_name': 'Dataset'},
'creation_date': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
'description': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
'experimentdate': ('django.db.models.fields.DateTimeField', [], {'null': 'True', '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'}),
'prefix': ('django.db.models.fields.CharField', [], {'max_length': '25'}),
'search_agorithm': ('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 'CLPeptide.link_type'
db.alter_column(u'CLMSpipeline_app_clpeptide', 'link_type', self.gf('django.db.models.fields.IntegerField')())
def backwards(self, orm):
# Changing field 'CLPeptide.link_type'
db.alter_column(u'CLMSpipeline_app_clpeptide', 'link_type', self.gf('django.db.models.fields.CharField')(max_length=15))
models = {
u'CLMSpipeline_app.clpeptide': {
'Meta': {'object_name': 'CLPeptide'},
'autovalidated': ('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', [], {}),
'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.FloatField', [], {}),
'validated': ('django.db.models.fields.CharField', [], {'max_length': '50'})
},
u'CLMSpipeline_app.dataset': {
'Meta': {'ordering': "['-experimentdate']", 'object_name': 'Dataset'},
'creation_date': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
'description': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
'experimentdate': ('django.db.models.fields.DateTimeField', [], {'null': 'True', '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'}),
'prefix': ('django.db.models.fields.CharField', [], {'max_length': '25'}),
'search_agorithm': ('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
......@@ -7,13 +7,15 @@ This is the data model module for the CLMSpipeline_app.
# Import standard librariesdjang
import os.path
#import os.path
# Import Django related libraries
from django.db import models
from django.db.models.signals import post_save, pre_save
from django.dispatch import receiver
# Import project libraries
#from CLMSpipeline.CLMSpipeline_app.parser.XiParser import *
......@@ -21,8 +23,7 @@ from django.db import models
def upload_path_handler(instance, filename):
fn, ext = os.path.splitext(filename)
return "dataset/{id}{ext}".format(id=instance.pk, ext=ext)
return "dataset/{id}-{filename}".format(id=instance.pk, filename=filename)
......@@ -76,16 +77,14 @@ class Dataset(models.Model):
This class holds dataset information of cross-linked peptides.
"""
experimentdate = models.DateTimeField("ExperimentDate", null=True,
blank=True)
creation_date = models.DateTimeField(auto_now_add=True)
file_name = models.CharField(max_length=1000)
name = models.CharField(max_length=100)
prefix = models.CharField(max_length=25, help_text="Short name that will be appeded in comparison.")
file = models.FileField(upload_to=upload_path_handler)
......@@ -108,7 +107,35 @@ class Dataset(models.Model):
ordering = ['-experimentdate']
class clPeptides(models.Model):
# Code for dataset file upload
# Code from http://stackoverflow.com/questions/9968532/django-admin-file-upload-with-current-model-id
_UNSAVED_FILEFIELD = 'unsaved_filefield'
@receiver(pre_save, sender=Dataset)
def skip_saving_file(sender, instance, **kwargs):
if not instance.pk and not hasattr(instance, _UNSAVED_FILEFIELD):
setattr(instance, _UNSAVED_FILEFIELD, instance.file)
instance.file = None
@receiver(post_save, sender=Dataset)
def save_file(sender, instance, created, **kwargs):
if created and hasattr(instance, _UNSAVED_FILEFIELD):
instance.file = getattr(instance, _UNSAVED_FILEFIELD)
instance.save()
# Launch result parsing
#parseXiResults(instance)
# delete it if you feel uncomfortable...
# instance.__dict__.pop(_UNSAVED_FILEFIELD)
class CLPeptide(models.Model):
"""
This class holds details of cross-linked peptides.
"""
......@@ -131,7 +158,7 @@ class clPeptides(models.Model):
spectrum_intensity_coverage = models.FloatField()
total_fragment_matches = models.IntegerField()
total_fragment_matches = models.FloatField()
delta = models.FloatField()
......@@ -139,23 +166,23 @@ class clPeptides(models.Model):
peptide1 = models.CharField(max_length=100)
peptide_mod1 = models.CharField(max_length=150)
peptide_wo_mod1 = models.CharField(max_length=150)
display_protein1 = models.CharField(max_length=250)
peptide_position1 = models.IntegerField()
pep_link_pos_1 = models.IntegerField()
pep1_link_pos = models.IntegerField()
peptide2 = models.CharField(max_length=100)
peptide_mod2 = models.CharField(max_length=150)
peptide_wo_mod2 = models.CharField(max_length=150)
display_protein2 = models.CharField(max_length=250)
peptide_position2 = models.IntegerField()
pep_link_pos_2 = models.IntegerField()
pep2_link_pos = models.IntegerField()
autovalidated = models.BooleanField()
......@@ -165,24 +192,38 @@ class clPeptides(models.Model):
notes = models.CharField(max_length=100)
LINK_TYPE_CHOICES = (
(1, 'Inter-protein'),
(2, 'Intra-protein'),
(3, 'Intra-peptide'),
(4, 'Mono-link'),
)
link_type = models.IntegerField(choices=LINK_TYPE_CHOICES)
from django.db.models.signals import post_save, pre_save
from django.dispatch import receiver
# Code from http://stackoverflow.com/questions/9968532/django-admin-file-upload-with-current-model-id
_UNSAVED_FILEFIELD = 'unsaved_filefield'
def guessLinkType(self):
"""
This method guess the type of peptide cross-link since Xi is not
providing this information.
"""
if self.peptide_wo_mod1 == self.peptide_wo_mod2:
self.link_type = 1
elif self.display_protein1 == self.display_protein2:
self.link_type = 2
else:
if self.pep2_link_pos == -1:
self.link_type = 4
elif self.peptide2 == 'none':
self.link_type = 3
@receiver(pre_save, sender=Dataset)
def skip_saving_file(sender, instance, **kwargs):
if not instance.pk and not hasattr(instance, _UNSAVED_FILEFIELD):
setattr(instance, _UNSAVED_FILEFIELD, instance.file)
instance.file = None
@receiver(post_save, sender=Dataset)
def save_file(sender, instance, created, **kwargs):
if created and hasattr(instance, _UNSAVED_FILEFIELD):
instance.file = getattr(instance, _UNSAVED_FILEFIELD)
instance.save()
# delete it if you feel uncomfortable...
# instance.__dict__.pop(_UNSAVED_FILEFIELD)
## Copyright 2013 Mathieu Courcelles
## Mike Tyers's lab / IRIC / Universite de Montreal
"""
This is a parser for Xi results.
"""
# Import standard librariesdjang
import csv
import re
# Import Django related libraries
from django.core import management;import CLMSpipeline.settings as settings;management.setup_environ(settings)
# Import project libraries
from CLMSpipeline.CLMSpipeline_app.models import Dataset
from CLMSpipeline.CLMSpipeline_app.models import CLPeptide
class XiParser:
@staticmethod
def parseXiResults(dataset):
with open(dataset.file.path, 'rb') as f:
# Skip line to header
filters_string = f.readline()
f.readline()
# Create CSV reader
reader = csv.DictReader(f)
# Iterate through lines and create clPeptide
count = 0
for row in reader:
print row
# Create the CLPeptide object
clpep = CLPeptide(**row)
# Add manual fields
clpep.peptide_wo_mod1 = re.sub("[a-z]", "", clpep.peptide1)
clpep.peptide_wo_mod2 = re.sub("[a-z]", "", clpep.peptide2)
clpep.guessLinkType()
# Save object to db
clpep.save()
# Link object to dataset
clpep.dataset.add(dataset)
count += 1
if count == 10:
break
# Append filter string to dataset description
dataset.description += filters_string
dataset.save()
# Manual test
XiParser.parseXiResults(Dataset.objects.all()[1])
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