Skip to content

Commit

Permalink
Reverting back to storage of raw data in a separate store
Browse files Browse the repository at this point in the history
  • Loading branch information
npalacioescat committed Nov 17, 2024
1 parent 6659617 commit 35a6748
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 15 deletions.
1 change: 1 addition & 0 deletions src/funki/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
app.layout = html.Div(
children=[
dcc.Store(id='data', storage_type=storage_type),
dcc.Store(id='raw', storage_type=storage_type),
html.Div(
html.Img(
src='assets/logos/funki_logo.svg',
Expand Down
11 changes: 7 additions & 4 deletions src/funki/pages/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@

@callback(
Output('data', 'data', allow_duplicate=True),
Output('raw', 'data', allow_duplicate=True),
Input('upload-data', 'contents'),
State('upload-data', 'filename'),
State('separator-data', 'value'),
Expand All @@ -225,19 +226,20 @@ def load_data(content, filename, sep):
df = parse_contents(content, filename, sep=sep).astype(np.float32)

serial = dataframe_to_serial(df)
serial.update({'raw': dataframe_to_serial(df.copy())})

return serial
return serial, serial.copy()

@callback(
Output('data', 'data', allow_duplicate=True),
Output('raw', 'data', allow_duplicate=True),
Input('upload-obs', 'contents'),
State('upload-obs', 'filename'),
State('data', 'data'),
State('raw', 'data'),
State('separator-obs', 'value'),
prevent_initial_call=True
)
def load_obs(content, filename, data, sep):
def load_obs(content, filename, data, raw, sep):
if filename is None:
raise PreventUpdate

Expand All @@ -246,8 +248,9 @@ def load_obs(content, filename, data, sep):

serial = dataframe_to_serial(parse_contents(content, filename, sep=sep))
data.update({'obs': serial})
raw.update({'obs': serial.copy()})

return data
return data, raw

@callback(
Output('table-data', 'columns'),
Expand Down
10 changes: 6 additions & 4 deletions src/funki/pages/difexp.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,20 +158,22 @@ def update_group_selector(data, obs_var, va, vb):
Output('plot-dex', 'figure'),
Input('apply-dex', 'n_clicks'),
State('data', 'data'),
State('raw', 'data'),
State('obs-selector', 'value'),
State('group-selector-a', 'value'),
State('group-selector-b', 'value'),
prevent_initial_call=True
)
def apply_dex(n_clicks, data, obs_var, groups_a, groups_b):
def apply_dex(n_clicks, data, raw, obs_var, groups_a, groups_b):
if data is None:
raise PreventUpdate

if not all([obs_var, groups_a, groups_b]):
raise PreventUpdate

dset_raw = serial_to_dataset(data['raw'])
dset_raw.obs = serial_to_dataframe(data['obs'])
dset_raw = serial_to_dataset(raw)
if 'obs' in raw.keys():
dset_raw.obs = serial_to_dataframe(raw['obs'])

# Retrieve var as dataframe if available
if 'var' in data.keys():
Expand All @@ -182,7 +184,7 @@ def apply_dex(n_clicks, data, obs_var, groups_a, groups_b):

# Re-applying filters to raw data if any
if 'uns' in data:
uns = uns = data['uns']['funki']['sc_trans_filter']
uns = data['uns']['funki']['sc_trans_filter']
dset_raw = fpp.sc_trans_filter(
dset_raw,
min_genes=uns['min_genes'] if 'min_genes' in uns.keys() else None,
Expand Down
1 change: 1 addition & 0 deletions src/funki/pages/norm.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ def apply_filter(n_clicks, data, max_genes, min_genes, mito_pct):
raise PreventUpdate

dset = serial_to_dataset(data)

dset = fpp.sc_trans_filter(
dset,
min_genes=min_genes,
Expand Down
9 changes: 2 additions & 7 deletions src/funki/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,9 @@ def serial_to_dataset(data):
if k in data.keys()
})

if 'raw' in data.keys():
kwargs.update({'raw': serial_to_dataset(data['raw'])})
dset = DataSet(df.astype(np.float32), **kwargs)

return DataSet(df.astype(np.float32), **kwargs)
return dset

def dataset_to_serial(dset):
data = dataframe_to_serial(dset.to_df())
Expand All @@ -82,10 +81,6 @@ def dataset_to_serial(dset):
if not getattr(dset, k).empty
})

if 'raw' in dset.__dict__.keys():
df = pd.DataFame(dset.raw.X, columns=dset.raw.var)
data['raw'] = dataframe_to_serial(df)

attrs = {}

for k in ('obsm', 'varm', 'obsp', 'varp'):
Expand Down

0 comments on commit 35a6748

Please sign in to comment.