Exemplo n.º 1
0
    def Gen_bragg(self, w, hkls, range_2th=(0, 90)):

        wl, wlintn = w
        r_tth = np.deg2rad(range_2th)
        tag = FT.where(self.xray.tag_wl, wl)
        if not hasattr(self, 'tags'):
            self.tags = []
        for hkl in hkls:
            d_spacing = self.px.d_spacing(hkl)
            sinth = wl / (2 * d_spacing)
            if sinth < -1 or sinth > 1:
                continue
            tth = 2 * np.arcsin(sinth)
            if tth < r_tth[0] or tth > r_tth[1]:
                continue
            peak = PK.Peak()
            peak.tth = tth
            peak.index = hkl
            peak.d_spacing = d_spacing
            peak.wl = wl
            peak.wlintn = wlintn
            peak.intn = self.Calc_peak_intn(peak)
            if tag:
                self.tags.append((peak, tag))
            logging.debug(
                'PEAK info:index: %r, d: %f, lambda:%f, tth: %f, intn: %f, tag: %r'
                % (hkl, d_spacing, wl, np.rad2deg(tth), peak.intn, tag))
            yield peak
Exemplo n.º 2
0
    def Calc_peak(self, hkls, EPS=0):
        def isdeplicate(peak, peaks, EPS=np.deg2rad(0.05)):
            if len(peaks) == 0:
                return False

            tth, gamma = peak.tth, peak.gamma
            for i, p in enumerate(peaks):
                if FT.equal(p.tth, tth, EPS) and FT.equal(p.gamma, gamma, EPS):
                    if peak.intn > p.intn:
                        logging.debug('%s is excluded because of %s' %
                                      (peak.index.str, p.index.str))
                        # print('%s is excluded because of %s'%(p.index.str, peak.index.str))
                        del peaks[i]
                    else:
                        logging.debug('%s is excluded because of %s' %
                                      (peak.index.str, p.index.str))
                        # print('%s is excluded because of %s'%(peak.index.str, p.index.str))
                        return True

            return False

        peaks = []
        for sx in self.sx:
            inc = self.inc
            xr = self.xray
            for hkl in hkls:
                vec = sx.vec_in_rcp(hkl)
                d_spacing = 1 / vec.length
                tth = 2 * vec.betweenangle_rad(inc) - np.pi
                if tth <= np.deg2rad(1) or tth >= np.deg2rad(179):
                    continue
                wl = 2 * d_spacing * np.sin(tth / 2)
                wlintn = xr.intn_wl(wl)
                if wlintn == 0:
                    continue
                k_inc = inc / wl
                k_out = k_inc + vec
                peak = PK.Peak()
                peak.index = hkl
                peak.vec = vec
                peak.tth, peak.gamma = sx.tthgam_rad(k_out, z=inc, x=self.vx)
                peak.wl = wl
                peak.energy = xr.energy_from_lambda(wl)
                peak.wlintn = wlintn
                peak.d_spacing = d_spacing
                peak.grain = sx
                peak.intn = self.Calc_peak_intn(peak)
                if peak.intn > EPS and not isdeplicate(peak, peaks):
                    logging.debug(
                        'PEAK info:index: %r, d: %f, lambda:%f, tth: %f, intn: %f'
                        % (hkl, d_spacing, wl, np.rad2deg(tth), peak.intn))
                    peaks.append(peak)
        return np.array(peaks)
Exemplo n.º 3
0
    def new_peak_f(self, npeak):
        self.payload_pix.insert(
            0, peak.Peak(npeak.rgb, npeak.red, npeak.green, npeak.blue))

        self.payload_pix.pop(len(self.payload_pix) - 1)

        send_payload = []

        for dd in range(self.parts):
            if bool(self.direction) ^ bool(self.parts & 1):
                for i in self.payload_pix[::-1]:
                    send_payload.append(i.red)
                    send_payload.append(i.green)
                    send_payload.append(i.blue)

            else:

                for i in self.payload_pix:
                    send_payload.append(i.red)
                    send_payload.append(i.green)
                    send_payload.append(i.blue)

        return send_payload
