Skip to content

Commit

Permalink
Quirk: nostar
Browse files Browse the repository at this point in the history
- preview LAPIS server for RSV is buggy and doesn't support star '*' lineage suffix
  • Loading branch information
DrYak committed Jun 3, 2024
1 parent 30916ca commit f298c36
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 7 deletions.
36 changes: 31 additions & 5 deletions cojac/cooc_curate.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
server = "https://lapis.cov-spectrum.org/open/v2"
lintype = "nextcladePangoLineage"
debug = False
noStar = False


def setURL(url):
Expand Down Expand Up @@ -56,6 +57,16 @@ def setDebug(d):
debug = d


def quirks(q):
if "noStar" in q:
global noStar
noStar = True
print(
"quirk: skipping star on lineages\n",
file=sys.stderr,
)


def getAccessKey():
# TODO proper global handling

Expand Down Expand Up @@ -131,7 +142,7 @@ def listmutations(lineage, extras={}):
if "variantQuery" in extras.keys():
# NOTE according to covspectrum: "Please specify the variant either by using the fields pangoLineage, nextstrainClade, gisaidClade, aaMutations and nucMutations, or by using variantQuery - don't use both at the same time."
return nucmutations(**extras)
return nucmutations(**{lintype: (lineage + "*")}, **extras)
return nucmutations(**{lintype: (lineage if noStar else f"{lineage}*")}, **extras)


def aggregated(**kwargs):
Expand All @@ -158,7 +169,10 @@ def aggregated(**kwargs):
def listsublineages(lineage):
"""list all lineages which are known to be either the variant it self or one of its sub-variants"""
return set(
s[lintype] for s in aggregated(**{lintype: (lineage + "*")}, fields=lintype)
s[lintype]
for s in aggregated(
**{lintype: (lineage if noStar else f"{lineage}*")}, fields=lintype
)
)


Expand Down Expand Up @@ -386,14 +400,26 @@ def curate_muts(
default=False,
help="show API calls details (urls and arguments)",
)
@click.option(
"--quirk",
"quirk",
multiple=True,
default=set(),
type=click.Choice(["noStar"], case_sensitive=False),
help="special work-around options",
)
@click.argument("voc", nargs=-1)
def cooc_curate(url, lintype, amp, domuts, high, low, collapse, colour, voc, debug):
def cooc_curate(
url, lintype, amp, domuts, high, low, collapse, colour, voc, debug, quirk
):
if url:
setURL(url)
if lintype:
setLinType(lintype)
if debug:
setDebug(debug)
if quirk:
quirks(quirk)
amplicons = None
if amp:
with open(amp, "r") as yf:
Expand Down Expand Up @@ -428,11 +454,11 @@ def cooc_curate(url, lintype, amp, domuts, high, low, collapse, colour, voc, deb
if len(sublineages) > 1 and collapse:
# do not use the common list of all lineage, instead collapse those who are part of the current considered variant into a single category
# e.g. combine counts of BA.1,BA.1.1,BA.2,BA.3,etc. => B.1.1.529*
combinedname = f"{lineage}*"
combinedname = lineage if noStar else f"{lineage}*"
common_kwargs["alllin"] = collapse_sublineages(
alllin, sublineages, combinedname
)
common_kwargs["combined"] = f"{lineage}*"
common_kwargs["combined"] = combinedname
else:
common_kwargs["combined"] = None

Expand Down
14 changes: 12 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, setDebug
from .cooc_curate import listfilteredmutations, setURL, setLinType, setDebug, quirks


# regex
Expand Down Expand Up @@ -97,13 +97,23 @@
default=False,
help="show 'extra' query content, show API details (urls and arguments)",
)
@click.option(
"--quirk",
"quirk",
multiple=True,
default=set(),
type=click.Choice(["noStar"], case_sensitive=False),
help="special work-around options",
)
def sig_generate(
url, lintype, var, minfreq, mindelfreq, minseqs, extras, covariants, debug
url, lintype, var, minfreq, mindelfreq, minseqs, extras, covariants, debug, quirk
):
if url:
setURL(url)
if lintype:
setLinType(lintype)
if quirk:
quirks(quirk)

if debug:
setDebug(debug)
Expand Down

0 comments on commit f298c36

Please sign in to comment.