Skip to content

Commit

Permalink
Options to add mutations strings to tabmut
Browse files Browse the repository at this point in the history
- Necessary for using "bootstraping" confidence intervals in LolliPop
  • Loading branch information
DrYak committed Oct 9, 2024
1 parent f298c36 commit 2287d89
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 12 deletions.
27 changes: 16 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,17 +127,22 @@ Usage: cojac cooc-tabmut [OPTIONS]
Make a table suitable for further processing: RStudio, etc

Options:
-j, --json JSON results generated by mutbamscan
-y, --yaml YAML results generated by mutbamscan
--batchname SEP separator used to split samplename/batchname in separate
column
-o, --output CSV name of (raw) csv file to save the table into
-l, --lines Line-oriented table alternative
-x, --excel use a semi-colon ';' instead of a comma ',' in the comma-
separated-files as required by Microsoft Excel
-m, --multiindex Use multi-level indexing (amplicons and counts categories)
-q, --quiet Run quietly: do not print the table
--help Show this message and exit.
-j, --json JSON results generated by mutbamscan
-y, --yaml YAML results generated by mutbamscan
--batchname SEP separator used to split samplename/batchname
in separate column
-o, --output CSV name of (raw) csv file to save the table
into
-l, --lines Line-oriented table alternative
-x, --excel use a semi-colon ';' instead of a comma ','
in the comma-separated-files as required by
Microsoft Excel
-m, --multiindex Use multi-level indexing (amplicons and
counts categories)
-a, --add-mutations, --am YAML add mutations descriptions using list of
query amplicons, from mutbamscan
-q, --quiet Run quietly: do not print the table
-h, --help Show this message and exit.
```

```console
Expand Down
50 changes: 49 additions & 1 deletion cojac/cooc_tabmut.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,17 @@
default=False,
help="Use multi-level indexing (amplicons and counts categories)",
)
@click.option(
"-a",
"--add-mutations",
"--am",
"amp",
metavar="YAML",
required=False,
default=None,
type=str,
help="add mutations descriptions using list of query amplicons, from mutbamscan",
)
@click.option(
"-q",
"--quiet",
Expand All @@ -79,8 +90,43 @@
help="Run quietly: do not print the table",
)
def cooc_tabmut(
json_fname, yaml_fname, batchname, csv_fname, lines, semi, multiindex, quiet
json_fname, yaml_fname, batchname, csv_fname, lines, semi, multiindex, amp, quiet
):
# load amplicons
amplicon_nfo = {}
if amp is not None:
assert os.path.isfile(amp), f"cannot find amplicon file yaml file {amp}"
with open(amp, "rt") as yf:
amp_str = yaml.safe_load(yf)

amplicon_nfo = {
a: "|".join(
[
# Mutations
",".join(
[
(
f"{p}{b}"
if len(b) == 1
else (
f"d{p}-{p + len(b) - 1}"
if b == "-" * len(b)
else f"{p}>{b}"
)
)
for p, b in aqu[4].items()
]
),
# Genomic position span
# f"[{aqu[0]}-{aqu[1]}]",
# Amplicon number
# f"Amp{a.split('_')[0]}",
]
)
for a, aqu in amp_str.items()
}
# print(amplicon_nfo)

# load table
table = {}

Expand Down Expand Up @@ -150,6 +196,8 @@ def cooc_tabmut(
line = {"sample": sam}
if batch:
line.update({"batch": batch})
if ampname in amplicon_nfo:
line.update({"mutations": amplicon_nfo[ampname]})
line.update(
{
"amplicon": anum,
Expand Down

0 comments on commit 2287d89

Please sign in to comment.