def _category_values(category, repo): if category in repo.categories: values = repo.category_values(category) return jsonify(values), 200 else: text = f"Metadata category: '{category}' does not exist." return jsonify(text=text, error=404), 404
def dataset_detail(dataset): resources = get_resources() dataset_key = 'datasets' detail_key = '__dataset_detail__' if dataset_key not in resources: return jsonify({}), 404 detail = resources[dataset_key].get(dataset) if detail is None: return jsonify({'message': f"{dataset} not found"}), 404 return jsonify({dataset: detail[detail_key]}), 200
def available(): resources = get_resources() escape = {schema.metadata_kw} dataset_key = 'datasets' detail_key = '__dataset_detail__' if dataset_key not in resources: return jsonify({}), 200 datasets = {} for k, v in resources[dataset_key].items(): if k in escape: continue datasets[k] = v.get(detail_key) return jsonify(datasets), 200
def _plot_alpha_percentiles_querybuilder(alpha_metric, percentiles, query, repo, sample_id, alpha_repo_getter): matching_ids = _filter_ids(repo, alpha_repo_getter(), alpha_metric, query, sample_id) if len(matching_ids) <= 1: return jsonify(text='Did not find more than 1 ID\'s matching ' 'request. Plot would be nonsensical.'), 422 alpha_summary, sample_diversity = _get_alpha_info( alpha_metric, matching_ids, percentiles, sample_id, alpha_repo_getter, ) chart = _plot_percentiles_plot(alpha_metric, alpha_summary, sample_diversity) return jsonify(**chart.to_dict()), 200
def _plot_alpha_percentiles_querybuilder(alpha_metric, percentiles, query, repo, sample_id): error_code, error_response, matching_ids = _filter_ids( repo, alpha_metric, query, sample_id) # TODO ideally these would raise an exception lower in the stack and # then be handled by an exception handler, but for now they are clunky # to refactor due to execution flow interruption if error_response: return error_response, error_code if len(matching_ids) <= 1: return jsonify(text='Did not find more than 1 ID\'s matching ' 'request. Plot would be nonsensical.'), 422 alpha_summary, sample_diversity = _get_alpha_info(alpha_metric, matching_ids, percentiles, sample_id) chart = _plot_percentiles_plot(alpha_metric, alpha_summary, sample_diversity) return jsonify(**chart.to_dict()), 200
def _filter_sample_ids(query, repo, alpha_metric, taxonomy): matching_ids = repo.sample_id_matches(query) matching_ids, error_code, error_response = _filter_matching_ids( matching_ids, TaxonomyRepo, 'resources', taxonomy, 'resource', ) matching_ids, error_code, error_response = _filter_matching_ids( matching_ids, AlphaRepo, 'available_metrics', alpha_metric, 'metric', error_response=error_response, error_code=error_code, ) if error_response: return error_response, error_code return jsonify(sample_ids=matching_ids), 200
def categories(): repo = _get_repo() return jsonify(repo.categories), 200
def get_metadata_values_alt(body, dataset, cat): repo = _get_repo_alt(dataset) # check all categories are valid metadata = _get_metadata_values(body, cat, repo) return jsonify(metadata.values.tolist()), 200
def _validate_query(dict_, repo): categories = set(repo.categories) for id_ in dict_: if id_ not in categories: text = f"Metadata category: '{id_}' does not exist." return jsonify(text=text, error=404), 404
def categories_alt(dataset): repo = _get_repo_alt(dataset) return jsonify(repo.categories), 200