Skip to content

Commit

Permalink
Keep the linter happy
Browse files Browse the repository at this point in the history
  • Loading branch information
DrYak committed Feb 22, 2024
1 parent 62b6bf1 commit a0159ae
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 41 deletions.
14 changes: 8 additions & 6 deletions cojac/cooc_colourmut.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,14 @@ def cooc_colourmut(amp, json_fname, yaml_fname):
amplicon_nfo = {
a: ",".join(
[
f"{p}{b}"
if len(b) == 1
else (
f"\u0394{p}-{p + len(b) - 1}"
if b == "-" * len(b)
else f"{p}\u2192{b}"
(
f"{p}{b}"
if len(b) == 1
else (
f"\u0394{p}-{p + len(b) - 1}"
if b == "-" * len(b)
else f"{p}\u2192{b}"
)
)
for p, b in aqu[4].items()
]
Expand Down
22 changes: 12 additions & 10 deletions cojac/cooc_curate.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,18 @@ def getAccessKey():
return netrc.netrc().authenticators(urlparse(server).netloc)[2]
except:
print(
f"no access key found for {urlparse(server).netloc} in ~/.netrc\n"
f"your requests are likely to be not allowed by the server\n"
f"please add the following entry in your ~/.netrc:\n"
f"```\n"
f"machine {urlparse(server).netloc}\n"
f"password <YOUR_ACCESS_KEY_HERE>\n"
f"```\n"
f"or use the COVSPECTRUM_ACCESSKEY envrionment variable\n"
if "open" not in server
else f"(not using access keys on API {server})",
(
f"no access key found for {urlparse(server).netloc} in ~/.netrc\n"
f"your requests are likely to be not allowed by the server\n"
f"please add the following entry in your ~/.netrc:\n"
f"```\n"
f"machine {urlparse(server).netloc}\n"
f"password <YOUR_ACCESS_KEY_HERE>\n"
f"```\n"
f"or use the COVSPECTRUM_ACCESSKEY envrionment variable\n"
if "open" not in server
else f"(not using access keys on API {server})"
),
file=sys.stderr,
)
# sys.exit(1)
Expand Down
30 changes: 18 additions & 12 deletions cojac/cooc_mutbamscan.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,16 @@ def scanamplicon(read_iter, mut_dict):

# look at last column only
return {
"sites": dict(zip(sites_cnt[0].tolist(), sites_cnt[1].tolist()))
if len(all_sites)
else {},
"muts": dict(zip(muts_cnt[0].tolist(), muts_cnt[1].tolist()))
if len(all_muts)
else {},
"sites": (
dict(zip(sites_cnt[0].tolist(), sites_cnt[1].tolist()))
if len(all_sites)
else {}
),
"muts": (
dict(zip(muts_cnt[0].tolist(), muts_cnt[1].tolist()))
if len(all_muts)
else {}
),
}


Expand Down Expand Up @@ -278,9 +282,11 @@ def make_all_amplicons(amp_bed, vocs, revert=False, n_cooc=2):
loaded_yamls.append(
filter_decode_vartiant(
loaded_yaml,
categories=["revert", "mut", "extra", "shared", "subset"]
if revert
else ["mut", "extra", "shared", "subset"],
categories=(
["revert", "mut", "extra", "shared", "subset"]
if revert
else ["mut", "extra", "shared", "subset"]
),
)
)

Expand All @@ -307,9 +313,9 @@ def make_all_amplicons(amp_bed, vocs, revert=False, n_cooc=2):
print(f"{k1} is identical to {k2}")
# sort the variant names part of the list, to be consistent between calls, no matter the filesystem's on-disk order
# (i.e.: no 76_AY42_IN2 vs 76_IN2_AY42)
amplicons[
"_".join([npart[0]] + sorted(npart[1:] + [yam["name"]]))
] = amplicons.pop(k2)
amplicons["_".join([npart[0]] + sorted(npart[1:] + [yam["name"]]))] = (
amplicons.pop(k2)
)
del amp_dict[k1]
break

Expand Down
14 changes: 8 additions & 6 deletions cojac/cooc_pubmut.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,14 @@ def cooc_pubmut(
# TODO incorporate output of curate
",".join(
[
f"{p}{b}"
if len(b) == 1
else (
f"\u0394{p}-{p + len(b) - 1}"
if b == "-" * len(b)
else f"{p}\u2192{b}"
(
f"{p}{b}"
if len(b) == 1
else (
f"\u0394{p}-{p + len(b) - 1}"
if b == "-" * len(b)
else f"{p}\u2192{b}"
)
)
for p, b in aqu[4].items()
]
Expand Down
16 changes: 10 additions & 6 deletions cojac/cooc_tabmut.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,11 @@ def cooc_tabmut(
line.update(
{
"amplicon": anum,
"frac": (float(muts_cnt) / float(sites_cnt))
if sites_cnt
else float("nan"),
"frac": (
(float(muts_cnt) / float(sites_cnt))
if sites_cnt
else float("nan")
),
"cooc": (sites_cnt_l if int(sites_cnt_l) > 0 else ""),
"count": sites_cnt,
"mut_all": muts_cnt,
Expand All @@ -171,9 +173,11 @@ def cooc_tabmut(
(ampcol, "count"): sites_cnt,
(ampcol, "mut_all"): muts_cnt,
(ampcol, "mut_oneless"): mut_oneless,
(ampcol, "frac"): (float(muts_cnt) / float(sites_cnt))
if sites_cnt
else float("nan"),
(ampcol, "frac"): (
(float(muts_cnt) / float(sites_cnt))
if sites_cnt
else float("nan")
),
(ampcol, "cooc"): (sites_cnt_l if int(sites_cnt_l) > 0 else ""),
}
)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ click = "^8.0.3"
requests = "^2.27.1"

[tool.poetry.dev-dependencies]
black = "^22.1.0"
black = "^24.2.0"
pytest = "^6.2.1"

[tool.poetry.scripts]
Expand Down

0 comments on commit a0159ae

Please sign in to comment.