Skip to content

Commit a72021a

Browse files
committed
Close plots when written
Update desciptions with floor range Resize pass rates by pool
1 parent 5338c76 commit a72021a

File tree

3 files changed

+67
-4
lines changed

3 files changed

+67
-4
lines changed

app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ def read_json_from_s3(bucket_name, filename, prefix):
527527
with st.spinner('Generating report and uploading results'):
528528

529529
# Read build and create metric dfs
530-
df_build = read_build.read_build_from_s3(build)
530+
df_build = read_build.read_build_from_s3(build, data_levels=['qc', 'mfi', 'lfc', 'inst', 'cell'])
531531
qc = df_build.qc
532532
mfi = df_build.mfi
533533
lfc = df_build.lfc

descriptions.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,13 @@
2727
'quantile of all cell line barcodes that the given median control barcode falls into. Note that this ' \
2828
'is limited to vehicle wells. The ideal distribution is signified by the dashed line on the plot.'
2929

30-
dr_and_er = 'Dynamic range and error rate are the two key QC metrics that we use when determining whether or not a ' \
30+
dr_and_er = 'Dynamic range, error rate and floor range are the two key QC metrics that we use when determining whether or not a ' \
3131
'cell line passes or fails on a given detection plate. **Dynamic range** is given by the difference ' \
3232
'between the logMFI of the vehicle control and the positive control. The **error rate** is a measure of the ' \
3333
'overlap between the positive and negative control values for each cell line and is given as **ER = (FP - FN)/n** ' \
34-
'where FP is the false positive rate, FN is the false negative rate, and n is the total number of controls.'
34+
'where FP is the false positive rate, FN is the false negative rate, and n is the total number of controls./n** ' \
35+
'**Floor range** is defined as the difference between the signal from a cell line in vehicle and a bead that ' \
36+
'has been coupled to a sequence that lacks any matching sequence.'
3537

3638
pass_by_plate = 'Fractions of cell lines within each detection plate that pass our thresholds for both dynamic range ' \
3739
'and error rate.'

plotting_functions.py

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

4245
def 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
7076
def 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

8796
def 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

267294
def 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

295325
def 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

374408
def 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

445482
def 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

508548
def 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

569612
def 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

632678
def 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

714766
def 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

755810
def 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

799857
def 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

Comments
 (0)