def compute(self, qlwell, qlwell_channel, well_channel_metric, dyeset=None): if dyeset: blue_hi, blue_lo, green_hi, green_lo = single_well_calibration_clusters(qlwell, dyeset) elif qlwell.sample_name == DYES_FAM_VIC_LABEL: blue_hi, blue_lo, green_hi, green_lo = single_well_calibration_clusters(qlwell, DYES_FAM_VIC) elif qlwell.sample_name == DYES_FAM_HEX_LABEL: blue_hi, blue_lo, green_hi, green_lo = single_well_calibration_clusters(qlwell, DYES_FAM_HEX) else: # do not know how to compute, return wcm return well_channel_metric if well_channel_metric.channel_num == 0: hi_amplitudes = fam_amplitudes(blue_hi) lo_amplitudes = fam_amplitudes(blue_lo) well_channel_metric.positive_peaks = len(blue_hi) well_channel_metric.positive_mean = np.mean(hi_amplitudes) well_channel_metric.positive_stdev = np.std(hi_amplitudes) well_channel_metric.negative_peaks = len(blue_lo) well_channel_metric.negative_mean = np.mean(lo_amplitudes) well_channel_metric.negative_stdev = np.std(lo_amplitudes) well_channel_metric.width_mean_hi = np.mean( fam_widths( blue_hi ) ) elif well_channel_metric.channel_num == 1: hi_amplitudes = vic_amplitudes(green_hi) lo_amplitudes = vic_amplitudes(green_lo) well_channel_metric.positive_peaks = len(green_hi) well_channel_metric.positive_mean = np.mean(hi_amplitudes) well_channel_metric.positive_stdev = np.std(hi_amplitudes) well_channel_metric.negative_peaks = len(green_lo) well_channel_metric.negative_mean = np.mean(lo_amplitudes) well_channel_metric.negative_stdev = np.std(lo_amplitudes) well_channel_metric.width_mean_hi = np.mean( fam_widths( green_hi )) return well_channel_metric
def cluster_csv(self, id=None, show_only_gated=True, *args, **kwargs): from pyqlb.nstats.well import accepted_peaks qlwell = self.__qlwell_from_threshold_form(id) if show_only_gated != 'False': peaks = accepted_peaks(qlwell) else: peaks = qlwell.peaks from pyqlb.nstats.peaks import fam_amplitudes, fam_widths, vic_amplitudes, vic_widths, peak_times from pyqlb.nstats.well import well_observed_cluster_assignments response.headers['Content-Type'] = 'text/csv' h.set_download_response_header(request, response, "%s_%s%s.csv" % \ (str(c.well.plate.plate.name), str(c.well.well_name), '' if show_only_gated != 'False' else '_all')) out = StringIO.StringIO() csvwriter = csv_pkg.writer(out) csvwriter.writerow(['Plate',c.well.plate.plate.name]) csvwriter.writerow(['Well',c.well.well_name]) csvwriter.writerow([]) csvwriter.writerow(['Time','FAMAmplitude','FAMWidth','VICAmplitude','VICWidth','Cluster']) csvwriter.writerow([]) pts = peak_times(peaks) fas = fam_amplitudes(peaks) fws = fam_widths(peaks) vas = vic_amplitudes(peaks) vws = vic_widths(peaks) cls = well_observed_cluster_assignments(qlwell, peaks) for row in zip(pts, fas, fws, vas, vws, cls): csvwriter.writerow(row) csv = out.getvalue() out.close() return csv
def svilen(self, id=None, *args, **kwargs): from pyqlb.nstats.well import accepted_peaks from pyqlb.nstats.peaks import cluster_2d, peak_times, fam_widths from pyqlb.factory import QLNumpyObjectFactory from qtools.lib.mplot import svilen, cleanup, render as plt_render qlwell = self.__qlwell_from_threshold_form(id) self.__set_threshold_context(qlwell) well_path = self.__well_path() # oh shit factory = QLNumpyObjectFactory() raw_well = factory.parse_well(well_path) crap, crap, gold, crap = cluster_2d(accepted_peaks(qlwell), c.fam_threshold, c.vic_threshold) times = peak_times(gold) widths = fam_widths(gold) title = "VIC+/FAM- droplet traces (accepted events)" ranges = [(int(t-(w*2)), int(t+(w*2))) for t, w in zip(times, widths)] if c.fam_threshold == 0 or c.vic_threshold == 0: ranges = [] title = "%s (no events in quadrant)" % title elif len(ranges) > 100: ranges = ranges[:100] title = "%s (truncated at first 100)" % title fig = svilen(title, raw_well.samples, ranges, widths) response.content_type = 'image/png' imgdata = plt_render(fig, dpi=72) cleanup(fig) return imgdata
def well_mean_sigma_closure(well): qplate = plate_objects[(well.plate.file.dirname, well.plate.file.basename)] if not qplate: return None well = qplate.wells[well.well_name] widths = fam_widths(well.peaks) mean = np.mean(widths) stddev = np.std(widths) return (mean, mean-stddev, mean+stddev)
def peak_csv(self, id=None, show_only_gated=True, *args, **kwargs): from qtools.lib.nstats.peaks import accepted_peaks qlwell = self.__qlwell_from_threshold_form(id) if show_only_gated != 'False': peaks = accepted_peaks(qlwell) else: peaks = qlwell.peaks from pyqlb.nstats.peaks import fam_amplitudes, fam_widths, fam_quality, vic_amplitudes, vic_widths, vic_quality, peak_times response.headers['Content-Type'] = 'text/csv' h.set_download_response_header(request, response, "%s_%s%s.csv" % \ (str(c.well.plate.plate.name), str(c.well.well_name), '' if show_only_gated != 'False' else '_all')) out = StringIO.StringIO() csvwriter = csv_pkg.writer(out) csvwriter.writerow(['Plate',c.well.plate.plate.name]) csvwriter.writerow(['Well',c.well.well_name]) csvwriter.writerow([]) csvwriter.writerow(['FAMThreshold',qlwell.channels[0].statistics.threshold]) csvwriter.writerow(['VICThreshold',qlwell.channels[1].statistics.threshold]) csvwriter.writerow(['WidthGate',qlwell.channels[0].statistics.min_width_gate,qlwell.channels[0].statistics.max_width_gate]) csvwriter.writerow(['MinQualityGate',qlwell.channels[0].statistics.min_quality_gate]) csvwriter.writerow([]) csvwriter.writerow(['Time','FAMAmplitude','FAMWidth','FAMQuality','VICAmplitude','VICWidth','VICQuality']) csvwriter.writerow([]) pts = peak_times(peaks) fas = fam_amplitudes(peaks) fws = fam_widths(peaks) fqs = fam_quality(peaks) vas = vic_amplitudes(peaks) vws = vic_widths(peaks) vqs = vic_quality(peaks) for row in zip(pts, fas, fws, fqs, vas, vws, vqs): csvwriter.writerow(row) csv = out.getvalue() out.close() return csv