Skip to content

Commit

Permalink
Support for debug option, etc.
Browse files Browse the repository at this point in the history
- "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
  • Loading branch information
DrYak committed May 30, 2024
1 parent b3d0a31 commit 04379d0
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 17 deletions.
17 changes: 9 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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/
```
Expand All @@ -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
Expand All @@ -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
Expand Down
48 changes: 41 additions & 7 deletions cojac/cooc_curate.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

server = "https://lapis.cov-spectrum.org/open/v1"
lintype = "nextcladePangoLineage"
debug = False


def setURL(url):
Expand All @@ -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

Expand Down Expand Up @@ -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
)
Expand All @@ -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)

Expand Down Expand Up @@ -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:
Expand Down
11 changes: 9 additions & 2 deletions cojac/sig_generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import yaml
import csv

from .cooc_curate import listfilteredmutations, setURL, setLinType
from .cooc_curate import listfilteredmutations, setURL, setLinType, setDebug


# regex
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 04379d0

Please sign in to comment.