Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
mirandaa
mfql_dessert
Commits
8bfbd92d
Commit
8bfbd92d
authored
Jun 22, 2020
by
mirandaa
Browse files
feat: now woth ranges
parent
4c44610b
Changes
1
Hide whitespace changes
Inline
Side-by-side
0.1-jm-Chem-composition2mfql.ipynb
View file @
8bfbd92d
...
...
@@ -13,8 +13,8 @@
"metadata": {},
"outputs": [],
"source": [
"
#https://pypi.org/project/molmass/
\n",
"
from molmass import Formula
"
"
from chem_parser import txt2dict
\n",
"
import warnings
"
]
},
{
...
...
@@ -39,18 +39,19 @@
"qn = input('Define query name (no spaces/underscores):')#Ultimate Species!\n",
"\n",
"#define formula and use molmass to generate the tuple\n",
"f = input ('Specify formula:')\n",
"f = input ('Specify formula
(eg h2o or C[1..20]H[4..80]O[0..1])
:')\n",
"f = f.upper()\n",
"warnings.warn('for H is in a range, the first number will indicate if it should be odd or even')\n",
"\n",
"#define adduct and use molmass to generate the tuple\n",
"adduct = input('Specify adduct type (
H, HCOO, NH4
):')\n",
"adduct = input('Specify adduct type (
optinal for ranges
):')\n",
"adduct = adduct.upper()\n",
"\n",
"#define MS mode\n",
"ms = input('Define MS mode (either + or -):')\n",
"\n",
"#define filename\n",
"filename = input('Define file name
(no special characters)
:')\n",
"filename = input('Define file name:')\n",
"mfql = '.mfql'\n",
"filename = \"\".join((filename, mfql))"
]
...
...
@@ -63,28 +64,8 @@
},
"outputs": [],
"source": [
"cc = Formula(f)\n",
"af = Formula(adduct) #get chemical composition of adduct"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"cc1 = cc.composition()\n",
"cc_dict = {t[0]:t[1] for t in cc1}"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"af1 = af.composition()\n",
"af_dict = {t[0]:t[1] for t in af1}"
"cc = txt2dict(f)\n",
"af = txt2dict(adduct) #get chemical composition of adduct"
]
},
{
...
...
@@ -94,17 +75,6 @@
"### Based on the adduct it will be added or substracted"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"allelems = dict(cc_dict)\n",
"allelems.update(af_dict)\n",
"allelems.keys()"
]
},
{
"cell_type": "code",
"execution_count": null,
...
...
@@ -113,17 +83,35 @@
"source": [
"#adjust for the adduct\n",
"# only H, NH4 and HCOO are defined\n",
"allelems = dict(cc
_dict
)\n",
"allelems.update(af
_dict
)\n",
"allelems = dict(cc)\n",
"allelems.update(af)\n",
"allelems.keys() # just to get all the keys in both dicts\n",
"if adduct == 'H' and ms == '+':\n",
" res = {key: cc_dict.get(key, 0) + af_dict.get(key, 0) for key in allelems.keys()}\n",
" res = {}\n",
" for key in allelems.keys():\n",
" low = cc.get(key, (0,0))[0]\n",
" high = cc.get(key, (0,0))[1]\n",
" low += af.get(key, (0,0))[0]\n",
" high += af.get(key, (0,0))[1]\n",
" res[key] = (low,high)\n",
" \n",
"elif adduct == 'H' and ms == '-':\n",
" res = {key: cc_dict.get(key, 0) - af_dict.get(key, 0) for key in allelems.keys()}\n",
" res = {}\n",
" for key in allelems.keys():\n",
" low = cc.get(key, (0,0))[0]\n",
" high = cc.get(key, (0,0))[1]\n",
" low -= af.get(key, (0,0))[0]\n",
" high -= af.get(key, (0,0))[1]\n",
" res[key] = (low,high)\n",
" \n",
"else : # al other adduc.getts\n",
" res = {key: cc_dict.get(key, 0) + af_dict.get(key, 0) for key in allelems.keys()}\n",
"else : # al other adducts\n",
" res = {}\n",
" for key in allelems.keys():\n",
" low = cc.get(key, (0,0))[0]\n",
" high = cc.get(key, (0,0))[1]\n",
" low += af.get(key, (0,0))[0]\n",
" high += af.get(key, (0,0))[1]\n",
" res[key] = (low,high)\n",
" \n"
]
},
...
...
@@ -155,11 +143,10 @@
"outputs": [],
"source": [
"#test for odd/even number of hydrogens\n",
"if res['H'] % 2 == 0:\n",
"if res['H']
[0]
% 2 == 0:\n",
" such = 'isEven'\n",
"else:\n",
" such = 'isOdd'\n",
" "
" such = 'isOdd'\n"
]
},
{
...
...
@@ -172,7 +159,10 @@
"for k,v in res.items():\n",
" if k == '2H':\n",
" k = 'D' \n",
" ec += f'{k}[{v}] '\n",
" if v[0]==v[1]:\n",
" ec += f'{k}[{v[0]}] '\n",
" else:\n",
" ec += f'{k}[{v[0]}..{v[1]}] '\n",
"ec"
]
},
...
...
@@ -182,7 +172,18 @@
"metadata": {},
"outputs": [],
"source": [
"dbe = calc_dbe(res)"
"low_res = {k:v[0] for k,v in res.items()}\n",
"high_res = {k:v[1] for k,v in res.items()}"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"dbe_low = calc_dbe(low_res)\n",
"dbe_high = calc_dbe(high_res)"
]
},
{
...
...
@@ -193,7 +194,7 @@
"source": [
"line1 = f'#Identify {cn}#'\n",
"line2 = f'QUERYNAME = {qn};'\n",
"line3 = f\"DEFINE pr = '{ec}' WITH DBR = ({dbe},{dbe}), CHG = {ms}1;\"\n",
"line3 = f\"DEFINE pr = '{ec}' WITH DBR = ({dbe
_low
},{dbe
_high
}), CHG = {ms}1;\"\n",
"line4 = f'IDENTIFY\\n\\tpr in MS1{ms}'\n",
"line5 = f'SUCHTHAT\\n\\t{such}(pr.chemsc[H]) AND \\n\\tisOdd(pr.chemsc[db]*2)'\n",
"line6 = f'REPORT\\n\\tPRM = pr.mass;\\n\\tEC = pr.chemsc;\\n\\tCLASS = \"{qn}\" % \"()\";\\n\\tQSERR = \"%2.2f\" % \"(pr.errppm)\";\\n\\tQS = pr.intensity;;'\n",
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment