def dnr_by_bin(plate_objects, fam_channels, sample_names, bin_func): """ @deprecated - use metrics """ bins = set([bin_func(c) for c in fam_channels]) # TODO: do sample names here bin_plots = dict([(bin, [[0.001,None],[0.01,None],[0.1,None],[1,None],[5,None]]) for bin in bins]) groups = [] groups.extend([(sample_name, groupinto(sample_name_channel_filter(fam_channels, sample_name), bin_func)) for sample_name in sample_names]) for i, (sample, group) in enumerate(groups): for bin, channels in group: conc_array = [] for c in channels: qplate = plate_objects[(c.well.plate.file.dirname, c.well.plate.file.basename)] well = qplate.wells[c.well.well_name] # TODO: use dynamic threshold or keep 4000? pos, neg = cluster_1d(accepted_peaks(well), 0, 4000) conc, clow, chigh = concentration_interval(len(pos), len(neg), droplet_vol=well.droplet_volume) conc_array.append((max(conc,0.0001), max(clow,0.0001), max(chigh,0.0001))) if len(conc_array) > 0: conc_mean = np.mean([ca[0] for ca in conc_array]) bin_plots[bin][i][1] = (conc_mean, conc_array) return bin_plots
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