コード例 #1
0
ファイル: peaks.py プロジェクト: v-makarenko/vtoolsmq
def revb_extracluster_peaks(well, channel_num, threshold=None, pct_boundary=0.3, exclude_min_amplitude_peaks=True):
    """
    Return the peaks that are outside the clusters.
    A superset of polydispersity peaks, meant primarily for dye wells,
    where there should be no biological basis for rain.

    Returns a 3-tuple: peaks, rain gates, width gates
    """
    if not threshold:
        threshold = well.channels[channel_num].statistics.threshold
    if not threshold:
        threshold = None
    
    if exclude_min_amplitude_peaks:
        peaks = above_min_amplitude_peaks(well)
    else:
        peaks = well.peaks
    
    # get rain_pvalues
    p_plus, p, p_minus, pos, middle_high, middle_low, neg = \
            rain_pvalues_thresholds(peaks,
                                    channel_num=channel_num,
                                    threshold=threshold,
                                    pct_boundary=pct_boundary)
    
    binned_peaks = bin_peaks_by_amplitude(peaks, well.sum_amplitude_bins)

    extra_peaks = np.ndarray([0], dtype=peak_dtype(2))
    for bin, (min_gate, max_gate, boundary) in zip(binned_peaks, well.sum_amplitude_bins):
        if middle_high and middle_low:
            extra_peaks = np.hstack([extra_peaks, np.extract(np.logical_not(
                np.logical_or(
                       reduce(np.logical_and,
                              (channel_widths(bin, channel_num) > min_gate,
                               channel_widths(bin, channel_num) < max_gate,
                               channel_amplitudes(bin, channel_num) > middle_high,
                               channel_amplitudes(bin, channel_num) < pos)),
                       reduce(np.logical_and,
                              (channel_widths(bin, channel_num) > min_gate,
                               channel_widths(bin, channel_num) < max_gate,
                               channel_amplitudes(bin, channel_num) > neg,
                               channel_amplitudes(bin, channel_num) < middle_low))
                )
            ), bin)])
        else:
            extra_peaks = np.hstack([extra_peaks, np.extract(np.logical_not(
                reduce(np.logical_and,
                       (channel_widths(bin, channel_num) > min_gate,
                        channel_widths(bin, channel_num) < max_gate,
                        channel_amplitudes(bin, channel_num) > neg,
                        channel_amplitudes(bin, channel_num) < pos)
                )
            ), bin)])
    
    return (extra_peaks,
            (pos, middle_high, middle_low, neg),
            (np.mean(fam_amplitudes(peaks)), np.mean(vic_amplitudes(peaks))))
コード例 #2
0
ファイル: peaks.py プロジェクト: v-makarenko/vtoolsmq
def extracluster_peaks(well, channel_num, threshold=None, pct_boundary=0.3, exclude_min_amplitude_peaks=True):
    """
    Return the peaks that are outside the clusters.
    A superset of polydispersity peaks, meant primarily for dye wells,
    where there should be no biological basis for rain.

    Returns a 3-tuple: peaks, rain gates, width gates
    """
    if not threshold:
        threshold = well.channels[channel_num].statistics.threshold
    if not threshold:
        threshold = None
    
    if exclude_min_amplitude_peaks:
        peaks = above_min_amplitude_peaks(well)
    else:
        peaks = well.peaks
    
    # get rain_pvalues
    p_plus, p, p_minus, pos, middle_high, middle_low, neg = \
            rain_pvalues_thresholds(peaks,
                                    channel_num=channel_num,
                                    threshold=threshold,
                                    pct_boundary=pct_boundary)
    
    min_gate, max_gate = well_static_width_gates(well)

    if middle_high and middle_low:
        extracluster_peaks = np.extract(np.logical_not(
            np.logical_or(
                   reduce(np.logical_and,
                          (channel_widths(peaks, channel_num) > min_gate,
                           channel_widths(peaks, channel_num) < max_gate,
                           channel_amplitudes(peaks, channel_num) > middle_high,
                           channel_amplitudes(peaks, channel_num) < pos)),
                   reduce(np.logical_and,
                          (channel_widths(peaks, channel_num) > min_gate,
                           channel_widths(peaks, channel_num) < max_gate,
                           channel_amplitudes(peaks, channel_num) > neg,
                           channel_amplitudes(peaks, channel_num) < middle_low))
            )
        ), peaks)
    else:
        extracluster_peaks = np.extract(np.logical_not(
            reduce(np.logical_and,
                   (channel_widths(peaks, channel_num) > min_gate,
                    channel_widths(peaks, channel_num) < max_gate,
                    channel_amplitudes(peaks, channel_num) > neg,
                    channel_amplitudes(peaks, channel_num) < pos)
            )
        ), peaks)
    
    return (extracluster_peaks,
            (pos, middle_high, middle_low, neg),
            (min_gate, max_gate))
