def quartile_concentration_ratio(well, channel_num=0, threshold=None, peaks=None, min_events=4000): if peaks is None: peaks = accepted_peaks(well) if len(peaks) < min_events: return None if not threshold: threshold = well.channels[channel_num].statistics.threshold if not threshold: return None quartile_size = len(peaks)/4 first_quartile = peaks[0:quartile_size] last_quartile = peaks[len(peaks)-quartile_size:] first_pos, first_neg = cluster_1d(first_quartile, channel_num, threshold) fq_conc = concentration(len(first_pos), len(first_neg), droplet_vol=well.droplet_volume) # could be nan last_pos, last_neg = cluster_1d(last_quartile, channel_num, threshold) lq_conc = concentration(len(last_pos), len(last_neg), droplet_vol=well.droplet_volume) # could be nan # if conc is nan or zero, we can't compute a real ratio if math.isnan(fq_conc) or math.isnan(lq_conc) or fq_conc == 0 or lq_conc == 0: return None else: return lq_conc/fq_conc
def well_statistics(qlwell, override_thresholds=None): from pyqlb.nstats import concentration, concentration_interval from pyqlb.nstats.peaks import cluster_1d from pyqlb.nstats.well import well_observed_positives_negatives, accepted_peaks if override_thresholds is None: override_thresholds = [None]*len(qlwell.channels) wellui = WellStatisticsUI(channels=[]) for idx, channel in enumerate(qlwell.channels): if not override_thresholds[idx]: positives, negatives, unclassified = well_observed_positives_negatives(qlwell, idx) threshold = channel.statistics.threshold conc = channel.statistics.concentration conc_interval = (channel.statistics.concentration, channel.statistics.concentration_lower_bound, channel.statistics.concentration_upper_bound) else: positives, negatives = cluster_1d(accepted_peaks(qlwell), idx, override_thresholds[idx]) threshold = override_thresholds[idx] conc = concentration(len(positives), len(negatives), qlwell.droplet_volume) conc_interval = concentration_interval(len(positives), len(negatives), qlwell.droplet_volume) channelui = WellChannelStatisticsUI(positives=len(positives), negatives=len(negatives), threshold=threshold, concentration=conc, concentration_interval=conc_interval) wellui.channels.append(channelui) return wellui