首页 > 其他 > 详细

如何在一序列中寻找E-BOX 元件,并将其变为小写

时间:2015-09-17 19:41:07      阅读:245      评论:0      收藏:0      [点我收藏+]

给定一个序列,寻找所有的E-BOX motif (CNNTTG) , 并且将其变为小写, 用 python 实现如下:

 

 1 #!/bin/python
 2 # Date: 2015.8.01
 3 # Author: 
 4 """ Search E-box motif(CNNTTG) in a DNA seq and replace this motif with lower character """
 5 
 6 import re                           # using regular expression
 7 
 8 dna_seq = open("/home/genome_seq.txt")
 9 dna_test = open("/home/test_new.txt","w")
10 
11 my_seq = ""                           # create a empity string not a list
12 for line in dna_seq:
13     my_seq = my_seq + line.rstrip("\n") # create a whole string with string concencating 
14                                         # remove the "\n"
15 Ebox_motif = re.findall(r"C[TACG][TACG]TTG", my_seq) # use regular expression to find the motif
16                                                  # use findall method to return a list contains the motif
17 seq = my_seq
18 
19 for motif in Ebox_motif:
20     seq = seq.replace(motif, motif.lower())          #  use str.replace() method  **** the key step*****
21 
22 dna_test.write(seq)                            # write the string to a file
23 dna_test.close()                               # good habit
24 dna_seq.close()                                # good habit

 

如何在一序列中寻找E-BOX 元件,并将其变为小写

原文:http://www.cnblogs.com/OA-maque/p/4817339.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!