Exemplo n.º 1
0
def make_nanodiscs(array):
    """
    :param array: Array of different nanodiscs of form:
     N x 6 [belt mass, lipid mass, lipid num, lipid std dev, mass sig, z, zstd dev]
    :return:
    """
    arrays = []
    for n in array:
        bmass = n[0]
        lmass = n[1]
        lnum = n[2]
        lsig = n[3]
        z = n[5]
        zsig = n[6]
        msig = n[4]
        thresh = 4
        dist = np.arange(-int(lsig * thresh), int(lsig * thresh))
        masses = np.array([bmass * 2. + lmass * (lnum + i) for i in dist])
        ints = ud.ndis_std(dist, 0, lsig)

        newarray = np.array([[m, msig, z, zsig, ints[i]]
                             for i, m in enumerate(masses)])
        for a in newarray:
            arrays.append(a)
    arrays = np.array(arrays)
    out, ztab = msb.make_mass_spectrum(arrays, mzrange=(6000, 9000))
    plt.plot(out[:, 0], out[:, 1])
    plt.show()
Exemplo n.º 2
0
    def fit(self, e):
        """
        Fit the offset totals to a series of overlapping Gaussians.
        Update the plots and listctrl from the result.
        :param e: Unused event
        :return: None
        """
        self.update(e)
        guess = []
        for z in self.zoffs:
            guess.append(
                [z.offset, z.intensity * 1 / (0.5 * np.sqrt(2 * np.pi))])
        guess = np.array(guess)
        mf = MassFitter.MassFitter(self.offset_totals, guess, 0, "smallguess")
        fitspec, fitres = mf.perform_fit("nonorm", "smallguess")
        print("Output", fitres)

        for i in range(0, len(self.zoffs)):
            fit = fitres[i]
            self.zoffs[i].offset = fit[0]
            self.zoffs[i].width = fit[1]
            self.zoffs[i].intensity = fit[2] * 1 / (fit[1] *
                                                    np.sqrt(2 * np.pi))
        self.update_list()
        self.plot_zoffs()
        for z in self.zoffs:
            yvals = ud.ndis_std(z.offset,
                                self.offset_totals[:, 0],
                                z.width,
                                a=z.intensity,
                                norm_area=False)
            self.plot1.plotadd(self.offset_totals[:, 0], yvals,
                               np.array(z.color) / 255, "Fit")
        self.plot1.repaint()
Exemplo n.º 3
0
def make_mixed_nanodiscs(array, plot=True):
    outarray = []
    for n in array:
        arrays = []
        bmass = n[0]
        ratio = n[1]
        lnum = n[2]
        lsig = n[3]
        z = n[5]
        zsig = n[6]
        msig = n[4]
        lmass1 = n[7]
        lmass2 = n[8]
        thresh = 4
        dist = np.arange(-int(lsig * thresh), int(lsig * thresh)) + lnum
        ints = ud.ndis_std(dist, lnum, lsig)

        masses = []
        ivals = []
        for n, d in enumerate(dist):
            nvals = np.arange(0, d + 1.)
            nvals2 = d - nvals

            p1 = stats.binom.pmf(nvals, d, ratio)

            m = np.array([
                bmass * 2. + lmass1 * nvals[i] + lmass2 * nvals2[i]
                for i in range(0, len(nvals))
            ])
            ival = np.array([ints[n] * p1[i] for i in range(0, len(nvals))])

            for mass in m:
                masses.append(mass)
            for i in ival:
                ivals.append(i)

        masses = np.array(masses)
        ivals = np.array(ivals)

        print(len(masses))

        b1 = ivals / np.amax(ivals) > 0.01

        masses = masses[b1]
        ivals = ivals[b1]

        newarray = np.array([[m, msig, z, zsig, ivals[i]]
                             for i, m in enumerate(masses)])
        for a in newarray:
            arrays.append(a)
        arrays = np.array(arrays)
        avgmass = np.average(masses)
        #start = np.amin(masses)
        #end = np.amax(masses)
        start = avgmass - 10000
        end = avgmass + 10000
        out, ztab = msb.make_mass_spectrum(arrays,
                                           mzrange=(start, end),
                                           zrange=(1, 2),
                                           mz_bin_size=1)
        outarray.append(out)

    if plot:
        plt.figure()
        for out in outarray:
            plt.plot(out[:, 0], out[:, 1])
        # print(ud.fft_diff(out, [360, 400])[0])
        # print(ud.fft_diff(out, [750, 770])[0])
        plt.show()

    return outarray
Exemplo n.º 4
0
def make_mass_spectrum(array, zrange=(10, 50), mzrange=(2000, 10000), mz_bin_size=1, adductmass=1.00727647, psfun=0,
                       noise=0, baseline=0, **kwargs):
    """
    Create a new mass spectrum.

    First, create the mzaxis from mzrange and the possible charge states from zrange.
    Then, add in peaks at the appropriate mz values for the parameters defined in array.
    Then, normalize and add optional background and noise.
    Finally, renormalize.

    :param array: P x 5 array of parameters [mass, mass fwhm, z avg, z std dev, intensity]
    :param zrange: Tuple of list define range of allowed charge states
    :param mzrange: Tuple or list defining range of m/z values
    :param mz_bin_size: delta mz of mzaxis
    :param adductmass: Mass of electrospray adduct species
    :param psfun: Peak shape function integer code
    :param noise: Std deviation of random Gaussian noise to be added to normalized spectrum
    :param baseline: Peak intensity of sinusoidal baseline to be added to normalized spectrum
    :param kwargs: Keyword catcher
    :return: Spectrum, ztab (new spectrum in N x 2 (m/z, intensity) and charge states allowed)
    """
    mzaxis = np.arange(mzrange[0], mzrange[1], mz_bin_size)
    ztab = np.arange(zrange[0], zrange[1], 1)

    array = np.array(array)
    num = int(len(array.flatten()) / 5)
    array = np.reshape(array, (num, 5))
    array = np.abs(array)
    output = np.zeros(len(mzaxis))
    for i in range(0, len(array)):
        mmid = array[i, 0]
        msig = array[i, 1]
        zmid = array[i, 2]
        zsig = array[i, 3]
        inten = array[i, 4]

        zint = ud.ndis_std(ztab, zmid, zsig, norm_area=True)

        mzvals = (mmid + adductmass * ztab) / ztab
        mzsigs = msig / ztab

        for j in range(0, len(ztab)):
            output += ud.make_peak_shape(mzaxis, psfun, mzsigs[j], mzvals[j], norm_area=True) * zint[j] * inten
    output /= np.amax(output)

    if baseline > 0:
        background = np.sin((mzaxis - mzrange[0]) / (mzrange[1] - mzrange[0]) * np.pi) * baseline
        output = output + background
    if baseline < 0:
        output += np.abs(baseline)
    output /= np.amax(output)

    if noise > 0:
        noisedat = np.random.normal(0, noise, size=len(output))
        output = np.abs(output + noisedat)

    output /= np.amax(output)

    if "scramble" in kwargs:
        if kwargs['scramble']:
            np.random.shuffle(output)

    return np.transpose([mzaxis, output]), ztab