Example #1
0
    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
Example #2
0
def well_fragmentation_probability(well):
    """
    Returns the percentage likelihood per droplet that the molecules in
    the two channels are unlinked (TODO: refine definition)

    Returns the 3-tuple (probability, ci_low, ci_high).  If thresholds are
    not present, then the function will return the 3-tuple (None, None, None)
    """
    from qtools.lib.nstats.frag import prob_of_frag

    fam_threshold = well.channels[0].statistics.threshold
    vic_threshold = well.channels[1].statistics.threshold

    if not (fam_threshold and vic_threshold):
        return (None, None, None)
    
    ok_peaks = accepted_peaks(well)
    fampos_vicpos, fampos_vicneg, famneg_vicpos, famneg_vicneg = \
        cluster_2d(ok_peaks, fam_threshold, vic_threshold)
    
    retarr = prob_of_frag(len(fampos_vicneg), len(fampos_vicpos),
                          len(famneg_vicneg), len(famneg_vicpos),
                          len(ok_peaks))
    if not retarr:
        return (None, None, None)
    else:
        pct_interval, vic_interval, fam_interval, linked_interval = retarr
        return pct_interval
Example #3
0
def pos_cluster_angle_2d(qlwell, fam_threshold=None, vic_threshold=None):
    if fam_threshold is None:
        fam_threshold = qlwell.channels[0].statistics.threshold
    if vic_threshold is None:
        vic_threshold = qlwell.channels[1].statistics.threshold

    ok_peaks = accepted_peaks(qlwell)

    fampos_vicpos, fampos_vicneg, famneg_vicpos, famneg_vicneg = \
        cluster_2d(ok_peaks, fam_threshold, vic_threshold)

    if len(fampos_vicneg) == 0 or len(famneg_vicpos) == 0 or len(fampos_vicpos) == 0:
        return 0

    return cluster_angle_ccw(fampos_vicpos, fampos_vicneg, famneg_vicpos)