Skip to content

Commit

Permalink
fix: Allow mismatch_to_mapDamage to work with forward-only data
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristianMichelsen committed May 23, 2022
1 parent 6c0126c commit c59240f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/metaDMG/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ def mismatch_to_mapDamage(
filename: Path = typer.Argument(
...,
file_okay=True,
help="Path to the config-file.",
help="Path to the mismatch-file to convert.",
),
csv_out: Path = typer.Option(
"misincorporation.txt",
Expand Down
1 change: 1 addition & 0 deletions src/metaDMG/fit/bayesian.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ def make_fits(fit_result, data, mcmc_PMD, mcmc_null):
fit_mcmc(mcmc_null, data)
add_Bayesian_fit_result(fit_result, data, mcmc_PMD, mcmc_null)
# mcmc_PMD.print_summary(prob=0.68)
# mcmc_null.print_summary(prob=0.68)

# if False:
# use_last_state_as_warmup_state(mcmc_PMD)
Expand Down
23 changes: 17 additions & 6 deletions src/metaDMG/fit/mismatch_to_mapDamage.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,26 @@
#%%

import numpy as np
import pandas as pd

from metaDMG import __version__ as version
from metaDMG.fit import mismatches


#%%


def df_mismatch_to_mapDamage(df_mismatch):

df_mapDamage = df_mismatch.copy()

bases = ["A", "C", "G", "T"]
for base in bases:
if base not in df_mapDamage.columns:
mismatches.add_reference_count(df_mapDamage, ref=base)

df_mapDamage["Total"] = df_mapDamage[bases].sum(axis=1)

# fmt: off
columns = [
"Chr", "End", "Std", "Pos",
Expand All @@ -28,12 +42,6 @@ def df_mismatch_to_mapDamage(df_mismatch):
for sub in columns[idx_start:idx_end]:
d_rename[sub[0] + sub[-1]] = sub

df_mapDamage = df_mismatch.copy()

mismatches.add_reference_count(df_mapDamage, ref="A")
mismatches.add_reference_count(df_mapDamage, ref="T")
df_mapDamage["Total"] = df_mapDamage[["A", "C", "G", "T"]].sum(axis=1)

df_mapDamage = df_mapDamage.rename(columns=d_rename)
df_mapDamage["End"] = np.where(df_mapDamage["Pos"] > 0, "5p", "3p")
df_mapDamage["Std"] = "+"
Expand Down Expand Up @@ -65,3 +73,6 @@ def convert(filename, csv_out):

with open(csv_out, "w", encoding="utf-8") as file:
file.write(out)


# %%

0 comments on commit c59240f

Please sign in to comment.