コード例 #3
0
ファイル: well.py プロジェクト: v-makarenko/vtoolsmq
    def temporal_galaxy(self, id=None, channel_num=0, *args, **kwargs):
        from qtools.lib.nstats.peaks import above_min_amplitude_peaks
        from pyqlb.nstats.peaks import peak_times, channel_amplitudes, channel_widths
        
        qlwell = self.__qlwell_from_threshold_form(id)
        self.__set_threshold_context(qlwell)
        c.channel_num = int(channel_num)

        ok_peaks = above_min_amplitude_peaks(qlwell)
        c.taw = zip(peak_times(ok_peaks), channel_amplitudes(ok_peaks, c.channel_num), channel_widths(ok_peaks, c.channel_num))
        if c.channel_num == 0:
            c.channel_name = 'FAM'
        else:
            c.channel_name = 'VIC'

        return render('/well/temporal_galaxy.html')
コード例 #4
0
ファイル: peaks.py プロジェクト: v-makarenko/vtoolsmq
def revb_polydisperse_peaks(well, channel_num, threshold=None, pct_boundary=0.3, exclude_min_amplitude_peaks=True):
    """
    Computes polydispersity for a well which has amplitude bins defined.

    Returns a 3-tuple (4-tuple, 4-tuple, 2-tuple).  The first 4-tuple is:

    * positive droplets, with widths above the width gate set for that droplet's amplitude bin.
    * middle rain, with widths above the bin width gate.
    * middle rain, with width below the bin width gate.
    * negative rain, with width below the bin width gate.

    The second 4-tuple is:

    * positive rain boundary
    * middle rain upper boundary (can be None)
    * middle rain lower boundary (can be None)
    * negative rain boundary

    The third 2-tuple is:

    * mean FAM amplitude
    * mean VIC amplitude

    This is for being able to draw approximate single-channel polydispersity graphs
    down the line (this does beg the question, is there a better 2D definition of
    polydispersity?)

    Will raise an error if amplitude bins are not defined on the well.
    """
    if not hasattr(well, 'sum_amplitude_bins') or len(well.sum_amplitude_bins) == 0:
        raise ValueError("No amplitude bins for this well.")
    
    if not threshold:
        threshold = well.channels[channel_num].statistics.threshold
    if not threshold:
        threshold = None
    
    if exclude_min_amplitude_peaks:
        peaks = above_min_amplitude_peaks(well)
    else:
        peaks = well.peaks
    
    p_plus, p, p_minus, pos, middle_high, middle_low, neg = \
            rain_pvalues_thresholds(peaks,
                                    channel_num=channel_num,
                                    threshold=threshold,
                                    pct_boundary=pct_boundary)
    
    binned_peaks         = bin_peaks_by_amplitude(peaks, well.sum_amplitude_bins)
    
    pos_peaks     = np.ndarray([0], dtype=peak_dtype(2))
    midhigh_peaks = np.ndarray([0], dtype=peak_dtype(2))
    midlow_peaks  = np.ndarray([0], dtype=peak_dtype(2))
    neg_peaks     = np.ndarray([0], dtype=peak_dtype(2))

    for bin, (min_gate, max_gate, boundary) in zip(binned_peaks, well.sum_amplitude_bins):
        pos_peaks = np.hstack([pos_peaks, np.extract(
            reduce(np.logical_and,
                   (channel_widths(bin, channel_num) > max_gate,
                    channel_amplitudes(bin, channel_num) > pos)),
            bin)])
    
        if middle_high and middle_low:
            midhigh_peaks = np.hstack([midhigh_peaks, np.extract(
                reduce(np.logical_and,
                       (channel_widths(bin, channel_num) > max_gate,
                        reduce(np.logical_and,
                               (channel_amplitudes(bin, channel_num) < middle_high,
                                channel_amplitudes(bin, channel_num) > middle_low)))),
                bin)])
            
            midlow_peaks = np.hstack([midlow_peaks, np.extract(
                reduce(np.logical_and,
                       (channel_widths(bin, channel_num) < min_gate,
                        reduce(np.logical_and,
                               (channel_amplitudes(bin, channel_num) < middle_high,
                                channel_amplitudes(bin, channel_num) > middle_low)))),
                bin)])
        
        neg_peaks = np.hstack([neg_peaks, np.extract(
            reduce(np.logical_and,
                   (channel_widths(bin, channel_num) < min_gate,
                    channel_amplitudes(bin, channel_num) < neg)),
            bin)])
    
    return ((pos_peaks, midhigh_peaks, midlow_peaks, neg_peaks),
            (pos, middle_high, middle_low, neg),
            (np.mean(fam_amplitudes(peaks)), np.mean(vic_amplitudes(peaks))))
