From 04379d0d1de502d224a271cc25bbd1e35c06aa36 Mon Sep 17 00:00:00 2001 From: Ivan Blagoev Topolsky Date: Thu, 30 May 2024 16:56:22 +0200 Subject: [PATCH] Support for debug option, etc. - "debug" option passed to CovSpectrum code in cooc_cojac - debug also shows urls and arguments - [bugfix] lintype wasn't properly passed to cooc_cojac - also update REAMDE.md --- README.md | 17 +++++++-------- cojac/cooc_curate.py | 48 ++++++++++++++++++++++++++++++++++++------- cojac/sig_generate.py | 11 ++++++++-- 3 files changed, 59 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 2652050..e0b4893 100644 --- a/README.md +++ b/README.md @@ -144,8 +144,8 @@ Options: $ cojac cooc-curate --help Usage: cojac cooc-curate [OPTIONS] [VOC]... - Helps determining specific mutations and cooccurrences by querying CoV- - Spectrum + Helps determining specific mutations and cooccurrences by querying + covSPECTRUM Options: -u, --url URL url to use when querying covspectrum (e.g. @@ -166,7 +166,8 @@ Options: assessing signatures of old variants that have branched out by now. --colour / --no-colour use coloured output - --help Show this message and exit. + --debug / --no-debug show API calls details (urls and arguments) + -h, --help Show this message and exit. This tool queries LAPIS, see https://lapis-docs.readthedocs.io/en/latest/ ``` @@ -187,7 +188,7 @@ Options: ```console $ cojac sig-generate --help -Usage: cojac sig-generate [OPTIONS] +Usage: cojac sig-generate [OPTIONS] Helps generating a list of mutations frequently found in a variant by querying covSPECTRUM @@ -206,18 +207,18 @@ Options: -f, --minfreq FREQ Minimum frequency for inclusion in list -d, --mindelfreq FREQ Use a different minimum frequency for deletions (useful early on when there are few sequences and - some of those were produced by pipeline that don't + some of those were produced by pipelines that don't handle deletions) -s, --minseqs NUM Minimum number of sequence supporting for inclusion in list --covariants TSV import from a covariants.org TSV file instead of covSpectrum. (See: https://github.com/hodcroftlab/co variants/blob/master/defining_mutations/) - --debug / --no-debug - --help Show this message and exit. + --debug / --no-debug show 'extra' query content, show API details (urls + and arguments) + -h, --help Show this message and exit. This tool queries LAPIS, see https://lapis-docs.readthedocs.io/en/latest/ - ``` ## Howto diff --git a/cojac/cooc_curate.py b/cojac/cooc_curate.py index 5a46754..35bf215 100755 --- a/cojac/cooc_curate.py +++ b/cojac/cooc_curate.py @@ -23,6 +23,7 @@ server = "https://lapis.cov-spectrum.org/open/v1" lintype = "nextcladePangoLineage" +debug = False def setURL(url): @@ -42,9 +43,19 @@ def setLinType(lin): - nextcladePangoLineage : as found by nextclade - pangoLineage : as provided by GISAID """ + global lintype lintype = lin +def setDebug(d): + """ + Switch debug on or off + - this will show urlparse + """ + global debug + debug = d + + def getAccessKey(): # TODO proper global handling @@ -92,13 +103,20 @@ def nucmutations(**kwargs): - list of mutation, frequencies and sample counts (for all frequencies > 0.05 ) """ kwargs["accessKey"] = getAccessKey() + url = ( + f"{server}/sample/nuc-mutations" + if server[-2:] == "v1" or server[-3:] == "v1/" + else f"{server}/sample/nucleotideMutations" + ) + + if debug: + print( + f"url: {url}\nargs:\n{kwargs}\n", + file=sys.stderr, + ) reply = json.loads( requests.get( - ( - f"{server}/sample/nuc-mutations" - if server[-2:] == "v1" or server[-3:] == "v1/" - else f"{server}/sample/nucleotideMutations" - ), + url, params=kwargs, ).text ) @@ -122,7 +140,15 @@ def aggregated(**kwargs): - count of samples that fit criteria (the other parameters) """ kwargs["accessKey"] = getAccessKey() - reply = json.loads(requests.get(f"{server}/sample/aggregated", params=kwargs).text) + url = f"{server}/sample/aggregated" + + if debug: + print( + f"url: {url}\nargs:\n{kwargs}\n", + file=sys.stderr, + ) + + reply = json.loads(requests.get(url, params=kwargs).text) checkerror(reply) @@ -354,12 +380,20 @@ def curate_muts( default=True, help="use coloured output", ) +@click.option( + "--debug/--no-debug", + "debug", + default=False, + help="show API calls details (urls and arguments)", +) @click.argument("voc", nargs=-1) -def cooc_curate(url, lintype, amp, domuts, high, low, collapse, colour, voc): +def cooc_curate(url, lintype, amp, domuts, high, low, collapse, colour, voc, debug): if url: setURL(url) if lintype: setLinType(lintype) + if debug: + setDebug(debug) amplicons = None if amp: with open(amp, "r") as yf: diff --git a/cojac/sig_generate.py b/cojac/sig_generate.py index 73e4258..be64c45 100644 --- a/cojac/sig_generate.py +++ b/cojac/sig_generate.py @@ -7,7 +7,7 @@ import yaml import csv -from .cooc_curate import listfilteredmutations, setURL, setLinType +from .cooc_curate import listfilteredmutations, setURL, setLinType, setDebug # regex @@ -95,6 +95,7 @@ "--debug/--no-debug", "debug", default=False, + help="show 'extra' query content, show API details (urls and arguments)", ) def sig_generate( url, lintype, var, minfreq, mindelfreq, minseqs, extras, covariants, debug @@ -105,10 +106,16 @@ def sig_generate( setLinType(lintype) if debug: + setDebug(debug) import sys print( - "extra:\n", yaml.load(extras, Loader=yaml.FullLoader), "\n", file=sys.stderr + ( + "extra:\n", + yaml.load(extras, Loader=yaml.FullLoader) if extras else "extra: None", + ), + "\n", + file=sys.stderr, ) # get initial list