def air_hist(self, id=None, channel_num=0, *args, **kwargs): from qtools.lib.nstats.peaks import gap_air from pyqlb.nstats.well import accepted_peaks from pyqlb.nstats.peaks import color_uncorrected_peaks, channel_amplitudes, peak_times from qtools.lib.mplot import air_hist, cleanup, render as plt_render qlwell = self.__qlwell_from_threshold_form(id) self.__set_threshold_context(qlwell) c.channel_num = int(channel_num) threshold = c.vic_threshold if c.channel_num == 1 else c.fam_threshold cutoff = request.params.get('cutoff', 500) # can detect air on either channel (especially if VICs super low) # but always report VIC amplitude air_drops = gap_air(qlwell, c.channel_num, threshold=threshold) uncorrected_air = color_uncorrected_peaks(air_drops, qlwell.color_compensation_matrix) # count number of accepted peak times air_drop_times = peak_times(air_drops) accepted_times = peak_times(accepted_peaks(qlwell)) num_air_accepted = len([t for t in air_drop_times if t in accepted_times]) # always gate on VIC air_amps = channel_amplitudes(uncorrected_air, 1) title = 'Air Droplet Histogram - %s, %s (%s)' % (c.well.plate.plate.name, c.well.well_name, 'VIC' if c.channel_num == 1 else 'FAM') fig = air_hist(title, air_amps, cutoff=cutoff, num_accepted=num_air_accepted) response.content_type = 'image/png' imgdata = plt_render(fig, dpi=72) cleanup(fig) return imgdata
def single_well_calibration_clusters(qlwell, dye_cal_props): """ Returns the clusters for the specified color calibration well. Returns them in ch0-HI, ch0-LO, ch1-HI, ch1-LO order. :param qlwell: The well to analyze :param dye_cal_props: A list of dye properties representing the calibration properties on the dyes for each channel. (Should be a 2-tuple.) """ ok_peaks = accepted_peaks(qlwell) if ( len( ok_peaks ) < 1 ): #pass back a 4-tuple of empty peaks return ( ok_peaks,ok_peaks,ok_peaks,ok_peaks) peaks = color_uncorrected_peaks(accepted_peaks(qlwell), qlwell.color_compensation_matrix) # FAM is y, VIC is x. polars = np.array([cmath.polar(complex(f, v)) for f, v in zip(vic_amplitudes(peaks), fam_amplitudes(peaks))]) blue_hi = np.extract(reduce(np.logical_and, (polars[...,1] >= THETA_THRESHOLD, polars[...,0] >= dye_cal_props[0].expected_magnitude_threshold)), ok_peaks) blue_lo = np.extract(reduce(np.logical_and, (polars[...,1] >= THETA_THRESHOLD, polars[...,0] < dye_cal_props[0].expected_magnitude_threshold)), ok_peaks) green_hi = np.extract(reduce(np.logical_and, (polars[...,1] < THETA_THRESHOLD, polars[...,0] >= dye_cal_props[1].expected_magnitude_threshold)), ok_peaks) green_lo = np.extract(reduce(np.logical_and, (polars[...,1] < THETA_THRESHOLD, polars[...,0] < dye_cal_props[1].expected_magnitude_threshold)), ok_peaks) return blue_hi, blue_lo, green_hi, green_lo