Skip to content

Instantly share code, notes, and snippets.

@jittat
Created February 12, 2019 06:01
Show Gist options
  • Save jittat/90f7a8974e4a7d4528165b6a72785b07 to your computer and use it in GitHub Desktop.
Save jittat/90f7a8974e4a7d4528165b6a72785b07 to your computer and use it in GitHub Desktop.
Pep mass
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"from random import choice"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"MASS = {\n",
" 'G':57,\n",
" 'A':71,\n",
" 'S':87,\n",
" 'P':97,\n",
" 'V':99,\n",
" 'T':101,\n",
" 'C':103,\n",
" 'I':113,\n",
" 'L':113,\n",
" 'N':114,\n",
" 'D':115,\n",
" 'Q':128,\n",
" 'K':128,\n",
" 'E':129,\n",
" 'M':131,\n",
" 'H':137,\n",
" 'F':147,\n",
" 'R':156,\n",
" 'Y':163,\n",
" 'W':186,\n",
"}"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"ALPHA='GASPVTCLNDKEMHFRYW' # remove I and Q"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"def random_peptide(length=10):\n",
" return ''.join([choice(ALPHA) for i in range(length)])"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"def weight(peptide):\n",
" return sum([MASS[p] for p in peptide])\n",
"\n",
"def compute_spectrum(peptide):\n",
" mset = set()\n",
" n = len(peptide)\n",
" for i in range(n):\n",
" for j in range(n - i):\n",
" s = peptide[i:i+j+1]\n",
" mset.add(weight(s))\n",
" return mset"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"LPAAS\n"
]
},
{
"data": {
"text/plain": [
"{71, 87, 97, 113, 142, 158, 168, 210, 229, 239, 281, 326, 352, 439}"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"p = random_peptide(5)\n",
"print(p)\n",
"compute_spectrum(p)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"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.6.5"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment