fohrloop / dash-uploader

The alternative upload component for python Dash applications.
MIT License
141 stars 29 forks source link

Server files overlapping #116

Closed divya-thota closed 1 year ago

divya-thota commented 1 year ago

I hosted the code onto the server and when two different users upload two different files simultaneously, the retrieved details show that the files are overlapped. It does not cause this issue when a single user uploads a file, but only happens when multiple users upload their files. This is my code:

@du.callback( [Output('adata-path', 'data'), Output('session-id', 'data'), Output('preprocessing-div', 'style'), Output('dash-uploader','disabled'), Output('dash-uploader','disabledMessage')], id='dash-uploader', ) def get_adata(filename): print(filename) filename = filename[0] if '\' in filename: filename = filename.replace('\', '/') foldarpath = filename.rsplit('/', 1)[0] if filename.endswith('h5ad'): adata = sc.read(filename) adata.write(foldarpath+'/adata.h5ad') elif filename.endswith('zip'): with ZipFile(filename, 'r') as zip: zip.extractall(foldarpath) adata = sc.read_10x_mtx( Path(filename.replace('.zip','')), var_names='gene_symbols', cache=False) adata.write(foldarpath + '/adata.h5ad') elif filename.endswith('h5'): adata = sc.read_10x_h5(filename) adata.write(foldarpath + '/adata.h5ad') return foldarpath + '/adata.h5ad', filename.split('/')[1], {'display': 'block'}, True, 'Uploaded: '+filename.rsplit('/', 1)[1]

@app.callback( Output('genes', 'data'), Output('obsmdf', 'data'), Output('adata-div','style'), Output('gene', 'options'), Output('gene', 'value'), Output('scatter-plot', 'style'), State('adata-path', 'data'), Input('preprocessing-button','n_clicks'), State('svd_solver','value'), State('n_neighbors','value'), State('scatter-plot-div', 'children')) def preprocess_adata(adata_path, n, svd_solver, n_neighbors, children): if n is None: return dash.no_update else: adata = sc.read(adata_path) print("Preprocessing annData file...") adata.var_names_make_unique() print("Normalize annData file...") sc.pp.normalize_total(adata, target_sum=1e4) print("Logarithmize annData file...") sc.pp.log1p(adata) sc.pp.highly_variable_genes(adata, min_mean=0.0125, max_mean=3, min_disp=0.5) print("Perform principle component analysis...") sc.tl.pca(adata, svd_solver=svd_solver) print("Compute neighbors...") sc.pp.neighbors(adata, n_neighbors=n_neighbors, knn=True, n_pcs=40) print("Uniform Manifold Approximation and Projection for Dimension Reduction...") sc.tl.umap(adata) adata.write(adata_path) obsmdf = adata.obsm.to_df() genes = pd.DataFrame(adata.var.gene_ids) gene_ids = genes['gene_ids'].to_numpy() return genes.to_json(), obsmdf.to_json(), {'display': 'none'}, gene_ids, gene_ids[0], {'display': 'block'}