Skip to content

Commit

Permalink
Update run_herg_qc.py output
Browse files Browse the repository at this point in the history
  • Loading branch information
joeyshuttleworth committed Jun 12, 2024
1 parent 3a1b24f commit 3b47f9d
Showing 1 changed file with 51 additions and 21 deletions.
72 changes: 51 additions & 21 deletions scripts/run_herg_qc.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,39 +394,67 @@ def create_qc_table(qc_df):
if len(qc_df.index) == 0:
return None

qc_criteria = qc_df.drop(['protocol', 'well'], axis='columns').columns
qc_df = qc_df.drop('protocol', axis='columns')

def agg_func(x):
x = list(x.values.flatten())
x = [True if y == 'True' or y == True or y == 1 \
else False for y in x]
return np.all(x)
if 'Unnamed: 0' in qc_df:
qc_df = qc_df.drop('Unnamed: 0', axis='columns')

qc_criteria = list(qc_df.drop(['protocol', 'well'], axis='columns').columns)

qc_df = qc_df.groupby('well').agg(
func=agg_func).reset_index()
def agg_func(x):
x = x.values.flatten().astype(bool)
return bool(np.all(x))

qc_df[qc_criteria] = qc_df[qc_criteria].astype(bool)

agg_dict = {crit: 'min' for crit in qc_criteria}
qc_df = qc_df.groupby('well').agg(agg_dict).reset_index()
qc_df['protocol'] = ['staircaseramp1_2' if p == 'staircaseramp2' else p
for p in qc_df.protocol]

print(qc_df.protocol.unique())

fails_dict = {}
no_wells = 384
for crit in sorted(qc_criteria):
col = qc_df[crit].copy()

vals = list(col.values.flatten())
dfs = []
protocol_headings = ['staircaseramp1', 'staircaseramp1_2', 'all']
for protocol in protocol_headings:
fails_dict = {}
for crit in sorted(qc_criteria) + ['all']:
if protocol != 'all':
sub_df = qc_df[qc_df.protocol == protocol].copy()
else:
sub_df = qc_df.copy()

agg_dict = {crit: agg_func for crit in qc_criteria}
if crit != 'all':
col = sub_df.groupby('well').agg(agg_dict).reset_index()[crit]
vals = col.values.flatten()
n_passed = vals.sum()
else:
excluded = [crit for crit in qc_criteria
if 'all' in crit or 'spread' in crit or 'bookend' in crit]
if protocol == 'all':
excluded = []
crit_included = [crit for crit in qc_criteria if crit not in excluded]

col = sub_df.groupby('well').agg(agg_dict).reset_index()
n_passed = np.sum(np.all(col[crit_included].values, axis=1).flatten())

crit = re.sub('_', r'\_', crit)
fails_dict[crit] = (crit, no_wells - n_passed)

true_vals = [val for val in vals if val == True or val == 'True' or val == 1]
print(crit)
print(vals)
new_df = pd.DataFrame.from_dict(fails_dict, orient='index',
columns=['crit', 'wells failing'])
new_df['protocol'] = protocol
new_df.set_index('crit')
dfs.append(new_df)

crit = re.sub('_', r'\_', crit)
fails_dict[crit] = no_wells - len(true_vals)
ret_df = pd.concat(dfs, ignore_index=True)

ret_df['wells failing'] = ret_df['wells failing'].astype(int)

ret_df['protocol'] = pd.Categorical(ret_df['protocol'],
categories=protocol_headings,
ordered=True)

ret_df = pd.DataFrame.from_dict(fails_dict, orient='index', columns=['wells failing'])
return ret_df


Expand Down Expand Up @@ -638,6 +666,8 @@ def extract_protocol(readname, savename, time_strs, selected_wells, args):
row_dict['R_leftover'] =\
np.sqrt(np.sum((after_corrected)**2)/(np.sum(before_corrected**2)))

row_dict['QC.R_leftover'] = row_dict['R_leftover'] < 0.5

row_dict['E_rev'] = E_rev
row_dict['E_rev_before'] = E_rev_before
row_dict['E_rev_after'] = E_rev_after
Expand Down

0 comments on commit 3b47f9d

Please sign in to comment.