Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for one based pairs #54

Merged
merged 3 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions AnoPrimer/evaluate.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,12 +178,12 @@ def plot_primer_snp_frequencies(

# Loop through each primer pair and get the frequencies of alternate alleles
res_dict = {}
for i in range(len(self.df.columns)):
res_dict[i] = _get_primer_alt_frequencies(
for pair in self.df:
res_dict[pair] = _get_primer_alt_frequencies(
species=self.species,
primer_df=self.df,
gdna_pos=self.gdna_pos,
pair=i,
pair=pair,
assay_type=self.assay_type,
contig=self.contig,
sample_sets=sample_sets,
Expand Down Expand Up @@ -354,6 +354,7 @@ def _plot_primers(self, ax, oligos):
handles, labels = ax.get_legend_handles_labels()
for pair in self.df:
pair = int(pair)
pair_idx = pair - 1 # python based indexing
for oligo in oligos:
oligo_pos = _retrieve_span(
primer_df=self.df,
Expand All @@ -367,34 +368,34 @@ def _plot_primers(self, ax, oligos):
if oligo == "forward":
plt.arrow(
lower,
0.8 + (2 / (10 - (pair))),
0.8 + (2 / (10 - (pair_idx))),
upper - lower,
0,
width=0.03,
length_includes_head=True,
color=pal[pair],
color=pal[pair_idx],
)
elif oligo == "reverse":
plt.arrow(
upper,
0.8 + (2 / (10 - (pair))),
0.8 + (2 / (10 - (pair_idx))),
lower - upper,
0,
width=0.03,
length_includes_head=True,
color=pal[pair],
color=pal[pair_idx],
)
elif oligo == "probe":
ax.axhline(y=0.8 + (2 / (10 - (pair))), xmin=lower, xmax=upper)
ax.axhline(y=0.8 + (2 / (10 - (pair_idx))), xmin=lower, xmax=upper)
line = plt.Line2D(
(lower, upper),
(0.8 + (2 / (10 - (pair))), 0.8 + (2 / (10 - (pair)))),
lw=2.5,
color=pal[pair],
color=pal[pair_idx],
)
ax.add_line(line)

patch = patches.Patch(color=pal[pair], label=f"pair {pair}")
patch = patches.Patch(color=pal[pair_idx], label=f"pair {pair}")
handles.append(patch)

return handles
Expand Down
39 changes: 19 additions & 20 deletions AnoPrimer/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,30 +327,29 @@ def _plotly_primers(
fig.update_annotations(font_size=13)
for idx, oligo in enumerate(oligos):
idx = idx + 1
for i in primer_df:
i = int(i)
row_i = i + 1
for pair in primer_df:
row_i = int(pair)

color = [
-1 if v == 0 else 1 if v > 0 else 0
for v in res_dict[i][oligo]["alt_frequency"]
for v in res_dict[pair][oligo]["alt_frequency"]
]
colorscale = [[0, "lightgray"], [0.5, "lightgray"], [1, "dodgerblue"]]

tm = np.round(primer_df.loc[f"primer_{oligo}_tm", str(i)], 2)
gc = np.round(primer_df.loc[f"primer_{oligo}_gc_percent", str(i)], 2)
span = f"{int(res_dict[i][oligo]['position'].min())}-{int(res_dict[i][oligo]['position'].max())}"
# Write text to plot for Tm, GC, span, and 3/5'
tm = np.round(primer_df.loc[f"primer_{oligo}_tm", pair], 2)
gc = np.round(primer_df.loc[f"primer_{oligo}_gc_percent", pair], 2)
span = f"{int(res_dict[pair][oligo]['position'].min())}-{int(res_dict[pair][oligo]['position'].max())}"

for col in res_dict[i][oligo].columns:
for col in res_dict[pair][oligo].columns:
if col.endswith("freq"):
res_dict[i][oligo][col] = np.round(res_dict[i][oligo][col], 2)
res_dict[pair][oligo][col] = np.round(res_dict[pair][oligo][col], 2)

fig.add_trace(
go.Scatter(
x=res_dict[i][oligo]["base_pos"],
y=res_dict[i][oligo]["alt_frequency"],
customdata=res_dict[i][oligo][
x=res_dict[pair][oligo]["base_pos"],
y=res_dict[pair][oligo]["alt_frequency"],
customdata=res_dict[pair][oligo][
["A_freq", "C_freq", "G_freq", "T_freq", "base_pos"]
],
hovertemplate=hover_template,
Expand All @@ -369,39 +368,39 @@ def _plotly_primers(
fig.add_annotation(
row=row_i,
col=idx,
x=res_dict[i][oligo]["base_pos"][0],
x=res_dict[pair][oligo]["base_pos"][0],
y=0.8,
text="5'",
showarrow=False,
)
fig.add_annotation(
row=row_i,
col=idx,
x=res_dict[i][oligo]["base_pos"].to_numpy()[-1],
x=res_dict[pair][oligo]["base_pos"].to_numpy()[-1],
y=0.8,
text="3'",
showarrow=False,
)
fig.add_annotation(
row=row_i,
col=idx,
x=res_dict[i][oligo]["base_pos"].to_numpy()[4],
x=res_dict[pair][oligo]["base_pos"].to_numpy()[4],
y=0.92,
text=span,
showarrow=False,
)
fig.add_annotation(
row=row_i,
col=idx,
x=res_dict[i][oligo]["base_pos"].to_numpy()[-7],
x=res_dict[pair][oligo]["base_pos"].to_numpy()[-7],
y=0.92,
text=f"GC={gc}",
showarrow=False,
)
fig.add_annotation(
row=row_i,
col=idx,
x=res_dict[i][oligo]["base_pos"].to_numpy()[-3],
x=res_dict[pair][oligo]["base_pos"].to_numpy()[-3],
y=0.92,
text=f"TM={tm}",
showarrow=False,
Expand All @@ -411,8 +410,8 @@ def _plotly_primers(
row=row_i,
col=idx,
tickmode="array",
tickvals=res_dict[i][oligo]["base_pos"],
ticktext=res_dict[i][oligo]["base"],
tickvals=res_dict[pair][oligo]["base_pos"],
ticktext=res_dict[pair][oligo]["base"],
tickangle=0,
mirror=True,
)
Expand Down Expand Up @@ -446,7 +445,7 @@ def _plotly_primers(

# fig.update_traces(customdata=customdata, hovertemplate=hovertemplate)
fig.update_layout(
height=200 * len(primer_df.columns),
height=220 * len(primer_df.columns),
width=500 * len(oligos),
title_text=title_text,
title_x=0.5,
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "AnoPrimer"
version = "2.0.1"
version = "2.0.2"
description = "A package to design primers in Anopheles gambiae whilst considering genetic variation with malariagen_data"
readme = "README.md"
documentation = "https://sanjaynagi.github.io/anoprimer/latest/"
Expand Down
16 changes: 8 additions & 8 deletions tests/run_ci_notebooks.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@

papermill notebooks/AnoPrimer-long.ipynb qPCR_run.ipynb -k AnoPrimer -f tests/cDNA_Params_fun.json &&
papermill notebooks/AnoPrimer-long.ipynb qPCR2_run.ipynb -k AnoPrimer -f tests/cDNA_Params_2_fun.json &&
papermill notebooks/AnoPrimer-long.ipynb gDNA_run.ipynb -k AnoPrimer -f tests/gDNA_probe_Params_fun.json &&
papermill notebooks/AnoPrimer-long.ipynb qPCR_run.ipynb -k AnoPrimer -f tests/cDNA_Params.json &&
papermill notebooks/AnoPrimer-long.ipynb qPCR2_run.ipynb -k AnoPrimer -f tests/cDNA_Params_2.json &&
papermill notebooks/AnoPrimer-long.ipynb gDNA_run.ipynb -k AnoPrimer -f tests/gDNA_probe_Params.json &&
papermill notebooks/AnoPrimer-long.ipynb probe_run.ipynb -k AnoPrimer -f tests/probe_Params.json &&
papermill notebooks/AnoPrimer-short.ipynb short_run.ipynb -k AnoPrimer
papermill notebooks/AnoPrimer-long.ipynb tests/qPCR_run.ipynb -k AnoPrimer -f tests/cDNA_Params_fun.json &&
papermill notebooks/AnoPrimer-long.ipynb tests/qPCR2_run.ipynb -k AnoPrimer -f tests/cDNA_Params_2_fun.json &&
papermill notebooks/AnoPrimer-long.ipynb tests/gDNA_run.ipynb -k AnoPrimer -f tests/gDNA_probe_Params_fun.json &&
papermill notebooks/AnoPrimer-long.ipynb tests/qPCR_run.ipynb -k AnoPrimer -f tests/cDNA_Params.json &&
papermill notebooks/AnoPrimer-long.ipynb tests/qPCR2_run.ipynb -k AnoPrimer -f tests/cDNA_Params_2.json &&
papermill notebooks/AnoPrimer-long.ipynb tests/gDNA_run.ipynb -k AnoPrimer -f tests/gDNA_probe_Params.json &&
papermill notebooks/AnoPrimer-long.ipynb tests/probe_run.ipynb -k AnoPrimer -f tests/probe_Params.json &&
papermill notebooks/AnoPrimer-short.ipynb tests/short_run.ipynb -k AnoPrimer
Loading