From 2b21a8a97e8dc5aeae3efd65d640c081ccf53a98 Mon Sep 17 00:00:00 2001 From: Sanjay C Nagi Date: Fri, 27 Sep 2024 14:11:50 +0100 Subject: [PATCH 1/2] fixes for 1 based numbering --- AnoPrimer/evaluate.py | 19 ++++++++++--------- AnoPrimer/utils.py | 39 +++++++++++++++++++-------------------- pyproject.toml | 2 +- tests/run_ci_notebooks.sh | 9 +++++++++ 4 files changed, 39 insertions(+), 30 deletions(-) create mode 100755 tests/run_ci_notebooks.sh diff --git a/AnoPrimer/evaluate.py b/AnoPrimer/evaluate.py index 78d2e41..abfbbe6 100644 --- a/AnoPrimer/evaluate.py +++ b/AnoPrimer/evaluate.py @@ -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, @@ -353,6 +353,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, @@ -366,30 +367,30 @@ 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) diff --git a/AnoPrimer/utils.py b/AnoPrimer/utils.py index 8f55e77..621a083 100644 --- a/AnoPrimer/utils.py +++ b/AnoPrimer/utils.py @@ -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, @@ -369,7 +368,7 @@ 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, @@ -377,7 +376,7 @@ def _plotly_primers( 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, @@ -385,7 +384,7 @@ def _plotly_primers( 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, @@ -393,7 +392,7 @@ def _plotly_primers( 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, @@ -401,7 +400,7 @@ def _plotly_primers( 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, @@ -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, ) @@ -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, diff --git a/pyproject.toml b/pyproject.toml index 416f609..79aea44 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "AnoPrimer" -version = "2.0.0" +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/" diff --git a/tests/run_ci_notebooks.sh b/tests/run_ci_notebooks.sh new file mode 100755 index 0000000..b72f6e3 --- /dev/null +++ b/tests/run_ci_notebooks.sh @@ -0,0 +1,9 @@ + +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 From 43675168fda730510324334cd095c61dc159c0f9 Mon Sep 17 00:00:00 2001 From: Sanjay C Nagi Date: Fri, 27 Sep 2024 14:30:46 +0100 Subject: [PATCH 2/2] fix --- AnoPrimer/evaluate.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AnoPrimer/evaluate.py b/AnoPrimer/evaluate.py index 2453123..a2a0a02 100644 --- a/AnoPrimer/evaluate.py +++ b/AnoPrimer/evaluate.py @@ -395,7 +395,7 @@ def _plot_primers(self, ax, oligos): ) 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