def store_file_meta_data( contents, filename, dataset_name ): desc = '' subsets = [] row_options = [] col_options = [] if dataset_name is not None: dataset = datasets[dataset_name] if dataset['file'].endswith('.tsv'): desc, row_options, col_options = \ gene_expression_reader.read_tsv_file( filepath=dataset['file'], index_column=dataset['row_labels_source'], ignore_columns=dataset['ignore_columns'] ) subsets = None elif dataset['file'].endswith('.soft'): desc, subsets, row_options, col_options = \ gene_expression_reader.read_soft(dataset['file']) elif contents is not None: content_type, content_string = contents.split(',') decoded = base64.b64decode(content_string).decode('UTF-8') try: desc, subsets, row_options, col_options = \ gene_expression_reader.read_soft( decoded, is_datafile=False ) except Exception: pass return { 'desc': desc, 'subsets': subsets, 'row_options': row_options, 'col_options': col_options }
def display_clustergram(_, group_markers, sel_rows, sel_cols, fig_opts, dataset_name, contents, filename, computed_traces): ctx = dash.callback_context adding_grp_marker = ctx.triggered[0]['prop_id'].split( '.')[0] == 'group-markers' wrapper_content = '' curves = None comp_traces = computed_traces if len(sel_rows) < 2 or len(sel_cols) < 2 and \ dataset_name is None and contents is None: wrapper_content = html.Div( 'No data have been selected to display. Please upload a file \ or select a preloaded file from the dropdown, then select at \ least two columns and two rows.', style={ 'padding': '40px', 'font-size': '20pt' }) return wrapper_content, curves, comp_traces if fig_opts['cluster'] is None or len(fig_opts['cluster']) == 0: wrapper_content = html.Div( 'No dimension has been selected along which to perform \ clustering. \ Please select at least one option from the dropdown.', style={ 'padding': '30px', 'font-size': '20pt' }) return wrapper_content, curves, comp_traces if dataset_name is not None: dataset = datasets[dataset_name] if dataset['file'].endswith('.tsv'): data = gene_expression_reader.read_tsv_file( filepath=dataset['file'], rows=sel_rows, columns=sel_cols, ignore_columns=dataset['ignore_columns'], index_column=dataset['row_labels_source'], return_filtered_data=True) elif dataset['file'].endswith('.soft'): data = gene_expression_reader.read_soft_file( filepath=dataset['file'], rows=sel_rows, columns=sel_cols, return_filtered_data=True) elif contents is not None and dataset_name is None: content_type, content_string = contents.split(',') decoded = base64.b64decode(content_string).decode('UTF-8') try: data = gene_expression_reader.read_soft_file( contents=decoded, rows=sel_rows, columns=sel_cols, return_filtered_data=True) except Exception: data = None if group_markers is not None: fig_opts['row_group_marker'] = group_markers['row_group_marker'] fig_opts['col_group_marker'] = group_markers['col_group_marker'] try: # don't recompute the dendrogram traces if we're just adding a group # marker if adding_grp_marker and computed_traces is not None: fig, curves = dash_bio.Clustergram( generate_curves_dict=True, computed_traces=computed_traces, data=data, **fig_opts) else: fig, curves, comp_traces = dash_bio.Clustergram( generate_curves_dict=True, return_computed_traces=True, data=data, **fig_opts) wrapper_content = dcc.Graph(id='clustergram', figure=fig) except IndexError: wrapper_content = "Loading data..." except ValueError: wrapper_content = "Loading data..." except Exception as e: wrapper_content = "There was an error: {}".format(e) return wrapper_content, curves, comp_traces