From a3b1cce73ad1700071bfbd1d40a137eabf71f93e Mon Sep 17 00:00:00 2001 From: Nader Morshed Date: Mon, 13 Nov 2017 15:12:50 -0500 Subject: [PATCH] Block interface during CSV export --- ChangeLog.md | 6 ++ package.json | 2 +- src/io/spectra.jsx | 23 +++-- src/ui/ModalBoxes/ModalExportBox.jsx | 63 +++++++++--- src/ui/ViewBox.jsx | 138 +++++++++++++-------------- 5 files changed, 133 insertions(+), 99 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index 7f9f5ba..27ae8ac 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,5 +1,11 @@ # Change Log +## 0.16.1 (2017-11-13) + +Features + + - Block interface during CSV export. + ## 0.16.0 (2017-11-10) Features diff --git a/package.json b/package.json index 66c6f91..4c56ff4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "camv", - "version": "0.16.0", + "version": "0.16.1", "main": "src/main.js", "productName": "CAMV", "dependencies": { diff --git a/src/io/spectra.jsx b/src/io/spectra.jsx index a92b55f..cfbf554 100644 --- a/src/io/spectra.jsx +++ b/src/io/spectra.jsx @@ -36,7 +36,7 @@ exports.spectraToImage = async function(vb, dirName, export_spectras) { let current_node = vb.getSelectedNode() - vb.iterate_spectra( + await vb.iterate_spectra( export_spectras, async function(nodes, row, resolve) { let name = Array.from( @@ -68,17 +68,16 @@ exports.spectraToImage = async function(vb, dirName, export_spectras) { } ) }, - () => { - vb.setState({exporting: false}) - win.setResizable(true) + ) - if (maximized) { - win.maximize() - } else { - win.setSize(sizes.width, sizes.height) - } + vb.setState({exporting: false}) + win.setResizable(true) - vb.updateAll(current_node) - }, - ) + if (maximized) { + win.maximize() + } else { + win.setSize(sizes.width, sizes.height) + } + + vb.updateAll(current_node) } diff --git a/src/ui/ModalBoxes/ModalExportBox.jsx b/src/ui/ModalBoxes/ModalExportBox.jsx index 69c19cc..edbde73 100644 --- a/src/ui/ModalBoxes/ModalExportBox.jsx +++ b/src/ui/ModalBoxes/ModalExportBox.jsx @@ -1,9 +1,14 @@ +import fs from 'fs' +import path from 'path' + import React from 'react' import PropTypes from 'prop-types' import { Modal, Checkbox, Button } from 'react-bootstrap' import { remote } from 'electron' +import { exportCSV } from '../../io/csv.jsx' + class ModalExportBox extends React.Component { constructor(props) { super(props) @@ -14,6 +19,8 @@ class ModalExportBox extends React.Component { exportMaybeSpectra: false, exportRejectSpectra: false, exportTables: true, + + processing: false, } } @@ -31,7 +38,7 @@ class ModalExportBox extends React.Component { component.setState({ dirChosen: true, - exportDirectory: dirName[0] + exportDirectory: dirName[0], }) } ) @@ -42,16 +49,46 @@ class ModalExportBox extends React.Component { } export() { - this.props.exportCallback( - this.state.exportDirectory, - [ - this.state.exportAcceptSpectra, - this.state.exportMaybeSpectra, - this.state.exportRejectSpectra - ], - this.state.exportTables - ); - this.close(); + this.setState( + { + processing: true, + }, + () => { + fs.mkdir( + this.state.exportDirectory, + async function() { + if (this.state.exportTables) { + await exportCSV( + this.props.viewbox, + path.join( + this.state.exportDirectory, + this.props.viewbox.state.basename + ".csv", + ) + ) + } + + this.setState( + { + processing: false, + }, + () => { + this.props.exportCallback( + this.state.exportDirectory, + [ + this.state.exportAcceptSpectra, + this.state.exportMaybeSpectra, + this.state.exportRejectSpectra + ], + this.state.exportTables, + ); + + this.close(); + } + ) + }.bind(this) + ) + } + ) } render() { @@ -125,13 +162,14 @@ class ModalExportBox extends React.Component { @@ -145,6 +183,7 @@ ModalExportBox.propTypes = { exportCallback: PropTypes.func.isRequired, closeCallback: PropTypes.func.isRequired, showModal: PropTypes.bool.isRequired, + viewbox: PropTypes.object.isRequired, } module.exports = ModalExportBox diff --git a/src/ui/ViewBox.jsx b/src/ui/ViewBox.jsx index 7568f63..59da90b 100644 --- a/src/ui/ViewBox.jsx +++ b/src/ui/ViewBox.jsx @@ -594,7 +594,7 @@ class ViewBox extends React.Component { }) } - async iterate_spectra(export_spectras, cb, cb_done) { + async iterate_spectra(export_spectras, cb) { while (export_spectras.length < 4) { export_spectras.push(false) } @@ -611,65 +611,68 @@ class ViewBox extends React.Component { if (export_spectras[1]) { params.push("maybe") } if (export_spectras[2]) { params.push("reject") } - this.state.db.all( - `SELECT \ - protein_sets.protein_set_id, protein_sets.protein_set_name, \ - protein_sets.protein_set_accession, protein_sets.protein_set_uniprot, \ - peptides.peptide_id, peptides.peptide_seq, \ - peptides.protein_set_offsets, \ - mod_states.mod_state_id, mod_states.mod_desc, \ - scans.scan_id, scans.scan_num, \ - scan_ptms.ptm_id, scan_ptms.choice, scan_ptms.mascot_score, \ - ptms.name \ - \ - FROM scan_ptms \ - \ - INNER JOIN scans \ - ON scan_ptms.scan_id=scans.scan_id \ - \ - JOIN ptms \ - ON scan_ptms.ptm_id=ptms.ptm_id \ - \ - JOIN mod_states \ - ON ptms.mod_state_id=mod_states.mod_state_id \ - \ - JOIN peptides \ - ON mod_states.peptide_id=peptides.peptide_id \ - \ - INNER JOIN protein_sets \ - ON protein_sets.protein_set_id=peptides.protein_set_id \ - \ - WHERE \ - scan_ptms.choice IN (${params.map(i => '?').join(', ')}) \ - ${export_spectras[3] ? 'OR scan_ptms.choice IS NULL': ''} \ - \ - ORDER BY \ - protein_sets.protein_set_name, peptides.peptide_seq, \ - mod_states.mod_desc, ptms.name`, - params, - async function(err, rows) { - if (err != null || rows == null) { - console.error(err) - return - } + return new Promise( + (final_resolve, final_reject) => { + this.state.db.all( + `SELECT \ + protein_sets.protein_set_id, protein_sets.protein_set_name, \ + protein_sets.protein_set_accession, protein_sets.protein_set_uniprot, \ + peptides.peptide_id, peptides.peptide_seq, \ + peptides.protein_set_offsets, \ + mod_states.mod_state_id, mod_states.mod_desc, \ + scans.scan_id, scans.scan_num, \ + scan_ptms.ptm_id, scan_ptms.choice, scan_ptms.mascot_score, \ + ptms.name \ + \ + FROM scan_ptms \ + \ + INNER JOIN scans \ + ON scan_ptms.scan_id=scans.scan_id \ + \ + JOIN ptms \ + ON scan_ptms.ptm_id=ptms.ptm_id \ + \ + JOIN mod_states \ + ON ptms.mod_state_id=mod_states.mod_state_id \ + \ + JOIN peptides \ + ON mod_states.peptide_id=peptides.peptide_id \ + \ + INNER JOIN protein_sets \ + ON protein_sets.protein_set_id=peptides.protein_set_id \ + \ + WHERE \ + scan_ptms.choice IN (${params.map(i => '?').join(', ')}) \ + ${export_spectras[3] ? 'OR scan_ptms.choice IS NULL': ''} \ + \ + ORDER BY \ + protein_sets.protein_set_name, peptides.peptide_seq, \ + mod_states.mod_desc, ptms.name`, + params, + async function(err, rows) { + if (err != null || rows == null) { + console.error(err) + final_reject() + return + } - for (let row of rows) { - let nodes = [ - [row.protein_set_id], - [row.peptide_id, row.mod_state_id], - [row.scan_id], - [row.ptm_id], - ] + for (let row of rows) { + let nodes = [ + [row.protein_set_id], + [row.peptide_id, row.mod_state_id], + [row.scan_id], + [row.ptm_id], + ] - row.protein_set_offsets = row.protein_set_offsets.split(";") - .map(i => parseInt(i)) + row.protein_set_offsets = row.protein_set_offsets.split(";") + .map(i => parseInt(i)) - await new Promise(resolve => cb(nodes, row, resolve)) - } + await new Promise(resolve => cb(nodes, row, resolve)) + } - if (cb_done != null) { - cb_done() - } + final_resolve() + }, + ) }, ) } @@ -679,25 +682,11 @@ class ViewBox extends React.Component { modalExportOpen: false, }) - if (exportTables || export_spectras.some(i => i)) { - fs.mkdir( - dirName, - () => { - if (exportTables) { - exportCSV( - this, - path.join(dirName, this.state.basename + ".csv") - ) - } - - if (!export_spectras.some(i => i)) { - return - } - - spectraToImage(this, dirName, export_spectras) - } - ) + if (!export_spectras.some(i => i)) { + return } + + spectraToImage(this, dirName, export_spectras) } async getBase(node) { @@ -1235,6 +1224,7 @@ class ViewBox extends React.Component { showModal={this.state.modalExportOpen} closeCallback={this.closeExportModal.bind(this)} exportCallback={this.runExport.bind(this)} + viewbox={this} />