├── 01_WXN_Python_basic.Rmd ├── 02_CT_Python_training-chinese.Rmd ├── 02_MYK_PythonClass_File_RE_Exercises.Rmd.bak ├── 03_WXN_matplotlib.Rmd ├── 04_CT_Python_practice.Rmd ├── 06_CT_Pandas.Rmd ├── 07_Python_pythonic_numpy_scipy.Rmd ├── 08_CT_Python_training_exercise.Rmd ├── 09-1-refereneces.Rmd ├── 09-2-company.Rmd ├── Py3_course.Rproj ├── Py3_course ├── -1.html ├── .history ├── 02_CT_Python_training-chinese_files │ ├── 02_CT_Python_training-chinese_263_0.png │ ├── 02_CT_Python_training-chinese_267_0.png │ ├── 02_CT_Python_training-chinese_268_0.png │ ├── 02_CT_Python_training-chinese_270_0.png │ ├── 02_CT_Python_training-chinese_272_0.png │ ├── 02_CT_Python_training-chinese_273_0.png │ ├── 02_CT_Python_training-chinese_275_0.png │ ├── 02_CT_Python_training-chinese_277_0.png │ ├── 02_CT_Python_training-chinese_283_0.png │ ├── 02_CT_Python_training-chinese_285_0.png │ ├── 02_CT_Python_training-chinese_287_0.png │ ├── 02_CT_Python_training-chinese_289_0.png │ ├── 02_CT_Python_training-chinese_290_0.png │ ├── 02_CT_Python_training-chinese_292_0.png │ ├── 02_CT_Python_training-chinese_295_0.png │ ├── 02_CT_Python_training-chinese_298_0.png │ ├── 02_CT_Python_training-chinese_301_0.png │ ├── 02_CT_Python_training-chinese_302_0.png │ ├── 02_CT_Python_training-chinese_303_0.png │ ├── 02_CT_Python_training-chinese_304_0.png │ ├── 02_CT_Python_training-chinese_305_0.png │ └── 02_CT_Python_training-chinese_306_0.png ├── 03_WXN_matplotlib_files │ ├── 03_WXN_matplotlib_10_0.png │ ├── 03_WXN_matplotlib_11_0.png │ ├── 03_WXN_matplotlib_13_0.png │ ├── 03_WXN_matplotlib_16_0.png │ ├── 03_WXN_matplotlib_17_0.png │ ├── 03_WXN_matplotlib_19_0.png │ ├── 03_WXN_matplotlib_21_0.png │ ├── 03_WXN_matplotlib_22_0.png │ ├── 03_WXN_matplotlib_27_0.png │ ├── 03_WXN_matplotlib_29_0.png │ ├── 03_WXN_matplotlib_31_0.png │ ├── 03_WXN_matplotlib_32_0.png │ ├── 03_WXN_matplotlib_34_0.png │ ├── 03_WXN_matplotlib_36_0.png │ ├── 03_WXN_matplotlib_37_0.png │ ├── 03_WXN_matplotlib_39_0.png │ ├── 03_WXN_matplotlib_42_0.png │ ├── 03_WXN_matplotlib_45_0.png │ ├── 03_WXN_matplotlib_48_0.png │ ├── 03_WXN_matplotlib_4_0.png │ ├── 03_WXN_matplotlib_50_0.png │ ├── 03_WXN_matplotlib_59_0.png │ ├── 03_WXN_matplotlib_5_0.png │ ├── 03_WXN_matplotlib_63_0.png │ ├── 03_WXN_matplotlib_9_0.png │ └── 03_WXN_matplotlib_9_1.png ├── 06_CT_Pandas_files │ ├── 06_CT_Pandas_103_1.png │ ├── 06_CT_Pandas_105_0.png │ ├── 06_CT_Pandas_107_1.png │ ├── 06_CT_Pandas_114_1.png │ ├── 06_CT_Pandas_116_1.png │ ├── 06_CT_Pandas_117_0.png │ ├── 06_CT_Pandas_118_1.png │ ├── 06_CT_Pandas_119_1.png │ └── 06_CT_Pandas_122_0.png ├── 08_Python_pythonic_numpy_scipy_files │ ├── 08_Python_pythonic_numpy_scipy_35_0.png │ ├── 08_Python_pythonic_numpy_scipy_37_0.png │ ├── 08_Python_pythonic_numpy_scipy_39_0.png │ ├── 08_Python_pythonic_numpy_scipy_43_0.png │ ├── 08_Python_pythonic_numpy_scipy_45_0.png │ ├── 08_Python_pythonic_numpy_scipy_49_0.png │ ├── 08_Python_pythonic_numpy_scipy_52_0.png │ └── 08_Python_pythonic_numpy_scipy_55_0.png ├── Py3-pratcise-ct.html ├── Py3-test.html ├── Py3_course.pdf ├── Py3_course.tex ├── Python-plot-WXN.html ├── Python_start_run_linux.png ├── coding_is_hard_confidence_competence.png ├── company-intro.html ├── ehbio │ ├── company_1.png │ ├── company_2.png │ └── cover.png ├── index.html ├── libs │ ├── gitbook-2.6.7 │ │ ├── css │ │ │ ├── fontawesome │ │ │ │ └── fontawesome-webfont.ttf │ │ │ ├── plugin-bookdown.css │ │ │ ├── plugin-fontsettings.css │ │ │ ├── plugin-highlight.css │ │ │ ├── plugin-search.css │ │ │ └── style.css │ │ └── js │ │ │ ├── app.min.js │ │ │ ├── jquery.highlight.js │ │ │ ├── lunr.js │ │ │ ├── plugin-bookdown.js │ │ │ ├── plugin-fontsettings.js │ │ │ ├── plugin-search.js │ │ │ └── plugin-sharing.js │ └── jquery-2.2.3 │ │ └── jquery.min.js ├── numpy-scipy.html ├── py3-ct.html ├── py3-file.html ├── py3-pandas-ct.html ├── pyre.png ├── python-py3-ct.html ├── python-python-plot-wxn.html ├── pythonbasic.html ├── references.html ├── search_index.json ├── section-5.html └── style.css ├── Python_course.png ├── Python_start_run_linux.png ├── README.md ├── _bookdown.yml ├── _output.yml ├── coding_is_hard_confidence_competence.png ├── ehbio ├── company_1.pdf ├── company_1.png ├── company_2.pdf ├── company_2.png ├── cover.pdf ├── cover.png ├── ehbio.latex └── ehbio_logo.png ├── index.Rmd ├── pyre.png ├── style.css └── swap /03_WXN_matplotlib.Rmd: -------------------------------------------------------------------------------- 1 | # Python作图 {#Python_plot_WXN} 2 | 3 | ## 绘图基础 4 | 5 | ### Figure和Subplot 6 | 7 | 8 | ```python 9 | import matplotlib.pyplot as plt 10 | import numpy as np 11 | import pandas as pd 12 | from numpy.random import randn 13 | ``` 14 | 15 | 16 | ```python 17 | x = [1, 3, 5, 7, 9, 10, 23, 45, 45, 56] 18 | y = [2, 4, 6, 8, 11, 12, 23, 45, 56, 78] 19 | 20 | 21 | fig = plt.figure() # 创建一个Figure 22 | ax1 = fig.add_subplot(2, 2, 1) # 创建4个图的Figure对象,最后的1为选中第一个 23 | ax2 = fig.add_subplot(2, 2, 2) 24 | ax3 = fig.add_subplot(2, 2, 3) 25 | ax4 = fig.add_subplot(2, 2, 4) 26 | 27 | ax1.hist(x, y) # 在第一图中绘制直方图 28 | ax2.scatter(x, y) # 散点图 29 | ax4.plot(x, y) # 线图 30 | 31 | plt.show() 32 | ``` 33 | 34 | 35 | ```{r} 36 | knitr::include_graphics("03_WXN_matplotlib_files/03_WXN_matplotlib_4_0.png") 37 | ``` 38 | 39 | 40 | 41 | ```python 42 | fig, axes = plt.subplots(2, 3) # 创建一个Figure 绘制2 X3 图 43 | fig 44 | ``` 45 | 46 | 47 | 48 | 49 | ```{r} 50 | knitr::include_graphics("03_WXN_matplotlib_files/03_WXN_matplotlib_5_0.png") 51 | ``` 52 | 53 | 54 | 55 | 56 | ```python 57 | axes 58 | ``` 59 | 60 | 61 | 62 | 63 | array([[, 64 | , 65 | ], 66 | [, 67 | , 68 | ]], dtype=object) 69 | 70 | 71 | 72 | ``` 73 | 创建2 X 3图像,可以相当于对二维数组进行索引 74 | 参数 说明 75 | nrows subplot行数 76 | ncols subplot列数 77 | sharex 所有图使用相同的x轴 78 | sharey 所有图使用相同的y轴 79 | subplot_kw 用于创建各subplot的关键字字典 80 | ```| 81 | 82 | ### 调整subplot周围间距 83 | 84 | ``` 85 | subplots_ajust(left=None,bottom=None,right=None,top=None,wspace=None,hspace=None) 86 | wspace和hspace控制宽度和高度 87 | ``` 88 | 89 | 90 | ```python 91 | fig, axes = plt.subplots(2, 2, sharex=True, sharey=True) 92 | for i in range(2): 93 | for j in range(2): 94 | axes[i, j].hist(randn(500), bins=50, color='k', alpha=0.5) 95 | plt.subplots_adjust(wspace=0, hspace=0) 96 | plt.show() 97 | ``` 98 | 99 | 100 | ```{r} 101 | knitr::include_graphics("03_WXN_matplotlib_files/03_WXN_matplotlib_9_0.png") 102 | ``` 103 | 104 | 105 | 106 | ```{r} 107 | knitr::include_graphics("03_WXN_matplotlib_files/03_WXN_matplotlib_9_1.png") 108 | ``` 109 | 110 | 111 | 112 | ```python 113 | fig, axes = plt.subplots(2, 2, sharex=True, sharey=True) 114 | for i in range(2): 115 | for j in range(2): 116 | axes[i, j].hist(randn(500), bins=50, color='k', alpha=0.5) 117 | plt.subplots_adjust(wspace=2, hspace=0.5) 118 | plt.show() 119 | ``` 120 | 121 | 122 | ```{r} 123 | knitr::include_graphics("03_WXN_matplotlib_files/03_WXN_matplotlib_10_0.png") 124 | ``` 125 | 126 | 127 | 128 | ```python 129 | fig 130 | ``` 131 | 132 | 133 | 134 | 135 | ```{r} 136 | knitr::include_graphics("03_WXN_matplotlib_files/03_WXN_matplotlib_11_0.png") 137 | ``` 138 | 139 | 140 | 141 | ### 颜色 标记和线型 142 | 143 | 144 | ```python 145 | """ 146 | 绘制绿色虚线 147 | ax.plot(x,y,'g--') 148 | 另一种方式 149 | ax.plot(x,y,linestyle='--',color='g') 150 | 标记点(maker) 151 | """ 152 | fig, axes = plt.subplots(1, 2) 153 | 154 | axes[0].plot(randn(10), 'g--') # green --- 155 | axes[1].plot(randn(10), 'ko--') # k:black o:圆点 156 | 157 | plt.show() 158 | ``` 159 | 160 | 161 | ```{r} 162 | knitr::include_graphics("03_WXN_matplotlib_files/03_WXN_matplotlib_13_0.png") 163 | ``` 164 | 165 | 166 | ``` 167 | character description 168 | '-' solid line style 169 | '--' dashed line style 170 | '-.' dash-dot line style 171 | ':' dotted line style 172 | '.' point marker 173 | ',' pixel marker 174 | 'o' circle marker 175 | 'v' triangle_down marker 176 | '^' triangle_up marker 177 | '<' triangle_left marker 178 | '>' triangle_right marker 179 | '1' tri_down marker 180 | '2' tri_up marker 181 | '3' tri_left marker 182 | '4' tri_right marker 183 | 's' square marker 184 | 'p' pentagon marker 185 | '*' star marker 186 | 'h' hexagon1 marker 187 | 'H' hexagon2 marker 188 | '+' plus marker 189 | 'x' x marker 190 | 'D' diamond marker 191 | 'd' thin_diamond marker 192 | '|' vline marker 193 | '_' hline marker 194 | 195 | The following color abbreviations are supported: 196 | 197 | character color 198 | ‘b’ blue 199 | ‘g’ green 200 | ‘r’ red 201 | ‘c’ cyan(青色) 202 | ‘m’ magenta(紫红色) 203 | ‘y’ yellow 204 | ‘k’ black 205 | ‘w’ white 206 | 207 | https://matplotlib.org/api/_as_gen/matplotlib.pyplot.plot.html#matplotlib.pyplot.plot 208 | ``` 209 | 210 | ### 刻度、标签和图例 211 | 212 | 213 | ```python 214 | fig = plt.figure() # 创建一个Figure 215 | ax = fig.add_subplot(1, 1, 1) 216 | ax.plot(randn(100)) 217 | plt.show() 218 | ``` 219 | 220 | 221 | ```{r} 222 | knitr::include_graphics("03_WXN_matplotlib_files/03_WXN_matplotlib_16_0.png") 223 | ``` 224 | 225 | 226 | 227 | ```python 228 | """修改上图的轴""" 229 | 230 | fig = plt.figure() 231 | ax = fig.add_subplot(1, 1, 1) 232 | ax.plot(randn(100)) 233 | 234 | ticks = ax.set_xticks([0, 25, 50, 75, 100]) # 设置刻度 235 | labels = ax.set_xticklabels( 236 | ['first', 'second', 'third', 'forth', 'fifth'], rotation=30, fontsize='small') # 设置x轴标签 237 | 238 | ax.set_title('my first matplot plot') # 设置图片标题 239 | 240 | ax.set_xlabel('Stages') # 设置x轴名称 241 | 242 | plt.show() 243 | ``` 244 | 245 | 246 | ```{r} 247 | knitr::include_graphics("03_WXN_matplotlib_files/03_WXN_matplotlib_17_0.png") 248 | ``` 249 | 250 | 251 | ### 添加图例legend 252 | 253 | ``` 254 | https://matplotlib.org/api/legend_api.html?highlight=legend#module-matplotlib.legend 255 | ‘best’ 0 256 | ‘upper right’ 1 257 | ‘upper left’ 2 258 | ‘lower left’ 3 259 | ‘lower right’ 4 260 | ‘right’ 5 261 | ‘center left’ 6 262 | ‘center right’ 7 263 | ‘lower center’ 8 264 | ‘upper center’ 9 265 | ‘center’ 10 266 | bbox_to_anchor=(0.5,0.8) 267 | bbox_to_anchor被赋予的元组中,第一个数值用于控制legend的左右移动,值越大越向右边移动, 268 | 第二个数值用于控制legend的上下移动,值越大,越向上移动 269 | 270 | ``` 271 | 272 | 273 | ```python 274 | fig = plt.figure() 275 | ax = fig.add_subplot(1, 1, 1) 276 | 277 | ax.plot(randn(10), 'k', label='one') # 画一条线,k黑色 278 | ax.plot(randn(10), 'g--', label='two') # 画第二条线,g绿色 - -类型 279 | ax.plot(randn(10), 'ro--', label='three') # 画第三条线红色 ,类型 ... 280 | 281 | ax.legend(loc=0, bbox_to_anchor=(1, 1)) 282 | 283 | 284 | plt.show() 285 | ``` 286 | 287 | 288 | ```{r} 289 | knitr::include_graphics("03_WXN_matplotlib_files/03_WXN_matplotlib_19_0.png") 290 | ``` 291 | 292 | 293 | ### 注解 294 | 295 | 296 | ```python 297 | x = [2, 4, 6, 8, 10, 12] 298 | y = [1, 3, 5, 7, 9, 11] 299 | fig = plt.figure() 300 | ax = fig.add_subplot(1, 1, 1) 301 | ax.plot(x, y, 'r--') 302 | 303 | ax.text(2, 4, 'hello python') 304 | plt.show() 305 | ``` 306 | 307 | 308 | ```{r} 309 | knitr::include_graphics("03_WXN_matplotlib_files/03_WXN_matplotlib_21_0.png") 310 | ``` 311 | 312 | 313 | 314 | ```python 315 | ax = plt.subplot(111) 316 | 317 | t = np.arange(0.0, 5.0, 0.01) 318 | s = np.cos(2 * np.pi * t) 319 | line, = plt.plot(t, s, lw=2) 320 | 321 | plt.annotate('local max', xy=(2, 1), xytext=(3, 1.5), 322 | arrowprops=dict(facecolor='blue') # xy=(要注释的点),xytext=(注释在图中的位置) 323 | ) 324 | 325 | plt.ylim(-2, 2) 326 | plt.show() 327 | ``` 328 | 329 | 330 | ```{r} 331 | knitr::include_graphics("03_WXN_matplotlib_files/03_WXN_matplotlib_22_0.png") 332 | ``` 333 | 334 | 335 | ### 图片保存 336 | 337 | 338 | ```python 339 | x = [2, 4, 6, 8, 10, 12] 340 | y = [1, 3, 5, 7, 9, 11] 341 | fig = plt.figure() 342 | ax = fig.add_subplot(1, 1, 1) 343 | ax.plot(x, y, 'r--') 344 | 345 | ax.text(2, 4, 'hello python') 346 | 347 | # bbox_inches减除当前图片周围空白部分 348 | plt.savefig('figpath.jpg', dpi=300, bbox_inches='tight') 349 | ``` 350 | 351 | ## 绘图实例 352 | 353 | ### 绘制散点图 354 | 355 | 356 | ```python 357 | x = [1, 2, 3, 4, 5, 6] 358 | y = [1, 4, 9, 16, 25, 36] 359 | plt.scatter(x, # x轴数据 360 | y, # y轴数据 361 | s=20, # 设置点的大小 362 | c='green', # 设置点的颜色 363 | marker='s', # 设置点的形状 364 | alpha=0.9, # 设置点的透明度 365 | linewidths=0.8, # 设置散点边界的粗细 366 | edgecolors='red' # 设置散点边界的颜色 367 | ) 368 | 369 | plt.title('simple scatter plot') 370 | plt.xlabel('X') # x轴名称 371 | plt.ylabel('Y') 372 | 373 | plt.show() # 展示绘图 374 | ``` 375 | 376 | 377 | ```{r} 378 | knitr::include_graphics("03_WXN_matplotlib_files/03_WXN_matplotlib_27_0.png") 379 | ``` 380 | 381 | 382 | ### 折线图 383 | 384 | 385 | ```python 386 | x = [1, 2, 3, 4, 5, 6] 387 | y = [1, 4, 9, 16, 25, 36] 388 | 389 | plt.plot(x, # x轴数据 390 | y, # y轴数据 391 | linestyle='-', # 折线类型 392 | linewidth=2, # 折线宽度 393 | color='blue', # 折线颜色 394 | marker='o', # 点的形状 395 | markersize=8, # 点的大小 396 | markeredgecolor='black', # 点的边框色 397 | markerfacecolor='red') # 点的填充色 398 | 399 | 400 | # 添加标题和坐标轴标签 401 | plt.title('line plot') 402 | plt.xlabel('X') 403 | plt.ylabel('Y') 404 | 405 | plt.show() 406 | ``` 407 | 408 | 409 | ```{r} 410 | knitr::include_graphics("03_WXN_matplotlib_files/03_WXN_matplotlib_29_0.png") 411 | ``` 412 | 413 | 414 | 415 | ```python 416 | import numpy as np 417 | import matplotlib.pyplot as plt 418 | 419 | 420 | t = np.arange(0., 5., 0.2) 421 | 422 | t 423 | ``` 424 | 425 | 426 | 427 | 428 | array([ 0. , 0.2, 0.4, 0.6, 0.8, 1. , 1.2, 1.4, 1.6, 1.8, 2. , 429 | 2.2, 2.4, 2.6, 2.8, 3. , 3.2, 3.4, 3.6, 3.8, 4. , 4.2, 430 | 4.4, 4.6, 4.8]) 431 | 432 | 433 | 434 | 435 | ```python 436 | # red dashes, blue squares and green triangles 437 | plt.plot(t, t, 'r--', t, t**2, 'bs', t, t**3, 'g') 438 | plt.show() 439 | ``` 440 | 441 | 442 | ```{r} 443 | knitr::include_graphics("03_WXN_matplotlib_files/03_WXN_matplotlib_31_0.png") 444 | ``` 445 | 446 | 447 | 448 | ```python 449 | # 同一效果 450 | fig = plt.figure() 451 | ax = fig.add_subplot(1, 1, 1) 452 | ax.plot(t, t, 'r--') 453 | ax.plot(t, t**2, 'bs') # 'bs'表示blue square marker 454 | ax.plot(t, t**3, 'g') 455 | fig 456 | ``` 457 | 458 | 459 | 460 | 461 | ```{r} 462 | knitr::include_graphics("03_WXN_matplotlib_files/03_WXN_matplotlib_32_0.png") 463 | ``` 464 | 465 | 466 | 467 | ### 直方图 468 | 469 | 470 | ```python 471 | import numpy as np 472 | import pandas as pd 473 | import matplotlib.pyplot as plt 474 | 475 | plt.hist(np.random.randn(50), # 绘图数据 476 | bins=50, # 指定直方图的条形数 477 | color='red', # 指定填充色 478 | edgecolor='k') # 指定直方图的边界色k :black 479 | plt.show() 480 | ``` 481 | 482 | 483 | ```{r} 484 | knitr::include_graphics("03_WXN_matplotlib_files/03_WXN_matplotlib_34_0.png") 485 | ``` 486 | 487 | 488 | ### 直条图 489 | 490 | 491 | ```python 492 | x = [1, 2, 3, 4, 5, 6] 493 | y = [1, 4, 9, 16, 25, 36] 494 | 495 | plt.bar(x, y, 496 | color='steelblue', 497 | alpha=0.8) 498 | 499 | plt.title('bar plot') 500 | 501 | plt.ylim([0, 40]) 502 | plt.show() 503 | ``` 504 | 505 | 506 | ```{r} 507 | knitr::include_graphics("03_WXN_matplotlib_files/03_WXN_matplotlib_36_0.png") 508 | ``` 509 | 510 | 511 | 512 | ```python 513 | x = [1, 2, 3, 4, 5, 6] 514 | y = [1, 4, 9, 16, 25, 36] 515 | 516 | plt.barh(x, y, 517 | color='steelblue', 518 | alpha=0.8) 519 | 520 | plt.title('bar plot') 521 | 522 | plt.show() 523 | ``` 524 | 525 | 526 | ```{r} 527 | knitr::include_graphics("03_WXN_matplotlib_files/03_WXN_matplotlib_37_0.png") 528 | ``` 529 | 530 | 531 | ### 箱线图 532 | 533 | 534 | ```python 535 | x = [1, 2, 3, 4, 5, 6] 536 | plt.boxplot(x, 537 | patch_artist=True, # 箱体添加颜色 538 | labels=['boxplot'], # 添加具体的标签名称 539 | showmeans=True) 540 | 541 | # 显示图形 542 | plt.show() 543 | ``` 544 | 545 | 546 | ```{r} 547 | knitr::include_graphics("03_WXN_matplotlib_files/03_WXN_matplotlib_39_0.png") 548 | ``` 549 | 550 | 551 | 552 | ```python 553 | np.random.seed(2) # 设置随机种子 554 | df = pd.DataFrame(np.random.rand(5, 4), 555 | columns=(['A', 'B', 'C', 'D'])) 556 | df 557 | ``` 558 | 559 | 560 | 561 | 562 |
563 | 576 | 577 | 578 | 579 | 580 | 581 | 582 | 583 | 584 | 585 | 586 | 587 | 588 | 589 | 590 | 591 | 592 | 593 | 594 | 595 | 596 | 597 | 598 | 599 | 600 | 601 | 602 | 603 | 604 | 605 | 606 | 607 | 608 | 609 | 610 | 611 | 612 | 613 | 614 | 615 | 616 | 617 | 618 | 619 | 620 | 621 | 622 | 623 |
ABCD
00.4359950.0259260.5496620.435322
10.4203680.3303350.2046490.619271
20.2996550.2668270.6211340.529142
30.1345800.5135780.1844400.785335
40.8539750.4942370.8465610.079645
624 |
625 | 626 | 627 | 628 | 629 | ```python 630 | data = [] 631 | for i in range(4): 632 | data.append(df.iloc[:, i]) 633 | data 634 | ``` 635 | 636 | 637 | 638 | 639 | [0 0.435995 640 | 1 0.420368 641 | 2 0.299655 642 | 3 0.134580 643 | 4 0.853975 644 | Name: A, dtype: float64, 0 0.025926 645 | 1 0.330335 646 | 2 0.266827 647 | 3 0.513578 648 | 4 0.494237 649 | Name: B, dtype: float64, 0 0.549662 650 | 1 0.204649 651 | 2 0.621134 652 | 3 0.184440 653 | 4 0.846561 654 | Name: C, dtype: float64, 0 0.435322 655 | 1 0.619271 656 | 2 0.529142 657 | 3 0.785335 658 | 4 0.079645 659 | Name: D, dtype: float64] 660 | 661 | 662 | 663 | 664 | ```python 665 | plt.boxplot(data) 666 | plt.show() 667 | ``` 668 | 669 | 670 | ```{r} 671 | knitr::include_graphics("03_WXN_matplotlib_files/03_WXN_matplotlib_42_0.png") 672 | ``` 673 | 674 | 675 | ``` 676 | plt.boxplot(x, notch=None, sym=None, vert=None, 677 | whis=None, positions=None, widths=None, 678 | patch_artist=None, meanline=None, showmeans=None, 679 | showcaps=None, showbox=None, showfliers=None, 680 | boxprops=None, labels=None, flierprops=None, 681 | medianprops=None, meanprops=None, 682 | capprops=None, whiskerprops=None) 683 | 684 | x:指定要绘制箱线图的数据; 685 | notch:是否凹口的形式展现箱线图,默认非凹口; 686 | sym:指定异常点的形状,默认为+号显示; 687 | vert:是否需要将箱线图垂直摆放,默认垂直摆放; 688 | whis:指定上下须与上下四分位的距离,默认为1.5倍的四分位差; 689 | positions:指定箱线图的位置,默认为[0,1,2…]; 690 | widths:指定箱线图的宽度,默认为0.5; 691 | patch_artist:是否填充箱体的颜色; 692 | meanline:是否用线的形式表示均值,默认用点来表示; 693 | showmeans:是否显示均值,默认不显示; 694 | showcaps:是否显示箱线图顶端和末端的两条线,默认显示; 695 | showbox:是否显示箱线图的箱体,默认显示; 696 | showfliers:是否显示异常值,默认显示; 697 | boxprops:设置箱体的属性,如边框色,填充色等; 698 | labels:为箱线图添加标签,类似于图例的作用; 699 | filerprops:设置异常值的属性,如异常点的形状、大小、填充色等; 700 | medianprops:设置中位数的属性,如线的类型、粗细等; 701 | meanprops:设置均值的属性,如点的大小、颜色等; 702 | capprops:设置箱线图顶端和末端线条的属性,如颜色、粗细等; 703 | whiskerprops:设置须的属性,如颜色、粗细、线的类型等; 704 | ``` 705 | 706 | ### 饼图 707 | 708 | 709 | ```python 710 | data = [0.2, 0.3, 0.4, 0.1] 711 | plt.pie(data) 712 | plt.show() 713 | ``` 714 | 715 | 716 | ```{r} 717 | knitr::include_graphics("03_WXN_matplotlib_files/03_WXN_matplotlib_45_0.png") 718 | ``` 719 | 720 | 721 | ``` 722 | plt.pie(x, explode=None, labels=None, colors=None, 723 | autopct=None, pctdistance=0.6, shadow=False, 724 | labeldistance=1.1, startangle=None, 725 | radius=None, counterclock=True, wedgeprops=None, 726 | textprops=None, center=(0, 0), frame=False) 727 | 728 | x:指定绘图的数据; 729 | explode:指定饼图某些部分的突出显示,即呈现爆炸式; 730 | labels:为饼图添加标签说明,类似于图例说明; 731 | colors:指定饼图的填充色; 732 | autopct:自动添加百分比显示,可以采用格式化的方法显示; 733 | pctdistance:设置百分比标签与圆心的距离; 734 | shadow:是否添加饼图的阴影效果; 735 | labeldistance:设置各扇形标签(图例)与圆心的距离; 736 | startangle:设置饼图的初始摆放角度; 737 | radius:设置饼图的半径大小; 738 | counterclock:是否让饼图按逆时针顺序呈现; 739 | wedgeprops:设置饼图内外边界的属性,如边界线的粗细、颜色等; 740 | textprops:设置饼图中文本的属性,如字体大小、颜色等; 741 | center:指定饼图的中心点位置,默认为原点 742 | frame:是否要显示饼图背后的图框,如果设置为True的话,需要同时控制图框x轴、y轴的范围和饼图的中心位置; 743 | ``` 744 | 745 | ### 绘制基因矩阵的热图 746 | 747 | 748 | ```python 749 | # 来源于百度经验 750 | import numpy as np 751 | from matplotlib import pyplot as plt 752 | from matplotlib import cm 753 | from matplotlib import axes 754 | 755 | 756 | def draw_heatmap(data, xlabels, ylabels): # 自定义函数,3个参数 757 | cmap = cm.Blues 758 | figure = plt.figure(facecolor='w') 759 | ax = figure.add_subplot(1, 1, 1, position=[0.1, 0.15, 0.8, 0.8]) 760 | ax.set_yticks(range(len(ylabels))) 761 | ax.set_yticklabels(ylabels) 762 | ax.set_xticks(range(len(xlabels))) 763 | ax.set_xticklabels(xlabels) 764 | vmax = data[0][0] 765 | vmin = data[0][0] 766 | for i in data: 767 | for j in i: 768 | if j > vmax: 769 | vmax = j 770 | if j < vmin: 771 | vmin = j 772 | map = ax.imshow(data, interpolation='nearest', cmap=cmap, aspect='auto', 773 | vmin=vmin, vmax=vmax) # interpolation插值,cmap:colormap 774 | cb = plt.colorbar(mappable=map, cax=None, ax=None, shrink=0.5) # 绘制颜色条 775 | plt.show() 776 | 777 | 778 | a = np.random.rand(10, 10) 779 | xlabels = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J'] 780 | ylabels = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'] 781 | draw_heatmap(a, xlabels, ylabels) 782 | ``` 783 | 784 | 785 | ```{r} 786 | knitr::include_graphics("03_WXN_matplotlib_files/03_WXN_matplotlib_48_0.png") 787 | ``` 788 | 789 | 790 | 791 | ```python 792 | import pandas as pd 793 | import numpy as np 794 | df = pd.DataFrame(np.random.randn(5, 6)) 795 | df 796 | ``` 797 | 798 | 799 | 800 | 801 | 802 |
803 | 816 | 817 | 818 | 819 | 820 | 821 | 822 | 823 | 824 | 825 | 826 | 827 | 828 | 829 | 830 | 831 | 832 | 833 | 834 | 835 | 836 | 837 | 838 | 839 | 840 | 841 | 842 | 843 | 844 | 845 | 846 | 847 | 848 | 849 | 850 | 851 | 852 | 853 | 854 | 855 | 856 | 857 | 858 | 859 | 860 | 861 | 862 | 863 | 864 | 865 | 866 | 867 | 868 | 869 | 870 | 871 | 872 | 873 | 874 | 875 |
012345
0-0.5969670.080979-1.890122-0.629949-1.187113-0.002018
11.2640420.044216-1.6693420.805476-0.173634-0.051918
20.7936841.7469970.785712-0.1571260.0726880.310271
30.9887160.4044720.967111-0.612160-0.259917-0.067299
40.0339111.177149-0.914153-0.579912-0.1001100.747296
876 |
877 | 878 | 879 | 880 | 881 | 882 | ```python 883 | plt.imshow(df) 884 | 885 | plt.show() 886 | ``` 887 | 888 | 889 | ```{r} 890 | knitr::include_graphics("03_WXN_matplotlib_files/03_WXN_matplotlib_50_0.png") 891 | ``` 892 | 893 | 894 | 读入基因表达数据,绘制某基因的箱线图 895 | 896 | 897 | ```python 898 | %cd F: \mega\ehbio\python\python课程包\merge 899 | import os 900 | os.getcwd() 901 | ``` 902 | 903 | F:\mega\ehbio\python\python课程包\merge 904 | 905 | 906 | 907 | 908 | 909 | 'F:\\mega\\ehbio\\python\\python课程包\\merge' 910 | 911 | 912 | 913 | 914 | ```python 915 | import pandas as pd 916 | df = pd.read_table("ehbio.xls", sep="\t", index_col=0, header=0) 917 | df.head(5) 918 | ``` 919 | 920 | 921 | 922 | 923 | 924 |
925 | 938 | 939 | 940 | 941 | 942 | 943 | 944 | 945 | 946 | 947 | 948 | 949 | 950 | 951 | 952 | 953 | 954 | 955 | 956 | 957 | 958 | 959 | 960 | 961 | 962 | 963 | 964 | 965 | 966 | 967 | 968 | 969 | 970 | 971 | 972 | 973 | 974 | 975 | 976 | 977 | 978 | 979 | 980 | 981 | 982 | 983 | 984 | 985 | 986 | 987 | 988 | 989 | 990 | 991 | 992 | 993 | 994 | 995 | 996 | 997 | 998 | 999 | 1000 | 1001 | 1002 | 1003 | 1004 | 1005 | 1006 | 1007 | 1008 | 1009 | 1010 | 1011 | 1012 | 1013 | 1014 | 1015 | 1016 | 1017 | 1018 | 1019 | 1020 |
MCF10FMCF12AT47DKBlucUACC812UACC893ZR751ZR7530ZR75B
EnsEMBL_Gene_ID
ENSG0000000000391.57406113.04087073.38731026.57928050.67657931.812999121.4599182.293898
ENSG00000001167164.221408170.101403106.114416138.140311106.34203268.45802273.91096461.625519
ENSG000000054710.0000000.0736800.5362260.4406490.0662130.5488650.6110360.556531
ENSG0000006662924.63077318.62745934.61961379.1878790.05883525.49380025.91732332.528112
ENSG000001542580.8966120.2142610.0000000.0409070.0211200.0000000.0335710.177808
1021 |
1022 | 1023 | 1024 | 1025 | 1026 | 1027 | ```python 1028 | df.shape 1029 | ``` 1030 | 1031 | 1032 | 1033 | 1034 | (36953, 8) 1035 | 1036 | 1037 | 1038 | 1039 | ```python 1040 | df.size 1041 | df.ndim 1042 | df.values 1043 | ``` 1044 | 1045 | 1046 | 1047 | 1048 | array([[ 9.15740610e+01, 1.30408701e+01, 7.33873101e+01, ..., 1049 | 3.18129988e+01, 1.21459918e+02, 2.29389818e+00], 1050 | [ 1.64221408e+02, 1.70101403e+02, 1.06114416e+02, ..., 1051 | 6.84580224e+01, 7.39109636e+01, 6.16255191e+01], 1052 | [ 0.00000000e+00, 7.36800986e-02, 5.36226145e-01, ..., 1053 | 5.48864965e-01, 6.11036013e-01, 5.56531115e-01], 1054 | ..., 1055 | [ 2.71701826e+00, 5.55925621e+00, 2.93123839e+00, ..., 1056 | 3.71765369e+00, 2.42540639e+00, 4.56656068e+00], 1057 | [ 1.74266818e+01, 3.72964028e+00, 3.49013629e+01, ..., 1058 | 5.04982802e+01, 3.75784692e+01, 4.79996494e+01], 1059 | [ 0.00000000e+00, 0.00000000e+00, 3.52988338e+00, ..., 1060 | 8.15259649e+00, 6.08178979e-01, 3.25252710e+00]]) 1061 | 1062 | 1063 | 1064 | 1065 | ```python 1066 | control = [] 1067 | for i in range(3): 1068 | control.append(df.iloc[0, i]) 1069 | control 1070 | ``` 1071 | 1072 | 1073 | 1074 | 1075 | [91.574060981100004, 13.0408701074, 73.387310079800002] 1076 | 1077 | 1078 | 1079 | 1080 | ```python 1081 | test = [] 1082 | for i in range(3, 8): 1083 | test.append(df.iloc[0, i]) 1084 | test 1085 | ``` 1086 | 1087 | 1088 | 1089 | 1090 | [26.579280359299997, 1091 | 50.676578905299998, 1092 | 31.812998762600003, 1093 | 121.4599177489, 1094 | 2.2938981847999997] 1095 | 1096 | 1097 | 1098 | 1099 | ```python 1100 | gene = [control, test] 1101 | ``` 1102 | 1103 | 1104 | ```python 1105 | fig = plt.figure() 1106 | ax = fig.add_subplot(1, 1, 1) 1107 | ax.boxplot(gene, patch_artist=True, # 箱体添加颜色 1108 | labels=['test', 'control'], # 添加具体的标签名称 1109 | showmeans=True, ) 1110 | plt.show() 1111 | ``` 1112 | 1113 | 1114 | ```{r} 1115 | knitr::include_graphics("03_WXN_matplotlib_files/03_WXN_matplotlib_59_0.png") 1116 | ``` 1117 | 1118 | 1119 | 热图 1120 | 1121 | 1122 | ```python 1123 | df2 = df.head(10) # 取部分数据 1124 | ``` 1125 | 1126 | 1127 | ```python 1128 | df2 1129 | ``` 1130 | 1131 | 1132 | 1133 | 1134 | 1135 |
1136 | 1149 | 1150 | 1151 | 1152 | 1153 | 1154 | 1155 | 1156 | 1157 | 1158 | 1159 | 1160 | 1161 | 1162 | 1163 | 1164 | 1165 | 1166 | 1167 | 1168 | 1169 | 1170 | 1171 | 1172 | 1173 | 1174 | 1175 | 1176 | 1177 | 1178 | 1179 | 1180 | 1181 | 1182 | 1183 | 1184 | 1185 | 1186 | 1187 | 1188 | 1189 | 1190 | 1191 | 1192 | 1193 | 1194 | 1195 | 1196 | 1197 | 1198 | 1199 | 1200 | 1201 | 1202 | 1203 | 1204 | 1205 | 1206 | 1207 | 1208 | 1209 | 1210 | 1211 | 1212 | 1213 | 1214 | 1215 | 1216 | 1217 | 1218 | 1219 | 1220 | 1221 | 1222 | 1223 | 1224 | 1225 | 1226 | 1227 | 1228 | 1229 | 1230 | 1231 | 1232 | 1233 | 1234 | 1235 | 1236 | 1237 | 1238 | 1239 | 1240 | 1241 | 1242 | 1243 | 1244 | 1245 | 1246 | 1247 | 1248 | 1249 | 1250 | 1251 | 1252 | 1253 | 1254 | 1255 | 1256 | 1257 | 1258 | 1259 | 1260 | 1261 | 1262 | 1263 | 1264 | 1265 | 1266 | 1267 | 1268 | 1269 | 1270 | 1271 | 1272 | 1273 | 1274 | 1275 | 1276 | 1277 | 1278 | 1279 | 1280 | 1281 | 1282 | 1283 | 1284 | 1285 | 1286 |
MCF10FMCF12AT47DKBlucUACC812UACC893ZR751ZR7530ZR75B
EnsEMBL_Gene_ID
ENSG0000000000391.57406113.04087073.38731026.57928050.67657931.812999121.4599182.293898
ENSG00000001167164.221408170.101403106.114416138.140311106.34203268.45802273.91096461.625519
ENSG000000054710.0000000.0736800.5362260.4406490.0662130.5488650.6110360.556531
ENSG0000006662924.63077318.62745934.61961379.1878790.05883525.49380025.91732332.528112
ENSG000001542580.8966120.2142610.0000000.0409070.0211200.0000000.0335710.177808
ENSG000001542623.4313132.4816360.0000000.3830600.0000000.0000000.0000000.105758
ENSG000001542630.8590710.9360690.5895470.2598980.0832580.4767940.5261620.221172
ENSG000001542652.4539711.4805539.8844252.0767231.1188195.86426810.1807964.383174
ENSG000001542690.2167390.0000000.8541110.9700530.7388030.5210944.6484100.000000
ENSG000001542742.9807920.217999276.12367982.82044334.664053106.35060794.85406914.976808
1287 |
1288 | 1289 | 1290 | 1291 | 1292 | 1293 | ```python 1294 | i = plt.imshow(df2) 1295 | plt.colorbar(i) 1296 | plt.show() 1297 | ``` 1298 | 1299 | 1300 | ```{r} 1301 | knitr::include_graphics("03_WXN_matplotlib_files/03_WXN_matplotlib_63_0.png") 1302 | ``` 1303 | 1304 | 1305 | https://matplotlib.org/api/pyplot_api.html#所有函数的详细参数。 1306 | -------------------------------------------------------------------------------- /04_CT_Python_practice.Rmd: -------------------------------------------------------------------------------- 1 | # Python实战 {#Py3_pratcise_ct} 2 | 3 | 欢迎访问我们的视频课程 。 4 | 5 | ## Python实战 6 | 7 | ### ID转换 8 | 9 | 不同数据库的名字互相转换,比如NCBI的ENTEZ ID转Gene symbol,ENSEMBL编号转ENTREZ ID。 10 | 11 | ID转换一般需要2个文件,一个文件是要转换的ID,另外一个文件是ID的对应关系。 12 | 13 | 14 | 以我们的测试文件 (**GRCh38.idmap**)为例,第一列为`ENSEMBLE ID`,第二列为`Gene symbol`,第三列为`Entrez ID`。 15 | 16 | ``` 17 | Gene ID Associated Gene Name EntrezGene ID 18 | ENSG00000252303 RNU6-280P 19 | ENSG00000281771 Y_RNA 20 | ENSG00000281876 RP11-399E6.4 101929901 21 | ENSG00000281766 RYBP 23429 22 | ENSG00000281518 FOXO6 100132074 23 | ENSG00000281614 INPP5D 3635 24 | ENSG00000280584 OBP2B 29989 25 | ENSG00000281230 SERTAD4 56256 26 | ENSG00000281917 SLC16A1 6566 27 | ``` 28 | 29 | 待转换的文件 (**ensm.id**)内容为,期望转换为`Gene symbol`。 30 | 31 | ``` 32 | ENSG00000252303 33 | ENSG00000281771 34 | ENSG00000281256 35 | ENSG00000283272 36 | ENSG00000280864 37 | ENSG00000280792 38 | ENSG00000282878 39 | ENSG00000283276 40 | ENSG00000281822 41 | ENSG00000281384 42 | ENSG00000280505 43 | ENSG00000281764 44 | ENSG00000281316 45 | ENSG00000280963 46 | ENSG00000280775 47 | ENSG00000281876 48 | ENSG00000281766 49 | ENSG00000281518 50 | ENSG00000281614 51 | ENSG00000280584 52 | ENSG00000281230 53 | ENSG00000281917 54 | ``` 55 | 56 | 我们怎么做呢? 直观看起来也比较简单,一个个的去比较、匹配、提取就可以了。 57 | 58 | 59 | ```python 60 | idD = {} 61 | for line in open("data/GRCh38.idmap"): 62 | lineL = line.strip().split("\t") 63 | ensm_id = lineL[0] 64 | symbol = lineL[1] 65 | idD[ensm_id] = symbol 66 | #-------------------------------- 67 | for line in open("data/ensm.id"): 68 | ensm = line.strip() 69 | print(ensm,idD[ensm],sep=": ") 70 | ``` 71 | 72 | ENSG00000252303: RNU6-280P 73 | ENSG00000281771: Y_RNA 74 | ENSG00000281256: RP11-222G7.2 75 | ENSG00000283272: Clostridiales-1 76 | ENSG00000280864: RP11-654C22.2 77 | ENSG00000280792: RP11-315F22.1 78 | ENSG00000282878: RP11-399E6.1 79 | ENSG00000283276: ABBA01000934.1 80 | ENSG00000281822: RNU1-62P 81 | ENSG00000281384: AC093802.1 82 | ENSG00000280505: RP11-654C22.1 83 | ENSG00000281764: RP11-399E6.2 84 | ENSG00000281316: DPPA2P2 85 | ENSG00000280963: SERTAD4-AS1 86 | ENSG00000280775: RNA5SP136 87 | ENSG00000281876: RP11-399E6.4 88 | ENSG00000281766: RYBP 89 | ENSG00000281518: FOXO6 90 | ENSG00000281614: INPP5D 91 | ENSG00000280584: OBP2B 92 | ENSG00000281230: SERTAD4 93 | ENSG00000281917: SLC16A1 94 | 95 | 96 | 97 | ```python 98 | # 首先读入GRCh38.idmap文件 99 | 100 | # 定义3个变量,文件名,ensembl_id所在列(0-start, source_col), symbol所在列 (1,target_col) 101 | # 提前定义的好处是,修改起来会比较方便。 102 | map_file = "data/GRCh38.idmap" 103 | source_col = 0 104 | target_col = 1 105 | aDict = {} 106 | for line in open(map_file): 107 | lineL = line.strip().split("\t") 108 | source = lineL[source_col] 109 | target = lineL[target_col] 110 | aDict[source] = target 111 | 112 | # 读入ensm.id文件 113 | # 边读边处理 114 | 115 | id_file = "data/ensm.id" 116 | for line in open(id_file): 117 | source_id = line.strip() 118 | map_id = aDict.get(source_id, source_id) 119 | print(map_id) 120 | 121 | # 输出到文件 122 | 123 | with open("data/symbol.id","w") as fh: 124 | id_file = "data/ensm.id" 125 | for line in open(id_file): 126 | source_id = line.strip() 127 | map_id = aDict.get(source_id, source_id) 128 | print(map_id, file=fh) 129 | ``` 130 | 131 | RNU6-280P 132 | Y_RNA 133 | RP11-222G7.2 134 | Clostridiales-1 135 | RP11-654C22.2 136 | RP11-315F22.1 137 | RP11-399E6.1 138 | ABBA01000934.1 139 | RNU1-62P 140 | AC093802.1 141 | RP11-654C22.1 142 | RP11-399E6.2 143 | DPPA2P2 144 | SERTAD4-AS1 145 | RNA5SP136 146 | RP11-399E6.4 147 | RYBP 148 | FOXO6 149 | INPP5D 150 | OBP2B 151 | SERTAD4 152 | SLC16A1 153 | 154 | 155 | ### 每条染色体基因数目统计 156 | 157 | GTF文件存储基因的注释信息。 158 | 159 | 1. seqname - name of the chromosome or scaffold; chromosome names can be given with or without the 'chr' prefix. Important note: the seqname must be one used within Ensembl, i.e. a standard chromosome name or an Ensembl identifier such as a scaffold ID, without any additional content such as species or assembly. See the example GFF output below. 160 | 2. source - name of the program that generated this feature, or the data source (database or project name) 161 | 3. feature - feature type name, e.g. Gene, Variation, Similarity 162 | 4. start - Start position of the feature, with sequence numbering starting at 1. 163 | 5. end - End position of the feature, with sequence numbering starting at 1. 164 | 6. score - A floating point value. 165 | 7. strand - defined as + (forward) or - (reverse). 166 | 8. frame - One of '0', '1' or '2'. '0' indicates that the first base of the feature is the first base of a codon, '1' that the second base is the first base of a codon, and so on.. 167 | 9. attribute - A semicolon-separated list of tag-value pairs, providing additional information about each feature. 168 | 169 | ``` 170 | chr1 HAVANA gene 11869 14409 . + . gene_id "ENSG00000223972.5"; gene_type "transcribed_unprocessed_pseudogene"; gene_status "KNOWN"; gene_name "DDX11L1"; level 2; havana_gene "OTTHUMG00000000961.2"; 171 | chr1 HAVANA gene 14404 29570 . - . gene_id "ENSG00000227232.5"; gene_type "unprocessed_pseudogene"; gene_status "KNOWN"; gene_name "WASH7P"; level 2; havana_gene "OTTHUMG00000000958.1"; 172 | chr1 ENSEMBL gene 17369 17436 . - . gene_id "ENSG00000278267.1"; gene_type "miRNA"; gene_status "KNOWN"; gene_name "MIR6859-3"; level 3; 173 | ``` 174 | 175 | 如果统计每条染色体基因数目,只需要读第一列和第三列就可以了。 176 | 177 | 178 | ```python 179 | chr_gene_cntD = {} 180 | for line in open("data/gencode.gene.gtf"): 181 | lineL = line.strip().split("\t") 182 | chrName = lineL[0] 183 | regionType = lineL[2] 184 | if (regionType == "gene"): 185 | if chrName not in chr_gene_cntD: 186 | chr_gene_cntD[chrName] = 1 187 | else: 188 | chr_gene_cntD[chrName] += 1 189 | #--------------------------------- 190 | for chrName, cnt in list(chr_gene_cntD.items()): 191 | print(chrName,"has",cnt,'genes.') 192 | ``` 193 | 194 | chr1 has 5397 genes. 195 | chr2 has 4150 genes. 196 | chr3 has 3163 genes. 197 | chr4 has 2633 genes. 198 | chr5 has 2993 genes. 199 | chr6 has 3001 genes. 200 | chr7 has 2980 genes. 201 | chr8 has 2444 genes. 202 | chr9 has 2350 genes. 203 | chr10 has 2306 genes. 204 | chr11 has 3381 genes. 205 | chr12 has 3047 genes. 206 | chr13 has 1383 genes. 207 | chr14 has 2289 genes. 208 | chr15 has 2247 genes. 209 | chr16 has 2597 genes. 210 | chr17 has 3111 genes. 211 | chr18 has 1206 genes. 212 | chr19 has 2997 genes. 213 | chr20 has 1436 genes. 214 | chr21 has 880 genes. 215 | chr22 has 1385 genes. 216 | chrX has 2476 genes. 217 | chrY has 594 genes. 218 | chrM has 37 genes. 219 | 220 | 221 | 222 | ```python 223 | gtf_file = "data/gencode.gene.gtf" 224 | 225 | # 一般字典命名,会在行尾加一个大写的D,作为类型代表 226 | chr_gene_cntD = {} 227 | 228 | for line in open(gtf_file): 229 | # 每行按TAB键分成4份 230 | lineL = line.split('\t',3) 231 | chr_name = lineL[0] 232 | feature = lineL[2] 233 | if feature == "gene": 234 | # 如果chr_name已经出现过,则获取其值,然后加1 235 | # 若没出现过,获取0,加1,表示第一次出现 236 | chr_gene_cntD[chr_name] = chr_gene_cntD.get(chr_name,0) + 1 237 | #-------------------------------------- 238 | for chr_name, count in chr_gene_cntD.items(): 239 | print(chr_name, count) 240 | ``` 241 | 242 | chr1 5397 243 | chr2 4150 244 | chr3 3163 245 | chr4 2633 246 | chr5 2993 247 | chr6 3001 248 | chr7 2980 249 | chr8 2444 250 | chr9 2350 251 | chr10 2306 252 | chr11 3381 253 | chr12 3047 254 | chr13 1383 255 | chr14 2289 256 | chr15 2247 257 | chr16 2597 258 | chr17 3111 259 | chr18 1206 260 | chr19 2997 261 | chr20 1436 262 | chr21 880 263 | chr22 1385 264 | chrX 2476 265 | chrY 594 266 | chrM 37 267 | 268 | 269 | ### 所有外显子总长度统计 270 | 271 | bed12格式 (前3列必须,其它可选) 272 | 273 | 1. chrom - The name of the chromosome (e.g. chr3, chrY, chr2_random) or scaffold (e.g. scaffold10671). 274 | 2. chromStart - The starting position of the feature in the chromosome or scaffold. The first base in a chromosome is numbered 0. 275 | 3. chromEnd - The ending position of the feature in the chromosome or scaffold. The chromEnd base is not included in the display of the feature. 276 | 4. name - Defines the name of the BED line. This label is displayed to the left of the BED line in the Genome Browser window when the track is open to full display mode or directly to the left of the item in pack mode. 277 | 5. score - A score between 0 and 1000. If the track line useScore attribute is set to 1 for this annotation data set, the score value will determine the level of gray in which this feature is displayed (higher numbers = darker gray). This table shows the Genome Browser's translation of BED score values into shades of gray: 278 | 279 | 5. thickStart - The starting position at which the feature is drawn thickly (for example, the start codon in gene displays). When there is no thick part, thickStart and thickEnd are usually set to the chromStart position. 280 | 6. thickEnd - The ending position at which the feature is drawn thickly (for example the stop codon in gene displays). 281 | 7. itemRgb - An RGB value of the form R,G,B (e.g. 255,0,0). If the track line itemRgb attribute is set to "On", this RBG value will determine the display color of the data contained in this BED line. NOTE: It is recommended that a simple color scheme (eight colors or less) be used with this attribute to avoid overwhelming the color resources of the Genome Browser and your Internet browser. 282 | 8. blockCount - The number of blocks (exons) in the BED line. 283 | 9. blockSizes - A comma-separated list of the block sizes. The number of items in this list should correspond to blockCount. 284 | 10. blockStarts - A comma-separated list of block starts. All of the blockStart positions should be calculated relative to chromStart. The number of items in this list should correspond to blockCount. 285 | 286 | 基因注释bed12格式 287 | 288 | ``` 289 | chr1 11868 14409 ENST00000456328.2 0 + 14409 14409 0 3 359,109,1189, 0,744,1352, 290 | chr1 12009 13670 ENST00000450305.2 0 + 13670 13670 0 6 48,49,85,78,154,218, 0,169,603,965,1211,1443, 291 | chr1 17368 17436 ENST00000619216.1 0 - 17436 17436 0 1 68, 0, 292 | chr1 29553 31097 ENST00000473358.1 0 + 31097 31097 0 3 486,104,122, 0,1010,1422, 293 | chr1 30266 31109 ENST00000469289.1 0 + 31109 31109 0 2 401,134, 0,709, 294 | chr1 30365 30503 ENST00000607096.1 0 + 30503 30503 0 1 138, 0, 295 | ``` 296 | 297 | 第十列是外显子的大小,所有我们只需要把他们加在一起就好了。 298 | 299 | **Note**:实际计算时需要考虑不同转录本之间存在重叠,需要对bed文件预处理,只保留唯一的外显子位置,然后再加和。 300 | 301 | 302 | ```python 303 | exonSizeSum = 0 304 | for line in open("data/gencode.gene.bed12"): 305 | lineL = line.split() 306 | exonSize = lineL[10] 307 | exonSizeL = exonSize.strip(',').split(',') 308 | for i in exonSizeL: 309 | exonSizeSum += int(i) 310 | print(exonSizeSum) 311 | ``` 312 | 313 | 291762517 314 | 315 | 316 | 317 | ```python 318 | bed12 = "data/gencode.gene.bed12" 319 | 320 | total_exon_sum = 0 321 | 322 | for line in open(bed12): 323 | # 从右侧分割为3个元素的列表 324 | # 关注的元素在第二位,索引为1 325 | # 去掉末尾的逗号 326 | lineL = line.rsplit("\t",2) 327 | exonSize = lineL[1].strip(',') 328 | exonSizeL = [int(i) for i in exonSize.split(',')] 329 | exonSum = sum(exonSizeL) 330 | 331 | total_exon_sum += exonSum 332 | print("Total exon size is", total_exon_sum, "nt.") 333 | 334 | # 更清晰展示数字大小 335 | print("Total exon size is", "{:,}".format(total_exon_sum), "nt.") 336 | ``` 337 | 338 | Total exon size is 291762517 nt. 339 | Total exon size is 291,762,517 nt. 340 | 341 | 342 | 343 | ```python 344 | print("{a[a]}".format(a={'a':"ehbio"})) 345 | ``` 346 | 347 | ehbio 348 | 349 | 350 | ## Python小技巧 351 | 352 | 链似比较 353 | 354 | 355 | ```python 356 | x = 5 357 | print("1 < x < 10 is", 1 < x < 10) 358 | print("10 > x <= 9", 10 > x <= 9) 359 | ``` 360 | 361 | 1 < x < 10 is True 362 | 10 > x <= 9 True 363 | 364 | 365 | 解释正则表达式 366 | 367 | 368 | ```python 369 | import re 370 | re.compile("^[a-z]*$", re.DEBUG) 371 | ``` 372 | 373 | AT AT_BEGINNING 374 | MAX_REPEAT 0 MAXREPEAT 375 | IN 376 | RANGE (97, 122) 377 | AT AT_END 378 | 379 | 380 | 381 | 382 | 383 | re.compile(r'^[a-z]*$', re.UNICODE|re.DEBUG) 384 | 385 | 386 | 387 | 388 | ```python 389 | re.compile("^[a-z][0-9]+$", re.DEBUG) 390 | ``` 391 | 392 | AT AT_BEGINNING 393 | IN 394 | RANGE (97, 122) 395 | MAX_REPEAT 1 MAXREPEAT 396 | IN 397 | RANGE (48, 57) 398 | AT AT_END 399 | 400 | 401 | 402 | 403 | 404 | re.compile(r'^[a-z][0-9]+$', re.UNICODE|re.DEBUG) 405 | 406 | 407 | 408 | 409 | ```python 410 | re.compile("^[a-z]([0-9]+)$", re.DEBUG) 411 | ``` 412 | 413 | AT AT_BEGINNING 414 | IN 415 | RANGE (97, 122) 416 | SUBPATTERN 1 0 0 417 | MAX_REPEAT 1 MAXREPEAT 418 | IN 419 | RANGE (48, 57) 420 | AT AT_END 421 | 422 | 423 | 424 | 425 | 426 | re.compile(r'^[a-z]([0-9]+)$', re.UNICODE|re.DEBUG) 427 | 428 | 429 | 430 | enumerate (不再使用len) 431 | 432 | 433 | ```python 434 | a = ['s','x','b','d'] 435 | 436 | # Preferred way 437 | for index, item in enumerate(a): 438 | print(index,item) 439 | 440 | print("\n") 441 | 442 | # Old way 443 | for i in range(len(a)): 444 | print(i,a[i]) 445 | 446 | ``` 447 | 448 | 0 s 449 | 1 x 450 | 2 b 451 | 3 d 452 | 453 | 454 | 0 s 455 | 1 x 456 | 2 b 457 | 3 d 458 | 459 | 460 | 列表解析、字典解析、元组解析 461 | 462 | 463 | ```python 464 | # 获得系列坐标点 465 | a = ((i,j) for i in range(3) for j in range(2)) 466 | a 467 | ``` 468 | 469 | 470 | 471 | 472 | at 0x7fa8d04d7fc0> 473 | 474 | 475 | 476 | 477 | ```python 478 | for i in a: 479 | print(i) 480 | ``` 481 | 482 | (0, 0) 483 | (0, 1) 484 | (1, 0) 485 | (1, 1) 486 | (2, 0) 487 | (2, 1) 488 | 489 | 490 | 491 | ```python 492 | str1 = "I love sheng xin bao dian" 493 | print([i for i in str1.split() if i.endswith('n')]) 494 | ``` 495 | 496 | ['xin', 'dian'] 497 | 498 | 499 | 500 | ```python 501 | a = {i:i*2 for i in range(5)} 502 | a 503 | ``` 504 | 505 | 506 | 507 | 508 | {0: 0, 1: 2, 2: 4, 3: 6, 4: 8} 509 | 510 | 511 | 512 | 513 | ```python 514 | [(x, y) for x in range(4) if x % 2 == 1 for y in range(4)] 515 | ``` 516 | 517 | 518 | 519 | 520 | [(1, 0), (1, 1), (1, 2), (1, 3), (3, 0), (3, 1), (3, 2), (3, 3)] 521 | 522 | 523 | 524 | 列表索引,反序 525 | 526 | 527 | ```python 528 | a = [1,2,3,4,5] 529 | a[::2] 530 | ``` 531 | 532 | 533 | 534 | 535 | [1, 3, 5] 536 | 537 | 538 | 539 | 540 | ```python 541 | a[::-1] 542 | ``` 543 | 544 | 545 | 546 | 547 | [5, 4, 3, 2, 1] 548 | 549 | 550 | 551 | for..else;若`for`循环中未执行`break`,则`else`会被执行 552 | 553 | 554 | ```python 555 | found = False 556 | for i in range(2,5): 557 | if i == 1: 558 | found = True 559 | break 560 | if not found: 561 | print("i was never 1") 562 | ``` 563 | 564 | i was never 1 565 | 566 | 567 | 568 | ```python 569 | for i in range(2,5): 570 | if i == 1: 571 | break 572 | else: 573 | print("i was never 1") 574 | ``` 575 | 576 | i was never 1 577 | 578 | 579 | 原位替换 580 | 581 | 582 | ```python 583 | a = 5 584 | b = 6 585 | c = 7 586 | a, b = b,a 587 | print("a is",a) 588 | print("b is",b) 589 | ``` 590 | 591 | a is 6 592 | b is 5 593 | 594 | 595 | 596 | ```python 597 | a, (b,c) = c, (a,b) 598 | print("a is",a) 599 | print("b is",b) 600 | print("c is",c) 601 | ``` 602 | 603 | a is 7 604 | b is 6 605 | c is 5 606 | 607 | 608 | 609 | ```python 610 | first, *middle_all, last = (1,2,3,4,5,6) 611 | middle_all 612 | ``` 613 | 614 | 615 | 616 | 617 | [2, 3, 4, 5] 618 | 619 | 620 | 621 | 集合操作 622 | 623 | 624 | ```python 625 | a = set(["sheng", "xin", "bao","dian","best","tutotials"]) 626 | b = set(["hong", "ji", "yin","zu","best","tutotials"]) 627 | a | b # union 628 | ``` 629 | 630 | 631 | 632 | 633 | {'bao', 'best', 'dian', 'hong', 'ji', 'sheng', 'tutotials', 'xin', 'yin', 'zu'} 634 | 635 | 636 | 637 | 638 | ```python 639 | a & b # intersection 640 | ``` 641 | 642 | 643 | 644 | 645 | {'best', 'tutotials'} 646 | 647 | 648 | 649 | 650 | ```python 651 | a ^ b # Symmetric Difference 652 | ``` 653 | 654 | 655 | 656 | 657 | {'bao', 'dian', 'hong', 'ji', 'sheng', 'xin', 'yin', 'zu'} 658 | 659 | 660 | 661 | Negative round 662 | 663 | 664 | ```python 665 | print("round整数:",str(round(1234.5678, -2))) 666 | 667 | print("round小数:",str(round(1234.5678, 2))) 668 | ``` 669 | 670 | round整数: 1200.0 671 | round小数: 1234.57 672 | 673 | 674 | 多行字符串的嵌套 675 | 676 | 677 | ```python 678 | # \可以,但是第二行需要起头 679 | system_command = "s-plot pheatmap -f matrix \ 680 | -t heatmap -a TRUE" 681 | print(system_command) 682 | ``` 683 | 684 | s-plot pheatmap -f matrix -t heatmap -a TRUE 685 | 686 | 687 | 688 | ```python 689 | # 字符串中包含换行符 690 | # 切第二行要起头,不然会有较多空格 691 | system_command = """s-plot pheatmap -f matrix 692 | -t heatmap -a TRUE""" 693 | print(system_command) 694 | print(system_command.replace('\n', ' ')) 695 | ``` 696 | 697 | s-plot pheatmap -f matrix 698 | -t heatmap -a TRUE 699 | s-plot pheatmap -f matrix -t heatmap -a TRUE 700 | 701 | 702 | 703 | ```python 704 | # 类元组的写法,既可以跨行,又可以自由格式 705 | # 需要注意2点 706 | # 类元组,无逗号 707 | # 字符串连接时不会自动加空格,空格需要保存在字符串里面 708 | system_command = ("s-plot pheatmap -f matrix " 709 | "-t heatmap -a TRUE") 710 | print(system_command) 711 | ``` 712 | 713 | s-plot pheatmap -f matrix -t heatmap -a TRUE 714 | 715 | 716 | 717 | ```python 718 | # 多一步join; 719 | system_command = ["s-plot pheatmap -f matrix", 720 | "-t heatmap -a TRUE"] 721 | print(' '.join(system_command)) 722 | ``` 723 | 724 | s-plot pheatmap -f matrix -t heatmap -a TRUE 725 | 726 | 727 | 矩阵转置 728 | 729 | 730 | ```python 731 | a = [(1,2), (3,4), (5,6)] 732 | b = zip(*a) 733 | for i in b: 734 | print(i) 735 | ``` 736 | 737 | (1, 3, 5) 738 | (2, 4, 6) 739 | 740 | 741 | zip转换两个列表为字典 742 | 743 | 744 | ```python 745 | keyL = [1,2,3] 746 | valueL = ['a','b','v'] 747 | for i ,j in zip(keyL, valueL): 748 | print(i,j) 749 | ``` 750 | 751 | 1 a 752 | 2 b 753 | 3 v 754 | 755 | 756 | 757 | ```python 758 | import pprint 759 | pprint.pprint(dict(zip(keyL, valueL))) 760 | ``` 761 | 762 | {1: 'a', 2: 'b', 3: 'v'} 763 | 764 | 765 | 766 | ```python 767 | dict([(i,j) for i ,j in zip(keyL, valueL)]) 768 | ``` 769 | 770 | 771 | 772 | 773 | {1: 'a', 2: 'b', 3: 'v'} 774 | 775 | 776 | 777 | 重复 778 | 779 | 780 | ```python 781 | 'xyz' * 3 782 | ``` 783 | 784 | 785 | 786 | 787 | 'xyzxyzxyz' 788 | 789 | 790 | 791 | 792 | ```python 793 | 3 * 'xyz' 794 | ``` 795 | 796 | 797 | 798 | 799 | 'xyzxyzxyz' 800 | 801 | 802 | 803 | 804 | ```python 805 | [1,2] * 3 806 | ``` 807 | 808 | 809 | 810 | 811 | [1, 2, 1, 2, 1, 2] 812 | 813 | 814 | 815 | 启动网络服务器,用于文件预览或传输 816 | 817 | 818 | ```python 819 | # run in commang line 820 | # python -m http.server 8000 821 | Serving HTTP on 0.0.0.0 port 8000 (http://0.0.0.0:8000/) ... 822 | ``` 823 | 824 | sum的另一用法,二维数组秒变1维 825 | 826 | 827 | ```python 828 | aList = [[1, 2, 3], [4, 5], [6], [7, 8, 9]] 829 | sum(aList, []) 830 | ``` 831 | 832 | 833 | 834 | 835 | [1, 2, 3, 4, 5, 6, 7, 8, 9] 836 | 837 | 838 | 839 | 打开一个关于Python漫画的网站 840 | 841 | 842 | ```python 843 | #import antigravity 844 | ``` 845 | 846 | 847 | ```python 848 | print('\n'.join([''.join([('Love'[(x-y) % len('Love')] if ((x*0.05)**2+(y*0.1)**2-1)**3-(x*0.05)**2*(y*0.1)**3 <= 0 else ' ') for x in range(-30, 30)]) for y in range(30, -30, -1)])) 849 | ``` 850 | 851 | 852 | 853 | 854 | 855 | 856 | 857 | 858 | 859 | 860 | 861 | 862 | 863 | 864 | 865 | 866 | 867 | 868 | 869 | veLoveLov veLoveLov 870 | eLoveLoveLoveLove eLoveLoveLoveLove 871 | veLoveLoveLoveLoveLoveLoveLoveLoveLoveLov 872 | veLoveLoveLoveLoveLoveLoveLoveLoveLoveLoveL 873 | veLoveLoveLoveLoveLoveLoveLoveLoveLoveLoveLov 874 | eLoveLoveLoveLoveLoveLoveLoveLoveLoveLoveLove 875 | LoveLoveLoveLoveLoveLoveLoveLoveLoveLoveLoveL 876 | oveLoveLoveLoveLoveLoveLoveLoveLoveLoveLoveLo 877 | veLoveLoveLoveLoveLoveLoveLoveLoveLoveLoveLov 878 | eLoveLoveLoveLoveLoveLoveLoveLoveLoveLoveLove 879 | oveLoveLoveLoveLoveLoveLoveLoveLoveLoveLove 880 | eLoveLoveLoveLoveLoveLoveLoveLoveLoveLove 881 | LoveLoveLoveLoveLoveLoveLoveLoveLoveLoveL 882 | eLoveLoveLoveLoveLoveLoveLoveLoveLove 883 | oveLoveLoveLoveLoveLoveLoveLoveLove 884 | eLoveLoveLoveLoveLoveLoveLoveLove 885 | veLoveLoveLoveLoveLoveLoveLov 886 | oveLoveLoveLoveLoveLoveLo 887 | LoveLoveLoveLoveLoveL 888 | LoveLoveLoveLov 889 | LoveLoveL 890 | Lov 891 | v 892 | 893 | 894 | 895 | 896 | 897 | 898 | 899 | 900 | 901 | 902 | 903 | 904 | 905 | 906 | 907 | 908 | 909 | 910 | 911 | 912 | 913 | 曼德勃罗集合 914 | 915 | 916 | ```python 917 | print('\n'.join([''.join(['*'if abs((lambda a:lambda z,c,n:a(a,z,c,n))(lambda s,z,c,n:z if n==0else s(s,z*z+c,c,n-1))(0,0.02*x+0.05j*y,40))<2 else' 'for x in range(-80,20)])for y in range(-20,20)])) 918 | ``` 919 | 920 | * 921 | 922 | 923 | ** 924 | *********** 925 | ************ 926 | ********* 927 | * * ************ * * 928 | ****** * *************************** * 929 | *************************************** ***** 930 | ******************************************* 931 | *** ******************************************** * 932 | ************************************************** 933 | ******************************************************* 934 | * * ***************************************************** 935 | **** ******* * ******************************************************* 936 | ***************** ******************************************************* 937 | *********************** ********************************************************* 938 | *********************** ******************************************************** 939 | **** ******************************************************************************** 940 | ********************************************************************************************* 941 | **** ******************************************************************************** 942 | *********************** ******************************************************** 943 | *********************** ********************************************************* 944 | ***************** ******************************************************* 945 | **** ******* * ******************************************************* 946 | * * ***************************************************** 947 | ******************************************************* 948 | ************************************************** 949 | *** ******************************************** * 950 | ******************************************* 951 | *************************************** ***** 952 | ****** * *************************** * 953 | * * ************ * * 954 | ********* 955 | ************ 956 | *********** 957 | ** 958 | 959 | 960 | 961 | 962 | python打印九九乘法表 963 | 964 | 965 | ```python 966 | print('\n'.join([' '.join(['%s*%s=%-2s' % (y,x,x*y) for y in range(1,x+1)]) for x in range(1,10)])) 967 | ``` 968 | 969 | 1*1=1 970 | 1*2=2 2*2=4 971 | 1*3=3 2*3=6 3*3=9 972 | 1*4=4 2*4=8 3*4=12 4*4=16 973 | 1*5=5 2*5=10 3*5=15 4*5=20 5*5=25 974 | 1*6=6 2*6=12 3*6=18 4*6=24 5*6=30 6*6=36 975 | 1*7=7 2*7=14 3*7=21 4*7=28 5*7=35 6*7=42 7*7=49 976 | 1*8=8 2*8=16 3*8=24 4*8=32 5*8=40 6*8=48 7*8=56 8*8=64 977 | 1*9=9 2*9=18 3*9=27 4*9=36 5*9=45 6*9=54 7*9=63 8*9=72 9*9=81 978 | 979 | 980 | `map`, `filter` 981 | 982 | 983 | ```python 984 | # 过滤大于4的元素 985 | a = [3,4,5] 986 | [i for i in a if i<4] 987 | ``` 988 | 989 | 990 | 991 | 992 | [3] 993 | 994 | 995 | 996 | 997 | ```python 998 | list(filter(lambda x: x<4, a)) 999 | ``` 1000 | 1001 | 1002 | 1003 | 1004 | [5] 1005 | 1006 | 1007 | 1008 | 1009 | ```python 1010 | # 每个元素加2 1011 | [i+2 for i in a] 1012 | ``` 1013 | 1014 | 1015 | 1016 | 1017 | [5, 6, 7] 1018 | 1019 | 1020 | 1021 | 1022 | ```python 1023 | map(lambda x: x+2, a) 1024 | ``` 1025 | 1026 | 1027 | 1028 | 1029 | 1030 | 1031 | 1032 | 1033 | 1034 | ```python 1035 | list(map(lambda x: x+2, a)) 1036 | ``` 1037 | 1038 | 1039 | 1040 | 1041 | [5, 6, 7] 1042 | 1043 | 1044 | 1045 | 算2的1000次方的各位数之和 1046 | 1047 | 1048 | ```python 1049 | sum(map(int, str(2**1000))) 1050 | ``` 1051 | 1052 | 1053 | 1054 | 1055 | 1366 1056 | 1057 | 1058 | -------------------------------------------------------------------------------- /07_Python_pythonic_numpy_scipy.Rmd: -------------------------------------------------------------------------------- 1 | # Python科学计算 {#numpy_scipy} 2 | 3 | ## NumPy 4 | 5 | 6 | ### NumPy数组 7 | 8 | 9 | ```python 10 | import numpy as np 11 | import numpy.random as rand 12 | import matplotlib.pyplot as plt 13 | ``` 14 | 15 | 16 | ```python 17 | ## Numpy克服了Python中list速度慢的缺点,创建了新数据类型ndarray 18 | ## ndarray的每列元素一般是相同类型的,是浮点数、整型或字符串,这点和list不同 19 | ## 下面的例子测试对比了ndarray和list速度上的区别 20 | ## 首先建立一个0...10^7-1的10^7个元素的数组 21 | arr=np.arange(1e7) 22 | ## 将ndarray转换为list 23 | larr=arr.tolist() 24 | ## 工具函数,模拟ndarray把list的每个元素乘以一个标量的运算 25 | def list_times(alist, scalar): 26 | for i, val in enumerate(alist): 27 | alist[i]=val*scalar 28 | return alist 29 | ## 比较ndarray和list每个元素乘以一个标量的运行时间 30 | ## 在我的电脑上,ndarray乘以一个标量的运行时间要比list快约33倍 31 | %timeit arr*1.1 32 | %timeit list_times(larr,1.1) 33 | ``` 34 | 35 | 37 ms ± 1.49 ms per loop (mean ± std. dev. of 7 runs, 10 loops each) 36 | 1.22 s ± 41.4 ms per loop (mean ± std. dev. of 7 runs, 1 loop each) 37 | 38 | 39 | 40 | ```python 41 | ## 两个2维ndarray相乘是对应元素相乘,而两个matrix相乘是进行矩阵乘法 42 | ## matrix只有2维,以下代码运行会出错:shape too large to be a matrix 43 | arr=np.zeros((3,3,3)) 44 | mat=np.matrix(arr) 45 | ``` 46 | 47 | 48 | --------------------------------------------------------------------------- 49 | 50 | ValueError Traceback (most recent call last) 51 | 52 | in () 53 | 2 # matrix只有2维,以下代码运行会出错 54 | 3 arr=np.zeros((3,3,3)) 55 | ----> 4 mat=np.matrix(arr) 56 | 57 | 58 | ~/anaconda3/lib/python3.6/site-packages/numpy/matrixlib/defmatrix.py in __new__(subtype, data, dtype, copy) 59 | 224 else: 60 | 225 intype = N.dtype(dtype) 61 | --> 226 new = data.view(subtype) 62 | 227 if intype != data.dtype: 63 | 228 return new.astype(intype) 64 | 65 | 66 | ~/anaconda3/lib/python3.6/site-packages/numpy/matrixlib/defmatrix.py in __array_finalize__(self, obj) 67 | 269 return 68 | 270 elif (ndim > 2): 69 | --> 271 raise ValueError("shape too large to be a matrix.") 70 | 272 else: 71 | 273 newshape = self.shape 72 | 73 | 74 | ValueError: shape too large to be a matrix. 75 | 76 | 77 | #### 创建数组和定义数据类型 78 | 79 | 80 | ```python 81 | ## 在NumPy中,创建数组有多种方法 82 | ## 首先创建一个list,然后用np.array()方法把它包裹起来 83 | alist=[1,2,3] 84 | arr=np.array(alist) 85 | arr 86 | ``` 87 | 88 | 89 | 90 | 91 | array([1, 2, 3]) 92 | 93 | 94 | 95 | 96 | ```python 97 | ## 创建一个5个元素的全零数组 98 | arr=np.zeros(5) 99 | arr 100 | ``` 101 | 102 | 103 | 104 | 105 | array([ 0., 0., 0., 0., 0.]) 106 | 107 | 108 | 109 | 110 | ```python 111 | ## 创建一个从0到99的数组 112 | arr=np.arange(100) 113 | arr 114 | ``` 115 | 116 | 117 | 118 | 119 | array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 120 | 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 121 | 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 122 | 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 123 | 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 124 | 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99]) 125 | 126 | 127 | 128 | 129 | ```python 130 | ## 10到99的数组? 131 | arr=np.arange(10,100) 132 | arr 133 | ``` 134 | 135 | 136 | 137 | 138 | array([10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 139 | 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 140 | 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 141 | 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 142 | 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 143 | 95, 96, 97, 98, 99]) 144 | 145 | 146 | 147 | 148 | ```python 149 | ## 0到1,中间有100步,linear space 150 | arr=np.linspace(0,1,100) 151 | arr 152 | ``` 153 | 154 | 155 | 156 | 157 | array([ 0. , 0.01010101, 0.02020202, 0.03030303, 0.04040404, 158 | 0.05050505, 0.06060606, 0.07070707, 0.08080808, 0.09090909, 159 | 0.1010101 , 0.11111111, 0.12121212, 0.13131313, 0.14141414, 160 | 0.15151515, 0.16161616, 0.17171717, 0.18181818, 0.19191919, 161 | 0.2020202 , 0.21212121, 0.22222222, 0.23232323, 0.24242424, 162 | 0.25252525, 0.26262626, 0.27272727, 0.28282828, 0.29292929, 163 | 0.3030303 , 0.31313131, 0.32323232, 0.33333333, 0.34343434, 164 | 0.35353535, 0.36363636, 0.37373737, 0.38383838, 0.39393939, 165 | 0.4040404 , 0.41414141, 0.42424242, 0.43434343, 0.44444444, 166 | 0.45454545, 0.46464646, 0.47474747, 0.48484848, 0.49494949, 167 | 0.50505051, 0.51515152, 0.52525253, 0.53535354, 0.54545455, 168 | 0.55555556, 0.56565657, 0.57575758, 0.58585859, 0.5959596 , 169 | 0.60606061, 0.61616162, 0.62626263, 0.63636364, 0.64646465, 170 | 0.65656566, 0.66666667, 0.67676768, 0.68686869, 0.6969697 , 171 | 0.70707071, 0.71717172, 0.72727273, 0.73737374, 0.74747475, 172 | 0.75757576, 0.76767677, 0.77777778, 0.78787879, 0.7979798 , 173 | 0.80808081, 0.81818182, 0.82828283, 0.83838384, 0.84848485, 174 | 0.85858586, 0.86868687, 0.87878788, 0.88888889, 0.8989899 , 175 | 0.90909091, 0.91919192, 0.92929293, 0.93939394, 0.94949495, 176 | 0.95959596, 0.96969697, 0.97979798, 0.98989899, 1. ]) 177 | 178 | 179 | 180 | 181 | ```python 182 | ## log10空间里1到10的数组,中间有100步 183 | ## numpy.logspace(start, stop, num=50, endpoint=True, base=10.0, dtype=None) 184 | ## base**start是数组的第一个元素,base**stop是数组的最后一个元素 185 | arr=np.logspace(0,1,100,base=10.0) 186 | arr 187 | ``` 188 | 189 | 190 | 191 | 192 | array([ 1. , 1.02353102, 1.04761575, 1.07226722, 193 | 1.09749877, 1.12332403, 1.149757 , 1.17681195, 194 | 1.20450354, 1.23284674, 1.26185688, 1.29154967, 195 | 1.32194115, 1.35304777, 1.38488637, 1.41747416, 196 | 1.45082878, 1.48496826, 1.51991108, 1.55567614, 197 | 1.59228279, 1.62975083, 1.66810054, 1.70735265, 198 | 1.7475284 , 1.78864953, 1.83073828, 1.87381742, 199 | 1.91791026, 1.96304065, 2.009233 , 2.05651231, 200 | 2.10490414, 2.15443469, 2.20513074, 2.25701972, 201 | 2.3101297 , 2.36448941, 2.42012826, 2.47707636, 202 | 2.53536449, 2.59502421, 2.65608778, 2.71858824, 203 | 2.7825594 , 2.84803587, 2.91505306, 2.98364724, 204 | 3.05385551, 3.12571585, 3.19926714, 3.27454916, 205 | 3.35160265, 3.43046929, 3.51119173, 3.59381366, 206 | 3.67837977, 3.76493581, 3.85352859, 3.94420606, 207 | 4.03701726, 4.1320124 , 4.22924287, 4.32876128, 208 | 4.43062146, 4.53487851, 4.64158883, 4.75081016, 209 | 4.86260158, 4.97702356, 5.09413801, 5.21400829, 210 | 5.33669923, 5.46227722, 5.59081018, 5.72236766, 211 | 5.85702082, 5.9948425 , 6.13590727, 6.28029144, 212 | 6.42807312, 6.57933225, 6.73415066, 6.8926121 , 213 | 7.05480231, 7.22080902, 7.39072203, 7.56463328, 214 | 7.74263683, 7.92482898, 8.11130831, 8.30217568, 215 | 8.49753436, 8.69749003, 8.90215085, 9.11162756, 216 | 9.32603347, 9.54548457, 9.77009957, 10. ]) 217 | 218 | 219 | 220 | 221 | ```python 222 | ## 创建一个5*5的全零数组 223 | image=np.zeros((5,5)) 224 | image 225 | ``` 226 | 227 | 228 | 229 | 230 | array([[ 0., 0., 0., 0., 0.], 231 | [ 0., 0., 0., 0., 0.], 232 | [ 0., 0., 0., 0., 0.], 233 | [ 0., 0., 0., 0., 0.], 234 | [ 0., 0., 0., 0., 0.]]) 235 | 236 | 237 | 238 | 239 | ```python 240 | ## 创建一个5*5*5的全1的cube 241 | ## astype()方法将数组的元素全部设为整型 242 | cube=np.zeros((5,5,5)).astype(int)+1 243 | cube 244 | ``` 245 | 246 | 247 | 248 | 249 | array([[[1, 1, 1, 1, 1], 250 | [1, 1, 1, 1, 1], 251 | [1, 1, 1, 1, 1], 252 | [1, 1, 1, 1, 1], 253 | [1, 1, 1, 1, 1]], 254 | 255 | [[1, 1, 1, 1, 1], 256 | [1, 1, 1, 1, 1], 257 | [1, 1, 1, 1, 1], 258 | [1, 1, 1, 1, 1], 259 | [1, 1, 1, 1, 1]], 260 | 261 | [[1, 1, 1, 1, 1], 262 | [1, 1, 1, 1, 1], 263 | [1, 1, 1, 1, 1], 264 | [1, 1, 1, 1, 1], 265 | [1, 1, 1, 1, 1]], 266 | 267 | [[1, 1, 1, 1, 1], 268 | [1, 1, 1, 1, 1], 269 | [1, 1, 1, 1, 1], 270 | [1, 1, 1, 1, 1], 271 | [1, 1, 1, 1, 1]], 272 | 273 | [[1, 1, 1, 1, 1], 274 | [1, 1, 1, 1, 1], 275 | [1, 1, 1, 1, 1], 276 | [1, 1, 1, 1, 1], 277 | [1, 1, 1, 1, 1]]]) 278 | 279 | 280 | 281 | 282 | ```python 283 | ## 或者用更简单的方法创建全1数组,元素是16位浮点精度 284 | cube=np.ones((5,5,5)).astype(np.float16) 285 | cube 286 | ``` 287 | 288 | 289 | 290 | 291 | array([[[ 1., 1., 1., 1., 1.], 292 | [ 1., 1., 1., 1., 1.], 293 | [ 1., 1., 1., 1., 1.], 294 | [ 1., 1., 1., 1., 1.], 295 | [ 1., 1., 1., 1., 1.]], 296 | 297 | [[ 1., 1., 1., 1., 1.], 298 | [ 1., 1., 1., 1., 1.], 299 | [ 1., 1., 1., 1., 1.], 300 | [ 1., 1., 1., 1., 1.], 301 | [ 1., 1., 1., 1., 1.]], 302 | 303 | [[ 1., 1., 1., 1., 1.], 304 | [ 1., 1., 1., 1., 1.], 305 | [ 1., 1., 1., 1., 1.], 306 | [ 1., 1., 1., 1., 1.], 307 | [ 1., 1., 1., 1., 1.]], 308 | 309 | [[ 1., 1., 1., 1., 1.], 310 | [ 1., 1., 1., 1., 1.], 311 | [ 1., 1., 1., 1., 1.], 312 | [ 1., 1., 1., 1., 1.], 313 | [ 1., 1., 1., 1., 1.]], 314 | 315 | [[ 1., 1., 1., 1., 1.], 316 | [ 1., 1., 1., 1., 1.], 317 | [ 1., 1., 1., 1., 1.], 318 | [ 1., 1., 1., 1., 1.], 319 | [ 1., 1., 1., 1., 1.]]], dtype=float16) 320 | 321 | 322 | 323 | 324 | ```python 325 | ## NumPy在生成数组时,默认使用系统的字长来创建数组元素 326 | ## 在64位的Python环境中,数组元素默认为64位精度的浮点数 327 | ## 这种设定消耗大量内存,很多时候并非必要 328 | ## 在创建数组时,用户可以自己设定元素的精度,即把dtype参数设为int, numpy.float16, 329 | ## numpy.float32, numpy.float64 330 | 331 | ## 下面定义了一个全零的整型数组 332 | arr1=np.zeros(2,dtype=int) 333 | ## 下面定义了一个全零的浮点型数组 334 | arr2=np.zeros(2,dtype=np.float32) 335 | print(arr1) 336 | print(arr2) 337 | ``` 338 | 339 | [0 0] 340 | [ 0. 0.] 341 | 342 | 343 | 344 | ```python 345 | ## 数组变形 346 | ## 创建一个125个元素的数组 347 | arr1d=np.arange(125) 348 | ## 把数组变形为5*5*5的三维数组 349 | arr3d=arr1d.reshape((5,5,5)) 350 | ## 另一种效果相同的变形方法 351 | arr3d=np.reshape(arr1d,(5,5,5)) 352 | print(arr3d) 353 | ## 把高维数组变形为一维数组 354 | arr4d=np.zeros((10,10,10,10)) 355 | arr1d=arr4d.ravel() 356 | print(arr1d.shape) 357 | ## 值得注意的是,数组的变形只是改变观察数组的角度, 358 | ## 并没有新创建数组,变形后的数组和变形前的数组使用的是相同的内存空间 359 | ## 因此改动其中一个数组的元素,另一个数组的元素也会跟着改变 360 | ## 要创建内存中完全不同的数组,需要使用numpy.copy函数 361 | ``` 362 | 363 | [[[ 0 1 2 3 4] 364 | [ 5 6 7 8 9] 365 | [ 10 11 12 13 14] 366 | [ 15 16 17 18 19] 367 | [ 20 21 22 23 24]] 368 | 369 | [[ 25 26 27 28 29] 370 | [ 30 31 32 33 34] 371 | [ 35 36 37 38 39] 372 | [ 40 41 42 43 44] 373 | [ 45 46 47 48 49]] 374 | 375 | [[ 50 51 52 53 54] 376 | [ 55 56 57 58 59] 377 | [ 60 61 62 63 64] 378 | [ 65 66 67 68 69] 379 | [ 70 71 72 73 74]] 380 | 381 | [[ 75 76 77 78 79] 382 | [ 80 81 82 83 84] 383 | [ 85 86 87 88 89] 384 | [ 90 91 92 93 94] 385 | [ 95 96 97 98 99]] 386 | 387 | [[100 101 102 103 104] 388 | [105 106 107 108 109] 389 | [110 111 112 113 114] 390 | [115 116 117 118 119] 391 | [120 121 122 123 124]]] 392 | (10000,) 393 | 394 | 395 | #### 记录数组(Record Arrays) 396 | 397 | 398 | ```python 399 | ## 数组一般来说是只包含一种数据类型,不过有些时候数组可以用来存储更复杂的数据结构, 400 | ## 每列由不同的数据类型组成,叫做记录数组 401 | ## 创建一个全零数组,定义列的类型(i4:32位整数,f4:32位浮点数,a10:长度为10的字符串) 402 | recarr=np.zeros((2,),dtype=('i4,f4,a10')) 403 | ## 创建我们想放进recarr数组的列 404 | col1=np.arange(2)+1 # array([1,2]) 405 | col2=np.arange(2,dtype=np.float32) # array([0.,1.], dtype=float32) 406 | col3=["Hello","World"] 407 | ## 创建一个列表,整合上面3列 408 | toadd=list(zip(col1,col2,col3)) 409 | ## 给recarr赋值 410 | recarr[:]=toadd 411 | recarr 412 | ## 结果中字符串前的"b":python3.x里默认的str是(py2.x里的)unicode, 413 | ## bytes是(py2.x)的str, b”“前缀代表的就是bytes 414 | ``` 415 | 416 | 417 | 418 | 419 | array([(1, 0., b'Hello'), (2, 1., b'World')], 420 | dtype=[('f0', '2) 468 | print(index) 469 | ## 根据索引创建需要的数组 470 | new_arr1=arr[index] 471 | print(new_arr) 472 | ## 使用np.delete()删除特定的索引 473 | ## 删除index中包含的元素 474 | new_arr2=np.delete(arr,index) 475 | print(new_arr2) 476 | ## 用简单的布尔列表作为下标返回需要的数组 477 | ## 使用布尔索引获得需要的元素比np.where()要迅速,并且可以通过~index轻易地反转布尔数组 478 | index=arr>2 479 | print(index) 480 | new_arr=arr[index] 481 | print(new_arr) 482 | ``` 483 | 484 | (array([3, 4]),) 485 | [3 4] 486 | [0 1 2] 487 | [False False False True True] 488 | [3 4] 489 | 490 | 491 | ### 布尔语句和NumPy数组 492 | 493 | 494 | ```python 495 | ## 创建一个图片 496 | img1=np.zeros((20,20))+3 497 | img1[4:-4,4:-4]=6 498 | img1[7:-7,7:-7]=9 499 | ## 见Plot A 500 | 501 | ## compound_index变量存储所有大于2或小于6的下标 502 | index1=img1>2 503 | index2=img1<6 504 | compound_index=index1 & index2 505 | 506 | ## 复合索引的语句也可以写成这样: 507 | compound_index=(img1>3) & (img1<7) 508 | img2=np.copy(img1) 509 | img2[compound_index]=0 510 | ## 见Plot B 511 | 512 | ## 使用更复杂的布尔数组 513 | index3=img1==9 514 | index4=(index1 & index2) | index3 515 | img3=np.copy(img1) 516 | img3[index4]=0 517 | ## 见Plot C 518 | ``` 519 | 520 | 521 | ```python 522 | ## 仅变更数组中选中变量的值 523 | ## 依据标准正态分布(均值为0,方差为1)创建一个100个随机元素的数组 524 | a=rand.randn(100) 525 | print(a) 526 | ## 去掉不需要的元素 527 | index=a>0.2 528 | b=a[index] 529 | ## 在选出的元素上应用某些运算 530 | b=b**2-2 531 | ## 把修改过的元素仍然放回原来的数组,这样就完成了对数组中某些值得变更 532 | a[index]=b 533 | print(a) 534 | ``` 535 | 536 | [-1.80712517 -0.13170284 1.93343213 0.80721035 2.52144275 0.16195953 537 | 0.11878839 1.88961184 -0.75881407 -1.22866865 -0.73857745 0.64046896 538 | 0.73563193 0.71783485 -0.37645069 0.90120663 -0.59161068 -1.16366655 539 | -0.50663906 -0.36447979 -1.8654699 0.92406343 0.8004173 -1.41016169 540 | 0.32592465 0.725013 0.29738016 -2.21113871 -0.68122701 0.66455187 541 | -0.32413105 1.13627295 0.13185364 1.38536725 0.19462378 -1.80775106 542 | -0.06199759 -1.30422952 -0.30685345 0.08940313 -0.67023186 -0.15051653 543 | -0.15879759 1.35984567 -0.2328225 -1.7265208 0.67232358 -0.59098342 544 | -1.20227104 -1.08216219 -0.53158487 1.33859499 0.66763318 -0.56431746 545 | 0.75334062 1.44683156 1.9512399 0.42510796 0.34020597 0.72372802 546 | -0.10372294 0.184639 0.01761624 -0.69082466 0.36432908 -0.56651026 547 | 0.21865567 -0.42096267 -0.73512854 -0.05493638 -1.94869892 0.76399321 548 | 1.41936848 0.05750032 -0.12937963 -0.02329108 -1.47156894 -0.84254776 549 | 0.75245785 0.07682322 0.96333808 0.92090036 0.76489123 0.63520238 550 | -0.08737849 -1.2083732 0.21328152 0.92891946 0.26792553 0.0672728 551 | -1.74821241 0.69335543 -0.60076278 -0.11200103 -1.4392716 -0.35400569 552 | -0.05871362 0.8178716 1.08160928 0.77033013] 553 | [-1.80712517 -0.13170284 1.73815979 -1.34841145 4.35767354 0.16195953 554 | 0.11878839 1.57063289 -0.75881407 -1.22866865 -0.73857745 -1.58979952 555 | -1.45884566 -1.48471313 -0.37645069 -1.1878266 -0.59161068 -1.16366655 556 | -0.50663906 -0.36447979 -1.8654699 -1.14610677 -1.35933214 -1.41016169 557 | -1.89377312 -1.47435616 -1.91156504 -2.21113871 -0.68122701 -1.55837081 558 | -0.32413105 -0.70888379 0.13185364 -0.08075759 0.19462378 -1.80775106 559 | -0.06199759 -1.30422952 -0.30685345 0.08940313 -0.67023186 -0.15051653 560 | -0.15879759 -0.15081976 -0.2328225 -1.7265208 -1.547981 -0.59098342 561 | -1.20227104 -1.08216219 -0.53158487 -0.20816344 -1.55426593 -0.56431746 562 | -1.43247792 0.09332155 1.80733714 -1.81928322 -1.8842599 -1.47621775 563 | -0.10372294 0.184639 0.01761624 -0.69082466 -1.86726432 -0.56651026 564 | -1.9521897 -0.42096267 -0.73512854 -0.05493638 -1.94869892 -1.41631438 565 | 0.01460689 0.05750032 -0.12937963 -0.02329108 -1.47156894 -0.84254776 566 | -1.43380718 0.07682322 -1.07197974 -1.15194253 -1.4149414 -1.59651793 567 | -0.08737849 -1.2083732 -1.95451099 -1.13710863 -1.92821591 0.0672728 568 | -1.74821241 -1.51925824 -0.60076278 -0.11200103 -1.4392716 -0.35400569 569 | -0.05871362 -1.33108605 -0.83012136 -1.40659148] 570 | 571 | 572 | ### NumPy读写文件 573 | 574 | 575 | ```python 576 | ## NumPy读文本文件中的矩阵 577 | arr=np.loadtxt("data5/somefile.txt") 578 | arr 579 | ``` 580 | 581 | 582 | 583 | 584 | array([[ 2., 3., 5.], 585 | [ 7., 11., 13.], 586 | [ 17., 19., 23.]]) 587 | 588 | 589 | 590 | 591 | ```python 592 | ## NumPy写矩阵到文本文件中 593 | ## numpy.savetxt(fname, X, fmt='%.18e', delimiter=' ', newline='\n', 594 | ## header='', footer='', comments='# ', encoding=None)[source] 595 | np.savetxt("data5/somenewfile.txt",arr,"%d","\t") 596 | ``` 597 | 598 | 599 | ```python 600 | ## loadtxt()读取文件中复杂的数据结构 601 | recarr=np.loadtxt("data5/example.txt", dtype={ 602 | "names":("Gene_ID","Sample1","Sample2","Sample3"), 603 | "formats":("S6","f4","f4","f4")}) 604 | recarr 605 | ``` 606 | 607 | 608 | 609 | 610 | array([(b'Gene1', 2.29999995, 5.69999981, 11.13000011), 611 | (b'Gene2', 17.19000053, 23.29000092, 31.37000084)], 612 | dtype=[('Gene_ID', 'S6'), ('Sample1', '。 4 | 5 | 1. `3*2**2`的输出是多少?(1分) 6 | 2. `8 % 4`的输出是多少?(1分) 7 | 3. `32 + '32'`的输出是什么?(1分) 8 | 4. `32 > '32'`的输出是什么?(1分) 9 | 5. `'Sheng Xin Bao Dian'.find('x')`和`'Sheng Xin Bao Dian'.find('X')`的输出分别是?(2分) 10 | 6. 一句话计算`'Sheng Xin Bao Dian'`字符串中`n`的数目?(1分) 11 | 7. 写出下面10段程序的输出?(1分/段) 12 | 13 | ``` 14 | aList = [1, 2, 3] 15 | bList = aList 16 | bList.append(4) 17 | aList 18 | ``` 19 | 20 | ``` 21 | aList = [1, 2, 3] 22 | cList = aList[:] 23 | cList.append(4) 24 | aList 25 | ``` 26 | 27 | ``` 28 | aList = [1,1,2,2,3,5,4,3] 29 | aSet = set(aList) 30 | aSet 31 | ``` 32 | 33 | ``` 34 | [1, 2, 3] * 2 35 | ``` 36 | 37 | ``` 38 | [i**2 for i in [1,2,3]] 39 | ``` 40 | 41 | ``` 42 | dict([(i, i**2) for i in range(5)]) 43 | ``` 44 | 45 | ``` 46 | import re 47 | re.findall("[Ii]mageGP", "www.ehbio.com/ImageGP") 48 | ``` 49 | 50 | ``` 51 | ' '.join(["Sheng", "Xin", "Bao", "Dian"]) 52 | ``` 53 | 54 | ``` 55 | def sumNumber(a, b): 56 | return a + b 57 | sumNumber(2,3) 58 | ``` 59 | 60 | ``` 61 | def sumNumber(a, b): 62 | return a + b 63 | print(sumNumber(2,3)) 64 | ``` 65 | 66 | 10. 写程序以下面列表中每个元素为`key`,元素出现的次数为`value`,构建一个字典,并遍历字典按元素的ASCII码顺序输出?(5分) 67 | 68 | ``` 69 | aList = ['a', 'b', 'c', 'a', 'd','e', 'A'] 70 | ``` 71 | 72 | 11. 对教案中脑筋急转弯问题的解法进行优化; 问题是:`现有100元钱,需要买100个物品,其中铅笔盒单价5元,笔单价3元,橡皮单价0.5元,怎么组合可以把100元花完,同时三种物品的个数和为100,请用编程解决。` (3分) 73 | 12. 写程序用高斯的计算方式计算`1+2+3+...+100`的加和。(3分) 74 | 13. 指出下面每个程序运行时可能会出现的错误。(1分/段) 75 | 76 | ``` 77 | aList = [1,2,3] 78 | aDict = {} 79 | aDict[aList] = 1 80 | b = aDict['a'] 81 | ``` 82 | 83 | ``` 84 | if 1: 85 | print("Sheng xin bao dian great!") 86 | ``` 87 | 88 | ``` 89 | 32 + '32' 90 | ``` 91 | 92 | ``` 93 | aList = [1, 2, 3] 94 | aList.add(4) 95 | ``` 96 | 97 | ``` 98 | aList = [1, 2, 3] 99 | ''.join(aList) 100 | ``` 101 | 102 | ``` 103 | int('a') 104 | ``` 105 | 106 | ``` 107 | 3 / 0 108 | ``` 109 | 110 | ``` 111 | for i in range(10) 112 | print(L) 113 | ``` 114 | 115 | ``` 116 | 'Sheng Xin * 3 117 | ``` 118 | 119 | ``` 120 | type = 1 121 | ``` 122 | 123 | 14. Python文件读写函数`open`的`mode`参数中`r`, `w`, `a`, `t`, `b`, `x`分别是什么意思?(3分) 124 | 15. Python中如何获取当前所在的工作目录? 如何修改工作目录?(3分) 125 | 16. Python中连接多个字符串的方法有哪些?优缺点是什么?(3分) 126 | 17. `print("%.2f%%" % (1/3))`的输出是什么?(2分) 127 | 18. 描述下语句`import pandas as pd`做了什么操作?(2分) 128 | 20. 教案中IDmap程序用pandas实现 (`GRCh38.idmap`,`ensm.id`)。(5分) 129 | 21. Jupyter中`%%writefile`, `%%run` 宏命令的用途是什么?(2分) 130 | 22. 找出教案中TP53 mRNA序列中的ORF (`human_TP53_mRNA.fa`)。(5分) 131 | 23. 列出教案中大肠杆菌基因组中限制性内切酶SecI的切割位置 (`Ecoli.fa`)。(5分) 132 | 24. 计算`data/test1.fa`中每条序列的GC含量。(5分) 133 | 25. 不使用pandas,写Python脚本处理Pandas教案中的TPM表达矩阵的提取和合并?(ENCFF060LPA.tsv, ENCFF262OBL.tsv, ENCFF289HGQ.tsv, ENCFF673KYR.tsv) (8分) 134 | 1. 给定FASTA格式的文件(test1.fa 和 test2.fa),写一个程序 `cat.py` 读入文件,并输出到屏幕 (2分) 135 | * 用到的知识点 136 | * open(file) 137 | * for .. in loop 138 | * print() 139 | * strip() function 140 | 2. 给定FASTQ格式的文件(test1.fq), 写一个程序 `cat.py` 读入文件,并输出到屏幕 (2分) 141 | * 用到的知识点 142 | * 同上 143 | 3. 写程序 `splitName.py`, 读入test2.fa, 并取原始序列名字第一个空格前的名字为处理后的序列名字,输出到屏幕 (2分) 144 | * 用到的知识点 145 | * split 146 | * 字符串的索引 147 | * 输出格式为: 148 | ``` 149 | >NM_001011874 150 | gcggcggcgggcgagcgggcgctggagtaggagctg....... 151 | ``` 152 | 153 | 4. 写程序 `formatFasta.py`, 读入test2.fa,把每条FASTA序列连成一行然后输出 (2分) 154 | * 用到的知识点 155 | * join 156 | * strip 157 | * 输出格式为: 158 | ``` 159 | >NM_001011874 160 | gcggcggcgggc......TCCGCTG......GCGTTCACC......CGGGGTCCGGAG 161 | ``` 162 | 4. 写程序 `formatFasta-2.py`, 读入test2.fa,把每条FASTA序列分割成80个字母一行的序列 (2分) 163 | * 用到的知识点 164 | * 字符串切片操作 165 | * range 166 | * 输出格式为 167 | ``` 168 | >NM_001011874 169 | gcggcggcgc.(60个字母).TCCGCTGACG #(每行80个字母) 170 | acgtgctacg.(60个字母).GCGTTCACCC 171 | ACGTACGATG(最后一行可不足80个字母) 172 | ``` 173 | 4. 写程序 `sortFasta.py`, 读入test2.fa, 并取原始序列名字第一个空格前的名字为处理后的序列名字,排序后输出 (2分) 174 | * 用到的知识点 175 | * sort 176 | * dict 177 | * aDict[key] = [] 178 | * aDict[key].append(value) 179 | 180 | 5. 提取给定名字的序列 (2分) 181 | * 写程序 `grepFasta.py`, 提取fasta.name中名字对应的test2.fa的序列,并输出到屏幕。 182 | * 写程序 `grepFastq.py`, 提取fastq.name中名字对应的test1.fq的序列,并输出到文件。 183 | * 用到的知识点 184 | * print >>fh, or fh.write() 185 | * 取模运算,4 % 2 == 0 186 | 187 | 6. 写程序 `screenResult.py`, 筛选test.expr中foldChange大于2的基因并且padj小于0.05的基,可以输出整行或只输出基因名字。(4分) 188 | * 用到的知识点 189 | * 逻辑与操作符 and 190 | * 文件中读取的内容都为字符串,需要用int转换为整数,float转换为浮点数 191 | 192 | 6. 写程序 `transferMultipleColumToMatrix.py` 将文件(multipleColExpr.txt)中基因在多个组织中的表达数据转换为矩阵形式,并绘制热图。(6分) 193 | * 用到的知识点 194 | * aDict['key'] = {} 195 | * aDict['key']['key2'] = value 196 | * if key not in aDict 197 | * aDict = {'ENSG00000000003': {"A-431": 21.3, "A-549", 32.5,...},"ENSG00000000003":{},} 198 | * 输入格式(只需要前3列就可以) 199 | ``` 200 | Gene Sample Value Unit Abundance 201 | ENSG00000000003 A-431 21.3 FPKM Medium 202 | ENSG00000000003 A-549 32.5 FPKM Medium 203 | ENSG00000000003 AN3-CA 38.2 FPKM Medium 204 | ENSG00000000003 BEWO 31.4 FPKM Medium 205 | ENSG00000000003 CACO-2 63.9 FPKM High 206 | ENSG00000000005 A-431 0.0 FPKM Not detected 207 | ENSG00000000005 A-549 0.0 FPKM Not detected 208 | ENSG00000000005 AN3-CA 0.0 FPKM Not detected 209 | ENSG00000000005 BEWO 0.0 FPKM Not detected 210 | ENSG00000000005 CACO-2 0.0 FPKM Not detected 211 | ``` 212 | * 输出格式 213 | ``` 214 | Name A-431 A-549 AN3-CA BEWO CACO-2 215 | ENSG00000000460 25.2 14.2 10.6 24.4 14.2 216 | ENSG00000000938 0.0 0.0 0.0 0.0 0.0 217 | ENSG00000001084 19.1 155.1 24.4 12.6 23.5 218 | ENSG00000000457 2.8 3.4 3.8 5.8 2.9 219 | ``` 220 | 221 | 6. 写程序 `reverseComplementary.py`计算序列 `ACGTACGTACGTCACGTCAGCTAGAC`的反向互补序列。(2分) 222 | * 用到的知识点 223 | * reverse 224 | * list(seq) 225 | 7. 写程序 `collapsemiRNAreads.py`转换smRNA-Seq的测序数据。(5分) 226 | * 输入文件格式(mir.collapse, tab-分割的两列文件,第一列为序列,第二列为序列被测到的次数) 227 | ``` 228 | ID_REF VALUE 229 | ACTGCCCTAAGTGCTCCTTCTGGC 2 230 | ATAAGGTGCATCTAGTGCAGATA 25 231 | TGAGGTAGTAGTTTGTGCTGTTT 100 232 | TCCTACGAGTTGCATGGATTC 4 233 | ``` 234 | * 输出文件格式 (mir.collapse.fa, 名字的前3个字母为样品的特异标示,中间的数字表示第几条序列,是序列名字的唯一标示,第三部分是x加每个reads被测到的次数。三部分用下划线连起来作为fasta序列的名字。) 235 | ``` 236 | >ESB_1_x2 237 | ACTGCCCTAAGTGCTCCTTCTGGC 238 | >ESB_2_x25 239 | ATAAGGTGCATCTAGTGCAGATA 240 | >ESB_3_x100 241 | TGAGGTAGTAGTTTGTGCTGTTT 242 | >ESB_4_x4 243 | TCCTACGAGTTGCATGGATTC 244 | ``` 245 | 8. 简化的短序列匹配程序 (map.py) 把short.fa中的序列比对到ref.fa, 输出短序列匹配到ref.fa文件中哪些序列的哪些位置。(10分) 246 | * 用到的知识点 247 | * find 248 | * 输出格式 (输出格式为bed格式,第一列为匹配到的染色体,第二列和第三列为匹配到染色体序列的起始终止位置(位置标记以0为起始,代表第一个位置;终止位置不包含在内,第一个例子中所示序列的位置是(199,208](前闭后开,实际是chr1染色体第199-206的序列,0起始). 第4列为短序列自身的序列.)。 249 | * 附加要求:可以只匹配到给定的模板链,也可以考虑匹配到模板链的互补链。这时第5列可以为短序列的名字,第六列为链的信息,匹配到模板链为'+',匹配到互补链为'-'。注意匹配到互补链时起始位置也是从模板链的5'端算起的。 250 | ``` 251 | chr1 199 208 TGGCGTTCA 252 | chr1 207 216 ACCCCGCTG 253 | chr2 63 70 AAATTGC 254 | chr3 0 7 AATAAAT 255 | ``` 256 | 257 | 10. 备注: 258 | * 每个提到提到的“用到的知识点”为相对于前面的题目新增的知识点,请综合考虑。此外,对于不同的思路并不是所有提到的知识点都会用着,而且也可能会用到未提到的知识点。但是所有知识点都在前面的讲义部分有介绍。 259 | * 每个程序对于你身边会写的人来说都很简单,因此你一定要克制住,独立去把答案做出,多看错误提示,多比对程序输出结果和预期结果的差异。 260 | * 学习锻炼“读程序”,即对着文件模拟整个的读入、处理过程来发现可能的逻辑问题。 261 | * 程序运行没有错误不代表你写的程序完成了你的需求,你要去查验输出结果是不是你想要的。 262 | 11. 关于程序调试 263 | * 在初写程序时,可能会出现各种各样的错误,常见的有缩进不一致,变量名字拼写错误,丢失冒号,文件名未加引号等,这时要根据错误提示查看错误类型是什么,出错的是哪一行来定位错误。当然,有的时候报错的行自身不一定有错,可能是其前面或后面的行出现了错误。 264 | * **用脑袋运行程序**:当程序写作完成后,自己尝试对着数据文件,一行一行的执行程序,来看程序的运行是否与自己想干的活一致,有没有纰漏。 265 | * 当结果不符合预期时,要学会**使用print来查看每步的操作是否正确**,比如我读入了字典,我就打印下字典,看看读入的是不是我想要的,是否含有不该存在的字符;或者**在每个判断句、函数调入的情况下打印个字符,来跟踪程序的运行轨迹** 266 | 267 | 12. 如果视频或文档中没有答案的或者有错误的,请提交题目和自己的答案到 http://www.ehbio.com/Esx 提问寻求解答。 268 | 269 | 270 | ```python 271 | import re 272 | re.findall("[Ii]mageGP", "www.ehbio.com/ImageGP") 273 | ``` 274 | 275 | 276 | 277 | 278 | ['ImageGP'] 279 | 280 | 281 | 282 | 283 | ```python 284 | ' '.join(["Sheng", "Xin", "Bao", "Dian"]) 285 | ``` 286 | 287 | 288 | 289 | 290 | 'Sheng Xin Bao Dian' 291 | 292 | 293 | 294 | 295 | ```python 296 | # 写程序以下面列表中每个元素为key,元素出现的次数为value, 297 | # 构建一个字典,并遍历字典按元素的ASCII码顺序输出? 298 | aList = ['a', 'b', 'c', 'a', 'd','e', 'A'] 299 | aDict = {} 300 | uniqList = list(set(aList)) 301 | aDict = dict([(i,aList.count(i)) for i in uniqList]) 302 | uniqList.sort() 303 | 304 | for key in uniqList: 305 | print(key, aDict[key], sep="-->") 306 | #for item in uniqList: 307 | # aDict[item] = aDict.get(item,0) + 1 308 | ``` 309 | 310 | A-->1 311 | a-->2 312 | b-->1 313 | c-->1 314 | d-->1 315 | e-->1 316 | 317 | 318 | 319 | ```python 320 | # 写程序以下面列表中每个元素为key,元素出现的次数为value, 321 | # 构建一个字典,并遍历字典按元素的ASCII码顺序输出? 322 | aList = ['a', 'b', 'c', 'a', 'd','e', 'A'] 323 | aDict = {} 324 | for item in aList: 325 | aDict[item] = aDict.get(item,0) + 1 326 | 327 | keyL = list(aDict.keys()) 328 | keyL.sort() 329 | 330 | for key in keyL: 331 | print(key, aDict[key], sep="\t") 332 | ``` 333 | 334 | A 1 335 | a 2 336 | b 1 337 | c 1 338 | d 1 339 | e 1 340 | 341 | 342 | 343 | ```python 344 | aList = ['a', 'b', 'c', 'a', 'd', 'e', 'A'] 345 | aDict = {} 346 | for i in aList: 347 | aDict.setdefault(i, 0) 348 | aDict[i] += 1 349 | print(aDict) 350 | ``` 351 | 352 | {'a': 2, 'b': 1, 'c': 1, 'd': 1, 'e': 1, 'A': 1} 353 | 354 | 355 | 356 | ```python 357 | aDict = {} 358 | aList = ['a', 'b', 'c', 'a', 'd','e', 'A'] 359 | #uniL = list(set(aList)) 360 | for i in aList: 361 | aDict[i] = aDict.get(i,0)+1 362 | #aDict += 1 363 | #break 364 | print(aDict) 365 | 366 | ``` 367 | 368 | {'a': 2, 'b': 1, 'c': 1, 'd': 1, 'e': 1, 'A': 1} 369 | 370 | 371 | 372 | ```python 373 | aList = ['a', 'b', 'c', 'a', 'd','e', 'A'] 374 | aSet = set(aList) 375 | aSet 376 | for i in aSet: 377 | print (i,aList.count(i)) 378 | ``` 379 | 380 | a 2 381 | d 1 382 | A 1 383 | b 1 384 | e 1 385 | c 1 386 | 387 | 388 | 389 | ```python 390 | list = ['a', 'b', 'c', 'a', 'd','e', 'A'] 391 | dic = {} 392 | for i in list: 393 | dic[i] = list.count(i) 394 | print(dic) 395 | ``` 396 | 397 | 398 | ```python 399 | #写程序用高斯的计算方式计算1+2+3+...+100的加和 400 | n = 100 401 | (1+n) * (n/2) 402 | ``` 403 | 404 | 405 | 406 | 407 | 5050.0 408 | 409 | 410 | 411 | 412 | ```python 413 | n = 99 414 | (1+n) * (n/2) 415 | ``` 416 | 417 | 418 | 419 | 420 | 4950.0 421 | 422 | 423 | 424 | 425 | ```python 426 | import pandas as pd 427 | idmap = pd.read_table("data/GRCh38.idmap", 428 | header=0, index_col=0) 429 | ensmL = [line.strip() for line in open("data/ensm.id")] 430 | idmap = idmap[idmap.index.isin(ensmL)] 431 | idmap["Associated Gene Name"] 432 | ``` 433 | 434 | 435 | 436 | 437 | Gene ID 438 | ENSG00000252303 RNU6-280P 439 | ENSG00000281771 Y_RNA 440 | ENSG00000281256 RP11-222G7.2 441 | ENSG00000283272 Clostridiales-1 442 | ENSG00000280864 RP11-654C22.2 443 | ENSG00000280792 RP11-315F22.1 444 | ENSG00000282878 RP11-399E6.1 445 | ENSG00000283276 ABBA01000934.1 446 | ENSG00000281822 RNU1-62P 447 | ENSG00000281384 AC093802.1 448 | ENSG00000280505 RP11-654C22.1 449 | ENSG00000281764 RP11-399E6.2 450 | ENSG00000281316 DPPA2P2 451 | ENSG00000280963 SERTAD4-AS1 452 | ENSG00000280775 RNA5SP136 453 | ENSG00000281876 RP11-399E6.4 454 | ENSG00000281766 RYBP 455 | ENSG00000281518 FOXO6 456 | ENSG00000281614 INPP5D 457 | ENSG00000280584 OBP2B 458 | ENSG00000281230 SERTAD4 459 | ENSG00000281917 SLC16A1 460 | Name: Associated Gene Name, dtype: object 461 | 462 | 463 | 464 | 465 | ```python 466 | mRNA = [] 467 | for line in open("data/human_TP53_mRNA.fa"): 468 | if line[0] == ">": 469 | continue 470 | else: 471 | mRNA.append(line.strip()) 472 | #-------------------------------- 473 | mRNA = ''.join(mRNA) 474 | orf = re.compile("(A[TU]G(...){99,}?([TU]AA|[TU]AG|[TU]GA))") 475 | for i in orf.findall(mRNA): 476 | print(i[0]) 477 | 478 | ``` 479 | 480 | ATGGGATTGGGGTTTTCCCCTCCCATGTGCTCAAGACTGGCGCTAAAAGTTTTGAGCTTCTCAAAAGTCTAGAGCCACCGTCCAGGGAGCAGGTAGCTGCTGGGCTCCGGGGACACTTTGCGTTCGGGCTGGGAGCGTGCTTTCCACGACGGTGACACGCTTCCCTGGATTGGCAGCCAGACTGCCTTCCGGGTCACTGCCATGGAGGAGCCGCAGTCAGATCCTAGCGTCGAGCCCCCTCTGAGTCAGGAAACATTTTCAGACCTATGGAAACTACTTCCTGAAAACAACGTTCTGTCCCCCTTGCCGTCCCAAGCAATGGATGATTTGATGCTGTCCCCGGACGATATTGAACAATGGTTCACTGAAGACCCAGGTCCAGATGAAGCTCCCAGAATGCCAGAGGCTGCTCCCCCCGTGGCCCCTGCACCAGCAGCTCCTACACCGGCGGCCCCTGCACCAGCCCCCTCCTGGCCCCTGTCATCTTCTGTCCCTTCCCAGAAAACCTACCAGGGCAGCTACGGTTTCCGTCTGGGCTTCTTGCATTCTGGGACAGCCAAGTCTGTGACTTGCACGTACTCCCCTGCCCTCAACAAGATGTTTTGCCAACTGGCCAAGACCTGCCCTGTGCAGCTGTGGGTTGATTCCACACCCCCGCCCGGCACCCGCGTCCGCGCCATGGCCATCTACAAGCAGTCACAGCACATGACGGAGGTTGTGAGGCGCTGCCCCCACCATGAGCGCTGCTCAGATAGCGATGGTCTGGCCCCTCCTCAGCATCTTATCCGAGTGGAAGGAAATTTGCGTGTGGAGTATTTGGATGACAGAAACACTTTTCGACATAGTGTGGTGGTGCCCTATGAGCCGCCTGAGGTTGGCTCTGACTGTACCACCATCCACTACAACTACATGTGTAACAGTTCCTGCATGGGCGGCATGAACCGGAGGCCCATCCTCACCATCATCACACTGGAAGACTCCAGTGGTAATCTACTGGGACGGAACAGCTTTGAGGTGCGTGTTTGTGCCTGTCCTGGGAGAGACCGGCGCACAGAGGAAGAGAATCTCCGCAAGAAAGGGGAGCCTCACCACGAGCTGCCCCCAGGGAGCACTAAGCGAGCACTGCCCAACAACACCAGCTCCTCTCCCCAGCCAAAGAAGAAACCACTGGATGGAGAATATTTCACCCTTCAGATCCGTGGGCGTGAGCGCTTCGAGATGTTCCGAGAGCTGAATGAGGCCTTGGAACTCAAGGATGCCCAGGCTGGGAAGGAGCCAGGGGGGAGCAGGGCTCACTCCAGCCACCTGAAGTCCAAAAAGGGTCAGTCTACCTCCCGCCATAAAAAACTCATGTTCAAGACAGAAGGGCCTGACTCAGACTGA 481 | ATGGGGAGTAGGACATACCAGCTTAGATTTTAAGGTTTTTACTGTGAGGGATGTTTGGGAGATGTAAGAAATGTTCTTGCAGTTAAGGGTTAGTTTACAATCAGCCACATTCTAGGTAGGGGCCCACTTCACCGTACTAACCAGGGAAGCTGTCCCTCACTGTTGAATTTTCTCTAACTTCAAGGCCCATATCTGTGAAATGCTGGCATTTGCACCTACCTCACAGAGTGCATTGTGAGGGTTAATGAAATAATGTACATCTGGCCTTGAAACCACCTTTTATTACATGGGGTCTAGAACTTGACCCCCTTGAGGGTGCTTGTTCCCTCTCCCTGTTGGTCGGTGGGTTGGTAG 482 | ATGATGATCTGGATCCACCAAGACTTGTTTTATGCTCAGGGTCAATTTCTTTTTTCTTTTTTTTTTTTTTTTTTCTTTTTCTTTGAGACTGGGTCTCGCTTTGTTGCCCAGGCTGGAGTGGAGTGGCGTGATCTTGGCTTACTGCAGCCTTTGCCTCCCCGGCTCGAGCAGTCCTGCCTCAGCCTCCGGAGTAGCTGGGACCACAGGTTCATGCCACCATGGCCAGCCAACTTTTGCATGTTTTGTAGAGATGGGGTCTCACAGTGTTGCCCAGGCTGGTCTCAAACTCCTGGGCTCAGGCGATCCACCTGTCTCAGCCTCCCAGAGTGCTGGGATTACAATTGTGAGCCACCACGTCCAGCTGGAAGGGTCAACATCTTTTACATTCTGCAAGCACATCTGCATTTTCACCCCACCCTTCCCCTCCTTCTCCCTTTTTATATCCCATTTTTATATCGATCTCTTATTTTACAATAA 483 | 484 | 485 | 486 | ```python 487 | #SecI识别CCNNGG 488 | ecoli = [] 489 | for line in open("data/Ecoli.fa"): 490 | if line[0] != '>': 491 | ecoli.append(line.strip()) 492 | #print(line.strip()) 493 | #--------------- 494 | ecoli = ''.join(ecoli) 495 | 496 | secI = re.compile("CC..GG") 497 | for i in secI.finditer(ecoli): 498 | print(i.start()) 499 | ``` 500 | 501 | 174 502 | 299 503 | 556 504 | 505 | 506 | 507 | ```python 508 | lineL = [] 509 | for line in open("data/Ecoli.fa"): 510 | line = line.strip() 511 | if line[0] == ">": 512 | continue 513 | else: 514 | lineL.append(line) 515 | #--------------------------- 516 | seq = ''.join(lineL) 517 | 518 | seci = re.compile("CC[ATGC]GG") 519 | print(seci) 520 | ``` 521 | 522 | re.compile('CC[ATGC]GG') 523 | 524 | 525 | 526 | ```python 527 | help(re.finditer) 528 | ``` 529 | 530 | Help on function finditer in module re: 531 | 532 | finditer(pattern, string, flags=0) 533 | Return an iterator over all non-overlapping matches in the 534 | string. For each match, the iterator returns a match object. 535 | 536 | Empty matches are included in the result. 537 | 538 | 539 | 540 | 541 | ```python 542 | gc_cnt = 0 543 | seqLen = 0 544 | for line in open("data/test1.fa"): 545 | if line[0] == '>': 546 | if seqLen: 547 | gc_percent = gc_cnt / seqLen * 100 548 | print(key, round(gc_percent,2),"%") 549 | gc_cnt = seqLen = 0 550 | key = line.split()[0][1:] 551 | else: 552 | line = line.strip().upper() 553 | gc_cnt += line.count('C') + line.count('G') 554 | seqLen += len(line) 555 | #------------------------------- 556 | if seqLen: 557 | gc_percent = gc_cnt / seqLen * 100 558 | print(key, round(gc_percent,2),"%") 559 | ``` 560 | 561 | NM_001011874 81.43 % 562 | NM_001195662 42.86 % 563 | NM_0112835 37.14 % 564 | NM_011283 37.14 % 565 | 566 | 567 | 568 | ```python 569 | for line in open("data/test1.fa"): 570 | if line[0] == ">": 571 | continue 572 | else: 573 | line = line.strip().upper() 574 | gc_cnt = line.count("G") + line.count("C") 575 | total_len = len(line) 576 | gc_per = gc_cnt / total_len * 100 577 | print(round(gc_per,2)) 578 | ``` 579 | 580 | 81.43 581 | 42.86 582 | 37.14 583 | 37.14 584 | 585 | 586 | 587 | ```python 588 | count = 5 589 | for line in open("data/ENCFF060LPA.tsv"): 590 | if count == 0: 591 | break 592 | print(line) 593 | count -= 1 594 | ``` 595 | 596 | gene_id transcript_id(s) length effective_length expected_count TPM FPKM 597 | 598 | ENSG00000000003.14 ENST00000373020.8,ENST00000494424.1,ENST00000496771.5,ENST00000612152.4,ENST00000614008.4 2240.53 2020.49 5126.00 6.64 18.24 599 | 600 | ENSG00000000005.5 ENST00000373031.4,ENST00000485971.1 940.50 720.47 0.00 0.00 0.00 601 | 602 | ENSG00000000419.12 ENST00000371582.8,ENST00000371584.8,ENST00000371588.9,ENST00000413082.1,ENST00000466152.5,ENST00000494752.1 1072.03 851.99 3222.00 9.91 27.19 603 | 604 | ENSG00000000457.13 ENST00000367770.5,ENST00000367771.10,ENST00000367772.8,ENST00000423670.1,ENST00000470238.1 3527.59 3307.55 1092.00 0.86 2.37 605 | 606 | 607 | 608 | 609 | ```python 610 | fileL = ["data/ENCFF060LPA.tsv", "data/ENCFF262OBL.tsv", 611 | "data/ENCFF289HGQ.tsv", "data/ENCFF673KYR.tsv"] 612 | ''' 613 | aDict = { 614 | 'ENCFF060LPA': {'a': 5, 'b': 3}, 615 | 'ENCFF289HGQ': {'a': 3, 'c': 5}, 616 | } 617 | 618 | aDict = { 619 | 'a': {'ENCFF060LPA': 5, 'ENCFF289HGQ':3}, 620 | 'b': {'ENCFF060LPA': 3}, 621 | 'c': {'ENCFF289HGQ': 5} 622 | } 623 | ''' 624 | aDict = {} 625 | labelL = [] 626 | 627 | for file_name in fileL: 628 | label = file_name.replace('data/','') 629 | label = label.replace('.tsv','') 630 | labelL.append(label) 631 | #print(label) 632 | header = 1 633 | count = 3 634 | #print(label) 635 | for line in open(file_name): 636 | if header == 1: 637 | header -= 1 638 | continue 639 | #-------------------- 640 | lineL = line.strip().split('\t') 641 | gene = lineL[0] 642 | FPKM = lineL[-1] 643 | aDict.setdefault(gene, {}) 644 | aDict[gene][label] = FPKM 645 | #if count: 646 | # print("\t",aDict) 647 | # count -= 1 648 | #-------------------------------------- 649 | print("GeneName", '\t'.join(labelL), sep="\t") 650 | 651 | count = 5 652 | for gene,exprD in list(aDict.items()): 653 | exprL = [exprD.get(label, '0') for label in labelL] 654 | exprL = [gene] + exprL 655 | #if count: 656 | print('\t'.join(exprL)) 657 | # count -= 1 658 | ``` 659 | 660 | GeneName ENCFF060LPA ENCFF262OBL ENCFF289HGQ ENCFF673KYR 661 | ENSG00000000003.14 18.24 26.74 10.84 15.07 662 | ENSG00000000005.5 0.00 0.00 0.00 0.00 663 | ENSG00000000419.12 27.19 29.44 15.23 11.17 664 | ENSG00000000457.13 2.37 3.87 2.53 2.37 665 | ENSG00000000460.16 4.14 8.37 2.70 0.98 666 | 667 | 668 | 669 | ```python 670 | for line in open("data/test2.fa"): 671 | if line[0] == '>': 672 | ``` 673 | 674 | >NM_001011874 gene=Xkr4 CDS=151-2091 675 | gcggcggcgggcgagcgggcgctggagtaggagctggggagcggcgcggccggggaaggaagccagggcg 676 | aggcgaggaggtggcgggaggaggagacagcagggacaggTGTCAGATAAAGGAGTGCTCTCCTCCGCTG 677 | CCGAGGCATCATGGCCGCTAAGTCAGACGGGAGGCTGAAGATGAAGAAGAGCAGCGACGTGGCGTTCACC 678 | CCGCTGCAGAACTCGGACAATTCGGGCTCTGTGCAAGGACTGGCTCCAGGCTTGCCGTCGGGGTCCGGAG 679 | >NM_001195662 gene=Rp1 CDS=55-909 680 | AAGCTCAGCCTTTGCTCAGATTCTCCTCTTGATGAAACAAAGGGATTTCTGCACATGCTTGAGAAATTGC 681 | AGGTCTCACCCAAAATGAGTGACACACCTTCTACTAGTTTCTCCATGATTCATCTGACTTCTGAAGGTCA 682 | AGTTCCTTCCCCTCGCCATTCAAATATCACTCATCCTGTAGTGGCTAAACGCATCAGTTTCTATAAGAGT 683 | GGAGACCCACAGTTTGGCGGCGTTCGGGTGGTGGTCAACCCTCGTTCCTTTAAGACTTTTGACGCTCTGC 684 | TGGACAGTTTATCCAGGAAGGTACCCCTGCCCTTTGGGGTAAGGAACATCAGCACGCCCCGTGGACGACA 685 | CAGCATCACCAGGCTGGAGGAGCTAGAGGACGGCAAGTCTTATGTGTGCTCCCACAATAAGAAGGTGCTG 686 | >NM_011283 gene=Rp1 CDS=128-6412 687 | AATAAATCCAAAGACATTTGTTTACGTGAAACAAGCAGGTTGCATATCCAGTGACGTTTATACAGACCAC 688 | ACAAACTATTTACTCTTTTCTTCGTAAGGAAAGGTTCAACTTCTGGTCTCACCCAAAATGAGTGACACAC 689 | CTTCTACTAGTTTCTCCATGATTCATCTGACTTCTGAAGGTCAAGTTCCTTCCCCTCGCCATTCAAATAT 690 | CACTCATCCTGTAGTGGCTAAACGCATCAGTTTCTATAAGAGTGGAGACCCACAGTTTGGCGGCGTTCGG 691 | GTGGTGGTCAACCCTCGTTCCTTTAAGACTTTTGACGCTCTGCTGGACAGTTTATCCAGGAAGGTACCCC 692 | TGCCCTTTGGGGTAAGGAACATCAGCACGCCCCGTGGACGACACAGCATCACCAGGCTGGAGGAGCTAGA 693 | GGACGGCAAGTCTTATGTGTGCTCCCACAATAAGAAGGTGCTGCCAGTTGACCTGGACAAGGCCCGCAGG 694 | CGCCCTCGGCCCTGGCTGAGTAGTCGCTCCATAAGCACGCATGTGCAGCTCTGTCCTGCAACTGCCAATA 695 | TGTCCACCATGGCACCTGGCATGCTCCGTGCCCCAAGGAGGCTCGTGGTCTTCCGGAATGGTGACCCGAA 696 | >NM_0112835 gene=Rp1 CDS=128-6412 697 | AATAAATCCAAAGACATTTGTTTACGTGAAACAAGCAGGTTGCATATCCAGTGACGTTTATACAGACCAC 698 | ACAAACTATTTACTCTTTTCTTCGTAAGGAAAGGTTCAACTTCTGGTCTCACCCAAAATGAGTGACACAC 699 | CTTCTACTAGTTTCTCCATGATTCATCTGACTTCTGAAGGTCAAGTTCCTTCCCCTCGCCATTCAAATAT 700 | CACTCATCCTGTAGTGGCTAAACGCATCAGTTTCTATAAGAGTGGAGACCCACAGTTTGGCGGCGTTCGG 701 | GTGGTGGTCAACCCTCGTTCCTTTAAGACTTTTGACGCTCTGCTGGACAGTTTATCCAGGAAGGTACCCC 702 | TGCCCTTTGGGGTAAGGAACATCAGCACGCCCCGTGGACGACACAGCATCACCAGGCTGGAGGAGCTAGA 703 | GGACGGCAAGTCTTATGTGTGCTCCCACAATAAGAAGGTGCTGCCAGTTGACCTGGACAAGGCCCGCAGG 704 | CGCCCTCGGCCCTGGCTGAGTAGTCGCTCCATAAGCACGCATGTGCAGCTCTGTCCTGCAACTGCCAATA 705 | TGTCCACCATGGCACCTGGCATGCTCCGTGCCCCAAGGAGGCTCGTGGTCTTCCGGAATGGTGACCCGAA 706 | 707 | -------------------------------------------------------------------------------- /09-2-company.Rmd: -------------------------------------------------------------------------------- 1 | # 公司简介 {#company_intro} 2 | 3 | ```{r company-html, eval=html, out.width="99%"} 4 | knitr::include_graphics(c("ehbio/company_1.png", "ehbio/company_2.png")) 5 | ``` 6 | 7 | ```{r company-pdf, eval=latex, out.width="99%", out.height='0.99\\textheight', out.extra='keepaspectratio'} 8 | knitr::include_graphics(c("ehbio/company_1.png", "ehbio/company_2.png")) 9 | ``` 10 | 11 | -------------------------------------------------------------------------------- /Py3_course.Rproj: -------------------------------------------------------------------------------- 1 | 2 | Version: 1.0 3 | 4 | RestoreWorkspace: Default 5 | SaveWorkspace: Default 6 | AlwaysSaveHistory: Default 7 | 8 | EnableCodeIndexing: Yes 9 | UseSpacesForTab: Yes 10 | NumSpacesForTab: 2 11 | Encoding: UTF-8 12 | 13 | RnwWeave: Sweave 14 | LaTeX: pdfLaTeX 15 | 16 | BuildType: Website 17 | 18 | -------------------------------------------------------------------------------- /Py3_course/.history: -------------------------------------------------------------------------------- 1 | [/MPATHB/training/python_course/Py3_course] 53263 [2018-05-09 19:39:39][ct][218.241.208.209]cd Py3_course; python -m SimpleHTTPServer 11521 2 | [/MPATHB/training/python_course/Py3_course] 53268 [2018-05-09 20:18:21][ct][218.241.208.209]cd Py3_course; python -m SimpleHTTPServer 11521 3 | [/MPATHB/training/python_course/Py3_course] 53327 [2018-05-09 22:44:54][ct][211.144.7.44]cd /MPATHB/training/python_course/Py3_course 4 | [/MPATHB/training/python_course/Py3_course] 53328 [2018-05-09 22:44:55][ct][211.144.7.44]ltr 5 | [/MPATHB/training/python_course/Py3_course] 53329 [2018-05-09 22:47:07][ct][211.144.7.44]python -m simpleHTTPserver 11521 6 | [/MPATHB/training/python_course/Py3_course] 53330 [2018-05-09 22:47:11][ct][211.144.7.44]python -m simpleHTTPServer 11521 7 | [/MPATHB/training/python_course/Py3_course] 53327 [2018-05-09 22:49:14][ct][211.144.7.44]cd /MPATHB/training/python_course/Py3_course 8 | [/MPATHB/training/python_course/Py3_course] 53328 [2018-05-09 22:49:15][ct][211.144.7.44]ltr 9 | [/MPATHB/training/python_course/Py3_course] 53327 [2018-05-09 22:49:32][ct][211.144.7.44]cd /MPATHB/training/python_course/Py3_course 10 | [/MPATHB/training/python_course/Py3_course] 53328 [2018-05-09 22:49:39][ct][211.144.7.44]python -m SimpleHTTPServer 11521 11 | [/MPATHB/training/python_course/Py3_course] 53329 [2018-05-09 22:49:58][ct][211.144.7.44]ps auwx | grep 'SimpleHTTPServer' 12 | [/MPATHB/training/python_course/Py3_course] 53330 [2018-05-09 22:50:03][ct][211.144.7.44]kill 11145 13 | [/MPATHB/training/python_course/Py3_course] 53331 [2018-05-09 22:47:15][ct][211.144.7.44]python -m SimpleHTTPServer 11521 14 | [/MPATHB/training/python_course/Py3_course] 53331 [2018-05-09 22:50:06][ct][211.144.7.44]python -m SimpleHTTPServer 11521 15 | [/MPATHB/training/python_course/Py3_course] 57589 [2018-08-27 16:02:04][ct][141.70.80.5]cd Py3_course 16 | [/MPATHB/training/python_course/Py3_course] 57590 [2018-08-27 16:02:06][ct][141.70.80.5]ls 17 | -------------------------------------------------------------------------------- /Py3_course/02_CT_Python_training-chinese_files/02_CT_Python_training-chinese_263_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tong-Chen/Bioinfo_course_python/f03b9ee0684eb2417b70378794ba1ea23ee39006/Py3_course/02_CT_Python_training-chinese_files/02_CT_Python_training-chinese_263_0.png -------------------------------------------------------------------------------- /Py3_course/02_CT_Python_training-chinese_files/02_CT_Python_training-chinese_267_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tong-Chen/Bioinfo_course_python/f03b9ee0684eb2417b70378794ba1ea23ee39006/Py3_course/02_CT_Python_training-chinese_files/02_CT_Python_training-chinese_267_0.png -------------------------------------------------------------------------------- /Py3_course/02_CT_Python_training-chinese_files/02_CT_Python_training-chinese_268_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tong-Chen/Bioinfo_course_python/f03b9ee0684eb2417b70378794ba1ea23ee39006/Py3_course/02_CT_Python_training-chinese_files/02_CT_Python_training-chinese_268_0.png -------------------------------------------------------------------------------- /Py3_course/02_CT_Python_training-chinese_files/02_CT_Python_training-chinese_270_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tong-Chen/Bioinfo_course_python/f03b9ee0684eb2417b70378794ba1ea23ee39006/Py3_course/02_CT_Python_training-chinese_files/02_CT_Python_training-chinese_270_0.png -------------------------------------------------------------------------------- /Py3_course/02_CT_Python_training-chinese_files/02_CT_Python_training-chinese_272_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tong-Chen/Bioinfo_course_python/f03b9ee0684eb2417b70378794ba1ea23ee39006/Py3_course/02_CT_Python_training-chinese_files/02_CT_Python_training-chinese_272_0.png -------------------------------------------------------------------------------- /Py3_course/02_CT_Python_training-chinese_files/02_CT_Python_training-chinese_273_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tong-Chen/Bioinfo_course_python/f03b9ee0684eb2417b70378794ba1ea23ee39006/Py3_course/02_CT_Python_training-chinese_files/02_CT_Python_training-chinese_273_0.png -------------------------------------------------------------------------------- /Py3_course/02_CT_Python_training-chinese_files/02_CT_Python_training-chinese_275_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tong-Chen/Bioinfo_course_python/f03b9ee0684eb2417b70378794ba1ea23ee39006/Py3_course/02_CT_Python_training-chinese_files/02_CT_Python_training-chinese_275_0.png -------------------------------------------------------------------------------- /Py3_course/02_CT_Python_training-chinese_files/02_CT_Python_training-chinese_277_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tong-Chen/Bioinfo_course_python/f03b9ee0684eb2417b70378794ba1ea23ee39006/Py3_course/02_CT_Python_training-chinese_files/02_CT_Python_training-chinese_277_0.png -------------------------------------------------------------------------------- /Py3_course/02_CT_Python_training-chinese_files/02_CT_Python_training-chinese_283_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tong-Chen/Bioinfo_course_python/f03b9ee0684eb2417b70378794ba1ea23ee39006/Py3_course/02_CT_Python_training-chinese_files/02_CT_Python_training-chinese_283_0.png -------------------------------------------------------------------------------- /Py3_course/02_CT_Python_training-chinese_files/02_CT_Python_training-chinese_285_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tong-Chen/Bioinfo_course_python/f03b9ee0684eb2417b70378794ba1ea23ee39006/Py3_course/02_CT_Python_training-chinese_files/02_CT_Python_training-chinese_285_0.png -------------------------------------------------------------------------------- /Py3_course/02_CT_Python_training-chinese_files/02_CT_Python_training-chinese_287_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tong-Chen/Bioinfo_course_python/f03b9ee0684eb2417b70378794ba1ea23ee39006/Py3_course/02_CT_Python_training-chinese_files/02_CT_Python_training-chinese_287_0.png -------------------------------------------------------------------------------- /Py3_course/02_CT_Python_training-chinese_files/02_CT_Python_training-chinese_289_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tong-Chen/Bioinfo_course_python/f03b9ee0684eb2417b70378794ba1ea23ee39006/Py3_course/02_CT_Python_training-chinese_files/02_CT_Python_training-chinese_289_0.png -------------------------------------------------------------------------------- /Py3_course/02_CT_Python_training-chinese_files/02_CT_Python_training-chinese_290_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tong-Chen/Bioinfo_course_python/f03b9ee0684eb2417b70378794ba1ea23ee39006/Py3_course/02_CT_Python_training-chinese_files/02_CT_Python_training-chinese_290_0.png -------------------------------------------------------------------------------- /Py3_course/02_CT_Python_training-chinese_files/02_CT_Python_training-chinese_292_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tong-Chen/Bioinfo_course_python/f03b9ee0684eb2417b70378794ba1ea23ee39006/Py3_course/02_CT_Python_training-chinese_files/02_CT_Python_training-chinese_292_0.png -------------------------------------------------------------------------------- /Py3_course/02_CT_Python_training-chinese_files/02_CT_Python_training-chinese_295_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tong-Chen/Bioinfo_course_python/f03b9ee0684eb2417b70378794ba1ea23ee39006/Py3_course/02_CT_Python_training-chinese_files/02_CT_Python_training-chinese_295_0.png -------------------------------------------------------------------------------- /Py3_course/02_CT_Python_training-chinese_files/02_CT_Python_training-chinese_298_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tong-Chen/Bioinfo_course_python/f03b9ee0684eb2417b70378794ba1ea23ee39006/Py3_course/02_CT_Python_training-chinese_files/02_CT_Python_training-chinese_298_0.png -------------------------------------------------------------------------------- /Py3_course/02_CT_Python_training-chinese_files/02_CT_Python_training-chinese_301_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tong-Chen/Bioinfo_course_python/f03b9ee0684eb2417b70378794ba1ea23ee39006/Py3_course/02_CT_Python_training-chinese_files/02_CT_Python_training-chinese_301_0.png -------------------------------------------------------------------------------- /Py3_course/02_CT_Python_training-chinese_files/02_CT_Python_training-chinese_302_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tong-Chen/Bioinfo_course_python/f03b9ee0684eb2417b70378794ba1ea23ee39006/Py3_course/02_CT_Python_training-chinese_files/02_CT_Python_training-chinese_302_0.png -------------------------------------------------------------------------------- /Py3_course/02_CT_Python_training-chinese_files/02_CT_Python_training-chinese_303_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tong-Chen/Bioinfo_course_python/f03b9ee0684eb2417b70378794ba1ea23ee39006/Py3_course/02_CT_Python_training-chinese_files/02_CT_Python_training-chinese_303_0.png -------------------------------------------------------------------------------- /Py3_course/02_CT_Python_training-chinese_files/02_CT_Python_training-chinese_304_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tong-Chen/Bioinfo_course_python/f03b9ee0684eb2417b70378794ba1ea23ee39006/Py3_course/02_CT_Python_training-chinese_files/02_CT_Python_training-chinese_304_0.png -------------------------------------------------------------------------------- /Py3_course/02_CT_Python_training-chinese_files/02_CT_Python_training-chinese_305_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tong-Chen/Bioinfo_course_python/f03b9ee0684eb2417b70378794ba1ea23ee39006/Py3_course/02_CT_Python_training-chinese_files/02_CT_Python_training-chinese_305_0.png -------------------------------------------------------------------------------- /Py3_course/02_CT_Python_training-chinese_files/02_CT_Python_training-chinese_306_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tong-Chen/Bioinfo_course_python/f03b9ee0684eb2417b70378794ba1ea23ee39006/Py3_course/02_CT_Python_training-chinese_files/02_CT_Python_training-chinese_306_0.png -------------------------------------------------------------------------------- /Py3_course/03_WXN_matplotlib_files/03_WXN_matplotlib_10_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tong-Chen/Bioinfo_course_python/f03b9ee0684eb2417b70378794ba1ea23ee39006/Py3_course/03_WXN_matplotlib_files/03_WXN_matplotlib_10_0.png -------------------------------------------------------------------------------- /Py3_course/03_WXN_matplotlib_files/03_WXN_matplotlib_11_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tong-Chen/Bioinfo_course_python/f03b9ee0684eb2417b70378794ba1ea23ee39006/Py3_course/03_WXN_matplotlib_files/03_WXN_matplotlib_11_0.png -------------------------------------------------------------------------------- /Py3_course/03_WXN_matplotlib_files/03_WXN_matplotlib_13_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tong-Chen/Bioinfo_course_python/f03b9ee0684eb2417b70378794ba1ea23ee39006/Py3_course/03_WXN_matplotlib_files/03_WXN_matplotlib_13_0.png -------------------------------------------------------------------------------- /Py3_course/03_WXN_matplotlib_files/03_WXN_matplotlib_16_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tong-Chen/Bioinfo_course_python/f03b9ee0684eb2417b70378794ba1ea23ee39006/Py3_course/03_WXN_matplotlib_files/03_WXN_matplotlib_16_0.png -------------------------------------------------------------------------------- /Py3_course/03_WXN_matplotlib_files/03_WXN_matplotlib_17_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tong-Chen/Bioinfo_course_python/f03b9ee0684eb2417b70378794ba1ea23ee39006/Py3_course/03_WXN_matplotlib_files/03_WXN_matplotlib_17_0.png -------------------------------------------------------------------------------- /Py3_course/03_WXN_matplotlib_files/03_WXN_matplotlib_19_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tong-Chen/Bioinfo_course_python/f03b9ee0684eb2417b70378794ba1ea23ee39006/Py3_course/03_WXN_matplotlib_files/03_WXN_matplotlib_19_0.png -------------------------------------------------------------------------------- /Py3_course/03_WXN_matplotlib_files/03_WXN_matplotlib_21_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tong-Chen/Bioinfo_course_python/f03b9ee0684eb2417b70378794ba1ea23ee39006/Py3_course/03_WXN_matplotlib_files/03_WXN_matplotlib_21_0.png -------------------------------------------------------------------------------- /Py3_course/03_WXN_matplotlib_files/03_WXN_matplotlib_22_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tong-Chen/Bioinfo_course_python/f03b9ee0684eb2417b70378794ba1ea23ee39006/Py3_course/03_WXN_matplotlib_files/03_WXN_matplotlib_22_0.png -------------------------------------------------------------------------------- /Py3_course/03_WXN_matplotlib_files/03_WXN_matplotlib_27_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tong-Chen/Bioinfo_course_python/f03b9ee0684eb2417b70378794ba1ea23ee39006/Py3_course/03_WXN_matplotlib_files/03_WXN_matplotlib_27_0.png -------------------------------------------------------------------------------- /Py3_course/03_WXN_matplotlib_files/03_WXN_matplotlib_29_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tong-Chen/Bioinfo_course_python/f03b9ee0684eb2417b70378794ba1ea23ee39006/Py3_course/03_WXN_matplotlib_files/03_WXN_matplotlib_29_0.png -------------------------------------------------------------------------------- /Py3_course/03_WXN_matplotlib_files/03_WXN_matplotlib_31_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tong-Chen/Bioinfo_course_python/f03b9ee0684eb2417b70378794ba1ea23ee39006/Py3_course/03_WXN_matplotlib_files/03_WXN_matplotlib_31_0.png -------------------------------------------------------------------------------- /Py3_course/03_WXN_matplotlib_files/03_WXN_matplotlib_32_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tong-Chen/Bioinfo_course_python/f03b9ee0684eb2417b70378794ba1ea23ee39006/Py3_course/03_WXN_matplotlib_files/03_WXN_matplotlib_32_0.png -------------------------------------------------------------------------------- /Py3_course/03_WXN_matplotlib_files/03_WXN_matplotlib_34_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tong-Chen/Bioinfo_course_python/f03b9ee0684eb2417b70378794ba1ea23ee39006/Py3_course/03_WXN_matplotlib_files/03_WXN_matplotlib_34_0.png -------------------------------------------------------------------------------- /Py3_course/03_WXN_matplotlib_files/03_WXN_matplotlib_36_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tong-Chen/Bioinfo_course_python/f03b9ee0684eb2417b70378794ba1ea23ee39006/Py3_course/03_WXN_matplotlib_files/03_WXN_matplotlib_36_0.png -------------------------------------------------------------------------------- /Py3_course/03_WXN_matplotlib_files/03_WXN_matplotlib_37_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tong-Chen/Bioinfo_course_python/f03b9ee0684eb2417b70378794ba1ea23ee39006/Py3_course/03_WXN_matplotlib_files/03_WXN_matplotlib_37_0.png -------------------------------------------------------------------------------- /Py3_course/03_WXN_matplotlib_files/03_WXN_matplotlib_39_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tong-Chen/Bioinfo_course_python/f03b9ee0684eb2417b70378794ba1ea23ee39006/Py3_course/03_WXN_matplotlib_files/03_WXN_matplotlib_39_0.png -------------------------------------------------------------------------------- /Py3_course/03_WXN_matplotlib_files/03_WXN_matplotlib_42_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tong-Chen/Bioinfo_course_python/f03b9ee0684eb2417b70378794ba1ea23ee39006/Py3_course/03_WXN_matplotlib_files/03_WXN_matplotlib_42_0.png -------------------------------------------------------------------------------- /Py3_course/03_WXN_matplotlib_files/03_WXN_matplotlib_45_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tong-Chen/Bioinfo_course_python/f03b9ee0684eb2417b70378794ba1ea23ee39006/Py3_course/03_WXN_matplotlib_files/03_WXN_matplotlib_45_0.png -------------------------------------------------------------------------------- /Py3_course/03_WXN_matplotlib_files/03_WXN_matplotlib_48_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tong-Chen/Bioinfo_course_python/f03b9ee0684eb2417b70378794ba1ea23ee39006/Py3_course/03_WXN_matplotlib_files/03_WXN_matplotlib_48_0.png -------------------------------------------------------------------------------- /Py3_course/03_WXN_matplotlib_files/03_WXN_matplotlib_4_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tong-Chen/Bioinfo_course_python/f03b9ee0684eb2417b70378794ba1ea23ee39006/Py3_course/03_WXN_matplotlib_files/03_WXN_matplotlib_4_0.png -------------------------------------------------------------------------------- /Py3_course/03_WXN_matplotlib_files/03_WXN_matplotlib_50_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tong-Chen/Bioinfo_course_python/f03b9ee0684eb2417b70378794ba1ea23ee39006/Py3_course/03_WXN_matplotlib_files/03_WXN_matplotlib_50_0.png -------------------------------------------------------------------------------- /Py3_course/03_WXN_matplotlib_files/03_WXN_matplotlib_59_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tong-Chen/Bioinfo_course_python/f03b9ee0684eb2417b70378794ba1ea23ee39006/Py3_course/03_WXN_matplotlib_files/03_WXN_matplotlib_59_0.png -------------------------------------------------------------------------------- /Py3_course/03_WXN_matplotlib_files/03_WXN_matplotlib_5_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tong-Chen/Bioinfo_course_python/f03b9ee0684eb2417b70378794ba1ea23ee39006/Py3_course/03_WXN_matplotlib_files/03_WXN_matplotlib_5_0.png -------------------------------------------------------------------------------- /Py3_course/03_WXN_matplotlib_files/03_WXN_matplotlib_63_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tong-Chen/Bioinfo_course_python/f03b9ee0684eb2417b70378794ba1ea23ee39006/Py3_course/03_WXN_matplotlib_files/03_WXN_matplotlib_63_0.png -------------------------------------------------------------------------------- /Py3_course/03_WXN_matplotlib_files/03_WXN_matplotlib_9_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tong-Chen/Bioinfo_course_python/f03b9ee0684eb2417b70378794ba1ea23ee39006/Py3_course/03_WXN_matplotlib_files/03_WXN_matplotlib_9_0.png -------------------------------------------------------------------------------- /Py3_course/03_WXN_matplotlib_files/03_WXN_matplotlib_9_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tong-Chen/Bioinfo_course_python/f03b9ee0684eb2417b70378794ba1ea23ee39006/Py3_course/03_WXN_matplotlib_files/03_WXN_matplotlib_9_1.png -------------------------------------------------------------------------------- /Py3_course/06_CT_Pandas_files/06_CT_Pandas_103_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tong-Chen/Bioinfo_course_python/f03b9ee0684eb2417b70378794ba1ea23ee39006/Py3_course/06_CT_Pandas_files/06_CT_Pandas_103_1.png -------------------------------------------------------------------------------- /Py3_course/06_CT_Pandas_files/06_CT_Pandas_105_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tong-Chen/Bioinfo_course_python/f03b9ee0684eb2417b70378794ba1ea23ee39006/Py3_course/06_CT_Pandas_files/06_CT_Pandas_105_0.png -------------------------------------------------------------------------------- /Py3_course/06_CT_Pandas_files/06_CT_Pandas_107_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tong-Chen/Bioinfo_course_python/f03b9ee0684eb2417b70378794ba1ea23ee39006/Py3_course/06_CT_Pandas_files/06_CT_Pandas_107_1.png -------------------------------------------------------------------------------- /Py3_course/06_CT_Pandas_files/06_CT_Pandas_114_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tong-Chen/Bioinfo_course_python/f03b9ee0684eb2417b70378794ba1ea23ee39006/Py3_course/06_CT_Pandas_files/06_CT_Pandas_114_1.png -------------------------------------------------------------------------------- /Py3_course/06_CT_Pandas_files/06_CT_Pandas_116_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tong-Chen/Bioinfo_course_python/f03b9ee0684eb2417b70378794ba1ea23ee39006/Py3_course/06_CT_Pandas_files/06_CT_Pandas_116_1.png -------------------------------------------------------------------------------- /Py3_course/06_CT_Pandas_files/06_CT_Pandas_117_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tong-Chen/Bioinfo_course_python/f03b9ee0684eb2417b70378794ba1ea23ee39006/Py3_course/06_CT_Pandas_files/06_CT_Pandas_117_0.png -------------------------------------------------------------------------------- /Py3_course/06_CT_Pandas_files/06_CT_Pandas_118_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tong-Chen/Bioinfo_course_python/f03b9ee0684eb2417b70378794ba1ea23ee39006/Py3_course/06_CT_Pandas_files/06_CT_Pandas_118_1.png -------------------------------------------------------------------------------- /Py3_course/06_CT_Pandas_files/06_CT_Pandas_119_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tong-Chen/Bioinfo_course_python/f03b9ee0684eb2417b70378794ba1ea23ee39006/Py3_course/06_CT_Pandas_files/06_CT_Pandas_119_1.png -------------------------------------------------------------------------------- /Py3_course/06_CT_Pandas_files/06_CT_Pandas_122_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tong-Chen/Bioinfo_course_python/f03b9ee0684eb2417b70378794ba1ea23ee39006/Py3_course/06_CT_Pandas_files/06_CT_Pandas_122_0.png -------------------------------------------------------------------------------- /Py3_course/08_Python_pythonic_numpy_scipy_files/08_Python_pythonic_numpy_scipy_35_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tong-Chen/Bioinfo_course_python/f03b9ee0684eb2417b70378794ba1ea23ee39006/Py3_course/08_Python_pythonic_numpy_scipy_files/08_Python_pythonic_numpy_scipy_35_0.png -------------------------------------------------------------------------------- /Py3_course/08_Python_pythonic_numpy_scipy_files/08_Python_pythonic_numpy_scipy_37_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tong-Chen/Bioinfo_course_python/f03b9ee0684eb2417b70378794ba1ea23ee39006/Py3_course/08_Python_pythonic_numpy_scipy_files/08_Python_pythonic_numpy_scipy_37_0.png -------------------------------------------------------------------------------- /Py3_course/08_Python_pythonic_numpy_scipy_files/08_Python_pythonic_numpy_scipy_39_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tong-Chen/Bioinfo_course_python/f03b9ee0684eb2417b70378794ba1ea23ee39006/Py3_course/08_Python_pythonic_numpy_scipy_files/08_Python_pythonic_numpy_scipy_39_0.png -------------------------------------------------------------------------------- /Py3_course/08_Python_pythonic_numpy_scipy_files/08_Python_pythonic_numpy_scipy_43_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tong-Chen/Bioinfo_course_python/f03b9ee0684eb2417b70378794ba1ea23ee39006/Py3_course/08_Python_pythonic_numpy_scipy_files/08_Python_pythonic_numpy_scipy_43_0.png -------------------------------------------------------------------------------- /Py3_course/08_Python_pythonic_numpy_scipy_files/08_Python_pythonic_numpy_scipy_45_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tong-Chen/Bioinfo_course_python/f03b9ee0684eb2417b70378794ba1ea23ee39006/Py3_course/08_Python_pythonic_numpy_scipy_files/08_Python_pythonic_numpy_scipy_45_0.png -------------------------------------------------------------------------------- /Py3_course/08_Python_pythonic_numpy_scipy_files/08_Python_pythonic_numpy_scipy_49_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tong-Chen/Bioinfo_course_python/f03b9ee0684eb2417b70378794ba1ea23ee39006/Py3_course/08_Python_pythonic_numpy_scipy_files/08_Python_pythonic_numpy_scipy_49_0.png -------------------------------------------------------------------------------- /Py3_course/08_Python_pythonic_numpy_scipy_files/08_Python_pythonic_numpy_scipy_52_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tong-Chen/Bioinfo_course_python/f03b9ee0684eb2417b70378794ba1ea23ee39006/Py3_course/08_Python_pythonic_numpy_scipy_files/08_Python_pythonic_numpy_scipy_52_0.png -------------------------------------------------------------------------------- /Py3_course/08_Python_pythonic_numpy_scipy_files/08_Python_pythonic_numpy_scipy_55_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tong-Chen/Bioinfo_course_python/f03b9ee0684eb2417b70378794ba1ea23ee39006/Py3_course/08_Python_pythonic_numpy_scipy_files/08_Python_pythonic_numpy_scipy_55_0.png -------------------------------------------------------------------------------- /Py3_course/Py3_course.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tong-Chen/Bioinfo_course_python/f03b9ee0684eb2417b70378794ba1ea23ee39006/Py3_course/Py3_course.pdf -------------------------------------------------------------------------------- /Py3_course/Python_start_run_linux.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tong-Chen/Bioinfo_course_python/f03b9ee0684eb2417b70378794ba1ea23ee39006/Py3_course/Python_start_run_linux.png -------------------------------------------------------------------------------- /Py3_course/coding_is_hard_confidence_competence.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tong-Chen/Bioinfo_course_python/f03b9ee0684eb2417b70378794ba1ea23ee39006/Py3_course/coding_is_hard_confidence_competence.png -------------------------------------------------------------------------------- /Py3_course/ehbio/company_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tong-Chen/Bioinfo_course_python/f03b9ee0684eb2417b70378794ba1ea23ee39006/Py3_course/ehbio/company_1.png -------------------------------------------------------------------------------- /Py3_course/ehbio/company_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tong-Chen/Bioinfo_course_python/f03b9ee0684eb2417b70378794ba1ea23ee39006/Py3_course/ehbio/company_2.png -------------------------------------------------------------------------------- /Py3_course/ehbio/cover.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tong-Chen/Bioinfo_course_python/f03b9ee0684eb2417b70378794ba1ea23ee39006/Py3_course/ehbio/cover.png -------------------------------------------------------------------------------- /Py3_course/libs/gitbook-2.6.7/css/fontawesome/fontawesome-webfont.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tong-Chen/Bioinfo_course_python/f03b9ee0684eb2417b70378794ba1ea23ee39006/Py3_course/libs/gitbook-2.6.7/css/fontawesome/fontawesome-webfont.ttf -------------------------------------------------------------------------------- /Py3_course/libs/gitbook-2.6.7/css/plugin-bookdown.css: -------------------------------------------------------------------------------- 1 | .book .book-header h1 { 2 | padding-left: 20px; 3 | padding-right: 20px; 4 | } 5 | .book .book-header.fixed { 6 | position: fixed; 7 | right: 0; 8 | top: 0; 9 | left: 0; 10 | border-bottom: 1px solid rgba(0,0,0,.07); 11 | } 12 | span.search-highlight { 13 | background-color: #ffff88; 14 | } 15 | @media (min-width: 600px) { 16 | .book.with-summary .book-header.fixed { 17 | left: 300px; 18 | } 19 | } 20 | @media (max-width: 1240px) { 21 | .book .book-body.fixed { 22 | top: 50px; 23 | } 24 | .book .book-body.fixed .body-inner { 25 | top: auto; 26 | } 27 | } 28 | @media (max-width: 600px) { 29 | .book.with-summary .book-header.fixed { 30 | left: calc(100% - 60px); 31 | min-width: 300px; 32 | } 33 | .book.with-summary .book-body { 34 | transform: none; 35 | left: calc(100% - 60px); 36 | min-width: 300px; 37 | } 38 | .book .book-body.fixed { 39 | top: 0; 40 | } 41 | } 42 | 43 | .book .book-body.fixed .body-inner { 44 | top: 50px; 45 | } 46 | .book .book-body .page-wrapper .page-inner section.normal sub, .book .book-body .page-wrapper .page-inner section.normal sup { 47 | font-size: 85%; 48 | } 49 | 50 | @media print { 51 | .book .book-summary, .book .book-body .book-header, .fa { 52 | display: none !important; 53 | } 54 | .book .book-body.fixed { 55 | left: 0px; 56 | } 57 | .book .book-body,.book .book-body .body-inner, .book.with-summary { 58 | overflow: visible !important; 59 | } 60 | } 61 | .kable_wrapper { 62 | border-spacing: 20px 0; 63 | border-collapse: separate; 64 | border: none; 65 | margin: auto; 66 | } 67 | .kable_wrapper > tbody > tr > td { 68 | vertical-align: top; 69 | } 70 | .book .book-body .page-wrapper .page-inner section.normal table tr.header { 71 | border-top-width: 2px; 72 | } 73 | .book .book-body .page-wrapper .page-inner section.normal table tr:last-child td { 74 | border-bottom-width: 2px; 75 | } 76 | .book .book-body .page-wrapper .page-inner section.normal table td, .book .book-body .page-wrapper .page-inner section.normal table th { 77 | border-left: none; 78 | border-right: none; 79 | } 80 | .book .book-body .page-wrapper .page-inner section.normal table.kable_wrapper > tbody > tr, .book .book-body .page-wrapper .page-inner section.normal table.kable_wrapper > tbody > tr > td { 81 | border-top: none; 82 | } 83 | .book .book-body .page-wrapper .page-inner section.normal table.kable_wrapper > tbody > tr:last-child > td { 84 | border-bottom: none; 85 | } 86 | 87 | div.theorem, div.lemma, div.corollary, div.proposition { 88 | font-style: italic; 89 | } 90 | span.theorem, span.lemma, span.corollary, span.proposition { 91 | font-style: normal; 92 | } 93 | div.proof:after { 94 | content: "\25a2"; 95 | float: right; 96 | } 97 | .header-section-number { 98 | padding-right: .5em; 99 | } 100 | -------------------------------------------------------------------------------- /Py3_course/libs/gitbook-2.6.7/css/plugin-fontsettings.css: -------------------------------------------------------------------------------- 1 | /* 2 | * Theme 1 3 | */ 4 | .color-theme-1 .dropdown-menu { 5 | background-color: #111111; 6 | border-color: #7e888b; 7 | } 8 | .color-theme-1 .dropdown-menu .dropdown-caret .caret-inner { 9 | border-bottom: 9px solid #111111; 10 | } 11 | .color-theme-1 .dropdown-menu .buttons { 12 | border-color: #7e888b; 13 | } 14 | .color-theme-1 .dropdown-menu .button { 15 | color: #afa790; 16 | } 17 | .color-theme-1 .dropdown-menu .button:hover { 18 | color: #73553c; 19 | } 20 | /* 21 | * Theme 2 22 | */ 23 | .color-theme-2 .dropdown-menu { 24 | background-color: #2d3143; 25 | border-color: #272a3a; 26 | } 27 | .color-theme-2 .dropdown-menu .dropdown-caret .caret-inner { 28 | border-bottom: 9px solid #2d3143; 29 | } 30 | .color-theme-2 .dropdown-menu .buttons { 31 | border-color: #272a3a; 32 | } 33 | .color-theme-2 .dropdown-menu .button { 34 | color: #62677f; 35 | } 36 | .color-theme-2 .dropdown-menu .button:hover { 37 | color: #f4f4f5; 38 | } 39 | .book .book-header .font-settings .font-enlarge { 40 | line-height: 30px; 41 | font-size: 1.4em; 42 | } 43 | .book .book-header .font-settings .font-reduce { 44 | line-height: 30px; 45 | font-size: 1em; 46 | } 47 | .book.color-theme-1 .book-body { 48 | color: #704214; 49 | background: #f3eacb; 50 | } 51 | .book.color-theme-1 .book-body .page-wrapper .page-inner section { 52 | background: #f3eacb; 53 | } 54 | .book.color-theme-2 .book-body { 55 | color: #bdcadb; 56 | background: #1c1f2b; 57 | } 58 | .book.color-theme-2 .book-body .page-wrapper .page-inner section { 59 | background: #1c1f2b; 60 | } 61 | .book.font-size-0 .book-body .page-inner section { 62 | font-size: 1.2rem; 63 | } 64 | .book.font-size-1 .book-body .page-inner section { 65 | font-size: 1.4rem; 66 | } 67 | .book.font-size-2 .book-body .page-inner section { 68 | font-size: 1.6rem; 69 | } 70 | .book.font-size-3 .book-body .page-inner section { 71 | font-size: 2.2rem; 72 | } 73 | .book.font-size-4 .book-body .page-inner section { 74 | font-size: 4rem; 75 | } 76 | .book.font-family-0 { 77 | font-family: Georgia, serif; 78 | } 79 | .book.font-family-1 { 80 | font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; 81 | } 82 | .book.color-theme-1 .book-body .page-wrapper .page-inner section.normal { 83 | color: #704214; 84 | } 85 | .book.color-theme-1 .book-body .page-wrapper .page-inner section.normal a { 86 | color: inherit; 87 | } 88 | .book.color-theme-1 .book-body .page-wrapper .page-inner section.normal h1, 89 | .book.color-theme-1 .book-body .page-wrapper .page-inner section.normal h2, 90 | .book.color-theme-1 .book-body .page-wrapper .page-inner section.normal h3, 91 | .book.color-theme-1 .book-body .page-wrapper .page-inner section.normal h4, 92 | .book.color-theme-1 .book-body .page-wrapper .page-inner section.normal h5, 93 | .book.color-theme-1 .book-body .page-wrapper .page-inner section.normal h6 { 94 | color: inherit; 95 | } 96 | .book.color-theme-1 .book-body .page-wrapper .page-inner section.normal h1, 97 | .book.color-theme-1 .book-body .page-wrapper .page-inner section.normal h2 { 98 | border-color: inherit; 99 | } 100 | .book.color-theme-1 .book-body .page-wrapper .page-inner section.normal h6 { 101 | color: inherit; 102 | } 103 | .book.color-theme-1 .book-body .page-wrapper .page-inner section.normal hr { 104 | background-color: inherit; 105 | } 106 | .book.color-theme-1 .book-body .page-wrapper .page-inner section.normal blockquote { 107 | border-color: inherit; 108 | } 109 | .book.color-theme-1 .book-body .page-wrapper .page-inner section.normal pre, 110 | .book.color-theme-1 .book-body .page-wrapper .page-inner section.normal code { 111 | background: #fdf6e3; 112 | color: #657b83; 113 | border-color: #f8df9c; 114 | } 115 | .book.color-theme-1 .book-body .page-wrapper .page-inner section.normal .highlight { 116 | background-color: inherit; 117 | } 118 | .book.color-theme-1 .book-body .page-wrapper .page-inner section.normal table th, 119 | .book.color-theme-1 .book-body .page-wrapper .page-inner section.normal table td { 120 | border-color: #f5d06c; 121 | } 122 | .book.color-theme-1 .book-body .page-wrapper .page-inner section.normal table tr { 123 | color: inherit; 124 | background-color: #fdf6e3; 125 | border-color: #444444; 126 | } 127 | .book.color-theme-1 .book-body .page-wrapper .page-inner section.normal table tr:nth-child(2n) { 128 | background-color: #fbeecb; 129 | } 130 | .book.color-theme-2 .book-body .page-wrapper .page-inner section.normal { 131 | color: #bdcadb; 132 | } 133 | .book.color-theme-2 .book-body .page-wrapper .page-inner section.normal a { 134 | color: #3eb1d0; 135 | } 136 | .book.color-theme-2 .book-body .page-wrapper .page-inner section.normal h1, 137 | .book.color-theme-2 .book-body .page-wrapper .page-inner section.normal h2, 138 | .book.color-theme-2 .book-body .page-wrapper .page-inner section.normal h3, 139 | .book.color-theme-2 .book-body .page-wrapper .page-inner section.normal h4, 140 | .book.color-theme-2 .book-body .page-wrapper .page-inner section.normal h5, 141 | .book.color-theme-2 .book-body .page-wrapper .page-inner section.normal h6 { 142 | color: #fffffa; 143 | } 144 | .book.color-theme-2 .book-body .page-wrapper .page-inner section.normal h1, 145 | .book.color-theme-2 .book-body .page-wrapper .page-inner section.normal h2 { 146 | border-color: #373b4e; 147 | } 148 | .book.color-theme-2 .book-body .page-wrapper .page-inner section.normal h6 { 149 | color: #373b4e; 150 | } 151 | .book.color-theme-2 .book-body .page-wrapper .page-inner section.normal hr { 152 | background-color: #373b4e; 153 | } 154 | .book.color-theme-2 .book-body .page-wrapper .page-inner section.normal blockquote { 155 | border-color: #373b4e; 156 | } 157 | .book.color-theme-2 .book-body .page-wrapper .page-inner section.normal pre, 158 | .book.color-theme-2 .book-body .page-wrapper .page-inner section.normal code { 159 | color: #9dbed8; 160 | background: #2d3143; 161 | border-color: #2d3143; 162 | } 163 | .book.color-theme-2 .book-body .page-wrapper .page-inner section.normal .highlight { 164 | background-color: #282a39; 165 | } 166 | .book.color-theme-2 .book-body .page-wrapper .page-inner section.normal table th, 167 | .book.color-theme-2 .book-body .page-wrapper .page-inner section.normal table td { 168 | border-color: #3b3f54; 169 | } 170 | .book.color-theme-2 .book-body .page-wrapper .page-inner section.normal table tr { 171 | color: #b6c2d2; 172 | background-color: #2d3143; 173 | border-color: #3b3f54; 174 | } 175 | .book.color-theme-2 .book-body .page-wrapper .page-inner section.normal table tr:nth-child(2n) { 176 | background-color: #35394b; 177 | } 178 | .book.color-theme-1 .book-header { 179 | color: #afa790; 180 | background: transparent; 181 | } 182 | .book.color-theme-1 .book-header .btn { 183 | color: #afa790; 184 | } 185 | .book.color-theme-1 .book-header .btn:hover { 186 | color: #73553c; 187 | background: none; 188 | } 189 | .book.color-theme-1 .book-header h1 { 190 | color: #704214; 191 | } 192 | .book.color-theme-2 .book-header { 193 | color: #7e888b; 194 | background: transparent; 195 | } 196 | .book.color-theme-2 .book-header .btn { 197 | color: #3b3f54; 198 | } 199 | .book.color-theme-2 .book-header .btn:hover { 200 | color: #fffff5; 201 | background: none; 202 | } 203 | .book.color-theme-2 .book-header h1 { 204 | color: #bdcadb; 205 | } 206 | .book.color-theme-1 .book-body .navigation { 207 | color: #afa790; 208 | } 209 | .book.color-theme-1 .book-body .navigation:hover { 210 | color: #73553c; 211 | } 212 | .book.color-theme-2 .book-body .navigation { 213 | color: #383f52; 214 | } 215 | .book.color-theme-2 .book-body .navigation:hover { 216 | color: #fffff5; 217 | } 218 | /* 219 | * Theme 1 220 | */ 221 | .book.color-theme-1 .book-summary { 222 | color: #afa790; 223 | background: #111111; 224 | border-right: 1px solid rgba(0, 0, 0, 0.07); 225 | } 226 | .book.color-theme-1 .book-summary .book-search { 227 | background: transparent; 228 | } 229 | .book.color-theme-1 .book-summary .book-search input, 230 | .book.color-theme-1 .book-summary .book-search input:focus { 231 | border: 1px solid transparent; 232 | } 233 | .book.color-theme-1 .book-summary ul.summary li.divider { 234 | background: #7e888b; 235 | box-shadow: none; 236 | } 237 | .book.color-theme-1 .book-summary ul.summary li i.fa-check { 238 | color: #33cc33; 239 | } 240 | .book.color-theme-1 .book-summary ul.summary li.done > a { 241 | color: #877f6a; 242 | } 243 | .book.color-theme-1 .book-summary ul.summary li a, 244 | .book.color-theme-1 .book-summary ul.summary li span { 245 | color: #877f6a; 246 | background: transparent; 247 | font-weight: normal; 248 | } 249 | .book.color-theme-1 .book-summary ul.summary li.active > a, 250 | .book.color-theme-1 .book-summary ul.summary li a:hover { 251 | color: #704214; 252 | background: transparent; 253 | font-weight: normal; 254 | } 255 | /* 256 | * Theme 2 257 | */ 258 | .book.color-theme-2 .book-summary { 259 | color: #bcc1d2; 260 | background: #2d3143; 261 | border-right: none; 262 | } 263 | .book.color-theme-2 .book-summary .book-search { 264 | background: transparent; 265 | } 266 | .book.color-theme-2 .book-summary .book-search input, 267 | .book.color-theme-2 .book-summary .book-search input:focus { 268 | border: 1px solid transparent; 269 | } 270 | .book.color-theme-2 .book-summary ul.summary li.divider { 271 | background: #272a3a; 272 | box-shadow: none; 273 | } 274 | .book.color-theme-2 .book-summary ul.summary li i.fa-check { 275 | color: #33cc33; 276 | } 277 | .book.color-theme-2 .book-summary ul.summary li.done > a { 278 | color: #62687f; 279 | } 280 | .book.color-theme-2 .book-summary ul.summary li a, 281 | .book.color-theme-2 .book-summary ul.summary li span { 282 | color: #c1c6d7; 283 | background: transparent; 284 | font-weight: 600; 285 | } 286 | .book.color-theme-2 .book-summary ul.summary li.active > a, 287 | .book.color-theme-2 .book-summary ul.summary li a:hover { 288 | color: #f4f4f5; 289 | background: #252737; 290 | font-weight: 600; 291 | } 292 | -------------------------------------------------------------------------------- /Py3_course/libs/gitbook-2.6.7/css/plugin-search.css: -------------------------------------------------------------------------------- 1 | .book .book-summary .book-search { 2 | padding: 6px; 3 | background: transparent; 4 | position: absolute; 5 | top: -50px; 6 | left: 0px; 7 | right: 0px; 8 | transition: top 0.5s ease; 9 | } 10 | .book .book-summary .book-search input, 11 | .book .book-summary .book-search input:focus, 12 | .book .book-summary .book-search input:hover { 13 | width: 100%; 14 | background: transparent; 15 | border: 1px solid #ccc; 16 | box-shadow: none; 17 | outline: none; 18 | line-height: 22px; 19 | padding: 7px 4px; 20 | color: inherit; 21 | box-sizing: border-box; 22 | } 23 | .book.with-search .book-summary .book-search { 24 | top: 0px; 25 | } 26 | .book.with-search .book-summary ul.summary { 27 | top: 50px; 28 | } 29 | -------------------------------------------------------------------------------- /Py3_course/libs/gitbook-2.6.7/js/jquery.highlight.js: -------------------------------------------------------------------------------- 1 | gitbook.require(["jQuery"], function(jQuery) { 2 | 3 | /* 4 | * jQuery Highlight plugin 5 | * 6 | * Based on highlight v3 by Johann Burkard 7 | * http://johannburkard.de/blog/programming/javascript/highlight-javascript-text-higlighting-jquery-plugin.html 8 | * 9 | * Code a little bit refactored and cleaned (in my humble opinion). 10 | * Most important changes: 11 | * - has an option to highlight only entire words (wordsOnly - false by default), 12 | * - has an option to be case sensitive (caseSensitive - false by default) 13 | * - highlight element tag and class names can be specified in options 14 | * 15 | * Copyright (c) 2009 Bartek Szopka 16 | * 17 | * Licensed under MIT license. 18 | * 19 | */ 20 | 21 | jQuery.extend({ 22 | highlight: function (node, re, nodeName, className) { 23 | if (node.nodeType === 3) { 24 | var match = node.data.match(re); 25 | if (match) { 26 | var highlight = document.createElement(nodeName || 'span'); 27 | highlight.className = className || 'highlight'; 28 | var wordNode = node.splitText(match.index); 29 | wordNode.splitText(match[0].length); 30 | var wordClone = wordNode.cloneNode(true); 31 | highlight.appendChild(wordClone); 32 | wordNode.parentNode.replaceChild(highlight, wordNode); 33 | return 1; //skip added node in parent 34 | } 35 | } else if ((node.nodeType === 1 && node.childNodes) && // only element nodes that have children 36 | !/(script|style)/i.test(node.tagName) && // ignore script and style nodes 37 | !(node.tagName === nodeName.toUpperCase() && node.className === className)) { // skip if already highlighted 38 | for (var i = 0; i < node.childNodes.length; i++) { 39 | i += jQuery.highlight(node.childNodes[i], re, nodeName, className); 40 | } 41 | } 42 | return 0; 43 | } 44 | }); 45 | 46 | jQuery.fn.unhighlight = function (options) { 47 | var settings = { className: 'highlight', element: 'span' }; 48 | jQuery.extend(settings, options); 49 | 50 | return this.find(settings.element + "." + settings.className).each(function () { 51 | var parent = this.parentNode; 52 | parent.replaceChild(this.firstChild, this); 53 | parent.normalize(); 54 | }).end(); 55 | }; 56 | 57 | jQuery.fn.highlight = function (words, options) { 58 | var settings = { className: 'highlight', element: 'span', caseSensitive: false, wordsOnly: false }; 59 | jQuery.extend(settings, options); 60 | 61 | if (words.constructor === String) { 62 | words = [words]; 63 | } 64 | words = jQuery.grep(words, function(word, i){ 65 | return word !== ''; 66 | }); 67 | words = jQuery.map(words, function(word, i) { 68 | return word.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"); 69 | }); 70 | if (words.length === 0) { return this; } 71 | 72 | var flag = settings.caseSensitive ? "" : "i"; 73 | var pattern = "(" + words.join("|") + ")"; 74 | if (settings.wordsOnly) { 75 | pattern = "\\b" + pattern + "\\b"; 76 | } 77 | var re = new RegExp(pattern, flag); 78 | 79 | return this.each(function () { 80 | jQuery.highlight(this, re, settings.element, settings.className); 81 | }); 82 | }; 83 | 84 | }); 85 | -------------------------------------------------------------------------------- /Py3_course/libs/gitbook-2.6.7/js/lunr.js: -------------------------------------------------------------------------------- 1 | /** 2 | * lunr - http://lunrjs.com - A bit like Solr, but much smaller and not as bright - 0.5.12 3 | * Copyright (C) 2015 Oliver Nightingale 4 | * MIT Licensed 5 | * @license 6 | */ 7 | !function(){var t=function(e){var n=new t.Index;return n.pipeline.add(t.trimmer,t.stopWordFilter,t.stemmer),e&&e.call(n,n),n};t.version="0.5.12",t.utils={},t.utils.warn=function(t){return function(e){t.console&&console.warn&&console.warn(e)}}(this),t.EventEmitter=function(){this.events={}},t.EventEmitter.prototype.addListener=function(){var t=Array.prototype.slice.call(arguments),e=t.pop(),n=t;if("function"!=typeof e)throw new TypeError("last argument must be a function");n.forEach(function(t){this.hasHandler(t)||(this.events[t]=[]),this.events[t].push(e)},this)},t.EventEmitter.prototype.removeListener=function(t,e){if(this.hasHandler(t)){var n=this.events[t].indexOf(e);this.events[t].splice(n,1),this.events[t].length||delete this.events[t]}},t.EventEmitter.prototype.emit=function(t){if(this.hasHandler(t)){var e=Array.prototype.slice.call(arguments,1);this.events[t].forEach(function(t){t.apply(void 0,e)})}},t.EventEmitter.prototype.hasHandler=function(t){return t in this.events},t.tokenizer=function(t){return arguments.length&&null!=t&&void 0!=t?Array.isArray(t)?t.map(function(t){return t.toLowerCase()}):t.toString().trim().toLowerCase().split(/[\s\-\/]+/):[]},t.Pipeline=function(){this._stack=[]},t.Pipeline.registeredFunctions={},t.Pipeline.registerFunction=function(e,n){n in this.registeredFunctions&&t.utils.warn("Overwriting existing registered function: "+n),e.label=n,t.Pipeline.registeredFunctions[e.label]=e},t.Pipeline.warnIfFunctionNotRegistered=function(e){var n=e.label&&e.label in this.registeredFunctions;n||t.utils.warn("Function is not registered with pipeline. This may cause problems when serialising the index.\n",e)},t.Pipeline.load=function(e){var n=new t.Pipeline;return e.forEach(function(e){var i=t.Pipeline.registeredFunctions[e];if(!i)throw new Error("Cannot load un-registered function: "+e);n.add(i)}),n},t.Pipeline.prototype.add=function(){var e=Array.prototype.slice.call(arguments);e.forEach(function(e){t.Pipeline.warnIfFunctionNotRegistered(e),this._stack.push(e)},this)},t.Pipeline.prototype.after=function(e,n){t.Pipeline.warnIfFunctionNotRegistered(n);var i=this._stack.indexOf(e);if(-1==i)throw new Error("Cannot find existingFn");i+=1,this._stack.splice(i,0,n)},t.Pipeline.prototype.before=function(e,n){t.Pipeline.warnIfFunctionNotRegistered(n);var i=this._stack.indexOf(e);if(-1==i)throw new Error("Cannot find existingFn");this._stack.splice(i,0,n)},t.Pipeline.prototype.remove=function(t){var e=this._stack.indexOf(t);-1!=e&&this._stack.splice(e,1)},t.Pipeline.prototype.run=function(t){for(var e=[],n=t.length,i=this._stack.length,o=0;n>o;o++){for(var r=t[o],s=0;i>s&&(r=this._stack[s](r,o,t),void 0!==r);s++);void 0!==r&&e.push(r)}return e},t.Pipeline.prototype.reset=function(){this._stack=[]},t.Pipeline.prototype.toJSON=function(){return this._stack.map(function(e){return t.Pipeline.warnIfFunctionNotRegistered(e),e.label})},t.Vector=function(){this._magnitude=null,this.list=void 0,this.length=0},t.Vector.Node=function(t,e,n){this.idx=t,this.val=e,this.next=n},t.Vector.prototype.insert=function(e,n){this._magnitude=void 0;var i=this.list;if(!i)return this.list=new t.Vector.Node(e,n,i),this.length++;if(en.idx?n=n.next:(i+=e.val*n.val,e=e.next,n=n.next);return i},t.Vector.prototype.similarity=function(t){return this.dot(t)/(this.magnitude()*t.magnitude())},t.SortedSet=function(){this.length=0,this.elements=[]},t.SortedSet.load=function(t){var e=new this;return e.elements=t,e.length=t.length,e},t.SortedSet.prototype.add=function(){var t,e;for(t=0;t1;){if(r===t)return o;t>r&&(e=o),r>t&&(n=o),i=n-e,o=e+Math.floor(i/2),r=this.elements[o]}return r===t?o:-1},t.SortedSet.prototype.locationFor=function(t){for(var e=0,n=this.elements.length,i=n-e,o=e+Math.floor(i/2),r=this.elements[o];i>1;)t>r&&(e=o),r>t&&(n=o),i=n-e,o=e+Math.floor(i/2),r=this.elements[o];return r>t?o:t>r?o+1:void 0},t.SortedSet.prototype.intersect=function(e){for(var n=new t.SortedSet,i=0,o=0,r=this.length,s=e.length,a=this.elements,h=e.elements;;){if(i>r-1||o>s-1)break;a[i]!==h[o]?a[i]h[o]&&o++:(n.add(a[i]),i++,o++)}return n},t.SortedSet.prototype.clone=function(){var e=new t.SortedSet;return e.elements=this.toArray(),e.length=e.elements.length,e},t.SortedSet.prototype.union=function(t){var e,n,i;return this.length>=t.length?(e=this,n=t):(e=t,n=this),i=e.clone(),i.add.apply(i,n.toArray()),i},t.SortedSet.prototype.toJSON=function(){return this.toArray()},t.Index=function(){this._fields=[],this._ref="id",this.pipeline=new t.Pipeline,this.documentStore=new t.Store,this.tokenStore=new t.TokenStore,this.corpusTokens=new t.SortedSet,this.eventEmitter=new t.EventEmitter,this._idfCache={},this.on("add","remove","update",function(){this._idfCache={}}.bind(this))},t.Index.prototype.on=function(){var t=Array.prototype.slice.call(arguments);return this.eventEmitter.addListener.apply(this.eventEmitter,t)},t.Index.prototype.off=function(t,e){return this.eventEmitter.removeListener(t,e)},t.Index.load=function(e){e.version!==t.version&&t.utils.warn("version mismatch: current "+t.version+" importing "+e.version);var n=new this;return n._fields=e.fields,n._ref=e.ref,n.documentStore=t.Store.load(e.documentStore),n.tokenStore=t.TokenStore.load(e.tokenStore),n.corpusTokens=t.SortedSet.load(e.corpusTokens),n.pipeline=t.Pipeline.load(e.pipeline),n},t.Index.prototype.field=function(t,e){var e=e||{},n={name:t,boost:e.boost||1};return this._fields.push(n),this},t.Index.prototype.ref=function(t){return this._ref=t,this},t.Index.prototype.add=function(e,n){var i={},o=new t.SortedSet,r=e[this._ref],n=void 0===n?!0:n;this._fields.forEach(function(n){var r=this.pipeline.run(t.tokenizer(e[n.name]));i[n.name]=r,t.SortedSet.prototype.add.apply(o,r)},this),this.documentStore.set(r,o),t.SortedSet.prototype.add.apply(this.corpusTokens,o.toArray());for(var s=0;s0&&(i=1+Math.log(this.documentStore.length/n)),this._idfCache[e]=i},t.Index.prototype.search=function(e){var n=this.pipeline.run(t.tokenizer(e)),i=new t.Vector,o=[],r=this._fields.reduce(function(t,e){return t+e.boost},0),s=n.some(function(t){return this.tokenStore.has(t)},this);if(!s)return[];n.forEach(function(e,n,s){var a=1/s.length*this._fields.length*r,h=this,l=this.tokenStore.expand(e).reduce(function(n,o){var r=h.corpusTokens.indexOf(o),s=h.idf(o),l=1,u=new t.SortedSet;if(o!==e){var c=Math.max(3,o.length-e.length);l=1/Math.log(c)}return r>-1&&i.insert(r,a*s*l),Object.keys(h.tokenStore.get(o)).forEach(function(t){u.add(t)}),n.union(u)},new t.SortedSet);o.push(l)},this);var a=o.reduce(function(t,e){return t.intersect(e)});return a.map(function(t){return{ref:t,score:i.similarity(this.documentVector(t))}},this).sort(function(t,e){return e.score-t.score})},t.Index.prototype.documentVector=function(e){for(var n=this.documentStore.get(e),i=n.length,o=new t.Vector,r=0;i>r;r++){var s=n.elements[r],a=this.tokenStore.get(s)[e].tf,h=this.idf(s);o.insert(this.corpusTokens.indexOf(s),a*h)}return o},t.Index.prototype.toJSON=function(){return{version:t.version,fields:this._fields,ref:this._ref,documentStore:this.documentStore.toJSON(),tokenStore:this.tokenStore.toJSON(),corpusTokens:this.corpusTokens.toJSON(),pipeline:this.pipeline.toJSON()}},t.Index.prototype.use=function(t){var e=Array.prototype.slice.call(arguments,1);e.unshift(this),t.apply(this,e)},t.Store=function(){this.store={},this.length=0},t.Store.load=function(e){var n=new this;return n.length=e.length,n.store=Object.keys(e.store).reduce(function(n,i){return n[i]=t.SortedSet.load(e.store[i]),n},{}),n},t.Store.prototype.set=function(t,e){this.has(t)||this.length++,this.store[t]=e},t.Store.prototype.get=function(t){return this.store[t]},t.Store.prototype.has=function(t){return t in this.store},t.Store.prototype.remove=function(t){this.has(t)&&(delete this.store[t],this.length--)},t.Store.prototype.toJSON=function(){return{store:this.store,length:this.length}},t.stemmer=function(){var t={ational:"ate",tional:"tion",enci:"ence",anci:"ance",izer:"ize",bli:"ble",alli:"al",entli:"ent",eli:"e",ousli:"ous",ization:"ize",ation:"ate",ator:"ate",alism:"al",iveness:"ive",fulness:"ful",ousness:"ous",aliti:"al",iviti:"ive",biliti:"ble",logi:"log"},e={icate:"ic",ative:"",alize:"al",iciti:"ic",ical:"ic",ful:"",ness:""},n="[^aeiou]",i="[aeiouy]",o=n+"[^aeiouy]*",r=i+"[aeiou]*",s="^("+o+")?"+r+o,a="^("+o+")?"+r+o+"("+r+")?$",h="^("+o+")?"+r+o+r+o,l="^("+o+")?"+i,u=new RegExp(s),c=new RegExp(h),f=new RegExp(a),d=new RegExp(l),p=/^(.+?)(ss|i)es$/,m=/^(.+?)([^s])s$/,v=/^(.+?)eed$/,y=/^(.+?)(ed|ing)$/,g=/.$/,S=/(at|bl|iz)$/,w=new RegExp("([^aeiouylsz])\\1$"),x=new RegExp("^"+o+i+"[^aeiouwxy]$"),k=/^(.+?[^aeiou])y$/,b=/^(.+?)(ational|tional|enci|anci|izer|bli|alli|entli|eli|ousli|ization|ation|ator|alism|iveness|fulness|ousness|aliti|iviti|biliti|logi)$/,E=/^(.+?)(icate|ative|alize|iciti|ical|ful|ness)$/,_=/^(.+?)(al|ance|ence|er|ic|able|ible|ant|ement|ment|ent|ou|ism|ate|iti|ous|ive|ize)$/,F=/^(.+?)(s|t)(ion)$/,O=/^(.+?)e$/,P=/ll$/,N=new RegExp("^"+o+i+"[^aeiouwxy]$"),T=function(n){var i,o,r,s,a,h,l;if(n.length<3)return n;if(r=n.substr(0,1),"y"==r&&(n=r.toUpperCase()+n.substr(1)),s=p,a=m,s.test(n)?n=n.replace(s,"$1$2"):a.test(n)&&(n=n.replace(a,"$1$2")),s=v,a=y,s.test(n)){var T=s.exec(n);s=u,s.test(T[1])&&(s=g,n=n.replace(s,""))}else if(a.test(n)){var T=a.exec(n);i=T[1],a=d,a.test(i)&&(n=i,a=S,h=w,l=x,a.test(n)?n+="e":h.test(n)?(s=g,n=n.replace(s,"")):l.test(n)&&(n+="e"))}if(s=k,s.test(n)){var T=s.exec(n);i=T[1],n=i+"i"}if(s=b,s.test(n)){var T=s.exec(n);i=T[1],o=T[2],s=u,s.test(i)&&(n=i+t[o])}if(s=E,s.test(n)){var T=s.exec(n);i=T[1],o=T[2],s=u,s.test(i)&&(n=i+e[o])}if(s=_,a=F,s.test(n)){var T=s.exec(n);i=T[1],s=c,s.test(i)&&(n=i)}else if(a.test(n)){var T=a.exec(n);i=T[1]+T[2],a=c,a.test(i)&&(n=i)}if(s=O,s.test(n)){var T=s.exec(n);i=T[1],s=c,a=f,h=N,(s.test(i)||a.test(i)&&!h.test(i))&&(n=i)}return s=P,a=c,s.test(n)&&a.test(n)&&(s=g,n=n.replace(s,"")),"y"==r&&(n=r.toLowerCase()+n.substr(1)),n};return T}(),t.Pipeline.registerFunction(t.stemmer,"stemmer"),t.stopWordFilter=function(e){return e&&t.stopWordFilter.stopWords[e]!==e?e:void 0},t.stopWordFilter.stopWords={a:"a",able:"able",about:"about",across:"across",after:"after",all:"all",almost:"almost",also:"also",am:"am",among:"among",an:"an",and:"and",any:"any",are:"are",as:"as",at:"at",be:"be",because:"because",been:"been",but:"but",by:"by",can:"can",cannot:"cannot",could:"could",dear:"dear",did:"did","do":"do",does:"does",either:"either","else":"else",ever:"ever",every:"every","for":"for",from:"from",get:"get",got:"got",had:"had",has:"has",have:"have",he:"he",her:"her",hers:"hers",him:"him",his:"his",how:"how",however:"however",i:"i","if":"if","in":"in",into:"into",is:"is",it:"it",its:"its",just:"just",least:"least",let:"let",like:"like",likely:"likely",may:"may",me:"me",might:"might",most:"most",must:"must",my:"my",neither:"neither",no:"no",nor:"nor",not:"not",of:"of",off:"off",often:"often",on:"on",only:"only",or:"or",other:"other",our:"our",own:"own",rather:"rather",said:"said",say:"say",says:"says",she:"she",should:"should",since:"since",so:"so",some:"some",than:"than",that:"that",the:"the",their:"their",them:"them",then:"then",there:"there",these:"these",they:"they","this":"this",tis:"tis",to:"to",too:"too",twas:"twas",us:"us",wants:"wants",was:"was",we:"we",were:"were",what:"what",when:"when",where:"where",which:"which","while":"while",who:"who",whom:"whom",why:"why",will:"will","with":"with",would:"would",yet:"yet",you:"you",your:"your"},t.Pipeline.registerFunction(t.stopWordFilter,"stopWordFilter"),t.trimmer=function(t){var e=t.replace(/^\W+/,"").replace(/\W+$/,"");return""===e?void 0:e},t.Pipeline.registerFunction(t.trimmer,"trimmer"),t.TokenStore=function(){this.root={docs:{}},this.length=0},t.TokenStore.load=function(t){var e=new this;return e.root=t.root,e.length=t.length,e},t.TokenStore.prototype.add=function(t,e,n){var n=n||this.root,i=t[0],o=t.slice(1);return i in n||(n[i]={docs:{}}),0===o.length?(n[i].docs[e.ref]=e,void(this.length+=1)):this.add(o,e,n[i])},t.TokenStore.prototype.has=function(t){if(!t)return!1;for(var e=this.root,n=0;n's that are truncated 95 | $('a').each(function(i, el) { 96 | if (el.offsetWidth >= el.scrollWidth) return; 97 | if (typeof el.title === 'undefined') return; 98 | el.title = el.text; 99 | }); 100 | 101 | // restore TOC scroll position 102 | var pos = gs.get('tocScrollTop'); 103 | if (typeof pos !== 'undefined') summary.scrollTop(pos); 104 | 105 | // highlight the TOC item that has same text as the heading in view as scrolling 106 | if (toc && toc.scroll_highlight !== false) (function() { 107 | // scroll the current TOC item into viewport 108 | var ht = $(window).height(), rect = li[0].getBoundingClientRect(); 109 | if (rect.top >= ht || rect.top <= 0 || rect.bottom <= 0) { 110 | summary.scrollTop(li[0].offsetTop); 111 | } 112 | // current chapter TOC items 113 | var items = $('a[href^="' + href + '"]').parent('li.chapter'), 114 | m = items.length; 115 | if (m === 0) { 116 | items = summary.find('li.chapter'); 117 | m = items.length; 118 | } 119 | if (m === 0) return; 120 | // all section titles on current page 121 | var hs = bookInner.find('.page-inner').find('h1,h2,h3'), n = hs.length, 122 | ts = hs.map(function(i, el) { return $(el).text(); }); 123 | if (n === 0) return; 124 | var scrollHandler = function(e) { 125 | var ht = $(window).height(); 126 | clearTimeout($.data(this, 'scrollTimer')); 127 | $.data(this, 'scrollTimer', setTimeout(function() { 128 | // find the first visible title in the viewport 129 | for (var i = 0; i < n; i++) { 130 | var rect = hs[i].getBoundingClientRect(); 131 | if (rect.top >= 0 && rect.bottom <= ht) break; 132 | } 133 | if (i === n) return; 134 | items.removeClass('active'); 135 | for (var j = 0; j < m; j++) { 136 | if (items.eq(j).children('a').first().text() === ts[i]) break; 137 | } 138 | if (j === m) j = 0; // highlight the chapter title 139 | // search bottom-up for a visible TOC item to highlight; if an item is 140 | // hidden, we check if its parent is visible, and so on 141 | while (j > 0 && items.eq(j).is(':hidden')) j--; 142 | items.eq(j).addClass('active'); 143 | }, 250)); 144 | }; 145 | bookInner.on('scroll.bookdown', scrollHandler); 146 | bookBody.on('scroll.bookdown', scrollHandler); 147 | })(); 148 | 149 | // do not refresh the page if the TOC item points to the current page 150 | $('a[href="' + href + '"]').parent('li.chapter').children('a') 151 | .on('click', function(e) { 152 | bookInner.scrollTop(0); 153 | bookBody.scrollTop(0); 154 | return false; 155 | }); 156 | 157 | var toolbar = config.toolbar; 158 | if (!toolbar || toolbar.position !== 'static') { 159 | var bookHeader = $('.book-header'); 160 | bookBody.addClass('fixed'); 161 | bookHeader.addClass('fixed') 162 | .css('background-color', bookBody.css('background-color')) 163 | .on('click.bookdown', function(e) { 164 | // the theme may have changed after user clicks the theme button 165 | bookHeader.css('background-color', bookBody.css('background-color')); 166 | }); 167 | } 168 | 169 | }); 170 | 171 | gitbook.events.bind("page.change", function(e) { 172 | // store TOC scroll position 173 | var summary = $('ul.summary'); 174 | gs.set('tocScrollTop', summary.scrollTop()); 175 | }); 176 | 177 | var bookBody = $('.book-body'), bookInner = bookBody.find('.body-inner'); 178 | var chapterTitle = function() { 179 | return bookInner.find('.page-inner').find('h1,h2').first().text(); 180 | }; 181 | var bookTitle = function() { 182 | return bookInner.find('.book-header > h1').first().text(); 183 | }; 184 | var saveScrollPos = function(e) { 185 | // save scroll position before page is reloaded 186 | gs.set('bodyScrollTop', { 187 | body: bookBody.scrollTop(), 188 | inner: bookInner.scrollTop(), 189 | focused: document.hasFocus(), 190 | title: chapterTitle() 191 | }); 192 | }; 193 | $(document).on('servr:reload', saveScrollPos); 194 | 195 | // check if the page is loaded in an iframe (e.g. the RStudio preview window) 196 | var inIFrame = function() { 197 | var inIframe = true; 198 | try { inIframe = window.self !== window.top; } catch (e) {} 199 | return inIframe; 200 | }; 201 | $(window).on('blur unload', function(e) { 202 | if (inIFrame()) saveScrollPos(e); 203 | gs.set('bookTitle', bookTitle()); 204 | }); 205 | 206 | $(function(e) { 207 | if (gs.get('bookTitle', '') !== bookTitle()) localStorage.clear(); 208 | var pos = gs.get('bodyScrollTop'); 209 | if (pos) { 210 | if (pos.title === chapterTitle()) { 211 | if (pos.body !== 0) bookBody.scrollTop(pos.body); 212 | if (pos.inner !== 0) bookInner.scrollTop(pos.inner); 213 | } 214 | if (pos.focused) bookInner.find('.page-wrapper').focus(); 215 | } 216 | // clear book body scroll position 217 | gs.remove('bodyScrollTop'); 218 | }); 219 | 220 | }); 221 | -------------------------------------------------------------------------------- /Py3_course/libs/gitbook-2.6.7/js/plugin-fontsettings.js: -------------------------------------------------------------------------------- 1 | gitbook.require(["gitbook", "lodash", "jQuery"], function(gitbook, _, $) { 2 | var fontState; 3 | 4 | var THEMES = { 5 | "white": 0, 6 | "sepia": 1, 7 | "night": 2 8 | }; 9 | 10 | var FAMILY = { 11 | "serif": 0, 12 | "sans": 1 13 | }; 14 | 15 | // Save current font settings 16 | function saveFontSettings() { 17 | gitbook.storage.set("fontState", fontState); 18 | update(); 19 | } 20 | 21 | // Increase font size 22 | function enlargeFontSize(e) { 23 | e.preventDefault(); 24 | if (fontState.size >= 4) return; 25 | 26 | fontState.size++; 27 | saveFontSettings(); 28 | }; 29 | 30 | // Decrease font size 31 | function reduceFontSize(e) { 32 | e.preventDefault(); 33 | if (fontState.size <= 0) return; 34 | 35 | fontState.size--; 36 | saveFontSettings(); 37 | }; 38 | 39 | // Change font family 40 | function changeFontFamily(index, e) { 41 | e.preventDefault(); 42 | 43 | fontState.family = index; 44 | saveFontSettings(); 45 | }; 46 | 47 | // Change type of color 48 | function changeColorTheme(index, e) { 49 | e.preventDefault(); 50 | 51 | var $book = $(".book"); 52 | 53 | if (fontState.theme !== 0) 54 | $book.removeClass("color-theme-"+fontState.theme); 55 | 56 | fontState.theme = index; 57 | if (fontState.theme !== 0) 58 | $book.addClass("color-theme-"+fontState.theme); 59 | 60 | saveFontSettings(); 61 | }; 62 | 63 | function update() { 64 | var $book = gitbook.state.$book; 65 | 66 | $(".font-settings .font-family-list li").removeClass("active"); 67 | $(".font-settings .font-family-list li:nth-child("+(fontState.family+1)+")").addClass("active"); 68 | 69 | $book[0].className = $book[0].className.replace(/\bfont-\S+/g, ''); 70 | $book.addClass("font-size-"+fontState.size); 71 | $book.addClass("font-family-"+fontState.family); 72 | 73 | if(fontState.theme !== 0) { 74 | $book[0].className = $book[0].className.replace(/\bcolor-theme-\S+/g, ''); 75 | $book.addClass("color-theme-"+fontState.theme); 76 | } 77 | }; 78 | 79 | function init(config) { 80 | var $bookBody, $book; 81 | 82 | //Find DOM elements. 83 | $book = gitbook.state.$book; 84 | $bookBody = $book.find(".book-body"); 85 | 86 | // Instantiate font state object 87 | fontState = gitbook.storage.get("fontState", { 88 | size: config.size || 2, 89 | family: FAMILY[config.family || "sans"], 90 | theme: THEMES[config.theme || "white"] 91 | }); 92 | 93 | update(); 94 | }; 95 | 96 | 97 | gitbook.events.bind("start", function(e, config) { 98 | var opts = config.fontsettings; 99 | 100 | // Create buttons in toolbar 101 | gitbook.toolbar.createButton({ 102 | icon: 'fa fa-font', 103 | label: 'Font Settings', 104 | className: 'font-settings', 105 | dropdown: [ 106 | [ 107 | { 108 | text: 'A', 109 | className: 'font-reduce', 110 | onClick: reduceFontSize 111 | }, 112 | { 113 | text: 'A', 114 | className: 'font-enlarge', 115 | onClick: enlargeFontSize 116 | } 117 | ], 118 | [ 119 | { 120 | text: 'Serif', 121 | onClick: _.partial(changeFontFamily, 0) 122 | }, 123 | { 124 | text: 'Sans', 125 | onClick: _.partial(changeFontFamily, 1) 126 | } 127 | ], 128 | [ 129 | { 130 | text: 'White', 131 | onClick: _.partial(changeColorTheme, 0) 132 | }, 133 | { 134 | text: 'Sepia', 135 | onClick: _.partial(changeColorTheme, 1) 136 | }, 137 | { 138 | text: 'Night', 139 | onClick: _.partial(changeColorTheme, 2) 140 | } 141 | ] 142 | ] 143 | }); 144 | 145 | 146 | // Init current settings 147 | init(opts); 148 | }); 149 | }); 150 | 151 | 152 | -------------------------------------------------------------------------------- /Py3_course/libs/gitbook-2.6.7/js/plugin-search.js: -------------------------------------------------------------------------------- 1 | gitbook.require(["gitbook", "lodash", "jQuery"], function(gitbook, _, $) { 2 | var index = null; 3 | var $searchInput, $searchForm; 4 | var $highlighted, hi = 0, hiOpts = { className: 'search-highlight' }; 5 | var collapse = false; 6 | 7 | // Use a specific index 8 | function loadIndex(data) { 9 | // [Yihui] In bookdown, I use a character matrix to store the chapter 10 | // content, and the index is dynamically built on the client side. 11 | // Gitbook prebuilds the index data instead: https://github.com/GitbookIO/plugin-search 12 | // We can certainly do that via R packages V8 and jsonlite, but let's 13 | // see how slow it really is before improving it. On the other hand, 14 | // lunr cannot handle non-English text very well, e.g. the default 15 | // tokenizer cannot deal with Chinese text, so we may want to replace 16 | // lunr with a dumb simple text matching approach. 17 | index = lunr(function () { 18 | this.ref('url'); 19 | this.field('title', { boost: 10 }); 20 | this.field('body'); 21 | }); 22 | data.map(function(item) { 23 | index.add({ 24 | url: item[0], 25 | title: item[1], 26 | body: item[2] 27 | }); 28 | }); 29 | } 30 | 31 | // Fetch the search index 32 | function fetchIndex() { 33 | return $.getJSON(gitbook.state.basePath+"/search_index.json") 34 | .then(loadIndex); // [Yihui] we need to use this object later 35 | } 36 | 37 | // Search for a term and return results 38 | function search(q) { 39 | if (!index) return; 40 | 41 | var results = _.chain(index.search(q)) 42 | .map(function(result) { 43 | var parts = result.ref.split("#"); 44 | return { 45 | path: parts[0], 46 | hash: parts[1] 47 | }; 48 | }) 49 | .value(); 50 | 51 | // [Yihui] Highlight the search keyword on current page 52 | hi = 0; 53 | $highlighted = results.length === 0 ? undefined : $('.page-inner') 54 | .unhighlight(hiOpts).highlight(q, hiOpts).find('span.search-highlight'); 55 | scrollToHighlighted(); 56 | toggleTOC(results.length > 0); 57 | 58 | return results; 59 | } 60 | 61 | // [Yihui] Scroll the chapter body to the i-th highlighted string 62 | function scrollToHighlighted() { 63 | if (!$highlighted) return; 64 | var n = $highlighted.length; 65 | if (n === 0) return; 66 | var $p = $highlighted.eq(hi), p = $p[0], rect = p.getBoundingClientRect(); 67 | if (rect.top < 0 || rect.bottom > $(window).height()) { 68 | ($(window).width() >= 1240 ? $('.body-inner') : $('.book-body')) 69 | .scrollTop(p.offsetTop - 100); 70 | } 71 | $highlighted.css('background-color', ''); 72 | // an orange background color on the current item and removed later 73 | $p.css('background-color', 'orange'); 74 | setTimeout(function() { 75 | $p.css('background-color', ''); 76 | }, 2000); 77 | } 78 | 79 | // [Yihui] Expand/collapse TOC 80 | function toggleTOC(show) { 81 | if (!collapse) return; 82 | var toc_sub = $('ul.summary').children('li[data-level]').children('ul'); 83 | if (show) return toc_sub.show(); 84 | var href = window.location.pathname; 85 | href = href.substr(href.lastIndexOf('/') + 1); 86 | if (href === '') href = 'index.html'; 87 | var li = $('a[href^="' + href + location.hash + '"]').parent('li.chapter').first(); 88 | toc_sub.hide().parent().has(li).children('ul').show(); 89 | li.children('ul').show(); 90 | } 91 | 92 | // Create search form 93 | function createForm(value) { 94 | if ($searchForm) $searchForm.remove(); 95 | if ($searchInput) $searchInput.remove(); 96 | 97 | $searchForm = $('
', { 98 | 'class': 'book-search', 99 | 'role': 'search' 100 | }); 101 | 102 | $searchInput = $('', { 103 | 'type': 'search', 104 | 'class': 'form-control', 105 | 'val': value, 106 | 'placeholder': 'Type to search' 107 | }); 108 | 109 | $searchInput.appendTo($searchForm); 110 | $searchForm.prependTo(gitbook.state.$book.find('.book-summary')); 111 | } 112 | 113 | // Return true if search is open 114 | function isSearchOpen() { 115 | return gitbook.state.$book.hasClass("with-search"); 116 | } 117 | 118 | // Toggle the search 119 | function toggleSearch(_state) { 120 | if (isSearchOpen() === _state) return; 121 | if (!$searchInput) return; 122 | 123 | gitbook.state.$book.toggleClass("with-search", _state); 124 | 125 | // If search bar is open: focus input 126 | if (isSearchOpen()) { 127 | gitbook.sidebar.toggle(true); 128 | $searchInput.focus(); 129 | } else { 130 | $searchInput.blur(); 131 | $searchInput.val(""); 132 | gitbook.storage.remove("keyword"); 133 | gitbook.sidebar.filter(null); 134 | $('.page-inner').unhighlight(hiOpts); 135 | toggleTOC(false); 136 | } 137 | } 138 | 139 | // Recover current search when page changed 140 | function recoverSearch() { 141 | var keyword = gitbook.storage.get("keyword", ""); 142 | 143 | createForm(keyword); 144 | 145 | if (keyword.length > 0) { 146 | if(!isSearchOpen()) { 147 | toggleSearch(true); // [Yihui] open the search box 148 | } 149 | gitbook.sidebar.filter(_.pluck(search(keyword), "path")); 150 | } 151 | } 152 | 153 | 154 | gitbook.events.bind("start", function(e, config) { 155 | // [Yihui] disable search 156 | if (config.search === false) return; 157 | collapse = !config.toc || config.toc.collapse === 'section' || 158 | config.toc.collapse === 'subsection'; 159 | 160 | // Pre-fetch search index and create the form 161 | fetchIndex() 162 | // [Yihui] recover search after the page is loaded 163 | .then(recoverSearch); 164 | 165 | 166 | // Type in search bar 167 | $(document).on("keyup", ".book-search input", function(e) { 168 | var key = (e.keyCode ? e.keyCode : e.which); 169 | // [Yihui] Escape -> close search box; Up/Down: previous/next highlighted 170 | if (key == 27) { 171 | e.preventDefault(); 172 | toggleSearch(false); 173 | } else if (key == 38) { 174 | if (hi <= 0 && $highlighted) hi = $highlighted.length; 175 | hi--; 176 | scrollToHighlighted(); 177 | } else if (key == 40) { 178 | hi++; 179 | if ($highlighted && hi >= $highlighted.length) hi = 0; 180 | scrollToHighlighted(); 181 | } 182 | }).on("input", ".book-search input", function(e) { 183 | var q = $(this).val().trim(); 184 | if (q.length === 0) { 185 | gitbook.sidebar.filter(null); 186 | gitbook.storage.remove("keyword"); 187 | $('.page-inner').unhighlight(hiOpts); 188 | toggleTOC(false); 189 | } else { 190 | var results = search(q); 191 | gitbook.sidebar.filter( 192 | _.pluck(results, "path") 193 | ); 194 | gitbook.storage.set("keyword", q); 195 | } 196 | }); 197 | 198 | // Create the toggle search button 199 | gitbook.toolbar.createButton({ 200 | icon: 'fa fa-search', 201 | label: 'Search', 202 | position: 'left', 203 | onClick: toggleSearch 204 | }); 205 | 206 | // Bind keyboard to toggle search 207 | gitbook.keyboard.bind(['f'], toggleSearch); 208 | }); 209 | 210 | // [Yihui] do not try to recover search; always start fresh 211 | // gitbook.events.bind("page.change", recoverSearch); 212 | }); 213 | -------------------------------------------------------------------------------- /Py3_course/libs/gitbook-2.6.7/js/plugin-sharing.js: -------------------------------------------------------------------------------- 1 | gitbook.require(["gitbook", "lodash", "jQuery"], function(gitbook, _, $) { 2 | var SITES = { 3 | 'github': { 4 | 'label': 'Github', 5 | 'icon': 'fa fa-github', 6 | 'onClick': function(e) { 7 | e.preventDefault(); 8 | var repo = $('meta[name="github-repo"]').attr('content'); 9 | if (typeof repo === 'undefined') throw("Github repo not defined"); 10 | window.open("https://github.com/"+repo); 11 | } 12 | }, 13 | 'facebook': { 14 | 'label': 'Facebook', 15 | 'icon': 'fa fa-facebook', 16 | 'onClick': function(e) { 17 | e.preventDefault(); 18 | window.open("http://www.facebook.com/sharer/sharer.php?s=100&p[url]="+encodeURIComponent(location.href)); 19 | } 20 | }, 21 | 'twitter': { 22 | 'label': 'Twitter', 23 | 'icon': 'fa fa-twitter', 24 | 'onClick': function(e) { 25 | e.preventDefault(); 26 | window.open("http://twitter.com/home?status="+encodeURIComponent(document.title+" "+location.href)); 27 | } 28 | }, 29 | 'google': { 30 | 'label': 'Google+', 31 | 'icon': 'fa fa-google-plus', 32 | 'onClick': function(e) { 33 | e.preventDefault(); 34 | window.open("https://plus.google.com/share?url="+encodeURIComponent(location.href)); 35 | } 36 | }, 37 | 'weibo': { 38 | 'label': 'Weibo', 39 | 'icon': 'fa fa-weibo', 40 | 'onClick': function(e) { 41 | e.preventDefault(); 42 | window.open("http://service.weibo.com/share/share.php?content=utf-8&url="+encodeURIComponent(location.href)+"&title="+encodeURIComponent(document.title)); 43 | } 44 | }, 45 | 'instapaper': { 46 | 'label': 'Instapaper', 47 | 'icon': 'fa fa-instapaper', 48 | 'onClick': function(e) { 49 | e.preventDefault(); 50 | window.open("http://www.instapaper.com/text?u="+encodeURIComponent(location.href)); 51 | } 52 | }, 53 | 'vk': { 54 | 'label': 'VK', 55 | 'icon': 'fa fa-vk', 56 | 'onClick': function(e) { 57 | e.preventDefault(); 58 | window.open("http://vkontakte.ru/share.php?url="+encodeURIComponent(location.href)); 59 | } 60 | } 61 | }; 62 | 63 | 64 | 65 | gitbook.events.bind("start", function(e, config) { 66 | var opts = config.sharing; 67 | if (!opts) return; 68 | 69 | // Create dropdown menu 70 | var menu = _.chain(opts.all) 71 | .map(function(id) { 72 | var site = SITES[id]; 73 | 74 | return { 75 | text: site.label, 76 | onClick: site.onClick 77 | }; 78 | }) 79 | .compact() 80 | .value(); 81 | 82 | // Create main button with dropdown 83 | if (menu.length > 0) { 84 | gitbook.toolbar.createButton({ 85 | icon: 'fa fa-share-alt', 86 | label: 'Share', 87 | position: 'right', 88 | dropdown: [menu] 89 | }); 90 | } 91 | 92 | // Direct actions to share 93 | _.each(SITES, function(site, sideId) { 94 | if (!opts[sideId]) return; 95 | 96 | gitbook.toolbar.createButton({ 97 | icon: site.icon, 98 | label: site.text, 99 | position: 'right', 100 | onClick: site.onClick 101 | }); 102 | }); 103 | }); 104 | }); 105 | -------------------------------------------------------------------------------- /Py3_course/pyre.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tong-Chen/Bioinfo_course_python/f03b9ee0684eb2417b70378794ba1ea23ee39006/Py3_course/pyre.png -------------------------------------------------------------------------------- /Py3_course/style.css: -------------------------------------------------------------------------------- 1 | 2 | p.caption { 3 | color: #777; 4 | margin-top: 10px; 5 | text-align: justify; 6 | } 7 | p code { 8 | white-space: inherit; 9 | } 10 | pre { 11 | word-break: normal; 12 | word-wrap: normal; 13 | } 14 | pre code { 15 | white-space: inherit; 16 | } 17 | 18 | body { 19 | text-align: justify; 20 | } 21 | 22 | .book .book-body .page-wrapper .page-inner section.normal table { 23 | display: block; 24 | overflow: auto; 25 | width: 100%; 26 | } 27 | 28 | .book .book-body .page-wrapper .page-inner section.normal caption { 29 | text-align: justify; 30 | width:100%; 31 | } 32 | 33 | .book .book-body .page-wrapper .page-inner section.normal table th { 34 | font-size: 70%; 35 | } 36 | 37 | .book .book-body .page-wrapper .page-inner section.normal table td { 38 | font-size: 70%; 39 | } 40 | 41 | .book .book-body .page-wrapper .page-inner section.normal ol { 42 | padding: 0 0 0 1em; 43 | } 44 | 45 | -------------------------------------------------------------------------------- /Python_course.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tong-Chen/Bioinfo_course_python/f03b9ee0684eb2417b70378794ba1ea23ee39006/Python_course.png -------------------------------------------------------------------------------- /Python_start_run_linux.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tong-Chen/Bioinfo_course_python/f03b9ee0684eb2417b70378794ba1ea23ee39006/Python_start_run_linux.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 生信的作用越来越大,想学的人越来越多,不管是为了以后发展,还是为了解决眼下的问题。但生信学习不是一朝一夕就可以完成的事情,也许你可以很短时间学会一个交互式软件的操作,却不能看完程序教学视频后就直接写程序。也许你可以跟着一个测序分析流程完成操作,但不懂得背后的原理,不知道什么参数需要修改,结果可以出来,却把握不住对还是错。 2 | 3 | 学习生信从来就不是一个简单的事,需要做好持久战的心理准备。 4 | 5 | 在学习时,我们都希望由浅入深的逐步深入,不断地练习和实践,这就是为什么我们需要一本书,因为书很系统。但生信发展的历史短于计算机编程的历史,如果想要一门程序设计的入门数据,每种语言都可以找到几本。但想要一个囊括生信的书,就有些难了。本身生信跨领域,需要多学科的知识,而其内部又有不少分子,都囊括了太大,包括的少又有些隔靴搔痒的感觉。 6 | 7 | 我们当时都是零基础下自学Linux, 自学Python,自学R,自学高通量测序;这些学习经历,之前都零星地记录在博客里。现在回头去看几年前自己记录的东西,觉得好简单,而当时却费了很大的力气。这些零星的随手记,当时也只是为了自己看,到现在确实只有自己能看得懂,不便惠及更多的人。 8 | 9 | 因此我们创建了生信宝典,希望从不同的角度传播知识。这个不同有三点含义,一是形式上的不同,摒弃之前主编们单人作战想写啥就写啥,而是有组织有计划的内容聚合,提供一系列的教程,由入门到提高。二是内容的不同,不去用网上现有教程的通用数据做例子,而是拿实际生物数据,讲述如何解释生信中普遍碰到的问题,讲述如何处理自己的数据。三是立足点不同。在写作时,我们回到了当年,在回忆中用整个阶段的学习去指导当初的那个小白,从那些会了的人觉得微不足道而不会的人又迈不过的坎入手,直击痛点。知识点的收录依据不是是否炫酷,是否难,而是是否必要。如果必要,再简单,也要提及;如果不必要,再炫酷,也暂不纳入。 10 | 11 | 通过大量的生信例子、关键的注释和浓缩的语句形成下面的一系列学习教程。每一篇内容都不多,可以当做小说阅读,也可以跟着去练,反复几遍,每读一次都会有不同的收获和体会。 12 | 13 | ### Python教程 14 | 15 | 16 | 17 | * [Python极简教程(一)](https://mp.weixin.qq.com/s/9BNrq8Lu7hjtO2BAKOIXOA) 18 | * [Python极简教程(二)](https://mp.weixin.qq.com/s/UyohxmUILG_0smL3cd62xg) 19 | * [Python极简教程(三)](https://mp.weixin.qq.com/s/H-WexJvXsS93al9UyO8_mw) 20 | * [Python极简教程(四)](https://mp.weixin.qq.com/s/478DiO0RdO9zEGSZ0NzsiA) 21 | * [Python极简教程(五)](https://mp.weixin.qq.com/s/4EVPYbSGsivGAB6bKdtWXQ) 22 | * [Python极简教程(六)](https://mp.weixin.qq.com/s/PMSFfScdG5uvZ0u8KHNncA) 23 | * [Pandas,让Python像R一样处理数据,但快](https://mp.weixin.qq.com/s/1h-_J2NKjD1KyymPAeHPOg) 24 | * [Python解析psiBlast输出的JSON文件结果](http://mp.weixin.qq.com/s/BN6u2aJkoMzffPv7rvbm8g) 25 | * [为啥我的Python这么慢 - 字符串连接 (一)](https://mp.weixin.qq.com/s/n5kkZfC8FGlzeBODarLHcw) 26 | * [为啥我的Python这么慢 - 项查找 (二)](http://mp.weixin.qq.com/s/-0UTgmdRQbF7I4fib62ooA) 27 | * [Python学习 - 可视化变量赋值、循环、程序运行过程](https://mp.weixin.qq.com/s/zhr251PCTDGBO1YxYB-P6Q) 28 | * [Python资源](http://mp.weixin.qq.com/s/1JlAROpOCBwaG574EwvkVw) 29 | * [关于Python中的__main__和编程模板](http://mp.weixin.qq.com/s/JHDvdqq3Z-7uDmsyroblNQ) 30 | * [莫烦Python机器学习](https://mp.weixin.qq.com/s/pXiV_cRZD8iu4jLAFMYPew) 31 | * [编程新手入门踩过的25个“坑”,你犯过其中哪些错误?](https://mp.weixin.qq.com/s/C19yj-p67FsDDe2LvApdHQ) 32 | * [Python文学化编程 - Jupyter notebook使用和插件拓展](https://mp.weixin.qq.com/s/mbJWNZr7rrJqQYCg2Wx_WA) 33 | * [Python3中正则表达式使用方法](https://mp.weixin.qq.com/s/3r0geQASuWI2e0Jj3WwxpQ) 34 | * [Python3中BeautifulSoup的使用方法](https://mp.weixin.qq.com/s/qZCQAuSM5mZbUyfam-2T0w) 35 | * [我用Python开发了个SCI-HUB本地版](https://mp.weixin.qq.com/s/TtW44gSRR5aDdAy1lARMjw) 36 | * [手把手 哇!用R也可以跑Python了](https://mp.weixin.qq.com/s/UIpGD7YF8kAaqluBoe8iWA) 37 | * [Bioconda软件安装神器:多版本并存、环境复制、环境导出](https://mp.weixin.qq.com/s/XZf652njPMg9qUTjcVCMgQ) 38 | * [还在用PCA降维?快学学大牛最爱的t-SNE算法吧, 附Python/R代码](https://mp.weixin.qq.com/s?__biz=MzI5MTcwNjA4NQ==&mid=2247484978&idx=1&sn=07b7f734ad0ad44562186c1ef3663057&scene=21#wechat_redirect) 39 | * [Python没有捷径,但可以加速,零基础九天你也可以会编程](http://mp.weixin.qq.com/s?__biz=MzI5MTcwNjA4NQ==&mid=2247484825&idx=1&sn=fb419aa1a9c4b03b8c406544ba31163c&scene=21#wechat_redirect) 40 | * [小学生都学Python了,你还不知道怎么开始*资源帖](http://mp.weixin.qq.com/s?__biz=MzI5MTcwNjA4NQ==&mid=2247484807&idx=1&sn=0a638f85a7dade1cce3c1759c30cb545&scene=21#wechat_redirect) 41 | * [一个月学会Python的Quora指南和资料放送](http://mp.weixin.qq.com/s?__biz=MzI5MTcwNjA4NQ==&mid=2247484807&idx=1&sn=0a638f85a7dade1cce3c1759c30cb545&scene=21#wechat_redirect) 42 | * [推荐一个牛逼的生物信息 Python 库 - Dash Bio](https://mp.weixin.qq.com/s/DQbtuvWkfpbyWogwxxIwHg) 43 | * [Matplotlib绘制的27个常用图(附对应代码实现)](https://mp.weixin.qq.com/s/W8GoPqkZiyjBSLIJDv8isw) 44 | * [Python语法糖之:列表解析、集合解析和字典解析](https://mp.weixin.qq.com/s/5r_nBSOxC-XvOeZakXsOsw) 45 | * [入门课的入门课,微软推出Python零基础教程,基于原生VS Code](https://mp.weixin.qq.com/s/F2DQpAE8FO0X9PLLiTptvw) 46 | 47 | ![](http://www.ehbio.com/ehbio_resource/Python_course.png) 48 | 49 | 视频课程地址: 50 | -------------------------------------------------------------------------------- /_bookdown.yml: -------------------------------------------------------------------------------- 1 | book_filename: "Py3_course" 2 | output_dir: "Py3_course" 3 | delete_merged_file: true 4 | language: 5 | ui: 6 | chapter_name: "" 7 | -------------------------------------------------------------------------------- /_output.yml: -------------------------------------------------------------------------------- 1 | bookdown::pdf_book: 2 | template: ehbio/ehbio.latex 3 | latex_engine: xelatex 4 | citation_package: natbib 5 | keep_tex: yes 6 | toc_unnumbered: no 7 | toc_depth: 3 8 | bookdown::epub_book: default 9 | bookdown::gitbook: 10 | css: style.css 11 | config: 12 | download: [pdf] 13 | toc: 14 | before: | 15 |
  • 16 | after: | 17 |
  • ct@ehbio.com
  • 18 | sharing: 19 | github: no 20 | facebook: no 21 | twitter: no 22 | -------------------------------------------------------------------------------- /coding_is_hard_confidence_competence.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tong-Chen/Bioinfo_course_python/f03b9ee0684eb2417b70378794ba1ea23ee39006/coding_is_hard_confidence_competence.png -------------------------------------------------------------------------------- /ehbio/company_1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tong-Chen/Bioinfo_course_python/f03b9ee0684eb2417b70378794ba1ea23ee39006/ehbio/company_1.pdf -------------------------------------------------------------------------------- /ehbio/company_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tong-Chen/Bioinfo_course_python/f03b9ee0684eb2417b70378794ba1ea23ee39006/ehbio/company_1.png -------------------------------------------------------------------------------- /ehbio/company_2.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tong-Chen/Bioinfo_course_python/f03b9ee0684eb2417b70378794ba1ea23ee39006/ehbio/company_2.pdf -------------------------------------------------------------------------------- /ehbio/company_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tong-Chen/Bioinfo_course_python/f03b9ee0684eb2417b70378794ba1ea23ee39006/ehbio/company_2.png -------------------------------------------------------------------------------- /ehbio/cover.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tong-Chen/Bioinfo_course_python/f03b9ee0684eb2417b70378794ba1ea23ee39006/ehbio/cover.pdf -------------------------------------------------------------------------------- /ehbio/cover.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tong-Chen/Bioinfo_course_python/f03b9ee0684eb2417b70378794ba1ea23ee39006/ehbio/cover.png -------------------------------------------------------------------------------- /ehbio/ehbio.latex: -------------------------------------------------------------------------------- 1 | \documentclass[$if(fontsize)$$fontsize$,$endif$$if(lang)$$lang$,$endif$$if(papersize)$$papersize$,$endif$]{$documentclass$} 2 | \usepackage{booktabs} 3 | \usepackage{geometry} % 設定邊界 4 | \geometry{ 5 | top=1in, 6 | inner=0.6in, 7 | outer=0.6in, 8 | bottom=0.6in, 9 | headheight=3ex, 10 | headsep=2ex 11 | } 12 | \errorcontextlines 10000 13 | \usepackage{titlesec} 14 | \newcommand{\sectionbreak}{\clearpage} 15 | 16 | \usepackage[section]{placeins} 17 | \usepackage{float} 18 | % set table unfloat 19 | \usepackage{varioref} 20 | 21 | % set table font size 22 | \usepackage[font=normalsize]{caption} %% make caption in normal size 23 | \usepackage{etoolbox} 24 | \AtBeginEnvironment{longtable}{\footnotesize}{}{} %% change all longtabu content to foot note size > 25 | 26 | %\renewcommand{\topfraction}{0.9} % max fraction of floats at top 27 | %\renewcommand{\bottomfraction}{0.8} % max fraction of floats at bottom 28 | % Parameters for TEXT pages (not float pages): 29 | %\setcounter{topnumber}{2} 30 | %\setcounter{bottomnumber}{2} 31 | %\setcounter{totalnumber}{4} % 2 may work better 32 | %\setcounter{dbltopnumber}{2} % for 2-column pages 33 | %\renewcommand{\dbltopfraction}{0.9} % fit big float above 2-col. text 34 | %\renewcommand{\textfraction}{0.07} % allow minimal text w. figs 35 | % Parameters for FLOAT pages (not text pages): 36 | %\renewcommand{\floatpagefraction}{0.7} % require fuller float pages 37 | % N.B.: floatpagefraction MUST be less than topfraction !! 38 | %\renewcommand{\dblfloatpagefraction}{0.7} % require fuller float pages 39 | 40 | 41 | 42 | \usepackage[T1]{fontenc} 43 | \usepackage{lmodern} 44 | \usepackage{amssymb,amsmath} 45 | \usepackage{ifxetex,ifluatex} 46 | \usepackage{fixltx2e} % provides \textsubscript 47 | % use upquote if available, for straight quotes in verbatim environments 48 | \IfFileExists{upquote.sty}{\usepackage{upquote}}{} 49 | \ifnum 0\ifxetex 1\fi\ifluatex 1\fi=0 % if pdftex 50 | \usepackage[utf8]{inputenc} 51 | $if(euro)$ 52 | \usepackage{eurosym} 53 | $endif$ 54 | \else % if luatex or xelatex 55 | \usepackage{fontspec} % 允許設定字體 56 | \usepackage{xeCJK} % 分開設置中英文字型 57 | %\setCJKmainfont{Microsoft YaHei} % 設定中文字型 58 | \setCJKmainfont{WenQuanYi Zen Hei} % 設定中文字型 59 | \setmainfont{Arial} % 設定英文字型 60 | \setromanfont{Arial} % 字型 61 | \setmonofont{Courier New} 62 | \linespread{1.2}\selectfont % 行距 63 | \XeTeXlinebreaklocale "zh" % 針對中文自動換行 64 | \XeTeXlinebreakskip = 0pt plus 1pt % 字與字之間加入0pt至1pt的間距,確保左右對整齊 65 | \parindent 0em % 段落縮進 66 | \setlength{\parskip}{20pt} % 段落之間的距離 67 | \ifxetex 68 | \usepackage{xltxtra,xunicode} 69 | \fi 70 | \defaultfontfeatures{Mapping=tex-text,Scale=MatchLowercase} 71 | \newcommand{\euro}{€} 72 | $if(mainfont)$ 73 | \setmainfont{$mainfont$} 74 | $endif$ 75 | $if(sansfont)$ 76 | \setsansfont{$sansfont$} 77 | $endif$ 78 | $if(monofont)$ 79 | \setmonofont{$monofont$} 80 | $endif$ 81 | $if(mathfont)$ 82 | \setmathfont{$mathfont$} 83 | $endif$ 84 | \fi 85 | % use microtype if available 86 | \IfFileExists{microtype.sty}{\usepackage{microtype}}{} 87 | $if(geometry)$ 88 | \usepackage[$for(geometry)$$geometry$$sep$,$endfor$]{geometry} 89 | $endif$ 90 | $if(natbib)$ 91 | \usepackage{natbib} 92 | \bibliographystyle{$if(biblio-style)$$biblio-style$$else$plainnat$endif$} 93 | $endif$ 94 | 95 | $if(biblatex)$ 96 | \usepackage[$if(biblio-style)$style=$biblio-style$,$endif$$for(biblatexoptions)$$biblatexoptions$$sep$,$endfor$]{biblatex} 97 | $for(bibliography)$ 98 | \addbibresource{$bibliography$} 99 | $endfor$ 100 | $endif$ 101 | 102 | 103 | $if(listings)$ 104 | \usepackage{listings} 105 | $endif$ 106 | $if(lhs)$ 107 | \lstnewenvironment{code}{\lstset{language=bash,basicstyle=\ttfamily\tiny, breaklines=true}}{} 108 | $endif$ 109 | $if(highlighting-macros)$ 110 | $highlighting-macros$ 111 | $endif$ 112 | $if(verbatim-in-note)$ 113 | \usepackage{fancyvrb} 114 | $endif$ 115 | $if(tables)$ 116 | \usepackage{longtable,booktabs} 117 | $endif$ 118 | \let\Oldincludegraphics\includegraphics 119 | $if(graphics)$ 120 | \usepackage{graphicx} 121 | % We will generate all images so they have a width \maxwidth. This means 122 | % that they will get their normal width if they fit onto the page, but 123 | % are scaled down if they would overflow the margins. 124 | \makeatletter 125 | \def\maxwidth{\ifdim\Gin@nat@width>\linewidth\linewidth 126 | \else\Gin@nat@width\fi} 127 | \makeatother 128 | \let\Oldincludegraphics\includegraphics 129 | %\renewcommand{\includegraphics}[1]{\Oldincludegraphics[width=0.7\maxwidth,height=0.8\textheight,keepaspectratio=true]{#1}} 130 | $endif$ 131 | \ifxetex 132 | \usepackage[setpagesize=false, % page size defined by xetex 133 | unicode=false, % unicode breaks when used with xetex 134 | xetex]{hyperref} 135 | \else 136 | \usepackage[unicode=true]{hyperref} 137 | \fi 138 | \hypersetup{breaklinks=true, 139 | bookmarks=true, 140 | pdfauthor={$author-meta$}, 141 | pdftitle={$title-meta$}, 142 | colorlinks=true, 143 | urlcolor=$if(urlcolor)$$urlcolor$$else$blue$endif$, 144 | linkcolor=$if(linkcolor)$$linkcolor$$else$magenta$endif$, 145 | filecolor=green, 146 | pdfcreator={Chen Tong} 147 | pdfborder={0 0 0}} 148 | \urlstyle{same} % don't use monospace font for urls 149 | $if(links-as-notes)$ 150 | % Make links footnotes instead of hotlinks: 151 | \renewcommand{\href}[2]{#2\footnote{\url{#1}}} 152 | $endif$ 153 | $if(strikeout)$ 154 | \usepackage[normalem]{ulem} 155 | % avoid problems with \sout in headers with hyperref: 156 | \pdfstringdefDisableCommands{\renewcommand{\sout}{}} 157 | $endif$ 158 | \setlength{\parindent}{0pt} 159 | %\setlength{\parskip}{6pt plus 2pt minus 1pt} 160 | \setlength{\emergencystretch}{3em} % prevent overfull lines 161 | \providecommand{\tightlist}{% 162 | \setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}} 163 | 164 | \usepackage{titling} 165 | \setlength{\droptitle}{-8em} % 將標題移動至頁面的上面 166 | 167 | % Remove list identation 168 | \usepackage{enumitem} 169 | \setlist[itemize]{leftmargin=*} 170 | \setlist[enumerate]{leftmargin=*} 171 | 172 | % FIgure with section number 173 | \usepackage{amsmath} 174 | \numberwithin{figure}{section} 175 | \numberwithin{table}{section} 176 | 177 | 178 | \usepackage{fancyhdr} 179 | \usepackage{lastpage} 180 | \pagestyle{fancyplain} 181 | 182 | $if(numbersections)$ 183 | \setcounter{secnumdepth}{5} 184 | $else$ 185 | \setcounter{secnumdepth}{0} 186 | $endif$ 187 | $if(verbatim-in-note)$ 188 | \VerbatimFootnotes % allows verbatim text in footnotes 189 | $endif$ 190 | $if(lang)$ 191 | \ifxetex 192 | \usepackage{polyglossia} 193 | \setmainlanguage{$mainlang$} 194 | \else 195 | \usepackage[$lang$]{babel} 196 | \fi 197 | $endif$ 198 | $for(header-includes)$ 199 | $header-includes$ 200 | $endfor$ 201 | 202 | %\renewcommand{\sectionmark}[1]{\markboth{#1}} % set the \leftmark 203 | 204 | %\setlength{\headheight}{23pt} 205 | \fancypagestyle{plain}{ 206 | \fancyhf{} 207 | \renewcommand{\headrulewidth}{0pt} 208 | } 209 | \fancyhf{} 210 | \fancyhead[L]{\leftmark} 211 | %\fancyhead[C]{www.ehbio.com} 212 | \fancyhead[R]{ 213 | \href{http://www.ehbio.com}{\Oldincludegraphics[width=6cm]{/MPATHB/self/pandoc/ehbio_logo.png}} 214 | } 215 | \fancyfoot[R]{\thepage} 216 | 217 | %\pagestyle{plain} 218 | $if(title)$ 219 | %\titlehead{\centering\includegraphics{/MPATHB/self/pandoc/ehbio_logo.png}} 220 | \title{$title$$if(subtitle)$\\\vsapce{0.5em}{\large $subtitle$}$endif$} 221 | $endif$ 222 | \author{$for(author)$$author$\\\\ $endfor$} 223 | \date{$date$}% \\\\ 224 | 225 | %multidor pic 226 | \usepackage[multidot]{grffile} 227 | 228 | \begin{document} 229 | $if(title)$ 230 | %\maketitle 231 | %{\scshape\LARGE 易汉博基因科技(北京)有限公司 \par} 232 | 233 | \begin{titlepage} 234 | \centering{ 235 | 236 | \Oldincludegraphics[width=0.8\textwidth]{/MPATHB/self/pandoc/ehbio_logo.png} 237 | 238 | 239 | \vspace{4cm} 240 | 241 | {\Huge\bfseries $title$ \par} 242 | 243 | \vspace{4cm} 244 | } 245 | \begin{minipage}{0.8\linewidth} 246 | %\centering{ 247 | %\begin{flushleft} 248 | $if(subtitle)${\scshape\huge $subtitle$ \par}$endif$ 249 | 250 | \vspace{0.5cm} 251 | $for(author)$ 252 | {\scshape\huge $author$ \par} 253 | \vspace{0.3cm} 254 | $endfor$ 255 | %\end{flushleft} 256 | %} 257 | \end{minipage} 258 | 259 | \centering{ 260 | \vfill 261 | {\LARGE $date$\par} 262 | } 263 | \end{titlepage} 264 | %\thispagestyle{fancy} 265 | $endif$ 266 | 267 | $for(include-before)$ 268 | $include-before$ 269 | 270 | $endfor$ 271 | $if(toc)$ 272 | { 273 | \hypersetup{linkcolor=cyan} 274 | \setcounter{tocdepth}{$toc-depth$} 275 | \tableofcontents 276 | } 277 | $endif$ 278 | $body$ 279 | 280 | 281 | 282 | $if(natbib)$ 283 | $if(bibliography)$ 284 | $if(biblio-title)$ 285 | $if(book-class)$ 286 | \renewcommand\bibname{$biblio-title$} 287 | $else$ 288 | \renewcommand\refname{$biblio-title$} 289 | $endif$ 290 | $endif$ 291 | \bibliography{$for(bibliography)$$bibliography$$sep$,$endfor$} 292 | 293 | $endif$ 294 | $endif$ 295 | $if(biblatex)$ 296 | \printbibliography$if(biblio-title)$[title=$biblio-title$]$endif$ 297 | 298 | $endif$ 299 | 300 | 301 | 302 | $for(include-after)$ 303 | $include-after$ 304 | 305 | $endfor$ 306 | \end{document} 307 | 308 | -------------------------------------------------------------------------------- /ehbio/ehbio_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tong-Chen/Bioinfo_course_python/f03b9ee0684eb2417b70378794ba1ea23ee39006/ehbio/ehbio_logo.png -------------------------------------------------------------------------------- /index.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Python3学习教程" 3 | author: 4 | - "易生信培训团队" 5 | - "联系我们: train@ehbio.com" 6 | - "抱歉,转成PDF后部分格式问题还未解决,会继续更新调整" 7 | date: "`r Sys.Date()`" 8 | documentclass: article 9 | site: bookdown::bookdown_site 10 | --- 11 | 12 | ```{r setup, include=FALSE} 13 | library(knitr) 14 | output <- opts_knit$get("rmarkdown.pandoc.to") 15 | html = FALSE 16 | latex = FALSE 17 | opts_chunk$set(echo = FALSE, out.width="100%", fig.align="center", fig.show="hold", warning=FALSE, message=TRUE) 18 | if (output=="html") { 19 | html = TRUE 20 | } 21 | if (output=="latex") { 22 | opts_chunk$set(out.width="95%", out.height='0.7\\textheight', out.extra='keepaspectratio', fig.pos='H') 23 | latex = TRUE 24 | } 25 | knitr::opts_chunk$set(cache=TRUE, autodep=TRUE) 26 | mtime <- function(files){ 27 | lapply(Sys.glob(files), function(x) file.info(x)$mtime) 28 | } 29 | set.seed(0304) 30 | ``` 31 | 32 | ```{asis, echo=html} 33 | 34 | # EHBIO Gene Technology {-} 35 | 36 | ``` 37 | 38 | ```{r cover, echo=F, eval=html, out.width="99%"} 39 | knitr::include_graphics("ehbio/cover.png") 40 | 41 | ``` 42 | 43 | -------------------------------------------------------------------------------- /pyre.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tong-Chen/Bioinfo_course_python/f03b9ee0684eb2417b70378794ba1ea23ee39006/pyre.png -------------------------------------------------------------------------------- /style.css: -------------------------------------------------------------------------------- 1 | 2 | p.caption { 3 | color: #777; 4 | margin-top: 10px; 5 | text-align: justify; 6 | } 7 | p code { 8 | white-space: inherit; 9 | } 10 | pre { 11 | word-break: normal; 12 | word-wrap: normal; 13 | } 14 | pre code { 15 | white-space: inherit; 16 | } 17 | 18 | body { 19 | text-align: justify; 20 | } 21 | 22 | .book .book-body .page-wrapper .page-inner section.normal table { 23 | display: block; 24 | overflow: auto; 25 | width: 100%; 26 | } 27 | 28 | .book .book-body .page-wrapper .page-inner section.normal caption { 29 | text-align: justify; 30 | width:100%; 31 | } 32 | 33 | .book .book-body .page-wrapper .page-inner section.normal table th { 34 | font-size: 70%; 35 | } 36 | 37 | .book .book-body .page-wrapper .page-inner section.normal table td { 38 | font-size: 70%; 39 | } 40 | 41 | .book .book-body .page-wrapper .page-inner section.normal ol { 42 | padding: 0 0 0 1em; 43 | } 44 | 45 | -------------------------------------------------------------------------------- /swap: -------------------------------------------------------------------------------- 1 | 2 |
    3 | 16 | --------------------------------------------------------------------------------