コード例 #5
0
ファイル: peaks.py プロジェクト: v-makarenko/vtoolsmq
def revb_extracluster_peaks_by_region(well, channel_num, threshold=None, pct_boundary=0.3, exclude_min_amplitude_peaks=True):
    """
    Return the peaks that are not desired (outside clusters)
    and separate them by region.  The region order is:

    -- positive large peaks
    -- positive rain
    -- positive small peaks
    -- positive wide peaks (directly above positive cluster)
    -- positive narrow peaks (directly below positive cluster)
    -- middle large peaks
    -- middle rain
    -- middle small peaks
    -- negative large peaks
    -- negative rain
    -- negative small peaks
    -- negative wide peaks (directly above positive cluster)
    -- negative narrow peaks (directly below positive cluster)

    Returns this 9-tuple, then rain gates, then mean of FAM and VIC.
    """
    extra_peaks, rain_gates, means = \
        revb_extracluster_peaks(well, channel_num,
                                threshold=threshold,
                                pct_boundary=pct_boundary,
                                exclude_min_amplitude_peaks=exclude_min_amplitude_peaks)

    pos_gate, midhigh_gate, midlow_gate, neg_gate = rain_gates
    binned_peaks = bin_peaks_by_amplitude(extra_peaks, well.sum_amplitude_bins)
    plpeaks = np.ndarray([0], dtype=peak_dtype(2))
    prpeaks = np.ndarray([0], dtype=peak_dtype(2))
    pspeaks = np.ndarray([0], dtype=peak_dtype(2))
    pwpeaks = np.ndarray([0], dtype=peak_dtype(2))
    pnpeaks = np.ndarray([0], dtype=peak_dtype(2))
    mlpeaks = np.ndarray([0], dtype=peak_dtype(2))
    mrpeaks = np.ndarray([0], dtype=peak_dtype(2))
    mspeaks = np.ndarray([0], dtype=peak_dtype(2))
    nlpeaks = np.ndarray([0], dtype=peak_dtype(2))
    nrpeaks = np.ndarray([0], dtype=peak_dtype(2))
    nspeaks = np.ndarray([0], dtype=peak_dtype(2))
    nwpeaks = np.ndarray([0], dtype=peak_dtype(2))
    nnpeaks = np.ndarray([0], dtype=peak_dtype(2))

    for bin, (min_gate, max_gate, boundary) in zip(binned_peaks, well.sum_amplitude_bins):
        plpeaks = np.hstack([plpeaks, np.extract(
            reduce(np.logical_and,
                   (channel_widths(bin, channel_num) > max_gate,
                    channel_amplitudes(bin, channel_num) > pos_gate)
            ), bin)])
        prpeaks = np.hstack([prpeaks, np.extract(
            reduce(np.logical_and,
                   (channel_widths(bin, channel_num) >= min_gate,
                    channel_widths(bin, channel_num) <= max_gate,
                    channel_amplitudes(bin, channel_num) > pos_gate)
            ), bin)])
        pspeaks = np.hstack([pspeaks, np.extract(
            reduce(np.logical_and,
                   (channel_widths(bin, channel_num) < min_gate,
                    channel_amplitudes(bin, channel_num) > pos_gate)
            ), bin)])
        if midhigh_gate and midlow_gate:
            mlpeaks = np.hstack([mlpeaks, np.extract(
            reduce(np.logical_and,
                   (channel_widths(bin, channel_num) > max_gate,
                    channel_amplitudes(bin, channel_num) < midhigh_gate,
                    channel_amplitudes(bin, channel_num) > midlow_gate)
            ), bin)])
            mrpeaks = np.hstack([mrpeaks, np.extract(
                reduce(np.logical_and,
                       (channel_widths(bin, channel_num) >= min_gate,
                        channel_widths(bin, channel_num) <= max_gate,
                        channel_amplitudes(bin, channel_num) < midhigh_gate,
                        channel_amplitudes(bin, channel_num) > midlow_gate)
                ), bin)])
            mspeaks = np.hstack([mspeaks, np.extract(
                reduce(np.logical_and,
                       (channel_widths(bin, channel_num) < min_gate,
                        channel_amplitudes(bin, channel_num) < midhigh_gate,
                        channel_amplitudes(bin, channel_num) > midlow_gate)
                ), bin)])
            # this means there are positives
            pwpeaks = np.hstack([pwpeaks, np.extract(
                reduce(np.logical_and,
                       (channel_widths(bin, channel_num) > max_gate,
                        channel_amplitudes(bin, channel_num) >= midhigh_gate,
                        channel_amplitudes(bin, channel_num) <= pos_gate)
                ), bin)])
            pnpeaks = np.hstack([pnpeaks, np.extract(
                reduce(np.logical_and,
                       (channel_widths(bin, channel_num) < min_gate,
                        channel_amplitudes(bin, channel_num) >= midhigh_gate,
                        channel_amplitudes(bin, channel_num) <= pos_gate)
                ), bin)])
            nwpeaks = np.hstack([nwpeaks, np.extract(
                reduce(np.logical_and,
                       (channel_widths(bin, channel_num) > max_gate,
                        channel_amplitudes(bin, channel_num) >= neg_gate,
                        channel_amplitudes(bin, channel_num) <= midlow_gate)
                ), bin)])
            nnpeaks = np.hstack([nnpeaks, np.extract(
                reduce(np.logical_and,
                       (channel_widths(bin, channel_num) < min_gate,
                        channel_amplitudes(bin, channel_num) >= neg_gate,
                        channel_amplitudes(bin, channel_num) <= midlow_gate)
                ), bin)])
        else:
            nwpeaks = np.hstack([nwpeaks, np.extract(
                reduce(np.logical_and,
                       (channel_widths(bin, channel_num) > max_gate,
                        channel_amplitudes(bin, channel_num) >= neg_gate,
                        channel_amplitudes(bin, channel_num) <= pos_gate)
                ), bin)])
            nnpeaks = np.hstack([nnpeaks, np.extract(
                reduce(np.logical_and,
                       (channel_widths(bin, channel_num) < min_gate,
                        channel_amplitudes(bin, channel_num) >= neg_gate,
                        channel_amplitudes(bin, channel_num) <= pos_gate)
                ), bin)])

        nlpeaks = np.hstack([nlpeaks, np.extract(
            reduce(np.logical_and,
                   (channel_widths(bin, channel_num) > max_gate,
                    channel_amplitudes(bin, channel_num) < neg_gate)
            ), bin)])
        nrpeaks = np.hstack([nrpeaks, np.extract(
            reduce(np.logical_and,
                   (channel_widths(bin, channel_num) >= min_gate,
                    channel_widths(bin, channel_num) <= max_gate,
                    channel_amplitudes(bin, channel_num) < neg_gate)
            ), bin)])
        
        pbpeaks = np.hstack([pspeaks, np.extract(
            reduce(np.logical_and,
                   (channel_widths(bin, channel_num) < min_gate,
                    channel_amplitudes(bin, channel_num) >= midhigh_gate,
                    channel_amplitudes(bin, channel_num) <= pos_gate)
            ), bin)])

    return ((plpeaks, prpeaks, pspeaks,
             pwpeaks, pnpeaks,
             mlpeaks, mrpeaks, mspeaks,
             nlpeaks, nrpeaks, nspeaks,
             nwpeaks, nnpeaks),
            rain_gates,
            means)
コード例 #6
0
ファイル: peaks.py プロジェクト: v-makarenko/vtoolsmq
def polydisperse_peaks(well, channel_num, threshold=None, pct_boundary=0.3, exclude_min_amplitude_peaks=True):
    """
    Returns a 3-tuple (4-tuple, 4-tuple, 2-tuple).  The first 4-tuple is:
    
    * positive rain above the width gates.
    * middle rain above the width gates.
    * middle rain below the width gates.
    * negative rain below the width gates.

    The second 4-tuple is:

    * positive rain boundary
    * middle rain upper boundary (can be None)
    * middle rain lower boundary (can be None)
    * negative rain boundary

    The last 2-tuple is:

    * computed min width gate
    * computed max width gate

    Positives & negatives are computed on the specified channel number.
    """
    if not threshold:
        threshold = well.channels[channel_num].statistics.threshold
    if not threshold:
        threshold = None
    
    # filter out min_amplitude_peaks
    if exclude_min_amplitude_peaks:
        peaks = above_min_amplitude_peaks(well)
    else:
        peaks = well.peaks

    p_plus, p, p_minus, pos, middle_high, middle_low, neg = \
            rain_pvalues_thresholds(peaks,
                                    channel_num=channel_num,
                                    threshold=threshold,
                                    pct_boundary=pct_boundary)
    
    min_gate, max_gate = well_static_width_gates(well)

    pos_peaks = np.extract(
        reduce(np.logical_and,
               (channel_widths(peaks, channel_num) > max_gate,
                channel_amplitudes(peaks, channel_num) > pos)),
        peaks)
    
    
    if middle_high and middle_low:
        midhigh_peaks = np.extract(
            reduce(np.logical_and,
                   (channel_widths(peaks, channel_num) > max_gate,
                    reduce(np.logical_and,
                           (channel_amplitudes(peaks, channel_num) < middle_high,
                            channel_amplitudes(peaks, channel_num) > middle_low)))),
            peaks)
        midlow_peaks = np.extract(
            reduce(np.logical_and,
                   (channel_widths(peaks, channel_num) < min_gate,
                    reduce(np.logical_and,
                           (channel_amplitudes(peaks, channel_num) < middle_high,
                            channel_amplitudes(peaks, channel_num) > middle_low)))),
            peaks)
    else:
        midhigh_peaks = np.ndarray([0],dtype=peak_dtype(2))
        midlow_peaks = np.ndarray([0],dtype=peak_dtype(2))
    
    neg_peaks = np.extract(
        reduce(np.logical_and,
               (channel_widths(peaks, channel_num) < min_gate,
                channel_amplitudes(peaks, channel_num) < neg)),
        peaks)
    
    return ((pos_peaks, midhigh_peaks, midlow_peaks, neg_peaks),
            (pos, middle_high, middle_low, neg),
            (min_gate, max_gate))