Skip to content

Commit

Permalink
Block interface during CSV export
Browse files Browse the repository at this point in the history
  • Loading branch information
naderm committed Nov 13, 2017
1 parent c2afb49 commit a3b1cce
Show file tree
Hide file tree
Showing 5 changed files with 133 additions and 99 deletions.
6 changes: 6 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "camv",
"version": "0.16.0",
"version": "0.16.1",
"main": "src/main.js",
"productName": "CAMV",
"dependencies": {
Expand Down
23 changes: 11 additions & 12 deletions src/io/spectra.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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)
}
63 changes: 51 additions & 12 deletions src/ui/ModalBoxes/ModalExportBox.jsx
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -14,6 +19,8 @@ class ModalExportBox extends React.Component {
exportMaybeSpectra: false,
exportRejectSpectra: false,
exportTables: true,

processing: false,
}
}

Expand All @@ -31,7 +38,7 @@ class ModalExportBox extends React.Component {

component.setState({
dirChosen: true,
exportDirectory: dirName[0]
exportDirectory: dirName[0],
})
}
)
Expand All @@ -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() {
Expand Down Expand Up @@ -125,13 +162,14 @@ class ModalExportBox extends React.Component {
</Modal.Body>
<Modal.Footer>
<Button
disabled={!this.state.dirChosen}
disabled={!this.state.dirChosen || this.state.processing}
onClick={this.export.bind(this)}
>
Export
</Button>
<Button
onClick={this.close.bind(this)}
disabled={this.state.processing}
>
Cancel
</Button>
Expand All @@ -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
138 changes: 64 additions & 74 deletions src/ui/ViewBox.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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()
},
)
},
)
}
Expand All @@ -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) {
Expand Down Expand Up @@ -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}
/>
<ModalSearchBox
ref="modalSearchBox"
Expand Down

0 comments on commit a3b1cce

Please sign in to comment.