def trait_associations(trait): args = request.args.to_dict() try: start, size, p_lower, p_upper, pval_interval, reveal = apiu._get_basic_arguments( args) except ValueError as error: logging.error("/traits/" + trait + ". " + (str(error))) raise BadUserRequest(str(error)) searcher = search.Search(apiu.properties) try: datasets, index_marker = searcher.search_trait( trait=trait, start=start, size=size, pval_interval=pval_interval) data_dict = apiu._get_array_to_display(datasets=datasets, reveal=reveal) params = dict(trait=trait, p_lower=p_lower, p_upper=p_upper) response = apiu._create_response(method_name='api.get_trait_assocs', start=start, size=size, index_marker=index_marker, data_dict=data_dict, params=params) return simplejson.dumps(response, ignore_nan=True) except NotFoundError as error: logging.error("/traits/" + trait + ". " + (str(error))) raise RequestedNotFound(str(error))
def variant_resource(variant, chromosome=None): args = request.args.to_dict() try: start, size, p_lower, p_upper, pval_interval, reveal = apiu._get_basic_arguments( args) study = apiu._retrieve_endpoint_arguments(args, "study_accession") except ValueError as error: logging.debug("/chromosomes/" + chromosome + "/associations/" + variant + ". " + (str(error))) raise BadUserRequest(str(error)) searcher = search.Search(apiu.properties) try: datasets, index_marker = searcher.search_snp( snp=variant, chromosome=chromosome, start=start, size=size, pval_interval=pval_interval, study=study) data_dict = apiu._get_array_to_display(datasets=datasets, variant=variant, reveal=reveal) params = {'variant_id': variant, 'study_accession': study} if chromosome is not None: params['chromosome'] = chromosome response = apiu._create_resource_response(data_dict=data_dict, params=params) return simplejson.dumps(response, ignore_nan=True) except (NotFoundError, SubgroupError) as error: logging.debug(str(error)) raise RequestedNotFound(str(error))
def chromosome_associations(chromosome): args = request.args.to_dict() try: start, size, p_lower, p_upper, pval_interval, reveal = apiu._get_basic_arguments( args) bp_lower, bp_upper, bp_interval = apiu._get_bp_arguments(args) study = apiu._retrieve_endpoint_arguments(args, 'study_accession') except ValueError as error: logging.error("/chromosomes/" + chromosome + ". " + (str(error))) raise BadUserRequest(str(error)) searcher = search.Search(apiu.properties) try: datasets, index_marker = searcher.search_chromosome( chromosome=chromosome, start=start, size=size, study=study, pval_interval=pval_interval, bp_interval=bp_interval) data_dict = apiu._get_array_to_display(datasets=datasets, chromosome=chromosome, reveal=reveal) return _create_chromosome_response( dict(chromosome=chromosome, data_dict=data_dict, start=start, size=size, index_marker=index_marker, bp_lower=bp_lower, bp_upper=bp_upper, p_lower=p_lower, p_upper=p_upper, study=study)) except NotFoundError as error: logging.error("/chromosomes/" + chromosome + ". " + (str(error))) raise RequestedNotFound(str(error)) except SubgroupError: # we have not found bp in chromosome, return empty collection data_dict = {} index_marker = 0 return _create_chromosome_response( dict(chromosome=chromosome, data_dict=data_dict, start=start, size=size, index_marker=index_marker, bp_lower=bp_lower, bp_upper=bp_upper, p_lower=p_lower, p_upper=p_upper, study=study))
def trait_associations(trait): args = request.args.to_dict() try: start, size, p_lower, p_upper, pval_interval, quant_method, snp, tissue, gene, study, _ , paginate, links, qtl_group = apiu._get_basic_arguments(args) except ValueError as error: logging.error("/molecular_phenotypes/" + trait + ". " + (str(error))) raise BadUserRequest(str(error)) searcher = search.Search(apiu.properties) try: datasets, index_marker, paginate = searcher.search(trait=trait, start=start, size=size, pval_interval=pval_interval, quant_method=quant_method, tissue=tissue, gene=gene, study=study, snp=snp, paginate=paginate, qtl_group=qtl_group) data_dict = apiu._get_array_to_display(datasets=datasets, links=links) params = dict(molecular_trait_id=trait, p_lower=p_lower, p_upper=p_upper, quant_method=quant_method, tissue=tissue, gene_id=gene, study=study, variant_id=snp, qtl_group=qtl_group, links=links) response = apiu._create_response(method_name='api.get_trait_assocs', start=start, size=size, index_marker=index_marker, data_dict=data_dict, params=params) return simplejson.dumps(response, ignore_nan=True) except NotFoundError as error: logging.error("/molecular_phenotypes/" + trait + ". " + (str(error))) raise RequestedNotFound(str(error))
def qtl_groups(): args = request.args.to_dict() try: start, size, p_lower, p_upper, pval_interval, quant_method, snp, _, gene, study, trait, paginate, links, qtl_group = apiu._get_basic_arguments(args) except ValueError as error: logging.error("/qtl_groups. " + (str(error))) raise BadUserRequest(str(error)) explorer = ex.Explorer(apiu.properties) qtls = explorer.get_qtl_list() qtl_list = apiu._get_qtl_list(qtls=qtls, start=start, size=size, links=links) response = apiu._create_response(collection_name='qtl_groups', method_name='api.get_qtl_groups', start=start, size=size, index_marker=size, data_dict=qtl_list) return simplejson.dumps(response)
def variant_resource(variant, chromosome=None): args = request.args.to_dict() try: start, size, p_lower, p_upper, pval_interval, quant_method, _, tissue, gene, study, trait, paginate, links, qtl_group = apiu._get_basic_arguments(args) except ValueError as error: logging.debug("/chromosomes/" + chromosome + "/associations/" + variant + ". " + (str(error))) raise BadUserRequest(str(error)) searcher = search.Search(apiu.properties) try: datasets, index_marker, paginate = searcher.search(snp=variant, chromosome=chromosome, start=start, size=size, pval_interval=pval_interval, study=study, quant_method=quant_method, tissue=tissue, gene=gene, trait=trait, paginate=paginate, qtl_group=qtl_group) data_dict = apiu._get_array_to_display(datasets=datasets, variant=variant, links=links) params = {'variant_id': variant, 'study': study, 'quant_method': quant_method, 'tissue': tissue, 'gene_id': gene, 'molecular_trait_id': trait, 'qtl_group': qtl_group, 'links': links} if chromosome is not None: params['chromosome'] = chromosome response = apiu._create_resource_response(data_dict=data_dict, params=params) print(response) return simplejson.dumps(response, ignore_nan=True) except (NotFoundError, SubgroupError) as error: logging.debug(str(error)) raise RequestedNotFound(str(error))
def chromosome_associations(chromosome): args = request.args.to_dict() try: start, size, p_lower, p_upper, pval_interval, quant_method, snp, tissue, gene, study, trait, paginate, links, qtl_group = apiu._get_basic_arguments(args) bp_lower, bp_upper, bp_interval = apiu._get_bp_arguments(args) except ValueError as error: logging.error("/chromosomes/" + chromosome + ". " + (str(error))) raise BadUserRequest(str(error)) searcher = search.Search(apiu.properties) try: datasets, index_marker, paginate = searcher.search(chromosome=chromosome, start=start, size=size, study=study, snp=snp, pval_interval=pval_interval, bp_interval=bp_interval, quant_method=quant_method, tissue=tissue, gene=gene, trait=trait, paginate=paginate, qtl_group=qtl_group) data_dict = apiu._get_array_to_display(datasets=datasets, chromosome=chromosome, links=links) return _create_chromosome_response(dict(chromosome=chromosome, data_dict=data_dict, start=start, size=size, index_marker=index_marker, bp_lower=bp_lower, bp_upper=bp_upper, variant_id=snp, p_lower=p_lower, p_upper=p_upper, study=study, quant_method=quant_method, tissue=tissue, gene=gene, trait=trait, qtl_group=qtl_group, links=links)) except NotFoundError as error: logging.error("/chromosomes/" + chromosome + ". " + (str(error))) raise RequestedNotFound(str(error)) except SubgroupError: # we have not found bp in chromosome, return empty collection data_dict = {} index_marker = 0 return _create_chromosome_response(dict(chromosome=chromosome, data_dict=data_dict, start=start, size=size, index_marker=index_marker, bp_lower=bp_lower, bp_upper=bp_upper, variant_id=snp, p_lower=p_lower, p_upper=p_upper, study=study, quant_method=quant_method, tissue=tissue, gene=gene, trait=trait, qtl_group=qtl_group, links=links))
def tissue_study_associations(study, tissue=None): args = request.args.to_dict() try: start, size, p_lower, p_upper, pval_interval, quant_method, snp, _, gene, _, trait, paginate, links, qtl_group = apiu._get_basic_arguments(args) except ValueError as error: logging.error("/studies/" + study + ". " + (str(error))) raise BadUserRequest(str(error)) try: #trait = apiu._find_study_info(study=study, trait=trait) searcher = search.Search(apiu.properties) #datasets, index_marker = searcher.search_study(trait=trait, study=study, # start=start, size=size, pval_interval=pval_interval) if tissue: datasets, index_marker, paginate = searcher.search(tissue=tissue, study=study, trait=trait, gene=gene, snp=snp, start=start, size=size, pval_interval=pval_interval, quant_method=quant_method, paginate=paginate, qtl_group=qtl_group) data_dict = apiu._get_array_to_display(datasets=datasets, links=links) params = dict(tissue=tissue, molecular_trait_id=trait, variant_id=snp, study=study, p_lower=p_lower, p_upper=p_upper, gene_id=gene, quant_method=quant_method, qtl_group=qtl_group, links=links) else: datasets, index_marker, paginate = searcher.search(study=study, gene=gene, snp=snp, trait=trait, start=start, size=size, pval_interval=pval_interval, quant_method=quant_method, paginate=paginate, qtl_group=qtl_group) data_dict = apiu._get_array_to_display(datasets=datasets, links=links) params = dict(study=study, p_lower=p_lower, p_upper=p_upper, variant_id=snp, gene_id=gene, molecular_trait_id=trait, quant_method=quant_method, qtl_group=qtl_group, links=links) response = apiu._create_response(method_name='api.get_tissue_study_assocs', start=start, size=size, index_marker=index_marker, data_dict=data_dict, params=params) return simplejson.dumps(response, ignore_nan=True) except (NotFoundError, SubgroupError) as error: logging.error("/studies/" + study + ". " + (str(error))) raise RequestedNotFound(str(error))