Commit 02d80551 authored by mirandaa's avatar mirandaa
Browse files

calculate dbe

parent 3ed41dae
......@@ -4,20 +4,18 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# Import dependencies"
"# Automatically create mfql files"
]
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"import pandas\n",
"#https://pypi.org/project/molmass/\n",
"from molmass import Formula\n",
"from collections import Counter\n",
"from collections import defaultdict"
"from molmass import Formula"
]
},
{
......@@ -29,25 +27,9 @@
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"scrolled": true
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Define compound name:19:0 Lyso PS-d5 (Na Salt)\n",
"Define query name (no spaces/underscores):LPS190\n",
"Specify formula:C25H45D5NO9P\n",
"Specify adduct type (H, HCOO, NH4):H\n",
"Define MS mode (either + or -):-\n",
"Define lipid class (PL, NL, Cer, SM, PI, PG):PL\n",
"Define file name (no special characters):19_0_Lyso_PS-d5_(M-H)-\n"
]
}
],
"execution_count": 11,
"metadata": {},
"outputs": [],
"source": [
"#specify some parameters, for now only works for chemical compositions with CHDNOP\n",
"#probably it's better to use dictionaries!\n",
......@@ -59,11 +41,11 @@
"\n",
"#define formula and use molmass to generate the tuple\n",
"f = input ('Specify formula:')\n",
"cc = Formula(f)\n",
"f = f.upper()\n",
"\n",
"#define adduct and use molmass to generate the tuple\n",
"adduct = input('Specify adduct type (H, HCOO, NH4):')\n",
"af = Formula(adduct) #get chemical composition of adduct\n",
"adduct = adduct.upper()\n",
"\n",
"#define MS mode\n",
"ms = input('Define MS mode (either + or -):')\n",
......@@ -79,61 +61,158 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 18,
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"#parse chemical composition using molmass for precursor and adduct\n",
"cc = Formula(f)\n",
"af = Formula(adduct) #get chemical composition of adduct"
]
},
{
"cell_type": "code",
"execution_count": 33,
"metadata": {},
"outputs": [],
"source": [
"cc1 = cc.composition()\n",
"cc_dict = {t[0]:t[1] for t in cc1}"
]
},
{
"cell_type": "code",
"execution_count": 34,
"metadata": {},
"outputs": [],
"source": [
"af1 = af.composition()\n",
"\n",
"#right elements and element count to two lists and combine them in a dictionary\n",
"#for compound of interest (cc) and adduct (af)\n",
"cc_keys = []\n",
"for key in cc1:\n",
" cc_keys.append(key[0])\n",
"cc_values = []\n",
"for value in cc1:\n",
" cc_values.append(value[1])\n",
"\n",
"cc_dict = {k: v for k, v in zip(cc_keys,cc_values)}\n",
" \n",
"af_keys = []\n",
"for key in af1:\n",
" af_keys.append(key[0])\n",
"af_values = []\n",
"for value in af1:\n",
" af_values.append(value[1])\n",
"\n",
"af_dict = {k: v for k, v in zip(af_keys,af_values)}"
"af_dict = {t[0]:t[1] for t in af1}"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Based on the adduct it will be added or substracted"
]
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 35,
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": "dict_keys(['C', '2H', 'H'])"
},
"metadata": {},
"execution_count": 35
}
],
"source": [
"allelems = dict(cc_dict)\n",
"allelems.update(af_dict)\n",
"allelems.keys()"
]
},
{
"cell_type": "code",
"execution_count": 37,
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": "{'C': 3, '2H': 4, 'H': 1}"
},
"metadata": {},
"execution_count": 37
}
],
"source": [
"allelems"
]
},
{
"cell_type": "code",
"execution_count": 41,
"metadata": {},
"outputs": [],
"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.keys() # just to get all the keys in both dicts\n",
"if adduct == 'H' and ms == '+':\n",
" res = {key: cc_dict[key] + af_dict.get(key, 0) \n",
" for key in cc_dict.keys()}\n",
" res = {key: cc_dict.get(key, 0) + af_dict.get(key, 0) for key in allelems.keys()}\n",
" \n",
"if adduct == 'H' and ms == '-':\n",
" res = {key: cc_dict[key] - af_dict.get(key, 0) \n",
" for key in cc_dict.keys()}\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",
" \n",
"if adduct == 'HCOO':\n",
" res = {key: cc_dict[key] + af_dict.get(key, 0) \n",
" for key in cc_dict.keys()}\n",
" \n",
"if adduct == 'NH4':\n",
" res = {key: cc_dict[key] + af_dict.get(key, 0) \n",
" for key in cc_dict.keys()}\n",
" res['N'] = 1 \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",
" \n"
]
},
{
"cell_type": "code",
"execution_count": 43,
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": "{'C': 3, '2H': 4, 'H': 1}"
},
"metadata": {},
"execution_count": 43
}
],
"source": [
"res"
]
},
{
"cell_type": "code",
"execution_count": 46,
"metadata": {},
"outputs": [],
"source": [
"def calc_dbe(cc_dict):\n",
" val_minus_2 = {\n",
" 'C' : 2,\n",
" 'H' : -1,\n",
" 'N' : 1,\n",
" 'P' : 1,\n",
" 'O' : 0,\n",
" 'S' : 4,\n",
" '2H' : -1\n",
" }\n",
" # from Man-XCALI-97617-Xcalibur-31-Qual-ManXCALI97617-A-EN.pdf page 189: Double Bond/Ring equevelentse\n",
" dbe = 1 + sum([cc_dict.get(e, 0)*val_minus_2[e] for e in val_minus_2.keys()])/2\n",
" return dbe"
]
},
{
"cell_type": "code",
"execution_count": 47,
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": "1.5"
},
"metadata": {},
"execution_count": 47
}
],
"source": [
"calc_dbe(res)"
]
},
{
......@@ -292,9 +371,9 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3.7.5 64-bit ('mfql_des': conda)",
"language": "python",
"name": "python3"
"name": "python37564bitmfqldesconda008f121642b041f890de0d051e241abf"
},
"language_info": {
"codemirror_mode": {
......@@ -306,9 +385,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.3"
"version": "3.7.5-final"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment