-
Notifications
You must be signed in to change notification settings - Fork 42
/
animalMiRNATargetSite.py
executable file
·129 lines (123 loc) · 4.26 KB
/
animalMiRNATargetSite.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#from __future__ import division, with_statement
'''
Copyright 2010, 陈同 (chentong_biology@163.com).
Please see the license file for legal information.
===========================================================
'''
__author__ = 'chentong & ct586[9]'
__author_email__ = 'chentong_biology@163.com'
#=========================================================
import sys
from time import localtime, strftime
import string
timeformat = "%Y-%m-%d %H:%M:%S"
def readtarget(target):
targetDict = {}
for line in open(target):
if line[0] == '>':
locus = line[1:-1]
assert locus not in targetDict
targetDict[locus] = ''
else:
targetDict[locus] += line.strip().upper().replace('T','U')
#-------------------------------------------
return targetDict
#-------------------------------------------------
def alignOneMirnaMultipleTarget(mirna, targetDict, mature, transTable):
seed = mature[1:8]
seed = seed.translate(transTable)
seed = seed[::-1]
lenm = len(mature)
newmature = mature[::-1]
for key, seq in targetDict.items():
target_pre = []
index = seq.find(seed)
lenseq = len(seq)
while index != -1:
utr_s = index - lenm + 8
utr_e = index + 8 #not included
#------------------
newpos_s = index
newpos_e = index + 7
# if utr_s < 0:
# newpos_s = 0
# else:
# newpos_s = utr_s
# if utr_e > lenseq:
# newpos_e = lenseq
# else:
# newpos_e = utr_e
matchSeq = "Position " + str(newpos_s+1) + '-' + str(newpos_e)\
+ ' of ' + key + ' 3\' UTR'
#------------------
matchSeq += "\n\n5\' ..."
if utr_s < 0:
utr_s = 0
matchSeq += '-' * (-1 * utr_s)
#-------------------------
if utr_e > lenseq:
seq += '-' * (lenseq - utr_e)
matchSeq += seq[utr_s:utr_e]
matchSeq += '\n ' + ' ' * (lenm-8) + '|' * len(seed)
matchSeq += '\n3\' ' + newmature
target_pre.append(matchSeq)
oldindex = index
index = seq[index+1:].find(seed)
if index != -1:
index += oldindex+1
#------------END while--------------
if len(target_pre) > 0:
print "%s\n\n%s\n\n" % (mirna, '\n\n'.join(target_pre))
#----------------------------------------
return target_pre
#----------------------------------------
def readMir(mirna):
#------------------------------
#>cel-miR-1-5p MIMAT0020301 Caenorhabditis elegans miR-1-5p
#CAUACUUCCUUACAUGCCCAUA
#------------------------------
mirnaDict = {}
for line in open(mirna):
if line[0] == '>':
locus = line[1:].strip().split()[0]
mirnaDict[locus] = ''
else:
mirnaDict[locus] += line.strip().upper()
#-------------------------------
return mirnaDict
#--------------------------------------------
def main():
'''
1.character case, all transfer to uppercase
2.all U and T will transfer to A in mirna seed reverse
complementary.
3.all utr sequence T->U
'''
print >>sys.stderr, "Print the result to file"
if len(sys.argv) != 3:
print >>sys.stderr, 'Using python %s matureMirna[fasta,\
sequence in one line] \
targetSequence[fasta, 3"UTR, CDS, 5"UTR]' % sys.argv[0]
sys.exit(0)
#-----------------------------------
transTable = string.maketrans('ACGUT', 'UGCAA')
mirna=sys.argv[1]
target=sys.argv[2]
targetDict = readtarget(target)
mirnaDict = readMir(mirna)
#---mirna index----------------------
#newmirnaDict = {} #for target index
for key, value in mirnaDict.items():
#newmirnaDict[key] = value
alignOneMirnaMultipleTarget\
(key, targetDict, value, transTable)
if __name__ == '__main__':
startTime = strftime(timeformat, localtime())
main()
endTime = strftime(timeformat, localtime())
fh = open('python.log', 'a')
print >>fh, "%s\n\tRun time : %s - %s " % \
(' '.join(sys.argv), startTime, endTime)
fh.close()