@@ -38,6 +38,9 @@ def plot_dynamic_range(df, metric, build, filename, bucket_name='cup.clue.io'):
3838 fig_json = g .to_json ()
3939 s3 .put_object (Bucket = bucket_name , Key = f"{ build } /{ filename } " , Body = fig_json .encode ('utf-8' ))
4040
41+ # Close the plot
42+ plt .close ('all' )
43+
4144
4245def plot_dynamic_range_norm_raw (df , build , filename , bucket_name = 'cup.clue.io' ):
4346 g = px .scatter (data_frame = df ,
@@ -65,6 +68,9 @@ def plot_dynamic_range_norm_raw(df, build, filename, bucket_name='cup.clue.io'):
6568 fig_json = g .to_json ()
6669 s3 .put_object (Bucket = bucket_name , Key = f"{ build } /{ filename } " , Body = fig_json .encode ('utf-8' ))
6770
71+ # Close the plot
72+ plt .close ('all' )
73+
6874
6975# PASS RATES
7076def plot_pass_rates_by_plate (df , build , filename , bucket_name = 'cup.clue.io' ):
@@ -83,6 +89,9 @@ def plot_pass_rates_by_plate(df, build, filename, bucket_name='cup.clue.io'):
8389 json = g .to_json ()
8490 s3 .put_object (Bucket = bucket_name , Key = f"{ build } /{ filename } " , Body = json .encode ('utf-8' ))
8591
92+ # Close the plot
93+ plt .close ('all' )
94+
8695
8796def plot_pass_rates_by_pool (df , culture , build ):
8897 df ['replicate' ] = df ['prism_replicate' ].str .split ('_' ).str [3 ]
@@ -105,7 +114,7 @@ def plot_pass_rates_by_pool(df, culture, build):
105114 stat_count () +
106115 facet_grid ('rep_number ~ pert_plate' ) +
107116 theme (axis_text_x = element_text (rotation = 90 )) +
108- theme (figure_size = (10 , 6 )) +
117+ theme (figure_size = (10 , 4 )) +
109118 xlab ('' ) +
110119 ylab ('' ) +
111120 scale_fill_manual (values = colors ) +
@@ -122,6 +131,9 @@ def plot_pass_rates_by_pool(df, culture, build):
122131 object_key = f"{ build } /{ culture } _pass_by_pool.png"
123132 s3 .upload_fileobj (img_data , 'cup.clue.io' , object_key )
124133
134+ # Close the plot
135+ plt .close ('all' )
136+
125137
126138# DISTRIBUTIONS
127139
@@ -156,6 +168,9 @@ def plot_distributions_by_plate(df, build, filename, culture, pert_types=['trt_p
156168 full_filename = f"{ culture } _{ filename } "
157169 s3 .upload_fileobj (buffer , bucket_name , f"{ build } /{ full_filename } " )
158170
171+ # Close the plot
172+ plt .close ('all' )
173+
159174
160175# BANANA PLOTS
161176
@@ -193,6 +208,9 @@ def plot_banana_plots(df, x, y, filename, build, bucket_name='cup.clue.io'):
193208 fig_json = g .to_json ()
194209 s3 .put_object (Bucket = bucket_name , Key = f"{ build } /{ filename } " , Body = fig_json .encode ('utf-8' ))
195210
211+ # Close the plot
212+ plt .close ('all' )
213+
196214
197215# LIVER PLOTS
198216
@@ -221,6 +239,9 @@ def plot_liver_plots(df, build, filename, bucket_name='cup.clue.io'):
221239 fig_json = g .to_json ()
222240 s3 .put_object (Bucket = bucket_name , Key = f"{ build } /{ filename } " , Body = fig_json .encode ('utf-8' ))
223241
242+ # Close the plot
243+ plt .close ('all' )
244+
224245
225246# ERROR RATE V SSMD
226247
@@ -248,6 +269,9 @@ def plot_dr_error_rate(df, build, filename, bucket_name='cup.clue.io'):
248269 fig_json = g .to_json ()
249270 s3 .put_object (Bucket = bucket_name , Key = f"{ build } /{ filename } " , Body = fig_json .encode ('utf-8' ))
250271
272+ # Close the plot
273+ plt .close ('all' )
274+
251275
252276# REPLICATE CORRELATION
253277
@@ -263,6 +287,9 @@ def corrdot(*args, **kwargs):
263287 ax .annotate (corr_text , [.5 , .5 , ], xycoords = "axes fraction" ,
264288 ha = 'center' , va = 'center' , fontsize = font_size )
265289
290+ # Close the plot
291+ plt .close ('all' )
292+
266293
267294def make_corrplots (df , pert_plate , build , culture , metric = 'logMFI_norm' , bucket_name = 'cup.clue.io' ):
268295 data = df [(df .pert_plate == pert_plate ) & (df .culture == culture )]
@@ -291,6 +318,9 @@ def make_corrplots(df, pert_plate, build, culture, metric='logMFI_norm', bucket_
291318 filename = f"{ pert_plate } :{ culture } _corrplot.png"
292319 s3 .upload_fileobj (buffer , bucket_name , f"{ build } /{ filename } " )
293320
321+ # Close plot
322+ plt .close ('all' )
323+
294324
295325def plot_plate_heatmaps (df , metric , build , culture , vmax = 4 , vmin = 16 , by_type = True ):
296326 metric = metric
@@ -370,6 +400,10 @@ def plot_plate_heatmaps(df, metric, build, culture, vmax=4, vmin=16, by_type=Tru
370400 s3 = boto3 .client ('s3' )
371401 s3 .upload_fileobj (img_data , 'cup.clue.io' , object_key )
372402
403+ # Close plot
404+ plt .close ('all' )
405+
406+
373407
374408def make_pert_type_heatmaps (df , build , vmax , vmin , metric = 'logMFI' ):
375409 for culture in df .culture .unique ():
@@ -441,6 +475,9 @@ def make_pert_type_heatmaps(df, build, vmax, vmin, metric='logMFI'):
441475 s3 = boto3 .client ('s3' )
442476 s3 .upload_fileobj (img_data , 'cup.clue.io' , object_key )
443477
478+ # Close plot
479+ plt .close ('all' )
480+
444481
445482def make_build_count_heatmaps (df , build , metric = 'count' ):
446483 for culture in df .culture .unique ():
@@ -504,6 +541,9 @@ def make_build_count_heatmaps(df, build, metric='count'):
504541 s3 = boto3 .client ('s3' )
505542 s3 .upload_fileobj (img_data , 'cup.clue.io' , object_key )
506543
544+ # Close plot
545+ plt .close ('all' )
546+
507547
508548def generate_cbc_quantile_plot (df , build , culture ):
509549 # Filter and get unique values
@@ -565,6 +605,9 @@ def generate_cbc_quantile_plot(df, build, culture):
565605 s3 = boto3 .client ('s3' )
566606 s3 .upload_fileobj (img_data , 'cup.clue.io' , object_key )
567607
608+ # Close plot
609+ plt .close ('all' )
610+
568611
569612def make_build_mfi_heatmaps (df , build , vmax , vmin , metric = 'logMFI' ):
570613 for culture in df .culture .unique ():
@@ -628,6 +671,9 @@ def make_build_mfi_heatmaps(df, build, vmax, vmin, metric='logMFI'):
628671 s3 = boto3 .client ('s3' )
629672 s3 .upload_fileobj (img_data , 'cup.clue.io' , object_key )
630673
674+ # Close plot
675+ plt .close ('all' )
676+
631677
632678def make_control_violin_plot (df , build , culture ):
633679 # Subset data
@@ -659,6 +705,9 @@ def make_control_violin_plot(df, build, culture):
659705 g .save (img_data , format = 'png' , width = fig_width , height = fig_height , dpi = 100 )
660706 img_data .seek (0 )
661707
708+ # Close the plot
709+ plt .close ('all' )
710+
662711 # Upload to S3
663712 s3 = boto3 .client ('s3' )
664713 object_key = f"{ build } /{ culture } _ctl_violin.png"
@@ -710,6 +759,9 @@ def make_ctlbc_rank_heatmaps(df, build, culture):
710759 object_key = f"{ build } /{ culture } _ctlbc_rank_heatmap.png"
711760 s3 .upload_fileobj (img_data , 'cup.clue.io' , object_key )
712761
762+ # Close the plot
763+ plt .close ('all' )
764+
713765
714766def make_ctlbc_rank_violin (df , build , culture , corrs ):
715767 # Subset data and add row/col
@@ -751,6 +803,9 @@ def make_ctlbc_rank_violin(df, build, culture, corrs):
751803 object_key = f"{ build } /{ culture } _ctlbc_rank_violin.png"
752804 s3 .upload_fileobj (img_data , 'cup.clue.io' , object_key )
753805
806+ # Close the plot
807+ plt .close ('all' )
808+
754809
755810def make_control_norm_plots (mfi , qc , culture , build ):
756811 df = mfi .merge (qc [['prism_replicate' , 'ccle_name' , 'pass' ]], on = ['prism_replicate' , 'ccle_name' ], how = 'left' )
@@ -795,6 +850,9 @@ def make_control_norm_plots(mfi, qc, culture, build):
795850 object_key = f"{ build } /{ culture } _{ pert } _norm.png"
796851 s3 .upload_fileobj (img_data , 'cup.clue.io' , object_key )
797852
853+ # Close the plot
854+ plt .close ('all' )
855+
798856
799857def heatmap_plate (df , metric , build , culture , facet_method = None , facets = None , limits = None ,
800858 fig_size = (8 , 3 ), title = '' , text_size = 5 , annotation = 'pert_type_annotation' , tick_size = 5 ,
@@ -922,3 +980,6 @@ def heatmap_plate(df, metric, build, culture, facet_method=None, facets=None, li
922980 s3 = boto3 .client ('s3' )
923981 object_key = f"{ build } /{ metric } _{ culture } _heatmaps.png"
924982 s3 .upload_fileobj (img_data , 'cup.clue.io' , object_key )
983+
984+ # Close the plot
985+ plt .close ('all' )
0 commit comments