Skip to content

Commit

Permalink
download dense data fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
sorenwacker committed Aug 15, 2023
1 parent 3ba83dc commit ab1946a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
2 changes: 1 addition & 1 deletion ms_mint_app/plugins/ms_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def outputs(self):
dbc.Col(
[
dbc.Button("Convert selected files to Feather", id="ms-convert"),
dbc.Button("Convert selected files to Parquet", id="ms-convert-parquet"),
# dbc.Button("Convert selected files to Parquet", id="ms-convert-parquet"),
]
),
dbc.Col(
Expand Down
23 changes: 17 additions & 6 deletions ms_mint_app/plugins/processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@

from .. import tools as T
from ..plugin_interface import PluginInterface
from dash import dcc

from ms_mint.standards import RESULTS_COLUMNS


class ProcessingPlugin(PluginInterface):
Expand All @@ -35,14 +37,20 @@ def outputs(self):

_label = "Processing"

_property_options = T.list_to_options(RESULTS_COLUMNS)

_layout = html.Div(
[
html.H3("Run MINT"),
dbc.Row([
dbc.Col(dbc.Button("Run MINT", id="run-mint", style={"width": "100%"})),
dbc.Col(dbc.Button("Download all results", id="res-download", style={"width": "100%"}, color='secondary')),
dbc.Col(dbc.Button("Download dense peak_max", id="res-download-peakmax", style={"width": "100%"}, color='secondary')),
dbc.Col(html.Div([
dbc.Button("Download dense matrix", id="res-download-peakmax", style={"width": "100%"}, color='secondary'),
dcc.Dropdown(id='proc-download-property', options=_property_options, value='peak_area_top3'),
dcc.Checklist(id='proc-download-options', options=['Transposed']),
])
),
dbc.Col(dbc.Button("Delete results", id="res-delete", style={"width": "100%"}, color='danger')),
])
]
Expand Down Expand Up @@ -84,10 +92,12 @@ def heat_delete(n_clicks, wdir):
Output("res-download-data", "data"),
Input("res-download", "n_clicks"),
Input("res-download-peakmax", "n_clicks"),
State("proc-download-property", "value"),
State('proc-download-options', 'value'),
State("wdir", "children"),
]
)
def download_results(n_clicks, n_clicks_peakmax, wdir):
def download_results(n_clicks, n_clicks_peakmax, property, options, wdir):
if (n_clicks is None) and (n_clicks_peakmax is None):
raise PreventUpdate
ctx = dash.callback_context
Expand All @@ -98,18 +108,19 @@ def download_results(n_clicks, n_clicks_peakmax, wdir):
fn = T.get_results_fn(wdir)
workspace = os.path.basename(wdir)
return [
send_file(fn, filename=f"{T.today()}-MINT__{workspace}__results.csv")
send_file(fn, filename=f"{T.today()}-MINT__{workspace}-long.csv")
]

elif prop_id == "res-download-peakmax.n_clicks":
workspace = os.path.basename(wdir)
results = T.get_results(wdir)
df = results.pivot_table("peak_max", "peak_label", "ms_file")
df.columns = [P(x).with_suffix("") for x in df.columns]
df = results.pivot_table(property, "ms_file_label", "peak_label")
if options is not None and 'Transposed' in options:
df = df.T
buffer = T.df_to_in_memory_excel_file(df)
return [
send_bytes(
buffer, filename=f"{T.today()}-MINT__{workspace}__results_peak-max.xlsx"
buffer, filename=f"{T.today()}-MINT__{workspace}__results_{property}.xlsx"
)
]

Expand Down
2 changes: 1 addition & 1 deletion ms_mint_app/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,7 @@ def df_to_in_memory_excel_file(df):
def to_xlsx(bytes_io):
xslx_writer = pd.ExcelWriter(bytes_io, engine="xlsxwriter")
df.to_excel(xslx_writer, index=True, sheet_name="sheet1")
xslx_writer.save()
xslx_writer.close()

return to_xlsx

Expand Down

0 comments on commit ab1946a

Please sign in to comment.