From 4a0944805b5b980a0abf43e7dd0c797fd0fb3447 Mon Sep 17 00:00:00 2001 From: johnne Date: Thu, 28 Apr 2022 10:30:32 +0200 Subject: [PATCH 1/3] Update jupyter code in extra material --- pages/jupyter/jupyter-9-extra-material.md | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/pages/jupyter/jupyter-9-extra-material.md b/pages/jupyter/jupyter-9-extra-material.md index ed5630ab..c78ef2b4 100644 --- a/pages/jupyter/jupyter-9-extra-material.md +++ b/pages/jupyter/jupyter-9-extra-material.md @@ -86,6 +86,7 @@ find an example in the code chunk below: rule make_supplementary: input: counts = "results/tables/counts.tsv", + summary = "results/tables/counts.tsv.summary", multiqc_file = "intermediate/multiqc_general_stats.txt", rulegraph = "results/rulegraph.png" output: @@ -151,6 +152,7 @@ version of the notebook using the `log: notebook=` directive: rule make_supplementary_plots: input: counts = "results/tables/counts.tsv", + summary = "results/tables/counts.tsv.summary", multiqc = "intermediate/multiqc_general_stats.txt", rulegraph = "results/rulegraph.png" output: @@ -167,6 +169,7 @@ defined notebook parameters edit the code so that it looks like this: ```python counts_file=snakemake.input.counts +summary_file=snakemake.input.summary multiqc_file=snakemake.input.multiqc rulegraph_file=snakemake.input.rulegraph @@ -209,25 +212,23 @@ to save the plots to the output files. First, edit the cell that generates the barplot so that it looks like this: ```python -count_data = pd.DataFrame(counts.sum(), columns = ["genes"]) -count_data = pd.merge(count_data, counts_other.T, left_index=True, right_index=True) - -colors = sns.color_palette("husl", n_colors=count_data.shape[1]) -ax = count_data.plot(kind="bar", stacked=True, color=colors) -ax.legend(bbox_to_anchor=(1,1), title="Feature"); +# Create a stacked barplot +ax = summary_plot_data.T.plot(kind="bar", stacked=True, color=colors) +# Move legend and set legend title +ax.legend(bbox_to_anchor=(1,1), title="Category"); plt.savefig(snakemake.output.barplot, dpi=300, bbox_inches="tight") ## <-- Add this line! ``` Finally, edit the cell that generates the heatmap so that it looks like this: ```python -heatmap_data = counts.loc[(counts.std(axis=1).div(counts.mean(axis=1))>1.2)&(counts.max(axis=1)>5)] -heatmap_data = heatmap_data.rename(index=lambda x: f"{x} ({gene_names[x]})") -heatmap_data.rename(columns = lambda x: name_dict['title'][x], inplace=True) +count_data = counts.loc[:, SRR_IDs] +heatmap_data = count_data.loc[(count_data.std(axis=1).div(count_data.mean(axis=1))>1.2)&(count_data.max(axis=1)>5)] +heatmap_data = heatmap_data.rename(columns = name_dict['title']) with sns.plotting_context("notebook", font_scale=0.7): ax = sns.clustermap(data=np.log10(heatmap_data+1), cmap="RdYlBu_r", method="complete", yticklabels=True, linewidth=.5, - cbar_pos=(0.2, .8, 0.02, 0.15), figsize=(8,6)) + cbar_pos=(.7, .85, .05, .1), figsize=(3,9)) plt.setp(ax.ax_heatmap.get_xticklabels(), rotation=270) plt.savefig(snakemake.output.heatmap, dpi=300, bbox_inches="tight") ## <-- Add this line! ``` From 31f3f7ddbc72331554b6f9bd856e49bf6f5db8ca Mon Sep 17 00:00:00 2001 From: johnne Date: Thu, 28 Apr 2022 10:31:49 +0200 Subject: [PATCH 2/3] Update nbconvert version due to error --- tutorials/jupyter/environment.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tutorials/jupyter/environment.yml b/tutorials/jupyter/environment.yml index 0a8875f1..78c121e0 100644 --- a/tutorials/jupyter/environment.yml +++ b/tutorials/jupyter/environment.yml @@ -11,6 +11,6 @@ dependencies: - seaborn=0.11.2 - matplotlib=3.5.0 - ipywidgets=7.6.5 - - nbconvert=5.6.1 + - nbconvert=6.5.0 - jinja2<=3.0.3 - jupyter_contrib_nbextensions=0.5.1 \ No newline at end of file From 37b62068ac75188ab8dd95944fd7e5302a59ada8 Mon Sep 17 00:00:00 2001 From: johnne Date: Thu, 28 Apr 2022 10:58:37 +0200 Subject: [PATCH 3/3] Downgrade nbconvert again --- tutorials/jupyter/environment.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tutorials/jupyter/environment.yml b/tutorials/jupyter/environment.yml index 78c121e0..0a8875f1 100644 --- a/tutorials/jupyter/environment.yml +++ b/tutorials/jupyter/environment.yml @@ -11,6 +11,6 @@ dependencies: - seaborn=0.11.2 - matplotlib=3.5.0 - ipywidgets=7.6.5 - - nbconvert=6.5.0 + - nbconvert=5.6.1 - jinja2<=3.0.3 - jupyter_contrib_nbextensions=0.5.1 \ No newline at end of file