Skip to content

Commit

Permalink
Merge pull request #113 from lehtiolab/dia_longit_qc
Browse files Browse the repository at this point in the history
Include DIA in longitudinal qc
  • Loading branch information
glormph authored Jan 20, 2025
2 parents 3c26454 + 7f62784 commit 07cc93c
Show file tree
Hide file tree
Showing 22 changed files with 901 additions and 293 deletions.
4 changes: 1 addition & 3 deletions src/backend/analysis/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,12 @@ def process(self, **kwargs):
analysis=analysis)
run = {'timestamp': timestamp,
'analysis_id': analysis.id,
'qcrun_id': kwargs['qcrun_id'],
'token': analysis.nextflowsearch.token,
'rf_id': raw.rawfile_id,
'wf_commit': nfwf.commit,
'nxf_wf_fn': nfwf.filename,
'repo': nfwf.nfworkflow.repo,
'runname': f'{analysis.id}_longqc_{raw.rawfile.producer.name}_rawfile{raw.rawfile_id}_{timestamp}',
'filename': raw.filename,
'instrument': raw.rawfile.producer.name,
}
self.run_tasks.append(((run, params, stagefiles, ','.join(nfwf.profiles), nfwf.nfversion), {}))
analysis.log.append('[{}] Job queued'.format(datetime.strftime(timezone.now(), '%Y-%m-%d %H:%M:%S')))
Expand Down
5 changes: 2 additions & 3 deletions src/backend/analysis/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,9 +428,8 @@ def execute_normal_nf(run, params, rundir, gitwfdir, taskid, nf_version, profile
def run_nextflow_longitude_qc(self, run, params, stagefiles, profiles, nf_version):
print('Got message to run QC workflow, preparing')
reporturl = urljoin(settings.KANTELEHOST, reverse('jobs:storelongqc'))
postdata = {'client_id': settings.APIKEY, 'rf_id': run['rf_id'], 'plots': {},
'analysis_id': run['analysis_id'], 'task': self.request.id,
'instrument': run['instrument'], 'filename': run['filename']}
postdata = {'client_id': settings.APIKEY, 'qcrun_id': run['qcrun_id'], 'plots': {},
'task': self.request.id}
rundir = create_runname_dir(run)
params, gitwfdir, no_stagedir = prepare_nextflow_run(run, self.request.id, rundir, stagefiles, [], params)
# QC has no stagedir, we put the raw in rundir to stage
Expand Down
95 changes: 95 additions & 0 deletions src/backend/dashboard/migrations/0003_lineplotdata_plottype.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# Generated by Django 4.2.13 on 2025-01-09 13:53

from django.db import migrations, models
from django.db.models import F

from dashboard import models as dm


dtmap = {
'psms': dm.LineDataTypes.NRPSMS,
'scans': dm.LineDataTypes.NRSCANS,
'peptides': dm.LineDataTypes.NRPEPTIDES,
'unique_peptides': dm.LineDataTypes.NRPEPTIDES_UNI,
'proteins': dm.LineDataTypes.NRPROTEINS,
'miscleav1': dm.LineDataTypes.MISCLEAV1,
'miscleav2': dm.LineDataTypes.MISCLEAV2,
'peaks_fwhm': dm.LineDataTypes.PEAKS_FWHM,

'perror': dm.QuartileDataTypes.MASSERROR,
'msgfscore': dm.QuartileDataTypes.SCORE,
'rt': dm.QuartileDataTypes.RT,
'peparea': dm.QuartileDataTypes.PEPMS1AREA,
'ionmob': dm.QuartileDataTypes.IONMOB,
'fwhms': dm.QuartileDataTypes.FWHM,
'ioninj': dm.QuartileDataTypes.IONINJ,
'matched_peaks': dm.QuartileDataTypes.MATCHED_PEAKS,
}


def fill_datatypes_remove_old(a, s):
Box = a.get_model('dashboard', 'BoxplotData')
Box.objects.filter(shortname='sagescores').delete()
for b in Box.objects.all():
b.datatype = dtmap[b.shortname]
b.save()
Line = a.get_model('dashboard', 'LineplotData')
Line.objects.filter(shortname='miscleav3').delete()
Line.objects.filter(shortname='miscleav0').delete()
for l in Line.objects.all():
l.datatype = dtmap[l.shortname]
l.save()
# Remove thermo ion mob plots
Box.objects.filter(datatype=dm.QuartileDataTypes.IONMOB, q2=F('q3'), q1=0.0).delete()

def fake(a,s):
pass


class Migration(migrations.Migration):

dependencies = [
('dashboard', '0002_qcdata_is_ok_qcdata_message'),
]

operations = [
migrations.AddField(
model_name='boxplotdata',
name='datatype',
field=models.IntegerField(choices=[(1, 'FWHM'), (2, 'Peptide MS1 area'), (3, 'Mass error'), (4, 'Retention time'), (5, 'Score'), (6, 'Ion mobility'), (7, 'Ion injection time(ms)'), (8, 'Amount MS2 peaks matched')]),
preserve_default=False,
),

migrations.AddField(
model_name='lineplotdata',
name='datatype',
field=models.IntegerField(choices=[(1, 'Nr of proteins'), (2, 'Nr of peptides'), (3, 'Nr of peptides mapping uniquely'), (4, 'Nr of PSMs'), (5, 'Nr of scans'), (6, 'Nr of PSMs with 1 missed cleavage'), (7, 'Nr of PSMs with 2 missed cleavage'), (8, 'Amount scans FWHM')]),
preserve_default=False,
),

migrations.AddField(
model_name='qcdata',
name='runtype',
field=models.IntegerField(choices=[(1, 'DDA'), (2, 'DIA')], default=1),
preserve_default=False,
),

migrations.RunPython(fill_datatypes_remove_old, fake),

migrations.AlterField(
model_name='qcdata',
name='analysis',
field=models.OneToOneField(on_delete=models.deletion.CASCADE, to='analysis.analysis'),
),
migrations.AlterField(
model_name='qcdata',
name='rawfile',
field=models.OneToOneField(on_delete=models.deletion.CASCADE, to='rawstatus.rawfile'),
),

migrations.RenameModel(
old_name='QCData',
new_name='QCRun',
),

]
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Generated by Django 4.2.13 on 2025-01-13 14:47

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('dashboard', '0003_lineplotdata_plottype'),
]

operations = [
migrations.RemoveField(
model_name='lineplotdata',
name='shortname',
),
migrations.RemoveField(
model_name='boxplotdata',
name='shortname',
),
migrations.RemoveField(
model_name='boxplotdata',
name='lower',
),
migrations.RemoveField(
model_name='boxplotdata',
name='upper',
),
]
44 changes: 33 additions & 11 deletions src/backend/dashboard/models.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,49 @@
from django.db import models

from rawstatus import models as filemodels
from analysis import models as analysismodels
from rawstatus import models as rm
from analysis import models as am
from datasets import models as dm


class QCData(models.Model):
rawfile = models.ForeignKey(filemodels.RawFile, on_delete=models.CASCADE)
analysis = models.ForeignKey(analysismodels.Analysis, on_delete=models.CASCADE)
class QCRun(models.Model):
rawfile = models.OneToOneField(rm.RawFile, on_delete=models.CASCADE)
analysis = models.OneToOneField(am.Analysis, on_delete=models.CASCADE)
is_ok = models.BooleanField(default=True)
message = models.TextField()
runtype = models.IntegerField(choices=dm.AcquisistionMode.choices)


class LineDataTypes(models.IntegerChoices):
NRPROTEINS = 1, 'Nr of proteins'
NRPEPTIDES = 2, 'Nr of peptides'
NRPEPTIDES_UNI = 3, 'Nr of peptides mapping uniquely'
NRPSMS = 4, 'Nr of PSMs'
NRSCANS = 5, 'Nr of scans'
MISCLEAV1 = 6, 'Nr of PSMs with 1 missed cleavage'
MISCLEAV2 = 7, 'Nr of PSMs with 2 missed cleavage'
PEAKS_FWHM = 8, 'Amount scans FWHM'


class QuartileDataTypes(models.IntegerChoices):
FWHM = 1, 'FWHM'
PEPMS1AREA = 2, 'Peptide MS1 area'
MASSERROR = 3, 'Mass error'
RT = 4, 'Retention time'
SCORE = 5, 'Score'
IONMOB = 6, 'Ion mobility'
IONINJ = 7, 'Ion injection time(ms)'
MATCHED_PEAKS = 8, 'Amount MS2 peaks matched'


class LineplotData(models.Model):
qcrun = models.ForeignKey(QCData, on_delete=models.CASCADE)
qcrun = models.ForeignKey(QCRun, on_delete=models.CASCADE)
value = models.FloatField()
shortname = models.CharField(max_length=20)
datatype = models.IntegerField(choices=LineDataTypes.choices)


class BoxplotData(models.Model):
shortname = models.CharField(max_length=15)
qcrun = models.ForeignKey(QCData, on_delete=models.CASCADE)
upper = models.FloatField()
lower = models.FloatField()
datatype = models.IntegerField(choices=QuartileDataTypes.choices)
qcrun = models.ForeignKey(QCRun, on_delete=models.CASCADE)
q1 = models.FloatField()
q2 = models.FloatField()
q3 = models.FloatField()
5 changes: 2 additions & 3 deletions src/backend/dashboard/templates/dashboard/dashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

{% block head %}
<link rel='stylesheet' href='{% static "dashboard/bundle.css" %}'>
<script crossorigin="anonymous" src="https://polyfill.io/v3/polyfill.min.js?features=Object.fromEntries"></script>
<script defer src='{% static "dashboard/bundle.js" %}'></script>
<script>
const instruments = [
Expand All @@ -16,6 +15,6 @@
{% endblock head %}

{% block content %}
<section id="apps">
</section>
<div id="apps">
</div>
{% endblock %}
Loading

0 comments on commit 07cc93c

Please sign in to comment.