python⽣物信息实例_使⽤python处理⽣物信息数据(⼀)趁疫情被封闭在家,学习⼀下python,之前尝试过看过perl的书,代码看得我⼀脸懵逼,python乍看上去和蔼可亲多了,再加上有个师兄⿎励和推荐学习python,了这本书Managing Your Biological Data with Python先动起来吧,希望⾃⼰能坚持下去。
Managing Your Biological Data with Python
1. Anaconda安装和⽰例数据
在笔记本wins7上安装了anaconda,⽤的Spyder进⾏操作,
这本书是讲的python2,我从Library Genesis搜索下载的英⽂版,在github上Managing Your Biological Data with Python 3 将书中的⽰例代码转化为了python3,并提供了⽰例数据。
2. ⼀个简单⽰例,计算ATP的吉布斯⾃由能
计算ATP的吉布斯⾃由能,包含了⼀些基础操作:模块载⼊,简单的数学计算和查看模块中包含的函数功能和帮助。⾃⼰的理解:python 模块载⼊import类似于R语⾔中library()载⼊所需的R包,然后可以⼯作。
#已知数据
10010111补码怎么算
ATP = 3.5
ADP = 1.8
Pi = 5.0
R = 0.00831
T = 298
asp应用在哪些领域
mysql下载的怎么安装deltaG0 = -30.5
#载⼊math模块
import math
#计算
print (deltaG0 + R * T * math.log(ADP * Pi / ATP))
-28.161154161098693
#查看math模块中的函数
dir(math)
Out[12]:
['__doc__',
'__loader__',
'__name__',
'__package__',
'__spec__',
'acos',
'acosh',
'asin',
'atan2',
'atanh',
'ceil',
'copysign', 'cos',
'cosh',
'degrees', 'e',
'erf',
'erfc',
'exp',
'expm1', 'fabs',
'factorial', 'floor',
'fmod',
'frexp',
'fsum',
'gamma', 'gcd',
'hypot',
'inf',
'isclose', 'isfinite',
'isinf',
'isnan',
'ldexp',
'lgamma', 'log',
'log10',
'log1p',
'log2',
'pi',
'pow',
'radians',
'remainder',
'sin',
'sinh',
'sqrt',
'tan',
'tanh',
'tau',
'trunc']
#查看math模块使⽤的帮助
help(math)
Help on built-in module math:
NAME
eclipse mavenmath
DESCRIPTION
This module provides access to the mathematical functions defined by the C standard.
FUNCTIONS
acos(x, /)
Return the arc cosine (measured in radians) of x.
acosh(x, /)
Return the inverse hyperbolic cosine of x.
asin(x, /)
Return the arc sine (measured in radians) of x.
asinh(x, /)
Return the inverse hyperbolic sine of x.python的缺点有哪些
atan(x, /)
Return the arc tangent (measured in radians) of x. ...........
#查看math模块中sqrt函数的帮助
help(math.sqrt)
Help on built-in function sqrt in module math:
sqrt(x, /)
Return the square root of x.
3. 常⽤的数学计算符号以及math模块中的函数功能
数学计算符号
Operator
Meaning
a + b
addition
a – b
subtraction
a * b
multiplication
a/b
division
a ** b
power (ab)
a % b
modulo: the remainder of the division a / b
a // b
floor division, rounds down
a * (
b + c)
parentheses, b + c will be done before the multiplication math模块中的函数功能
Function
Meaning
log(x)
python基础代码实例natural logarithm of x (ln x)
log10(x)
decadic logarithm of x (log x)
exp(x)
natural exponent of x (ex)
sqrt(x)
square root of x
sin(x), cos(x)
sine and cosine of x (x given in radians)
asin(x), acos(x)
arcsin and arccos of x (result in radians)
4. 简单⽰例,计算空间中两点的距离
#载⼊math模块
from math import *
#(x1, y1, z1)和(x2, y2, z2)两点的坐标
x1, y1, z1 = 0.1, 0.0, -0.7
x2, y2, z2 = 0.5, -1.0, 2.7
#计算每个维度上的距离
dx = x1 - x2
dy = y1 - y2
dz = z1 - z2
#每个维度上距离的平⽅和
dsquare = pow(dx, 2) + pow(dy, 2) + pow(dz, 2)
#开平⽅
distance = sqrt(dsquare)
#打印结果
print (distance)
3.566510900025402
5. 简单⽰例,insulin中不同氨基酸出现的频率
#insulin的部分氨基酸序列
insulin = "GIVEQCCTSICSLYQLENYCNFVNQHLCGSHLVEALYLVCGERGFFYTPKT" #for循环统计20种氨基酸在insulin序列中出现的次数
for amino_acid in "ACDEFGHIKLMNPQRSTVWY":
number = unt(amino_acid)
print (amino_acid, number)
A 1
C 6
D 0
E 4
F 3

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。