python的计算_python计算smoothed PSSM(二)
Overview
上一篇文章python计算smoothed PSSM(一)当中,介绍了以当前氨基酸残基为基点,左右取相同数目的序列,然后叠加计算。Chris介绍,这样的算法有特定的用场:蛋白质后修饰。但是,普通的蛋白质序列提取特征就不太适用了:因为窗口值(smoothed window)只能取奇数,而如果有偶数长度的序列片段包含有特征,这种算法就会漏掉。于是决定写一个新的python脚本,把所有特征全部包含进去。
想法很简单:以当前残基为基点,直接向后连续取w_smth个氨基酸,并叠加计算最后存入新矩阵的当前位置。我做了一个循环,将窗口值不大于w_smth的矩阵全部存入一个相同的新矩阵当中,这样特征就全了。
1 python编码
1.1 t34pssm.py
这部分代码跟前面的代码只有一处不同:不用判断窗口值是否为奇数。这部分内容可参考上一篇内容。
1.2 pssm_smoothed_head.py
这部分代码完成的功能如下:
将每条序列的pssm矩阵的左半部分截取,存入矩阵PSSM-orig。
对矩阵PSSM_orig进行叠加操作,生成矩阵PSSM_smth_head_full。
根据需要截取PSSM_smth_head_full的前n个序列,并存入PSSM_smth_head_final。
将PSSM_smth_head_final合并为一行写入文件,每条序列占一行。
代码如下:
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
"""
Retrieve smoothed_head PSSM features
"""
import sys
import numpy as np
import math
import re
import fileinput
def pssm_smth_head_n(fi,output_smth_head,w_smth_head,n):
# 0-19 represents amino acid 'ARNDCQEGHILKMFPSTWYV'
w_smth_head=int(w_smth_head)
n=int(n)
Amino_vec = "ARNDCQEGHILKMFPSTWYV"
PSSM = []
PSSM_orig = []
seq_cn = 0
# 读取pssm文件
for line, strin in enumerate(fileinput.input(fi)):
if line > 2:
str_vec = strin.split()[1:22]
if len(str_vec) == 0:
break
PSSM.append(map(int, str_vec[1:]))
seq_cn += 1
print seq_cn
fileinput.close()
#original PSSM
#将每条序列的`pssm`矩阵的左半部分截取,存入矩阵`PSSM-orig`
PSSM_orig=np.array(PSSM)
#print PSSM_orig
PSSM_smth_head_final=np.array([[0.0]*20]*(n*w_smth_head))
#section for PSSM_smth_head features
for k in range(1,w_smth_head+1):
PSSM_smth_head = np.array([[0.0]*20]*seq_cn)
#print PSSM_smth_head
#对矩阵`PSSM_orig`进行叠加操作,生成矩阵`PSSM_smth_head_full`。
PSSM_smth_head_full=pssm_smth_head(PSSM_orig,PSSM_smth_head,k,seq_cn)
#print PSSM_smth_head_full
#print np.shape(PSSM_smth_head_full)
#根据需要截取`PSSM_smth_head_full`的前`n`个序列,并存入`PSSM_smth_head_final`。
for i in range(n):
PSSM_smth_head_final[i+n*(k-1)]=PSSM_smth_head_full[i]
#print PSSM_smth_head_final
PSSM_smth_head_final_shp=np.shape(PSSM_smth_head_final)
file_out_smth_head=file(output_smth_head,'a')
#将`PSSM_smth_head_final`合并为一行写入文件,每条序列占一行
np.savetxt(file_out_smth_head, [np.reshape(PSSM_smth_head_final, (PSSM_smth_head_final_shp[0] * PSSM_smth_head_final_shp[1], ))], delimiter=",")
def pssm_smth_head(PSSM_orig,PSSM_smth_head,w_smth_head,l):
for i in range(l):
if i <=l-w_smth_head:
for j in range(i,i+w_smth_head):
PSSM_smth_head[i]+=PSSM_orig[j]
else:
for j in range(i,l):
PSSM_smth_head[i]+=PSSM_orig[j]
return PSSM_smth_head
1.3 总结
这个程序可以得到比较全的特征。比如取窗口值为10,那么窗口值为1,2,3,4,5,6,7,8,9,10的特征将会全部被包含在内,并合成一行。
在linux中进入文件所在的目录,然后终端运行如下命令:
python t34pssm.py T4undrsmp.txt ./t4 ./t4pssm w_smth n
需要保存的结果文件,自己修改。
python的计算_python计算smoothed PSSM(二)相关推荐
- python笛卡尔_Python 计算笛卡尔积
Python 计算笛卡尔积 计算多个集合的笛卡尔积,有规律可循,算法和代码也不难,但是很多语言都没有提供直接计算笛卡尔积的方法,需要自己写大段大段的代码计算笛卡尔积,python 提供了一种最简单的计 ...
- python概率游戏_Python计算斗牛游戏的概率
Python计算斗牛游戏的概率 过年回家,都会约上亲朋好友聚聚会,会上经常会打麻将,斗地主,斗牛.在这些游戏中,斗牛是最受欢迎的,因为可以很多人一起玩,而且没有技术含量,都是看运气(专业术语是概率). ...
- python的计算_python 计算方位角实例(根据两点的坐标计算)
知道两点坐标,怎么计算两点方向的方位角? 答:首先计算坐标增量dx,dy(两个对应坐标分量相减,终点的减始点的). 若dx,dy中有一个为零时,根据另一个的正负决定方位角(0,90,180,270这四 ...
- python判断天数_Python计算两个日期相差天数的方法示例
本文实例讲述了Python计算两个日期相差天数的方法.分享给大家供大家参考,具体如下: #!/usr/bin/python import time import sys def dateinput() ...
- python离散积分_python 计算离散点的微分和积分(超详细)
前言: 本文计算离散点微分和积分的内容,参考的是origin软件提供的算法. 鉴于在百度和谷歌搜索标题的结果不尽人意,因此想在此做一个详细的总结. 若阅读时间有限,可直接阅读第二或第三部分的代码及其运 ...
- python 画三角函数_Python计算三角函数之asin()方法的使用
asin()方法返回x的反正弦,以弧度表示. 语法 以下是asin()方法语法: asin(x) 注意:此函数是无法直接访问的,所以我们需要导入math模块,然后需要用math的静态对象来调用这个函数 ...
- python中e怎么计算_python计算e
广告关闭 腾讯云11.11云上盛惠 ,精选热门产品助力上云,云服务器首年88元起,买的越多返的越多,最高返5000元! 开发准备下载和安装 python sdk . 首次使用批量计算,参考 开始前的准 ...
- python星期计算_python 计算一年内的所有周的具体日期
#!/usr/bin/env python # -*- coding:utf-8 -*- import datetime import collections def get_date_list(st ...
- python 移动平均线_Python 计算EMA(指数移动平均线)
总结 使用递归和循环两种方法来完成 python环境下循环相比于递归更快,更适应极端样本情况 递归 def _ema(arr,i=None): N = len(arr) α = 2/(N+1) #平滑 ...
- python excel计算_python计算excel平均值和标准差
############################################## ######## python计算excel平均值和标准差 ####### ############### ...
最新文章
- Linux TCP/IP协议栈笔记
- Spock测试框架中的注解使用
- vue-router同路由$router.push不跳转一个简单解决方案
- IAR实际使用过程中遇到的问题
- 搞懂function(*args,**kwargs)
- 随想录(校园招聘记)
- 【论文复现】Character-level Convolutional Networks for Text Classification
- java从包package中获取所有的Class
- 用iFrame遮挡DropDownList的方法
- 【C语言】科学计数法——复习总结
- 数字图像处理与Python实现-图像变换-Radon变换
- H5移动端出生日期插件
- 宾果消消消鸿蒙版,宾果消消消最新版
- 蝴蝶影视服务器响应异常,elasticsearch的服务器响应异常及解决策略(转)
- P2380 狗哥采矿 (二维dp)
- 水表读数图解_水表读数怎么正确看 水表怎么读?
- 大数据学习系列(九)Hadoop1.X痛点分析及Hadoop2.X提出的解决方案
- 运行vue项目报DONE Build complete. The dist directory is ready to be deployed.解决办法
- 动态gif图是什么?如何快速制作动态gif?
- 仅需1秒!搞定100万行数据:超强Python数据分析利器!掌握了吗!