Commit 04f4e84e authored by Mathieu Courcelles's avatar Mathieu Courcelles

Changed hardcode imports to explicit imports

parent 1e0b1757
......@@ -6,7 +6,7 @@
# Import Django related libraries
# Import project libraries
from CLMSpipeline.CLMSpipeline_app.models import ProcessedDataset
from .models import ProcessedDataset
class DatasetProcessing:
......@@ -85,7 +85,7 @@ class DatasetProcessing:
# Unique peptide
unique_msrun_pep = dict()
unique_key = dict()
if instance.clpeptidefilter != None:
if instance.clpeptidefilter != None and instance.clpeptidefilter.unique_key != None:
for key in instance.clpeptidefilter.unique_key.split('-'):
unique_key[key] = True;
......
......@@ -16,9 +16,11 @@ from django.dispatch import receiver
# Import project libraries
import CLMSpipeline.CLMSpipeline_app.models as CLMSpipelineModels
from CLMSpipeline.CLMSpipeline_app.parser.parser_generic import parser_generic
from CLMSpipeline.CLMSpipeline_app.DatasetProcessing import DatasetProcessing
from .models import CLPeptideFilterParam, RawDataset, ProcessedDataset,\
CrossLinker, FastaDB, Instrument, CLPeptide,\
SearchAlgorithm, Project, CLPeptideFilter
from .parser.parser_generic import parser_generic
from .DatasetProcessing import DatasetProcessing
import export
......@@ -95,7 +97,7 @@ class CLPeptideAdmin(admin.ModelAdmin):
"""
return export.make_Xi_csv(self, request, queryset, 'CLPeptide')
make_Xi_csv.short_description = 'Export as Xi CSV'
def match_score_2d(self, obj):
"""
......@@ -134,7 +136,7 @@ class CLPeptideFilterAdminInline(admin.TabularInline):
extra = 2
model = CLMSpipelineModels.CLPeptideFilterParam
model = CLPeptideFilterParam
......@@ -162,11 +164,11 @@ class RawDatasetAdmin(admin.ModelAdmin):
"""
actions = ['dataset_stats_csv', 'make_Xi_csv']
actions = ['compareRunIds_csv', 'dataset_stats_csv', 'make_Xi_csv']
date_hierarchy = 'creation_date'
list_display = ('pk', 'name', 'prefix', 'getProject', 'file', 'cross_linker',
list_display = ('pk', 'name', 'getProject', 'file', 'cross_linker',
'instrument_name', 'fasta_db',
'search_algorithm', 'description', 'parsing_status',
'creation_date', 'get_CLPeptides_URL')
......@@ -176,9 +178,16 @@ class RawDatasetAdmin(admin.ModelAdmin):
readonly_fields = ('parsing_log', 'parsing_status')
search_fields = ('name', 'prefix', 'file', 'description')
search_fields = ('name', 'file', 'description')
def compareRunIds_csv(self, request, queryset):
"""
Compares cross-linked peptides across MS runs and export it to CSV file format.
"""
return export.compareRunIds_csv(self, request, queryset, 'CLPeptide_comparison ')
compareRunIds_csv.short_description = 'Export cross-linked peptides comparison to CSV'
def dataset_stats_csv(self, request, queryset):
"""
......@@ -241,7 +250,7 @@ class RawDatasetAdmin(admin.ModelAdmin):
@staticmethod
@receiver(post_save, sender=CLMSpipelineModels.RawDataset)
@receiver(post_save, sender=RawDataset)
def process_file(sender, instance, created, **kwargs):
"""
This method initiates the parsing of uploaded search results.
......@@ -258,13 +267,13 @@ class ProcessedDatasetAdmin(admin.ModelAdmin):
"""
actions = ['dataset_stats_csv', 'make_Xi_csv']
actions = ['compareRunIds_csv', 'dataset_stats_csv', 'make_Xi_csv']
date_hierarchy = 'creation_date'
filter_horizontal = ('datasets',)
list_display = ('pk', 'name', 'prefix', 'getProject', 'getDataset', 'getFilter',
list_display = ('pk', 'name', 'getProject', 'getDataset', 'getFilter',
'cross_linker', 'instrument_name', 'fasta_db',
'search_algorithm', 'description',
'creation_date', 'get_CLPeptides_URL')
......@@ -272,12 +281,21 @@ class ProcessedDatasetAdmin(admin.ModelAdmin):
list_filter = ('project', 'clpeptidefilter__name', 'cross_linker',
'instrument_name', 'fasta_db', 'search_algorithm')
raw_id_fields = ('clpeptidefilter',)
readonly_fields = ('cross_linker', 'instrument_name',
'fasta_db', 'search_algorithm')
search_fields = ('name', 'prefix', 'file', 'description', 'clpeptidefilter')
search_fields = ('name', 'file', 'description', 'clpeptidefilter')
def compareRunIds_csv(self, request, queryset):
"""
Compares cross-linked peptides across MS runs and export it to CSV file format.
"""
return export.compareRunIds_csv(self, request, queryset, 'CLPeptide_comparison ')
compareRunIds_csv.short_description = 'Export cross-linked peptides comparison to CSV'
def dataset_stats_csv(self, request, queryset):
"""
......@@ -360,7 +378,7 @@ class ProcessedDatasetAdmin(admin.ModelAdmin):
@staticmethod
@receiver(post_save, sender=CLMSpipelineModels.ProcessedDataset)
@receiver(post_save, sender=ProcessedDataset)
def process_file(sender, instance, created, **kwargs):
"""
Launches dataset processing.
......@@ -372,6 +390,7 @@ class ProcessedDatasetAdmin(admin.ModelAdmin):
# 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()
......@@ -379,12 +398,13 @@ class ProcessedDatasetAdmin(admin.ModelAdmin):
## Register admin panels
admin.site.register(CLMSpipelineModels.RawDataset, RawDatasetAdmin)
admin.site.register(CLMSpipelineModels.ProcessedDataset, ProcessedDatasetAdmin)
admin.site.register(CLMSpipelineModels.CrossLinker)
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.Project)
admin.site.register(CLMSpipelineModels.CLPeptideFilter, CLPeptideFilterAdmin)
admin.site.register(RawDataset, RawDatasetAdmin)
admin.site.register(ProcessedDataset, ProcessedDatasetAdmin)
admin.site.register(CrossLinker)
admin.site.register(FastaDB)
admin.site.register(Instrument)
admin.site.register(CLPeptide, CLPeptideAdmin)
admin.site.register(SearchAlgorithm)
admin.site.register(Project)
admin.site.register(CLPeptideFilter, CLPeptideFilterAdmin)
......@@ -16,6 +16,71 @@ from django.http import HttpResponse
# Import project libraries
def compareRunIds_csv(self, request, queryset, tableName):
"""
Compares cross-linked peptides across MS runs and datasets.
Outputs results to CSV format.
"""
response = HttpResponse(mimetype='text/csv')
response['Content-Disposition'] = 'attachment; filename=' + tableName + \
'_' + request.META['QUERY_STRING'] + '.csv'
writer = csv.writer(response, quoting=csv.QUOTE_ALL)
header_list = OrderedDict([('Unique Key', True),
])
uniquePep_dict = dict()
# Iterates through datasets
for dataset in queryset:
header_list[dataset.__unicode__()] = ''
# Iterates over Clpeptides
for clpep in dataset.clpeptide_set.all():
dataset_run_name = dataset.__unicode__() + '__'+ clpep.run_name
header_list[dataset_run_name] = ''
d = dict()
d['sequence'] = True
unique_key = clpep.uniqueKey(d)
if not unique_key in uniquePep_dict:
uniquePep_dict[unique_key] = dict()
uniquePep_dict[unique_key][dataset.__unicode__()] = True
uniquePep_dict[unique_key][dataset_run_name] = True
print uniquePep_dict
# Write header
writer.writerow(header_list.keys())
# Write peptide rows
for uniquePep_key in sorted(uniquePep_dict.keys()):
tmp_dict = header_list.copy()
tmp_dict['Unique Key'] = uniquePep_key
for dataset_run_name in tmp_dict.keys()[1:]:
if dataset_run_name in uniquePep_dict[uniquePep_key]:
tmp_dict[dataset_run_name] = 'x'
writer.writerow(tmp_dict.values())
return response
def dataset_stats_csv(self, request, queryset, tableName):
"""
......
......@@ -94,7 +94,7 @@ class Instrument(models.Model):
class searchAlgorithm(models.Model):
class SearchAlgorithm(models.Model):
"""
This class holds the name of all the search algorithms.
"""
......@@ -137,10 +137,6 @@ class Dataset(models.Model, AdminURLMixin):
name = models.CharField(max_length=100)
prefix = models.CharField(max_length=25,
help_text='Short name that will be appended in \
comparison.')
project = models.ForeignKey(Project)
cross_linker = models.ForeignKey(CrossLinker, null=True)
......@@ -149,7 +145,7 @@ class Dataset(models.Model, AdminURLMixin):
fasta_db = models.ForeignKey(FastaDB, null=True)
search_algorithm = models.ForeignKey(searchAlgorithm, null=True)
search_algorithm = models.ForeignKey(SearchAlgorithm, null=True)
description = models.TextField('Detailed description', blank=True)
......
......@@ -11,8 +11,8 @@ import re
# Import Django related libraries
# Import project libraries
from CLMSpipeline.CLMSpipeline_app.models import CLPeptide
from CLMSpipeline.CLMSpipeline_app.models import RawDataset
from ..models import CLPeptide
from ..models import RawDataset
from parser_generic import InvalidFileFormatException
......@@ -44,18 +44,13 @@ class XiParser:
reader = csv.DictReader(f)
# Check header to validate file format
header_template = '"run_name","scan_number","precursor_mz",\
"precursor_charge","precursor_intensity","rank",\
"match_score","spectrum_intensity_coverage",\
"total_fragment_matches","delta","error","peptide1",\
"display_protein1","peptide_position1","pep1_link_pos",\
"peptide2","display_protein2","peptide_position2",\
"pep2_link_pos","autovalidated","validated","rejected",\
"notes",'
header_template = '"run_name","scan_number","precursor_mz","precursor_charge","precursor_intensity","rank","match_score","spectrum_intensity_coverage","total_fragment_matches","delta","error","peptide1","display_protein1","peptide_position1","pep1_link_pos","peptide2","display_protein2","peptide_position2","pep2_link_pos","autovalidated","validated","rejected","notes",'
header_file = '"' + '","'.join(name for name in reader.fieldnames) + '",'
if header_template != header_file:
print header_template
print header_file
raise InvalidFileFormatException('Uploaded file is not\
recognized as a Xi results file (bad file header)')
......
......@@ -8,8 +8,8 @@ import re
# Import Django related libraries
# Import project libraries
from CLMSpipeline.CLMSpipeline_app.models import CLPeptide
from CLMSpipeline.CLMSpipeline_app.models import RawDataset
from ..models import CLPeptide
from ..models import RawDataset
from parser_generic import InvalidFileFormatException
......
......@@ -9,8 +9,8 @@ import re
# Import Django related libraries
# Import project libraries
from CLMSpipeline.CLMSpipeline_app.models import CLPeptide
from CLMSpipeline.CLMSpipeline_app.models import RawDataset
from ..models import CLPeptide
from ..models import RawDataset
from parser_generic import InvalidFileFormatException
......
......@@ -9,7 +9,7 @@ from django.conf.urls import patterns, include, url
from django.contrib import admin
# Import project libraries
from CLMSpipeline import settings
from settings import MEDIA_ROOT
......@@ -27,5 +27,5 @@ urlpatterns = patterns('',
url(r'^admin/', include(admin.site.urls)),
url(r'^grappelli/', include('grappelli.urls')),
url(r'^media/(?P<path>.*)$', 'django.views.static.serve',
{'document_root': os.path.dirname(settings.MEDIA_ROOT)}),
{'document_root': os.path.dirname(MEDIA_ROOT)}),
)
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