Skip to content

Commit

Permalink
v2.0.33 plot updates
Browse files Browse the repository at this point in the history
allele plot sgRNAs that extend beyond plot are
marked quantification window shading and right-side correction version
  • Loading branch information
kclem committed Apr 3, 2020
1 parent 90e677f commit a66c402
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 14 deletions.
23 changes: 12 additions & 11 deletions CRISPResso2/CRISPRessoCORE.py
Original file line number Diff line number Diff line change
Expand Up @@ -2607,14 +2607,15 @@ def count_alternate_alleles(sub_base_vectors,ref_name,ref_sequence,ref_total_aln
if include_idxs_list[idx] == lastIdx + 1:
lastIdx = include_idxs_list[idx]
else:
p = matplotlib.patches.Rectangle((lastStart-0.5, 0), 1+(lastIdx-lastStart)-0.5, y_max,fill=None,edgecolor=(0,0,0,0.25),linestyle=(0,(5,2)),linewidth=2)
p = matplotlib.patches.Rectangle((lastStart-0.5, 0), 1+(lastIdx-lastStart), y_max,facecolor=(0,0,0,0.05),edgecolor=(0,0,0,0.25),linestyle=(0,(5,2)),linewidth=2)
plt.gca().add_patch(p) #gca = get current axis
lastStart = include_idxs_list[idx]
lastIdx = include_idxs_list[idx]
p = matplotlib.patches.Rectangle((lastStart-0.5, 0), 1+(lastIdx-lastStart)-0.5, y_max,fill=None,edgecolor=(0,0,0,0.25),linestyle=(0,(5,2)),linewidth=2,label='Quantification window')
p = matplotlib.patches.Rectangle((lastStart-0.5, 0), 1+(lastIdx-lastStart), y_max,facecolor=(0,0,0,0.05),edgecolor=(0,0,0,0.25),linestyle=(0,(5,2)),linewidth=2,label='Quantification window')
plt.gca().add_patch(p)

plt.plot(all_indelsub_count_vectors[ref_name],'r',lw=3,label=get_plot_title_with_ref_name('Combined Insertions/Deletions/Substitutions',ref_name))
# plt.plot(all_indelsub_count_vectors[ref_name],marker='o')
#plt.hold(True)

if cut_points:
Expand Down Expand Up @@ -2669,11 +2670,11 @@ def count_alternate_alleles(sub_base_vectors,ref_name,ref_sequence,ref_total_aln
if include_idxs_list[idx] == lastIdx + 1:
lastIdx = include_idxs_list[idx]
else:
p = matplotlib.patches.Rectangle((lastStart-0.5, 0), 1+(lastIdx-lastStart)-0.5, y_max,fill=None,edgecolor=(0,0,0,0.25),linestyle=(0,(5,2)),linewidth=2)
p = matplotlib.patches.Rectangle((lastStart-0.5, 0), 1+(lastIdx-lastStart), y_max,facecolor=(0,0,0,0.05),edgecolor=(0,0,0,0.25),linestyle=(0,(5,2)),linewidth=2)
plt.gca().add_patch(p) #gca = get current axis
lastStart = include_idxs_list[idx]
lastIdx = include_idxs_list[idx]
p = matplotlib.patches.Rectangle((lastStart-0.5, 0), 1+(lastIdx-lastStart)-0.5, y_max,fill=None,edgecolor=(0,0,0,0.25),linestyle=(0,(5,2)),linewidth=2,label='Quantification window')
p = matplotlib.patches.Rectangle((lastStart-0.5, 0), 1+(lastIdx-lastStart), y_max,facecolor=(0,0,0,0.05),edgecolor=(0,0,0,0.25),linestyle=(0,(5,2)),linewidth=2,label='Quantification window')
plt.gca().add_patch(p)

plt.plot(all_insertion_count_vectors[ref_name],'r',lw=3,label='Insertions')
Expand Down Expand Up @@ -2739,11 +2740,11 @@ def count_alternate_alleles(sub_base_vectors,ref_name,ref_sequence,ref_total_aln
if include_idxs_list[idx] == lastIdx + 1:
lastIdx = include_idxs_list[idx]
else:
p = matplotlib.patches.Rectangle((lastStart -0.5, 0), 1+(lastIdx-lastStart)-0.5, y_max,fill=None,edgecolor=(0,0,0,0.25),linestyle=(0,(5,2)),linewidth=2)
p = matplotlib.patches.Rectangle((lastStart -0.5, 0), 1+(lastIdx-lastStart), y_max,facecolor=(0,0,0,0.05),edgecolor=(0,0,0,0.25),linestyle=(0,(5,2)),linewidth=2)
plt.gca().add_patch(p) #gca = get current axis
lastStart = include_idxs_list[idx]
lastIdx = include_idxs_list[idx]
p = matplotlib.patches.Rectangle((lastStart -0.5, 0), 1+(lastIdx-lastStart)-0.5, y_max,fill=None,edgecolor=(0,0,0,0.25),linestyle=(0,(5,2)),linewidth=2,label='Quantification window')
p = matplotlib.patches.Rectangle((lastStart -0.5, 0), 1+(lastIdx-lastStart), y_max,facecolor=(0,0,0,0.05),edgecolor=(0,0,0,0.25),linestyle=(0,(5,2)),linewidth=2,label='Quantification window')
plt.gca().add_patch(p)


Expand Down Expand Up @@ -2886,11 +2887,11 @@ def count_alternate_alleles(sub_base_vectors,ref_name,ref_sequence,ref_total_aln
if include_idxs_list[idx] == lastIdx + 1:
lastIdx = include_idxs_list[idx]
else:
p = matplotlib.patches.Rectangle((lastStart-0.5, 0), 1+(lastIdx-lastStart)-0.5, y_max,fill=None,edgecolor=(0,0,0,0.25),linestyle=(0,(5,2)),linewidth=2)
p = matplotlib.patches.Rectangle((lastStart-0.5, 0), 1+(lastIdx-lastStart), y_max,facecolor=(0,0,0,0.05),edgecolor=(0,0,0,0.25),linestyle=(0,(5,2)),linewidth=2)
plt.gca().add_patch(p) #gca = get current axis
lastStart = include_idxs_list[idx]
lastIdx = include_idxs_list[idx]
p = matplotlib.patches.Rectangle((lastStart-0.5, 0), 1+(lastIdx-lastStart)-0.5, y_max,fill=None,edgecolor=(0,0,0,0.25),linestyle=(0,(5,2)),linewidth=2,label='Quantification window')
p = matplotlib.patches.Rectangle((lastStart-0.5, 0), 1+(lastIdx-lastStart), y_max,facecolor=(0,0,0,0.05),edgecolor=(0,0,0,0.25),linestyle=(0,(5,2)),linewidth=2,label='Quantification window')
plt.gca().add_patch(p)

if ref1_cut_points:
Expand Down Expand Up @@ -3123,11 +3124,11 @@ def count_alternate_alleles(sub_base_vectors,ref_name,ref_sequence,ref_total_aln
if include_idxs_list[idx] == lastIdx + 1:
lastIdx = include_idxs_list[idx]
else:
p = matplotlib.patches.Rectangle((lastStart-0.5, 0), 1+(lastIdx-lastStart)-0.5, y_max,fill=None,edgecolor=(0,0,0,0.25),linestyle=(0,(5,2)),linewidth=2)
p = matplotlib.patches.Rectangle((lastStart-0.5, 0), 1+(lastIdx-lastStart), y_max,facecolor=(0,0,0,0.05),edgecolor=(0,0,0,0.25),linestyle=(0,(5,2)),linewidth=2)
plt.gca().add_patch(p) #gca = get current axis
lastStart = include_idxs_list[idx]
lastIdx = include_idxs_list[idx]
p = matplotlib.patches.Rectangle((lastStart-0.5, 0), 1+(lastIdx-lastStart)-0.5, y_max,fill=None,edgecolor=(0,0,0,0.25),linestyle=(0,(5,2)),linewidth=2,label='Quantification window')
p = matplotlib.patches.Rectangle((lastStart-0.5, 0), 1+(lastIdx-lastStart), y_max,facecolor=(0,0,0,0.05),edgecolor=(0,0,0,0.25),linestyle=(0,(5,2)),linewidth=2,label='Quantification window')
plt.gca().add_patch(p)

if cut_points:
Expand Down Expand Up @@ -3271,7 +3272,7 @@ def count_alternate_alleles(sub_base_vectors,ref_name,ref_sequence,ref_total_aln
#adjust coordinates of sgRNAs
new_sel_cols_start = cut_point - plot_half_window
for (int_start,int_end) in refs[ref_name]['sgRNA_intervals']:
new_sgRNA_intervals += [(int_start - new_sel_cols_start,int_end - new_sel_cols_start)]
new_sgRNA_intervals += [(int_start - new_sel_cols_start - 1,int_end - new_sel_cols_start - 1)]

CRISPRessoPlot.plot_alleles_table(ref_seq_around_cut,df_alleles=df_to_plot,fig_filename_root=fig_filename_root,
MIN_FREQUENCY=args.min_frequency_alleles_around_cut_to_plot,MAX_N_ROWS=args.max_rows_alleles_around_cut_to_plot,SAVE_ALSO_PNG=save_png,base_editor_output=args.base_editor_output,sgRNA_intervals=new_sgRNA_intervals,sgRNA_names=sgRNA_names,sgRNA_mismatches=sgRNA_mismatches)
Expand Down
18 changes: 16 additions & 2 deletions CRISPResso2/CRISPRessoPlot.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,9 @@ def add_sgRNA_to_ax(ax,sgRNA_intervals,sgRNA_y_start,sgRNA_y_height,amp_len,x_of
)

#if plot has trimmed the sgRNA, add a mark
if this_sgRNA_start != sgRNA_int[0]:
if (this_sgRNA_start) != sgRNA_int[0]:
ax.add_patch(
#patches.Rectangle((x_offset + 0.1+this_sgRNA_start, sgRNA_y_start), 0.1, sgRNA_y_height,facecolor='w',clip_on=clip_on)
patches.Rectangle((x_offset + 0.1+this_sgRNA_start, sgRNA_y_start), 0.1, sgRNA_y_height,facecolor='w',clip_on=clip_on)
)
if this_sgRNA_end != sgRNA_int[1]:
Expand Down Expand Up @@ -1096,6 +1097,19 @@ def plot_alleles_heatmap(reference_seq,fig_filename_root,X,annot,y_labels,insert
N_ROWS=len(X)
N_COLUMNS=plot_nuc_len

if N_ROWS < 1:
fig=plt.figure()
ax = fig.add_subplot(111)
plt.text(0.5, 0.5,'No Alleles',horizontalalignment='center',verticalalignment='center',transform = ax.transAxes)
txt.set_clip_on(False)

plt.savefig(fig_filename_root+'.pdf',bbox_inches='tight',bbox_extra_artists=(lgd,))
if SAVE_ALSO_PNG:
plt.savefig(fig_filename_root+'.png',bbox_inches='tight',bbox_extra_artists=(lgd,))
plt.close()
return


if sgRNA_intervals and len(sgRNA_intervals) > 0:
fig=plt.figure(figsize=(plot_nuc_len*0.3,(N_ROWS+2)*0.6))
gs1 = gridspec.GridSpec(N_ROWS+2,N_COLUMNS)
Expand All @@ -1120,7 +1134,7 @@ def plot_alleles_heatmap(reference_seq,fig_filename_root,X,annot,y_labels,insert
ax_hm.xaxis.set_ticks([])

if sgRNA_intervals and len(sgRNA_intervals) > 0:
add_sgRNA_to_ax(ax_hm_ref,sgRNA_intervals,sgRNA_y_start=-1,sgRNA_y_height=0.7,amp_len=plot_nuc_len,font_size='small',clip_on=False,sgRNA_names=sgRNA_names,sgRNA_mismatches=sgRNA_mismatches,x_offset=-1)
add_sgRNA_to_ax(ax_hm_ref,sgRNA_intervals,sgRNA_y_start=-1,sgRNA_y_height=0.7,amp_len=plot_nuc_len,font_size='small',clip_on=False,sgRNA_names=sgRNA_names,sgRNA_mismatches=sgRNA_mismatches,x_offset=0)

# todo -- add sgRNAs below reference plot
# if sgRNA_intervals:
Expand Down
3 changes: 2 additions & 1 deletion CRISPResso2/CRISPRessoShared.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import argparse
from collections import defaultdict
import errno
import gzip
import numpy as np
import os
Expand All @@ -30,7 +31,7 @@
else:
import cPickle as cp #python 2.7

__version__ = "2.0.32"
__version__ = "2.0.33"

###EXCEPTIONS############################
class FlashException(Exception):
Expand Down

0 comments on commit a66c402

Please sign in to comment.