This repository has been archived by the owner on Nov 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
synthetic isotope pattern default to
averagine
1. examples/synthetics.ipynb + Started with example on synthetics 🔵⚪⚪⚪⚪⚪⚪⚪⚪⚪ 2. src/pystoms/synthetics.py: + Started to refactor synthetics module 🔵⚪⚪⚪⚪⚪⚪⚪⚪⚪
- Loading branch information
1 parent
d1d832b
commit 8523f33
Showing
2 changed files
with
122 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 6, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import pystoms.synthetics as syn\n", | ||
"import numpy as np\n", | ||
"import pandas as pd\n", | ||
"import scipy as sp" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 7, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"iso = syn.Isotopic_Averagine_Distribution()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 8, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"ename": "ValueError", | ||
"evalue": "The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()", | ||
"output_type": "error", | ||
"traceback": [ | ||
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", | ||
"\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)", | ||
"Cell \u001b[0;32mIn [8], line 6\u001b[0m\n\u001b[1;32m 4\u001b[0m num_peaks \u001b[39m=\u001b[39m \u001b[39m6\u001b[39m\n\u001b[1;32m 5\u001b[0m x \u001b[39m=\u001b[39m np\u001b[39m.\u001b[39marange(\u001b[39m30900\u001b[39m,\u001b[39m32000\u001b[39m)\u001b[39m/\u001b[39m\u001b[39m100\u001b[39m\n\u001b[0;32m----> 6\u001b[0m iso\u001b[39m.\u001b[39;49mpdf(x,mass,charge,sigma,num_peaks)\n", | ||
"File \u001b[0;32m~/miniconda3/envs/pymc_dev/lib/python3.10/site-packages/scipy/stats/_distn_infrastructure.py:2094\u001b[0m, in \u001b[0;36mrv_continuous.pdf\u001b[0;34m(self, x, *args, **kwds)\u001b[0m\n\u001b[1;32m 2092\u001b[0m goodargs \u001b[39m=\u001b[39m argsreduce(cond, \u001b[39m*\u001b[39m((x,)\u001b[39m+\u001b[39margs\u001b[39m+\u001b[39m(scale,)))\n\u001b[1;32m 2093\u001b[0m scale, goodargs \u001b[39m=\u001b[39m goodargs[\u001b[39m-\u001b[39m\u001b[39m1\u001b[39m], goodargs[:\u001b[39m-\u001b[39m\u001b[39m1\u001b[39m]\n\u001b[0;32m-> 2094\u001b[0m place(output, cond, \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m_pdf(\u001b[39m*\u001b[39;49mgoodargs) \u001b[39m/\u001b[39m scale)\n\u001b[1;32m 2095\u001b[0m \u001b[39mif\u001b[39;00m output\u001b[39m.\u001b[39mndim \u001b[39m==\u001b[39m \u001b[39m0\u001b[39m:\n\u001b[1;32m 2096\u001b[0m \u001b[39mreturn\u001b[39;00m output[()]\n", | ||
"File \u001b[0;32m~/Workspaces/pystoms/src/pystoms/synthetics.py:77\u001b[0m, in \u001b[0;36mIsotopic_Averagine_Distribution._pdf\u001b[0;34m(self, x, mass, charge, sigma, num_peaks)\u001b[0m\n\u001b[1;32m 49\u001b[0m \u001b[39m\"\"\"Calculates probability density function (PDF)\u001b[39;00m\n\u001b[1;32m 50\u001b[0m \n\u001b[1;32m 51\u001b[0m \u001b[39mOverwrites scipy.rv_continuous._pdf. Is internally called by Isotopic_Averagine_Distribution.pdf\u001b[39;00m\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 74\u001b[0m \u001b[39m Supported are \"averagine\" and \"non_averagine\".\u001b[39;00m\n\u001b[1;32m 75\u001b[0m \u001b[39m\"\"\"\u001b[39;00m\n\u001b[1;32m 76\u001b[0m \u001b[39m# means of normal distributions are [mass/charge,(mass+1)/charge,...,(mass+num_peaks-1)/charge]\u001b[39;00m\n\u001b[0;32m---> 77\u001b[0m means \u001b[39m=\u001b[39m (np\u001b[39m.\u001b[39mrepeat(mass, num_peaks) \u001b[39m+\u001b[39m np\u001b[39m.\u001b[39;49marange(num_peaks)) \u001b[39m/\u001b[39m charge\n\u001b[1;32m 78\u001b[0m \u001b[39m# sigmas of normal distributions are sigma for all\u001b[39;00m\n\u001b[1;32m 79\u001b[0m sigmas \u001b[39m=\u001b[39m np\u001b[39m.\u001b[39mrepeat(sigma, num_peaks)\n", | ||
"\u001b[0;31mValueError\u001b[0m: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"mass = 310.1\n", | ||
"charge = 2\n", | ||
"sigma = 1\n", | ||
"num_peaks = 6\n", | ||
"x = np.arange(30900,32000)/100\n", | ||
"iso.pdf(x,mass,charge,sigma,num_peaks)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 9, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"ename": "ValueError", | ||
"evalue": "The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()", | ||
"output_type": "error", | ||
"traceback": [ | ||
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", | ||
"\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)", | ||
"Cell \u001b[0;32mIn [9], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m syn_pep \u001b[39m=\u001b[39m syn\u001b[39m.\u001b[39;49mSyntheticPeptideFeature(\u001b[39m310\u001b[39;49m,\u001b[39m2\u001b[39;49m,\u001b[39m12\u001b[39;49m,\u001b[39m1\u001b[39;49m,\u001b[39m1\u001b[39;49m,)\n", | ||
"File \u001b[0;32m~/Workspaces/pystoms/src/pystoms/synthetics.py:294\u001b[0m, in \u001b[0;36mSyntheticPeptideFeature.__init__\u001b[0;34m(self, mass, charge, emg_μ, emg_σ, emg_λ, elution_noise, isotopic_noise, num_peaks, isotopic_sigma, scan_intervall, ms_resolution, isotopic_pattern_model, correctBaseline)\u001b[0m\n\u001b[1;32m 292\u001b[0m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39misotopic_sigma \u001b[39m=\u001b[39m isotopic_sigma\n\u001b[1;32m 293\u001b[0m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mcorrectBaseline \u001b[39m=\u001b[39m correctBaseline\n\u001b[0;32m--> 294\u001b[0m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mfeature_data \u001b[39m=\u001b[39m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m_generate()\n", | ||
"File \u001b[0;32m~/Workspaces/pystoms/src/pystoms/synthetics.py:342\u001b[0m, in \u001b[0;36mSyntheticPeptideFeature._generate\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 336\u001b[0m \u001b[39m# from first m/z peak -1 to last m/z peak +1\u001b[39;00m\n\u001b[1;32m 337\u001b[0m m_z_axis \u001b[39m=\u001b[39m np\u001b[39m.\u001b[39marange(\n\u001b[1;32m 338\u001b[0m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mmass \u001b[39m/\u001b[39m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mcharge \u001b[39m-\u001b[39m \u001b[39m1\u001b[39m,\n\u001b[1;32m 339\u001b[0m (\u001b[39mself\u001b[39m\u001b[39m.\u001b[39mmass \u001b[39m+\u001b[39m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mn \u001b[39m-\u001b[39m \u001b[39m1\u001b[39m) \u001b[39m/\u001b[39m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mcharge \u001b[39m+\u001b[39m \u001b[39m1\u001b[39m \u001b[39m+\u001b[39m \u001b[39m1\u001b[39m \u001b[39m/\u001b[39m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mresolution,\n\u001b[1;32m 340\u001b[0m \u001b[39m1\u001b[39m \u001b[39m/\u001b[39m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mresolution,\n\u001b[1;32m 341\u001b[0m )\n\u001b[0;32m--> 342\u001b[0m m_z_intensity \u001b[39m=\u001b[39m iso\u001b[39m.\u001b[39;49mpdf(\n\u001b[1;32m 343\u001b[0m m_z_axis, \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49mmass, \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49mcharge, \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49misotopic_sigma, \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49mn\n\u001b[1;32m 344\u001b[0m )\n\u001b[1;32m 345\u001b[0m measurements_per_frame \u001b[39m=\u001b[39m \u001b[39mlen\u001b[39m(m_z_axis)\n\u001b[1;32m 347\u001b[0m \u001b[39m# for each rt timepoint draw new noise samples and add them on isotopic dist.\u001b[39;00m\n\u001b[1;32m 348\u001b[0m \u001b[39m# then multiply with elution profile at this timepoint\u001b[39;00m\n", | ||
"File \u001b[0;32m~/miniconda3/envs/pymc_dev/lib/python3.10/site-packages/scipy/stats/_distn_infrastructure.py:2094\u001b[0m, in \u001b[0;36mrv_continuous.pdf\u001b[0;34m(self, x, *args, **kwds)\u001b[0m\n\u001b[1;32m 2092\u001b[0m goodargs \u001b[39m=\u001b[39m argsreduce(cond, \u001b[39m*\u001b[39m((x,)\u001b[39m+\u001b[39margs\u001b[39m+\u001b[39m(scale,)))\n\u001b[1;32m 2093\u001b[0m scale, goodargs \u001b[39m=\u001b[39m goodargs[\u001b[39m-\u001b[39m\u001b[39m1\u001b[39m], goodargs[:\u001b[39m-\u001b[39m\u001b[39m1\u001b[39m]\n\u001b[0;32m-> 2094\u001b[0m place(output, cond, \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m_pdf(\u001b[39m*\u001b[39;49mgoodargs) \u001b[39m/\u001b[39m scale)\n\u001b[1;32m 2095\u001b[0m \u001b[39mif\u001b[39;00m output\u001b[39m.\u001b[39mndim \u001b[39m==\u001b[39m \u001b[39m0\u001b[39m:\n\u001b[1;32m 2096\u001b[0m \u001b[39mreturn\u001b[39;00m output[()]\n", | ||
"File \u001b[0;32m~/Workspaces/pystoms/src/pystoms/synthetics.py:77\u001b[0m, in \u001b[0;36mIsotopic_Averagine_Distribution._pdf\u001b[0;34m(self, x, mass, charge, sigma, num_peaks)\u001b[0m\n\u001b[1;32m 49\u001b[0m \u001b[39m\"\"\"Calculates probability density function (PDF)\u001b[39;00m\n\u001b[1;32m 50\u001b[0m \n\u001b[1;32m 51\u001b[0m \u001b[39mOverwrites scipy.rv_continuous._pdf. Is internally called by Isotopic_Averagine_Distribution.pdf\u001b[39;00m\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 74\u001b[0m \u001b[39m Supported are \"averagine\" and \"non_averagine\".\u001b[39;00m\n\u001b[1;32m 75\u001b[0m \u001b[39m\"\"\"\u001b[39;00m\n\u001b[1;32m 76\u001b[0m \u001b[39m# means of normal distributions are [mass/charge,(mass+1)/charge,...,(mass+num_peaks-1)/charge]\u001b[39;00m\n\u001b[0;32m---> 77\u001b[0m means \u001b[39m=\u001b[39m (np\u001b[39m.\u001b[39mrepeat(mass, num_peaks) \u001b[39m+\u001b[39m np\u001b[39m.\u001b[39;49marange(num_peaks)) \u001b[39m/\u001b[39m charge\n\u001b[1;32m 78\u001b[0m \u001b[39m# sigmas of normal distributions are sigma for all\u001b[39;00m\n\u001b[1;32m 79\u001b[0m sigmas \u001b[39m=\u001b[39m np\u001b[39m.\u001b[39mrepeat(sigma, num_peaks)\n", | ||
"\u001b[0;31mValueError\u001b[0m: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"syn_pep = syn.SyntheticPeptideFeature(310,2,12,1,1,)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 13, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"norm = sp.stats.norm()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "pymc_dev", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.10.6" | ||
}, | ||
"orig_nbformat": 4, | ||
"vscode": { | ||
"interpreter": { | ||
"hash": "e72a8d8ce8364635d68c11ed264ecd033ec926576ac60b4957a81f7389674ed5" | ||
} | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters