From 9e796580f2867c6f1048a688251958db8fc7923a Mon Sep 17 00:00:00 2001 From: Sander van den Hoek Date: Thu, 31 May 2018 11:47:09 +0200 Subject: [PATCH 1/9] Gitignore now also ignores .idea files. --- .gitignore | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index aeccb9d..2ed898e 100644 --- a/.gitignore +++ b/.gitignore @@ -67,4 +67,7 @@ node_modules/ .otto # mkdocs -site/ \ No newline at end of file +site/ + +# PyCharm files. +.idea/ \ No newline at end of file From e17bd2eb0a059d9d23553d28194cc409068b8d8a Mon Sep 17 00:00:00 2001 From: Sander van den Hoek Date: Thu, 31 May 2018 11:52:14 +0200 Subject: [PATCH 2/9] If password is not given but a username is, requests password using getpass (so that the password is not stored in the command-line history). --- query_phenomizer/cli.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/query_phenomizer/cli.py b/query_phenomizer/cli.py index 7a30652..2d294f5 100755 --- a/query_phenomizer/cli.py +++ b/query_phenomizer/cli.py @@ -16,6 +16,8 @@ from query_phenomizer import query, validate_term +from getpass import getpass + from .log import (configure_stream, LEVELS) logger = logging.getLogger(__name__) @@ -69,10 +71,13 @@ def cli(ctx, hpo_term, check_terms, output, p_value_limit, verbose, username, logger.info("Please specify at least one hpo term with '-t/--hpo_term'.") ctx.abort() - if not (username and password): + if not username: logger.info("Please specify username with -u and password with -p.") logger.info("Contact sebastian.koehler@charite.de.") ctx.abort() + + if not password: + password = getpass("password:") hpo_list = [] for term in hpo_term: From c49a58bf9f192fead4eb6aaa48254b7bc554ff47 Mon Sep 17 00:00:00 2001 From: Sander van den Hoek Date: Thu, 31 May 2018 12:10:44 +0200 Subject: [PATCH 3/9] Added info to the usage regarding the alternative password input method. --- query_phenomizer/cli.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/query_phenomizer/cli.py b/query_phenomizer/cli.py index 2d294f5..b4f8600 100755 --- a/query_phenomizer/cli.py +++ b/query_phenomizer/cli.py @@ -63,7 +63,9 @@ def test_args(*args): @click.pass_context 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'" + """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) From 9f72c764d14dc0a8dbed58a2a50e13472c08f560 Mon Sep 17 00:00:00 2001 From: Sander van den Hoek Date: Thu, 31 May 2018 13:14:50 +0200 Subject: [PATCH 4/9] Output is now written to a file if -o is given. --- query_phenomizer/cli.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/query_phenomizer/cli.py b/query_phenomizer/cli.py index b4f8600..9d907c8 100755 --- a/query_phenomizer/cli.py +++ b/query_phenomizer/cli.py @@ -14,6 +14,7 @@ import click import json +from os import linesep from query_phenomizer import query, validate_term from getpass import getpass @@ -102,12 +103,14 @@ def cli(ctx, hpo_term, check_terms, output, p_value_limit, verbose, username, ctx.abort() else: try: + if output: + output.write("p-value\tdisease-id\tdisease-name\tgene-symbols") 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'], + print_string = '{0}\t{1}:{2}\t"{3}"\t{4}'.format( + result['p_value'], result['disease_source'], result['disease_nr'], result['description'], @@ -115,7 +118,11 @@ def cli(ctx, hpo_term, check_terms, output, p_value_limit, verbose, username, ) p_value = result['p_value'] if p_value <= p_value_limit: - click.echo(print_string) + 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) From 813ddc687bae84f95a18eb50ee15f55845df9f3a Mon Sep 17 00:00:00 2001 From: Sander van den Hoek Date: Thu, 31 May 2018 13:56:16 +0200 Subject: [PATCH 5/9] Fix for the file header. --- query_phenomizer/cli.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/query_phenomizer/cli.py b/query_phenomizer/cli.py index 9d907c8..15b4156 100755 --- a/query_phenomizer/cli.py +++ b/query_phenomizer/cli.py @@ -104,7 +104,8 @@ def cli(ctx, hpo_term, check_terms, output, p_value_limit, verbose, username, else: try: if output: - output.write("p-value\tdisease-id\tdisease-name\tgene-symbols") + 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)) From 872bc0403ff40e9e9199b04a43f2a60d31cd6b7a Mon Sep 17 00:00:00 2001 From: Sander van den Hoek Date: Fri, 1 Jun 2018 12:01:01 +0200 Subject: [PATCH 6/9] Removal of unneeded quotes. --- query_phenomizer/cli.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/query_phenomizer/cli.py b/query_phenomizer/cli.py index 15b4156..2aa58bf 100755 --- a/query_phenomizer/cli.py +++ b/query_phenomizer/cli.py @@ -110,7 +110,7 @@ def cli(ctx, hpo_term, check_terms, output, p_value_limit, verbose, username, if to_json: click.echo(json.dumps(result)) else: - print_string = '{0}\t{1}:{2}\t"{3}"\t{4}'.format( + print_string = '{0}\t{1}:{2}\t{3}\t{4}'.format( result['p_value'], result['disease_source'], result['disease_nr'], From d509aa11cc3ab07902433855181a0dcdef60160f Mon Sep 17 00:00:00 2001 From: Sander van den Hoek Date: Fri, 1 Jun 2018 12:02:48 +0200 Subject: [PATCH 7/9] Reverted format back to original. --- query_phenomizer/cli.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/query_phenomizer/cli.py b/query_phenomizer/cli.py index 2aa58bf..594b985 100755 --- a/query_phenomizer/cli.py +++ b/query_phenomizer/cli.py @@ -110,7 +110,7 @@ def cli(ctx, hpo_term, check_terms, output, p_value_limit, verbose, username, if to_json: click.echo(json.dumps(result)) else: - print_string = '{0}\t{1}:{2}\t{3}\t{4}'.format( + print_string = "{0}\t{1}:{2}\t{3}\t{4}".format( result['p_value'], result['disease_source'], result['disease_nr'], From 0a9978f7aec07cbac3b37ca9e81afa0b48e1b5f8 Mon Sep 17 00:00:00 2001 From: Sander van den Hoek Date: Fri, 1 Jun 2018 12:05:45 +0200 Subject: [PATCH 8/9] Minor adjustment to message for missing username. --- query_phenomizer/cli.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/query_phenomizer/cli.py b/query_phenomizer/cli.py index 594b985..7cbbf0d 100755 --- a/query_phenomizer/cli.py +++ b/query_phenomizer/cli.py @@ -75,7 +75,7 @@ def cli(ctx, hpo_term, check_terms, output, p_value_limit, verbose, username, ctx.abort() if not username: - logger.info("Please specify username with -u and password with -p.") + logger.info("Please specify username with -u (and password with -p).") logger.info("Contact sebastian.koehler@charite.de.") ctx.abort() From 3cb676a02f28f1416b81ff39ee41adeaa30c3dc4 Mon Sep 17 00:00:00 2001 From: Sander van den Hoek Date: Fri, 1 Jun 2018 12:41:56 +0200 Subject: [PATCH 9/9] Added a finally clause for output file flushing/closing. --- query_phenomizer/cli.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/query_phenomizer/cli.py b/query_phenomizer/cli.py index 7cbbf0d..2bfe0e8 100755 --- a/query_phenomizer/cli.py +++ b/query_phenomizer/cli.py @@ -128,3 +128,7 @@ def cli(ctx, hpo_term, check_terms, output, p_value_limit, verbose, username, except RuntimeError as e: click.echo(e) ctx.abort() + finally: + if output: + output.flush() + output.close()