Exemplo n.º 4
0
    bio_ps = [convert_biological_to_pvalue(sig) for sig in actual_sigs]
    tech_ps = [convert_technical_to_pvalue(sig, mad) for sig, mad in zip(actual_sigs, mad_sigs)]
    bio_qs = [convert_p_to_q(bio_p) for bio_p in bio_ps]
    tech_qs= [convert_p_to_q(tech_p) for tech_p in tech_ps]
    bio_tech_peaks = bio_and_tech_filter(bio_qs, tech_qs)
    peaks = call_peaks(idr_filter(bio_tech_peaks, idrs), consolidate=args.bins)
    averagerobustz = np.mean([rz.calculate_robust_z(sig) for sig in actual_sigs], 0)


    # Make peaks
    all_peaks = peak.PeakList()
    for i, entry in enumerate(peaks):
        start = entry[0]*args.resolution
        end = entry[1]*args.resolution
        max_value, max_idx = find_max_value(entry[0], entry[1], [averagerobustz], True)
        max_valbio = find_max_value(entry[0], entry[1], bio_qs)
        max_validr = find_max_value(entry[0], entry[1], idrs, False)
        max_valtech = find_max_value(entry[0], entry[1], tech_qs, False)
        this_peak = peak.Peak(args.chrom_name, start=int(start), end=int(end), 
                              name = "%s_%s"%(args.outpre,i),
                              score = max_value,
                              signalval = max_valtech,
                              pval = max_valbio,
                              qval = max_validr, peak = int(max_idx*args.resolution))
        if end-start >= args.bins*args.resolution:
            all_peaks.add_Peak(this_peak)
        else:
            continue
    # Write peaks
    all_peaks.write_narrowPeak_file(args.outpre + ".narrowPeak")
Exemplo n.º 5
0
    qvalues = arrays[2]

    # Make peaks
    all_peaks = peak.PeakList()
    for i, entry in enumerate(peaks):
        start, end = entry
        these_invals = array[start:end]
        these_pvalues = pvalues[start:end]
        these_qvalues = qvalues[start:end]
        true_start = convert_coordinate(start, span[0], args.resolution)
        true_end = convert_coordinate(end, span[0], args.resolution)
        try:
            max_idx = np.nanargmax(these_invals)

            this_peak = peak.Peak(chrm = args.chrom_name, start=true_start, end=true_end, 
                              name = "%s_%s"%(out_prefix,i), 
                              score = int(these_qvalues[max_idx]*10),
                              signalval = these_invals[max_idx], 
                              pval = these_pvalues[max_idx], 
                              qval = these_qvalues[max_idx], peak = max_idx)
            all_peaks.add_Peak(this_peak)
        except:
            max_idx = np.argmax(these_qvalues)
            print(true_start, true_end, "failed", qvalues[max_idx], pvalues[max_idx])
    # Write peaks
    all_peaks.write_narrowPeak_file(out_prefix + ".narrowPeak")
                  
    if args.plots:    
        plt.tight_layout()
        fig.savefig(out_prefix + ".png") 
Exemplo n.º 6
0
    bio_tech_peaks = bio_and_tech_filter(bio_qs, tech_qs)
    peaks = call_peaks(idr_filter(bio_tech_peaks, idrs), consolidate=args.bins)
    averagerobustz = np.mean(
        [rz.calculate_robust_z(sig) for sig in actual_sigs], 0)

    # Make peaks
    all_peaks = peak.PeakList()
    for i, entry in enumerate(peaks):
        start = entry[0] * args.resolution
        end = entry[1] * args.resolution
        max_value, max_idx = find_max_value(entry[0], entry[1],
                                            [averagerobustz], True)
        max_valbio = find_max_value(entry[0], entry[1], bio_qs)
        max_validr = find_max_value(entry[0], entry[1], idrs, False)
        max_valtech = find_max_value(entry[0], entry[1], tech_qs, False)
        this_peak = peak.Peak("gi|48994873|gb|U00096.2|mod|ATCC.47076|",
                              start=int(start),
                              end=int(end),
                              name="%s_%s" % (args.outpre, i),
                              score=max_value,
                              signalval=max_valtech,
                              pval=max_valbio,
                              qval=max_validr,
                              peak=int(max_idx * args.resolution))
        if end - start >= args.bins * args.resolution:
            all_peaks.add_Peak(this_peak)
        else:
            continue
    # Write peaks
    all_peaks.write_narrowPeak_file(args.outpre + ".narrowPeak")
Exemplo n.º 7
0
    def __init__(self, pix_len, zigzag):

        self.zigzag = zigzag
        self.parts = 2 * zigzag
        for i in range(pix_len // self.parts):
            self.payload_pix.append(peak.Peak(0, 0, 0, 0))