def hpo_genes(phenotype_ids, username, password): """Return list of HGNC symbols matching HPO phenotype ids. Args: phenotype_ids (list): list of phenotype ids username (str): username to connect to phenomizer password (str): password to connect to phenomizer Returns: query_result: a list of dictionaries on the form { 'p_value': float, 'gene_id': str, 'omim_id': int, 'orphanet_id': int, 'decipher_id': int, 'any_id': int, 'mode_of_inheritance': str, 'description': str, 'raw_line': str } """ if phenotype_ids: try: results = query_phenomizer.query(username, password, phenotype_ids) return [ result for result in results if result['p_value'] is not None ] except SystemExit, RuntimeError: pass
def hpo_diseases(username, password, hpo_ids, p_value_treshold=1): """Return the list of HGNC symbols that match annotated HPO terms. Args: username (str): username to use for phenomizer connection password (str): password to use for phenomizer connection Returns: query_result: a generator of dictionaries on the form { 'p_value': float, 'disease_source': str, 'disease_nr': int, 'gene_symbols': list(str), 'description': str, 'raw_line': str } """ # skip querying Phenomizer unless at least one HPO terms exists try: results = query_phenomizer.query(username, password, *hpo_ids) diseases = [result for result in results if result["p_value"] <= p_value_treshold] return diseases except SystemExit: return None
def hpo_diseases(username, password, hpo_ids, p_value_treshold=1): """Return the list of HGNC symbols that match annotated HPO terms. Args: username (str): username to use for phenomizer connection password (str): password to use for phenomizer connection Returns: query_result: a generator of dictionaries on the form { 'p_value': float, 'disease_source': str, 'disease_nr': int, 'gene_symbols': list(str), 'description': str, 'raw_line': str } """ # skip querying Phenomizer unless at least one HPO terms exists try: results = query_phenomizer.query(username, password, *hpo_ids) diseases = [result for result in results if result['p_value'] <= p_value_treshold] return diseases except SystemExit: return None
def hpo_genes(phenotype_terms): """Return the list of HGNC symbols that match annotated HPO terms. Returns: query_result: a list of dictionaries on the form { 'p_value': float, 'gene_id': str, 'omim_id': int, 'orphanet_id': int, 'decipher_id': int, 'any_id': int, 'mode_of_inheritance': str, 'description': str, 'raw_line': str } """ hpo_terms = [phenotype_term.phenotype_id for phenotype_term in phenotype_terms] # skip querying Phenomizer unless at least one HPO terms exists if hpo_terms: try: results = query_phenomizer.query(hpo_terms) return [result for result in results if result['p_value'] is not None] except SystemExit: return None else: return None
def hpo_genes(phenotype_ids, username, password): """Return list of HGNC symbols matching HPO phenotype ids. Args: phenotype_ids (list): list of phenotype ids username (str): username to connect to phenomizer password (str): password to connect to phenomizer Returns: query_result: a list of dictionaries on the form { 'p_value': float, 'gene_id': str, 'omim_id': int, 'orphanet_id': int, 'decipher_id': int, 'any_id': int, 'mode_of_inheritance': str, 'description': str, 'raw_line': str } """ if phenotype_ids: try: results = query_phenomizer.query(username, password, phenotype_ids) return [result for result in results if result['p_value'] is not None] except SystemExit, RuntimeError: pass
def hpo_genes(phenotype_terms): """Return the list of HGNC symbols that match annotated HPO terms. Returns: query_result: a list of dictionaries on the form { 'p_value': float, 'gene_id': str, 'omim_id': int, 'orphanet_id': int, 'decipher_id': int, 'any_id': int, 'mode_of_inheritance': str, 'description': str, 'raw_line': str } """ hpo_terms = [ phenotype_term.phenotype_id for phenotype_term in phenotype_terms ] # skip querying Phenomizer unless at least one HPO terms exists if hpo_terms: try: results = query_phenomizer.query(hpo_terms) return [ result for result in results if result['p_value'] is not None ] except SystemExit: return None else: return None
def cli(ctx, hpo_term, check_terms, output, p_value_limit, verbose, username, password, to_json): "Give hpo terms either on the form 'HP:0001623', or '0001623'" loglevel = LEVELS.get(min(verbose, 3)) configure_stream(level=loglevel) if not hpo_term: logger.info( "Please specify at least one hpo term with '-t/--hpo_term'.") ctx.abort() if not (username and password): logger.info("Please specify username with -u and password with -p.") logger.info("Contact [email protected].") ctx.abort() hpo_list = [] for term in hpo_term: if len(term.split(':')) < 2: term = ':'.join(['HP', term]) hpo_list.append(term) logger.info("HPO terms used: {0}".format(','.join(hpo_list))) if check_terms: for term in hpo_list: try: if not validate_term(username, password, term): logger.info("HPO term : {0} does not exist".format(term)) else: logger.info("HPO term : {0} does exist!".format(term)) except RuntimeError as err: click.echo(err) ctx.abort() ctx.abort() else: try: for result in query(username, password, *hpo_list): if to_json: click.echo(json.dumps(result)) else: print_string = "{0}\t{1}:{2}\t{3}\t{4}".format( result['p_value'], result['disease_source'], result['disease_nr'], result['description'], ','.join(result['gene_symbols'])) p_value = result['p_value'] if p_value <= p_value_limit: click.echo(print_string) except RuntimeError as e: click.echo(e) ctx.abort()
def hpo_genes(phenotype_ids): """Return list of HGNC symbols matching HPO phenotype ids. Returns: query_result: a list of dictionaries on the form { 'p_value': float, 'gene_id': str, 'omim_id': int, 'orphanet_id': int, 'decipher_id': int, 'any_id': int, 'mode_of_inheritance': str, 'description': str, 'raw_line': str } """ try: results = query_phenomizer.query(phenotype_ids) return [result for result in results if result["p_value"] is not None] except SystemExit: return None
def cli(ctx, hpo_term, check_terms, output, p_value_limit, verbose, username, password, to_json): """Give hpo terms either on the form 'HP:0001623', or '0001623'. If -p is not used, a password prompt will appear instead.""" loglevel = LEVELS.get(min(verbose, 3)) configure_stream(level=loglevel) if not hpo_term: logger.info( "Please specify at least one hpo term with '-t/--hpo_term'.") ctx.abort() if not username: logger.info("Please specify username with -u (and password with -p).") logger.info("Contact [email protected].") ctx.abort() if not password: password = getpass("password:"******"HPO terms used: {0}".format(','.join(hpo_list))) if check_terms: for term in hpo_list: try: if not validate_term(username, password, term): logger.info("HPO term : {0} does not exist".format(term)) else: logger.info("HPO term : {0} does exist!".format(term)) except RuntimeError as err: click.echo(err) ctx.abort() ctx.abort() else: try: if output: header = "p-value\tdisease-id\tdisease-name\tgene-symbols" + linesep # The file header. output.write( header.encode()) # "a bytes-like object is required" for result in query(username, password, *hpo_list): if to_json: click.echo(json.dumps(result)) else: print_string = "{0}\t{1}:{2}\t{3}\t{4}".format( result['p_value'], result['disease_source'], result['disease_nr'], result['description'], ','.join(result['gene_symbols'])) p_value = result['p_value'] if p_value <= p_value_limit: if output: print_string += linesep # Adds line separator to output. output.write(print_string.encode() ) # "a bytes-like object is required" else: click.echo(print_string) except RuntimeError as e: click.echo(e) ctx.abort() finally: if output: output.flush() output.close()
def test_query_unicode(username, password): res = query(username, password, "HP:0000252") assert res
def test_query_ataxia(ataxia, username, password): res = query(username, password, ataxia) assert res