Commit a1f7ebe2 authored by knittelf's avatar knittelf
Browse files

init

parent 2d0ceb35
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Import dependencies"
]
},
{
"cell_type": "code",
"execution_count": 1,
"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"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Generate mfql"
]
},
{
"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"
]
}
],
"source": [
"#specify some parameters, for now only works for chemical compositions with CHDNOP\n",
"#probably it's better to use dictionaries!\n",
"\n",
"#how to deal with other chemical compositions!\n",
"#make it more flexible\n",
"cn = input('Define compound name:')\n",
"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",
"cc = Formula(f)\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",
"\n",
"#define MS mode\n",
"ms = input('Define MS mode (either + or -):')\n",
"\n",
"#define lipid class\n",
"lipid_class = input('Define lipid class (PL, NL, Cer, SM, PI, PG):')\n",
"\n",
"#define filename\n",
"filename = input('Define file name (no special characters):')\n",
"mfql = '.mfql'\n",
"filename = \"\".join((filename, mfql))"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"#parse chemical composition using molmass for precursor and adduct\n",
"cc1 = cc.composition()\n",
"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)}"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"#adjust for the adduct\n",
"# only H, NH4 and HCOO are defined\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",
" \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",
" \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"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"scrolled": true
},
"outputs": [
{
"data": {
"text/plain": [
"'C25H44D5N1O9P1'"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"#print dictionary in one string to get dbe from LX1.0 tools\n",
"elemental_comp = \"\".join(f\"{key}{value}\" for key, value in res.items())\n",
"#replace 2H with D\n",
"elemental_comp = elemental_comp.replace('2H','D')\n",
"elemental_comp"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Enter dbe:2.5\n"
]
}
],
"source": [
"#input dbe\n",
"dbe = input('Enter dbe:')"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"#calculating dbr according to mfql_tools.py\n",
"#no idea to calculate the dbr correctly when deuterium is present so use output from LX tools\n",
"#if adduct == 'NH4':\n",
"# dbe = res['C'] + 1 - res['H']/2 + res['N']/2 - 2.5 #how is deuterium implemented?, check for other compounds\n",
"#if adduct == 'HCOO' and lipid_class == 'NL':\n",
"# dbe = res['C'] + 1 - res['H']/2 - 2.5\n",
"#if lipid_class == 'Cer':\n",
"# dbe = res['C'] + 1 - res['H']/2 + res['N']/2 - 3.5\n",
"#else:\n",
"# dbe = res['C'] + 1 - res['H']/2 + res['N']/2 - 2 #how is deuterium implemented?, check for other compounds"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"#test for odd/even number of hydrogens\n",
"if res['H'] % 2 == 0:\n",
" such = 'isEven'\n",
"else:\n",
" such = 'isOdd'"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'isEven'"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"such"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
"#generate mfql\n",
"#report adjusted to neutral lipids in pos mode\n",
"if lipid_class == 'NL' and ms == '+':\n",
" with open(filename, 'w') as f: #change name accordingly\n",
" print(f'#Identify {cn}#', file=f)\n",
" print(f'\\nQUERYNAME = {qn};', file=f)\n",
" print(f\"\\nDEFINE pr = 'C[{res['C']}] H[{res['H']}] D[{res['2H']}] N[{res['N']}] O[{res['O']}]' WITH DBR = ({dbe},{dbe}), CHG = {ms}1;\", file=f)\n",
" print(f'\\nIDENTIFY\\n\\tpr in MS1{ms}', file=f)\n",
" print(f'\\nSUCHTHAT\\n\\t{such}(pr.chemsc[H]) AND \\n\\tisOdd(pr.chemsc[db]*2)', file=f)\n",
" print(f'\\nREPORT\\n\\tPRM = pr.mass;\\n\\tEC = pr.chemsc;\\n\\tCLASS = \"{qn}\" % \"()\";\\n\\tQSERR = \"%2.2f\" % \"(pr.errppm)\";\\n\\tQS = pr.intensity;;', file=f)\n",
"\n",
"#report adjusted to DG in neg mode \n",
"if lipid_class == 'NL' and ms == '-':\n",
" with open(filename, 'w') as f: #change name accordingly\n",
" print(f'#Identify {cn}#', file=f)\n",
" print(f'\\nQUERYNAME = {qn};', file=f)\n",
" print(f\"\\nDEFINE pr = 'C[{res['C']}] H[{res['H']}] D[{res['2H']}] O[{res['O']}]' WITH DBR = ({dbe},{dbe}), CHG = {ms}1;\", file=f)\n",
" print(f'\\nIDENTIFY\\n\\tpr in MS1{ms}', file=f)\n",
" print(f'\\nSUCHTHAT\\n\\t{such}(pr.chemsc[H]) AND \\n\\tisOdd(pr.chemsc[db]*2)', file=f)\n",
" print(f'\\nREPORT\\n\\tPRM = pr.mass;\\n\\tEC = pr.chemsc;\\n\\tCLASS = \"{qn}\" % \"()\";\\n\\tQSERR = \"%2.2f\" % \"(pr.errppm)\";\\n\\tQS = pr.intensity;;', file=f)\n",
"\n",
"#report adjusted to Cer independent of mode \n",
"if lipid_class == 'Cer':\n",
" with open(filename, 'w') as f: #change name accordingly\n",
" print(f'#Identify {cn}#', file=f)\n",
" print(f'\\nQUERYNAME = {qn};', file=f)\n",
" print(f\"\\nDEFINE pr = 'C[{res['C']}] H[{res['H']}] D[{res['2H']}] N[{res['N']}] O[{res['O']}]' WITH DBR = ({dbe},{dbe}), CHG = {ms}1;\", file=f)\n",
" print(f'\\nIDENTIFY\\n\\tpr in MS1{ms}', file=f)\n",
" print(f'\\nSUCHTHAT\\n\\t{such}(pr.chemsc[H]) AND \\n\\tisOdd(pr.chemsc[db]*2)', file=f)\n",
" print(f'\\nREPORT\\n\\tPRM = pr.mass;\\n\\tEC = pr.chemsc;\\n\\tCLASS = \"{qn}\" % \"()\";\\n\\tQSERR = \"%2.2f\" % \"(pr.errppm)\";\\n\\tQS = pr.intensity;;', file=f) \n",
"\n",
"#report adjusted to SM and PLs\n",
"if lipid_class == 'PL' or lipid_class == 'SM':\n",
" with open(filename, 'w') as f: #change name accordingly\n",
" print(f'#Identify {cn}#', file=f)\n",
" print(f'\\nQUERYNAME = {qn};', file=f)\n",
" print(f\"\\nDEFINE pr = 'C[{res['C']}] H[{res['H']}] D[{res['2H']}] N[{res['N']}] O[{res['O']}] P[{res['P']}]' WITH DBR = ({dbe},{dbe}), CHG = {ms}1;\", file=f)\n",
" print(f'\\nIDENTIFY\\n\\tpr in MS1{ms}', file=f)\n",
" print(f'\\nSUCHTHAT\\n\\t{such}(pr.chemsc[H]) AND \\n\\tisOdd(pr.chemsc[db]*2)', file=f)\n",
" print(f'\\nREPORT\\n\\tPRM = pr.mass;\\n\\tEC = pr.chemsc;\\n\\tCLASS = \"{qn}\" % \"()\";\\n\\tQSERR = \"%2.2f\" % \"(pr.errppm)\";\\n\\tQS = pr.intensity;;', file=f)\n",
" \n",
"#report adjusted to PI and PG in neg mode \n",
"if lipid_class == 'PG' or lipid_class == 'PI' and ms == '-':\n",
" with open(filename, 'w') as f: #change name accordingly\n",
" print(f'#Identify {cn}#', file=f)\n",
" print(f'\\nQUERYNAME = {qn};', file=f)\n",
" print(f\"\\nDEFINE pr = 'C[{res['C']}] H[{res['H']}] D[{res['2H']}] O[{res['O']}] P[{res['P']}]' WITH DBR = ({dbe},{dbe}), CHG = {ms}1;\", file=f)\n",
" print(f'\\nIDENTIFY\\n\\tpr in MS1{ms}', file=f)\n",
" print(f'\\nSUCHTHAT\\n\\t{such}(pr.chemsc[H]) AND \\n\\tisOdd(pr.chemsc[db]*2)', file=f)\n",
" print(f'\\nREPORT\\n\\tPRM = pr.mass;\\n\\tEC = pr.chemsc;\\n\\tCLASS = \"{qn}\" % \"()\";\\n\\tQSERR = \"%2.2f\" % \"(pr.errppm)\";\\n\\tQS = pr.intensity;;', file=f) "
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"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.7.3"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
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