|
| 1 | +define(['backbone', 'marionette', 'views/dialog', |
| 2 | + 'collections/datacollections', |
| 3 | + 'collections/proteins', |
| 4 | + 'collections/autoprocattachments', |
| 5 | + 'models/datacollection', |
| 6 | + 'modules/mc/views/dcdistl_downstream', |
| 7 | + 'modules/samples/collections/pdbs', |
| 8 | + 'utils/kvcollection', |
| 9 | + 'templates/dc/downstream.html', 'templates/dc/downstream_dc.html' |
| 10 | +], function(Backbone, Marionette, DialogView, |
| 11 | + DataCollections, Proteins, AutoProcAttachments, |
| 12 | + DataCollection, DCDistlView, |
| 13 | + PDBs, |
| 14 | + KVCollection, |
| 15 | + template, dctemplate |
| 16 | + ) { |
| 17 | + |
| 18 | + |
| 19 | + var IDDataCollection = DataCollection.extend({ |
| 20 | + idAttribute: 'CID', |
| 21 | + }) |
| 22 | + |
| 23 | + var IDDataCollections = DataCollections.extend({ |
| 24 | + model: IDDataCollection, |
| 25 | + }) |
| 26 | + |
| 27 | + var DCDistlViewLarge = DCDistlView.extend({ |
| 28 | + template: dctemplate, |
| 29 | + intStatus: false, |
| 30 | + className: 'data_collection', |
| 31 | + |
| 32 | + initialize: function(options) { |
| 33 | + DCDistlView.prototype.initialize.apply(this, arguments) |
| 34 | + }, |
| 35 | + |
| 36 | + onRender: function() { |
| 37 | + this.$el.find('ul').addClass('half') |
| 38 | + this.$el.find('li input[type="text"]').css('width', '25%') |
| 39 | + }, |
| 40 | + |
| 41 | + }) |
| 42 | + |
| 43 | + |
| 44 | + var DCDistlsView = Marionette.CollectionView.extend({ |
| 45 | + childView: DCDistlViewLarge, |
| 46 | + childViewOptions: function() { |
| 47 | + return { |
| 48 | + pipelines: this.getOption('pipelines'), |
| 49 | + parent: this.model, |
| 50 | + } |
| 51 | + } |
| 52 | + }) |
| 53 | + |
| 54 | + |
| 55 | + var Pipelines = Backbone.Collection.extend(_.extend({ |
| 56 | + keyAttribute: 'NAME', |
| 57 | + valueAttribute: 'VALUE', |
| 58 | + }, KVCollection)) |
| 59 | + |
| 60 | + |
| 61 | + return ReprocessView = DialogView.extend({ |
| 62 | + template: template, |
| 63 | + dialog: true, |
| 64 | + title: 'Rerun downstream processing', |
| 65 | + className: 'rp content', |
| 66 | + dOptions: { |
| 67 | + width: '1000px', |
| 68 | + }, |
| 69 | + |
| 70 | + regions: { |
| 71 | + dcr: '.dcs', |
| 72 | + }, |
| 73 | + |
| 74 | + ui: { |
| 75 | + pipeline: 'select[name=pipeline]', |
| 76 | + warning: '#warning', |
| 77 | + }, |
| 78 | + |
| 79 | + buttons: { |
| 80 | + Submit: 'submit', |
| 81 | + Close: 'closeDialog', |
| 82 | + }, |
| 83 | + |
| 84 | + disabledButtons: { |
| 85 | + Close: 'closeDialog', |
| 86 | + }, |
| 87 | + |
| 88 | + events: { |
| 89 | + 'change @ui.pipeline': 'updatePipeline', |
| 90 | + }, |
| 91 | + |
| 92 | + templateHelpers: function() { |
| 93 | + return { |
| 94 | + VISIT: this.getOption('visit') |
| 95 | + } |
| 96 | + }, |
| 97 | + |
| 98 | + updatePipeline: function() { |
| 99 | + this.model.set('PIPELINE', this.ui.pipeline.val()) |
| 100 | + this.model.set('PIPELINENAME', this.ui.pipeline.find('option:selected').text()) |
| 101 | + var btns = this.buttons |
| 102 | + var warning = '' |
| 103 | + if (['MrBUMP', 'Dimple'].includes(this.model.get('PIPELINENAME')) && this.type.includes('autoPROC')) { |
| 104 | + warning = ' Cannot rerun ' + this.model.get('PIPELINENAME') + ' on ' + this.type + ' results' |
| 105 | + btns = this.disabledButtons |
| 106 | + } |
| 107 | + if (['MrBUMP', 'Big EP'].includes(this.model.get('PIPELINENAME')) && this.type.includes('fast_dp')) { |
| 108 | + warning = ' Cannot rerun ' + this.model.get('PIPELINENAME') + ' on ' + this.type + ' results' |
| 109 | + btns = this.disabledButtons |
| 110 | + } |
| 111 | + if (this.model.get('PIPELINENAME') === 'Dimple' && this.pdbs.length === 0) { |
| 112 | + warning = ' Cannot run Dimple as no PDBs defined' |
| 113 | + btns = this.disabledButtons |
| 114 | + } |
| 115 | + if (this.model.get('PIPELINENAME') === 'MrBUMP' && this.model.get('HASSEQ') === 'No') { |
| 116 | + warning = ' Cannot run MrBUMP as no sequence defined' |
| 117 | + btns = this.disabledButtons |
| 118 | + } |
| 119 | + if (this.model.get('PIPELINENAME') === 'Fast EP' && (!this.model.get('ANOMALOUSSCATTERER'))) { |
| 120 | + warning = ' Cannot run Fast EP as no anomalous scatterer defined' |
| 121 | + btns = this.disabledButtons |
| 122 | + } |
| 123 | + if (this.model.get('PIPELINENAME') === 'Big EP' && this.model.get('HASSEQ') === 'No') { |
| 124 | + warning = ' Cannot run Big EP as no sequence defined' |
| 125 | + btns = this.disabledButtons |
| 126 | + } |
| 127 | + if (this.model.get('PIPELINENAME') === 'Big EP' && (!this.model.get('ANOMALOUSSCATTERER'))) { |
| 128 | + warning = ' Cannot run Big EP as no anomalous scatterer defined' |
| 129 | + btns = this.disabledButtons |
| 130 | + } |
| 131 | + this.setButtons(btns) |
| 132 | + this.ui.warning.html(warning) |
| 133 | + }, |
| 134 | + |
| 135 | + submit: function(e) { |
| 136 | + e.preventDefault() |
| 137 | + |
| 138 | + this._enqueue({ RECIPE: this.model.get('PIPELINE'), DATACOLLECTIONID: this.model.get('ID'), SCALINGID: this.scalingid }) |
| 139 | + app.message({ message: 'Downstream processing job successfully submitted'}) |
| 140 | + |
| 141 | + }, |
| 142 | + |
| 143 | + |
| 144 | + _enqueue: function(options) { |
| 145 | + Backbone.ajax({ |
| 146 | + url: app.apiurl+'/process/enqueue/downstream', |
| 147 | + method: 'POST', |
| 148 | + data: { |
| 149 | + DATACOLLECTIONID: options.DATACOLLECTIONID, |
| 150 | + SCALINGID: options.SCALINGID, |
| 151 | + RECIPE: options.RECIPE |
| 152 | + }, |
| 153 | + }) |
| 154 | + }, |
| 155 | + |
| 156 | + |
| 157 | + initialize: function(options) { |
| 158 | + this.proteins = new Proteins(null, { queryParams: { sid: options.model.get('BLSAMPLEID') } }) |
| 159 | + this._ready = this.proteins.fetch() |
| 160 | + this._ready.done(this.doOnReady.bind(this)) |
| 161 | + this.scalingid = options.scalingid |
| 162 | + this.type = options.type |
| 163 | + this.attachments = new AutoProcAttachments() |
| 164 | + this.attachments.queryParams = { |
| 165 | + AUTOPROCPROGRAMID: options.autoprocprogramid, |
| 166 | + filetype: 'Result', |
| 167 | + } |
| 168 | + this.attachments.fetch() |
| 169 | + }, |
| 170 | + |
| 171 | + onRender: function() { |
| 172 | + |
| 173 | + this.pipelines = new Pipelines([ |
| 174 | + { NAME: 'Dimple', VALUE: 'trigger-dimple' }, |
| 175 | + { NAME: 'Fast EP', VALUE: 'trigger-fastep' }, |
| 176 | + { NAME: 'Big EP', VALUE: 'trigger-bigep' }, |
| 177 | + { NAME: 'MrBUMP', VALUE: 'trigger-mrbump' }, |
| 178 | + ]) |
| 179 | + |
| 180 | + this.ui.pipeline.html(this.pipelines.opts()) |
| 181 | + }, |
| 182 | + |
| 183 | + doOnReady: function() { |
| 184 | + var protein = this.proteins.at(0) |
| 185 | + var self = this |
| 186 | + _.each(['ACRONYM','PROTEINID','HASSEQ','PDBS','ANOMALOUSSCATTERER'], function(k) { |
| 187 | + self.model.set(k, protein.get(k)) |
| 188 | + }) |
| 189 | + this.pdbs = new PDBs(null, { pid: this.model.get('PROTEINID') }) |
| 190 | + this.pdbs.fetch().done(this.updatePipeline.bind(this)) |
| 191 | + this.collection = new IDDataCollections() |
| 192 | + if (this.model) { |
| 193 | + var nm = new IDDataCollection(this.model.toJSON()) |
| 194 | + nm.set('CID', this.collection.length+1) |
| 195 | + this.collection.add(nm) |
| 196 | + } |
| 197 | + this.distlview = new DCDistlsView({ collection: this.collection, pipelines: this.pipelines }) |
| 198 | + this.dcr.show(this.distlview) |
| 199 | + } |
| 200 | + |
| 201 | + |
| 202 | + }) |
| 203 | + |
| 204 | +}) |
0 commit comments