|
1 | 1 | import os |
| 2 | + |
2 | 3 | # from metapool.metapool import * |
3 | 4 | from sys import argv |
4 | | -import pandas as pd |
| 5 | + |
5 | 6 | import matplotlib.pyplot as plt |
6 | | -from metapool.metapool import (read_survival, make_2D_array, |
7 | | - calculate_iseqnorm_pooling_volumes, |
8 | | - format_pooling_echo_pick_list) |
| 7 | +import pandas as pd |
9 | 8 | import seaborn as sns |
| 9 | +from metapool.metapool import ( |
| 10 | + calculate_iseqnorm_pooling_volumes, |
| 11 | + format_pooling_echo_pick_list, |
| 12 | + make_2D_array, |
| 13 | + read_survival, |
| 14 | +) |
10 | 15 |
|
11 | 16 | input_sheet_filename = argv[1] |
12 | 17 |
|
13 | | -plate_df_w_reads = pd.read_csv(input_sheet_filename, sep='\t') |
14 | | -plate_df_w_reads['Blank'] = [True if 'blank' in s.lower() else False |
15 | | - for s in plate_df_w_reads['Sample_Name']] |
16 | | -reads_column = 'read_counts' |
| 18 | +plate_df_w_reads = pd.read_csv(input_sheet_filename, sep="\t") |
| 19 | +plate_df_w_reads["Blank"] = [ |
| 20 | + True if "blank" in s.lower() else False for s in plate_df_w_reads["Sample_Name"] |
| 21 | +] |
| 22 | +reads_column = "read_counts" |
17 | 23 |
|
18 | | -well_col = 'Sample_Well' |
| 24 | +well_col = "Sample_Well" |
19 | 25 | assert reads_column in plate_df_w_reads.columns |
20 | 26 |
|
21 | | -f, ((ax1, ax2), (ax3, ax4)) = plt.subplots(nrows=2, ncols=2, figsize=(8, 8)) |
| 27 | +_, ((ax1, ax2), (ax3, ax4)) = plt.subplots(nrows=2, ncols=2, figsize=(8, 8)) |
22 | 28 | # evenness plot |
23 | 29 | rmax = int(round(plate_df_w_reads[reads_column].max(), -2)) |
24 | 30 |
|
25 | | -foo = read_survival(plate_df_w_reads.loc[plate_df_w_reads['Blank'] is True, |
26 | | - reads_column], |
27 | | - label='Blanks', |
28 | | - rmax=rmax) |
| 31 | +foo = read_survival( |
| 32 | + plate_df_w_reads.loc[plate_df_w_reads["Blank"] is True, reads_column], |
| 33 | + label="Blanks", |
| 34 | + rmax=rmax, |
| 35 | +) |
29 | 36 |
|
30 | | -bar = read_survival(plate_df_w_reads.loc[plate_df_w_reads['Blank'] is False, |
31 | | - reads_column], |
32 | | - label='Samples', |
33 | | - rmax=rmax) |
| 37 | +bar = read_survival( |
| 38 | + plate_df_w_reads.loc[plate_df_w_reads["Blank"] is False, reads_column], |
| 39 | + label="Samples", |
| 40 | + rmax=rmax, |
| 41 | +) |
34 | 42 |
|
35 | 43 | survival_df = pd.concat([foo, bar]) |
36 | 44 |
|
37 | 45 | ax3.set_xlabel(reads_column) |
38 | | -ax3.set_ylabel('Samples') |
39 | | -survival_df.plot(color=['coral', 'steelblue'], ax=ax1) |
| 46 | +ax3.set_ylabel("Samples") |
| 47 | +survival_df.plot(color=["coral", "steelblue"], ax=ax1) |
40 | 48 | ax1.set_xlabel(reads_column) |
41 | | -ax1.set_ylabel('Samples') |
| 49 | +ax1.set_ylabel("Samples") |
42 | 50 |
|
43 | 51 | # Histogram |
44 | 52 | sns.histplot(plate_df_w_reads[reads_column], ax=ax3) |
45 | 53 |
|
46 | 54 | # Boxplot |
47 | 55 | sns.boxplot(x="Blank", y=reads_column, data=plate_df_w_reads, ax=ax4) |
48 | | -sns.stripplot(x="Blank", y=reads_column, data=plate_df_w_reads, ax=ax4, |
49 | | - size=3, color='black', alpha=0.5) |
| 56 | +sns.stripplot( |
| 57 | + x="Blank", |
| 58 | + y=reads_column, |
| 59 | + data=plate_df_w_reads, |
| 60 | + ax=ax4, |
| 61 | + size=3, |
| 62 | + color="black", |
| 63 | + alpha=0.5, |
| 64 | +) |
50 | 65 |
|
51 | 66 | plt.tight_layout() |
52 | | -plt.savefig(input_sheet_filename + '.comboplot.pdf') |
| 67 | +plt.savefig(input_sheet_filename + ".comboplot.pdf") |
53 | 68 |
|
54 | | -pdfn = calculate_iseqnorm_pooling_volumes(plate_df_w_reads, |
55 | | - dynamic_range=20, |
56 | | - normalization_column=reads_column) |
57 | | -plt.savefig(input_sheet_filename + '.normalizedplot.pdf') |
| 69 | +pdfn = calculate_iseqnorm_pooling_volumes( |
| 70 | + plate_df_w_reads, dynamic_range=20, normalization_column=reads_column |
| 71 | +) |
| 72 | +plt.savefig(input_sheet_filename + ".normalizedplot.pdf") |
58 | 73 |
|
59 | | -vols = make_2D_array(pdfn, |
60 | | - data_col='iSeq normpool volume', |
61 | | - well_col=well_col).astype(float) |
| 74 | +vols = make_2D_array(pdfn, data_col="iSeq normpool volume", well_col=well_col).astype( |
| 75 | + float |
| 76 | +) |
62 | 77 |
|
63 | 78 | # Write the picklist as .csv |
64 | | -picklist_fp = input_sheet_filename + '.picklist.csv' |
| 79 | +picklist_fp = input_sheet_filename + ".picklist.csv" |
65 | 80 |
|
66 | 81 | if os.path.isfile(picklist_fp): |
67 | 82 | print("Warning! This file exists already.") |
68 | 83 |
|
69 | 84 | picklist = format_pooling_echo_pick_list(vols, max_vol_per_well=30000) |
70 | 85 |
|
71 | | -with open(picklist_fp, 'w') as f: |
| 86 | +with open(picklist_fp, "w") as f: |
72 | 87 | f.write(picklist) |
0 commit comments