您的位置:首页 > 编程语言 > Python开发

获取指定位置序列

2016-09-17 11:27 183 查看
负号表示反向序列,并且start and end 的位置是序列反向互补之后的位置
Name	strand	start	end	total_length
UN000226	-2	1088	1411	1431
UN073473	3	861	1082	1158
UN082299	-1	838	1014	1105
UN064320	2	791	1006	1150
UN070736	-3	780	1271	1293
UN070422	2	776	955	1361
UN022140	2	758	1135	1235
UN215439	1	718	891	1044


代码
# encoding: utf-8
from Bio import SeqIO

record_dict = SeqIO.index('2.fa', "fasta")
name = open('1.txt', 'r')
for lines in name:
lines = lines.strip().split()
if lines[0] in record_dict.keys():
if int(lines[1][0]) >= 0:
print('>%s\n%s' % (lines[0], record_dict[lines[0]][int(lines[2]):int(lines[3])].seq))
else:
print('>%s\n%s' % (lines[0], record_dict[lines[0]].seq.reverse_complement()[int(lines[2]):int(lines[3])]))
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息