def _build_sample_summary(study_id, user_id): """Builds the row object for SlickGrid Parameters ---------- study_id : int Study to get samples from user_id : str User requesting the information Returns ------- columns : dicts keys represent fields and values names for the columns in SlickGrid rows : list of dicts [ {field_1: 'value', ...}, ...] """ # Load all samples available into dictionary and set rows = {s: {'sample': s} for s in sample_template_samples_get_req( study_id, user_id)['samples']} samples = rows.keys() # Add one column per prep template highlighting what samples exist preps = study_prep_get_req(study_id, user_id)["info"] columns = {} for preptype in preps: for prep in preps[preptype]: field = "prep%d" % prep["id"] name = "%s (%d)" % (prep["name"], prep["id"]) columns[field] = name prep_samples = prep_template_samples_get_req( prep['id'], user_id)['samples'] for s in samples: rows[s][field] = 'X' if s in prep_samples else '' return columns, rows
def _build_sample_summary(study_id, user_id): """Builds the initial table of samples associated with prep templates Parameters ---------- study_id : int Study to get samples from user_id : str User requesting the information Returns ------- columns : list of dict SlickGrid formatted list of columns samples_table : list of dict SlickGrid formatted table information """ # Load all samples available into dictionary and set samps_table = { s: { 'sample': s } for s in sample_template_samples_get_req(study_id, user_id)['samples'] } all_samps = set(samps_table.keys()) columns = [{ "id": "sample", "name": "Sample", "field": "sample", "width": 240, "sortable": False }] # Add one column per prep template highlighting what samples exist preps = study_prep_get_req(study_id, user_id)["info"] for dt in preps: for prep in preps[dt]: col_field = "prep%d" % prep["id"] col_name = "%s - %d" % (prep["name"], prep["id"]) columns.append({ "id": col_field, "name": col_name, "field": col_field, "sortable": False, "width": 240 }) prep_samples = prep_template_samples_get_req(prep['id'], user_id)['samples'] # Empty cell for samples not in the prep template for s in all_samps.difference(prep_samples): samps_table[s][col_field] = "" # X in cell for samples in the prep template for s in all_samps.intersection(prep_samples): samps_table[s][col_field] = "X" return columns, samps_table.values()
def get(self): study_id = to_int(self.get_argument('study_id')) # Retrieve the prep template information for the menu prep_info = study_prep_get_req(study_id, self.current_user.id) # Make sure study exists if prep_info['status'] != 'success': raise HTTPError(404, prep_info['message']) prep_info = prep_info['info'] self.render('study_ajax/data_type_menu.html', prep_info=prep_info, study_id=study_id)
def _build_sample_summary(study_id, user_id): """Builds the initial table of samples associated with prep templates Parameters ---------- study_id : int Study to get samples from user_id : str User requesting the information Returns ------- columns : list of dict SlickGrid formatted list of columns samples_table : list of dict SlickGrid formatted table information """ # Load all samples available into dictionary and set samps_table = {s: {'sample': s} for s in sample_template_samples_get_req( study_id, user_id)['samples']} all_samps = set(samps_table.keys()) columns = [{"id": "sample", "name": "Sample", "field": "sample", "width": 240, "sortable": False}] # Add one column per prep template highlighting what samples exist preps = study_prep_get_req(study_id, user_id)["info"] for dt in preps: for prep in preps[dt]: col_field = "prep%d" % prep["id"] col_name = "%s - %d" % (prep["name"], prep["id"]) columns.append({"id": col_field, "name": col_name, "field": col_field, "sortable": False, "width": 240}) prep_samples = prep_template_samples_get_req( prep['id'], user_id)['samples'] # Empty cell for samples not in the prep template for s in all_samps.difference(prep_samples): samps_table[s][col_field] = "" # X in cell for samples in the prep template for s in all_samps.intersection(prep_samples): samps_table[s][col_field] = "X" return columns, samps_table.values()