heatmap.ipynb 19.4 KB
Newer Older
1
{
Jeroen F.J. Laros's avatar
Jeroen F.J. Laros committed
2
 "cells": [
3
  {
Jeroen F.J. Laros's avatar
Jeroen F.J. Laros committed
4
5
6
7
8
9
10
11
12
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Back translation"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
Jeroen F.J. Laros's avatar
Jeroen F.J. Laros committed
13
   "metadata": {},
Jeroen F.J. Laros's avatar
Jeroen F.J. Laros committed
14
   "outputs": [
Jeroen F.J. Laros's avatar
Jeroen F.J. Laros committed
15
    {
Jeroen F.J. Laros's avatar
Jeroen F.J. Laros committed
16
17
18
19
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Populating the interactive namespace from numpy and matplotlib\n"
Jeroen F.J. Laros's avatar
Jeroen F.J. Laros committed
20
     ]
Jeroen F.J. Laros's avatar
Jeroen F.J. Laros committed
21
22
23
24
25
26
27
28
29
    }
   ],
   "source": [
    "%pylab inline"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
Jeroen F.J. Laros's avatar
Jeroen F.J. Laros committed
30
   "metadata": {},
Jeroen F.J. Laros's avatar
Jeroen F.J. Laros committed
31
32
33
34
   "outputs": [],
   "source": [
    "from collections import defaultdict\n",
    "\n",
Jeroen F.J. Laros's avatar
Jeroen F.J. Laros committed
35
36
    "from mutalyzer_backtranslate import BackTranslate\n",
    "from mutalyzer_backtranslate.util import protein_letters"
Jeroen F.J. Laros's avatar
Jeroen F.J. Laros committed
37
38
39
40
41
42
43
44
45
46
47
48
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Create a reverse translation class instance."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
Jeroen F.J. Laros's avatar
Jeroen F.J. Laros committed
49
   "metadata": {},
Jeroen F.J. Laros's avatar
Jeroen F.J. Laros committed
50
51
52
53
54
55
56
57
58
59
60
61
62
63
   "outputs": [],
   "source": [
    "bt = BackTranslate()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "For each pair of amino acids, calculate the number of one-nucleotide substitutions that transform one amino acid into the other."
   ]
  },
  {
   "cell_type": "code",
Jeroen F.J. Laros's avatar
Jeroen F.J. Laros committed
64
65
   "execution_count": 4,
   "metadata": {},
Jeroen F.J. Laros's avatar
Jeroen F.J. Laros committed
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
   "outputs": [],
   "source": [
    "table = []\n",
    "for i in protein_letters:\n",
    "    table.append([])\n",
    "    for j in protein_letters:\n",
    "        s = bt.without_dna(i, j)\n",
    "        table[-1].append(int(sum(list(map(len, s.values())))))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Visualise the resutling matrix."
   ]
  },
  {
   "cell_type": "code",
Jeroen F.J. Laros's avatar
Jeroen F.J. Laros committed
85
86
   "execution_count": 5,
   "metadata": {},
Jeroen F.J. Laros's avatar
Jeroen F.J. Laros committed
87
   "outputs": [
Jeroen F.J. Laros's avatar
Jeroen F.J. Laros committed
88
    {
Jeroen F.J. Laros's avatar
Jeroen F.J. Laros committed
89
     "data": {
Jeroen F.J. Laros's avatar
Jeroen F.J. Laros committed
90
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAASgAAAD8CAYAAADE3zmUAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjIsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+WH4yJAAAcnUlEQVR4nO3df9AcVZ3v8feHRIGIghB+KD91zeIuiFzIFWFXUeJeg3AF7mW9yYLKXm5RbgmIwCLq3mu8VbtarvgTdqksICKYoCg/tBBhFQqUgJtgIAkoQX4ZkCUhtWqUXwnf/aN7cJjMPM/pfrpnuofPq2oqT/ecOX1mnsn36T79PecoIjAza6ItRt0AM7NBHKDMrLEcoMyssRygzKyxHKDMrLE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112
113
114
115
116
117
      "text/plain": [
       "<Figure size 432x288 with 2 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "imshow(table, interpolation='nearest')\n",
    "xticks(range(21), protein_letters)\n",
    "yticks(range(21), protein_letters)\n",
    "set_cmap('cool')\n",
    "colorbar();"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Visualise the distribution of values in the matrix."
   ]
  },
  {
   "cell_type": "code",
Jeroen F.J. Laros's avatar
Jeroen F.J. Laros committed
118
119
   "execution_count": 6,
   "metadata": {},
Jeroen F.J. Laros's avatar
Jeroen F.J. Laros committed
120
   "outputs": [
Jeroen F.J. Laros's avatar
Jeroen F.J. Laros committed
121
    {
Jeroen F.J. Laros's avatar
Jeroen F.J. Laros committed
122
     "data": {
Jeroen F.J. Laros's avatar
Jeroen F.J. Laros committed
123
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXcAAAD4CAYAAAAXUaZHAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjIsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+WH4yJAAAOo0lEQVR4nO3df6zd9V3H8edLOqcMIpDeVdY2XrJUTLe4Qm4QxRgUtzFYVpYYAlFWJ6b7AxQMyVJm4vYPpokbc4uK6QbSZcgkG4RGcFLrkmXJfnBBxq8OaUYZrYXeOQXiks2yt3+cb91Ze27vj3PuPZcPz0dyc7/nc77nnnd/3Ge//fZ7TlNVSJLa8lPjHkCSNHrGXZIaZNwlqUHGXZIaZNwlqUGrxj0AwOrVq2tycnLcY0jSq8pDDz303aqaGHTfioj75OQk09PT4x5Dkl5Vkjw7232elpGkBhl3SWqQcZekBhl3SWqQcZekBhl3SWqQcZekBs0Z9yTrk3wpyZNJnkhyXbf+kSQHkzzSfVzS95gbk+xL8lSSdy7lD0CSd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DSX5+OZ685biv+LdASBJ654j3VtXN455nkKq6sarWVdUkvZ/Df62qFXe0WVXPA88lObtbuoiV9xbT3wHOT3Jy92t/ESvsH3377AK2dNtbgHvHOMtA3X8I9EHgPVX1/XHPc6yqeqyq3lhVk933zwHg3O736pJrNu7dP7QcfQuEvcBdY34LhEEuAK6idzT8SPdxybiHehX7I+COJI8Cm4A/H/M8P6H7W8XngYeBx+h9/439JfRJ7gS+Cpyd5ECSq4HtwNuTPE3vbxxj/Z/UZpnxr4BTgd3d987frsAZxzfPyvubjCRpWM0euUvSa5lxl6QGGXdJapBxl6QGGXdJapBxl6QGGXdJatD/AT89wfiOemvIAAAAAElFTkSuQmCC\n",
Jeroen F.J. Laros's avatar
Jeroen F.J. Laros committed
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "d = defaultdict(int)\n",
    "\n",
    "for row in table:\n",
    "    for element in row:\n",
    "        d[element] += 1\n",
    "\n",
    "ind = sorted(d.keys())\n",
    "values = []\n",
    "for i in ind:\n",
    "     values.append(d[i])\n",
    "        \n",
    "bar(ind, values);"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Print some summaries."
   ]
  },
  {
   "cell_type": "code",
Jeroen F.J. Laros's avatar
Jeroen F.J. Laros committed
158
159
   "execution_count": 7,
   "metadata": {},
Jeroen F.J. Laros's avatar
Jeroen F.J. Laros committed
160
   "outputs": [
161
    {
Jeroen F.J. Laros's avatar
Jeroen F.J. Laros committed
162
163
164
     "name": "stdout",
     "output_type": "stream",
     "text": [
Jeroen F.J. Laros's avatar
Jeroen F.J. Laros committed
165
      "\n",
Jeroen F.J. Laros's avatar
Jeroen F.J. Laros committed
166
167
168
169
      "441 substitutions in total.\n",
      "252 impossible substitutions (57.14%).\n",
      "130 perfect substitutions (29.48%).\n",
      " 59 imperfect substitutions (13.38%).\n",
Jeroen F.J. Laros's avatar
Jeroen F.J. Laros committed
170
      "\n",
Jeroen F.J. Laros's avatar
Jeroen F.J. Laros committed
171
      "189 possible substitutions, of which 68.78% is perfect and 31.22% is imperfect.\n"
Laros's avatar
Laros committed
172
     ]
173
174
    }
   ],
Jeroen F.J. Laros's avatar
Jeroen F.J. Laros committed
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
   "source": [
    "total = 21 ** 2\n",
    "total_p = total / 100\n",
    "imperfect = sum(values[2:])\n",
    "\n",
    "print('\\n{} substitutions in total.'.format(total))\n",
    "print('{:3} impossible substitutions ({:.2f}%).'.format(values[0], values[0] / total_p))\n",
    "print('{:3} perfect substitutions ({:.2f}%).'.format(values[1], values[1] / total_p))\n",
    "print('{:3} imperfect substitutions ({:.2f}%).'.format(imperfect, imperfect / total_p))\n",
    "\n",
    "possible = sum(values[1:])\n",
    "possible_p = possible / 100\n",
    "print('\\n{:3} possible substitutions, of which {:.2f}% is perfect and {:.2f}% is imperfect.'.format(\n",
    "    possible, values[1] / possible_p, imperfect / possible_p))"
   ]
190
  }
Jeroen F.J. Laros's avatar
Jeroen F.J. Laros committed
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "backtranslate",
   "language": "python",
   "name": "backtranslate"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
Jeroen F.J. Laros's avatar
Jeroen F.J. Laros committed
208
   "version": "3.7.3"
Jeroen F.J. Laros's avatar
Jeroen F.J. Laros committed
209
210
211
  }
 },
 "nbformat": 4,
Jeroen F.J. Laros's avatar
Jeroen F.J. Laros committed
212
 "nbformat_minor": 1
Jeroen F.J. Laros's avatar
Jeroen F.J. Laros committed
213
}