-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathfind-miRNA-target.py
More file actions
executable file
·74 lines (69 loc) · 2.31 KB
/
Copy pathfind-miRNA-target.py
File metadata and controls
executable file
·74 lines (69 loc) · 2.31 KB
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
#!/usr/bin/python
#-*- coding:utf-8 -*-
################################################
#File Name: find_miRNA_target.py
#Author: C.J. Liu
#Mail: samliu@hust.edu.cn
#Created Time: Thu 24 Mar 2016 01:39:06 PM CST
################################################
import sys, os
import pickle
import pprint
import re
def miRNA2target():
miRNA2targetDict = dict()
with open(os.path.dirname(os.path.realpath(__file__))+"/Total_miRNA2target.20160314.txt", "r") as foo:
for line in foo:
arr = line.rstrip().split("\t")
if len(arr) <2 :
continue
try:
miRNA2targetDict[arr[0]].append(arr[1])
except:
miRNA2targetDict.setdefault(arr[0],[arr[1]])
pickle.dump(miRNA2targetDict, open("miRNA2target.dict.pickle","wb"))
# pprint.pprint(miRNA2targetDict)
def run(f):
miRNA2targetDict = pickle.load(open(os.path.dirname(os.path.realpath(__file__))+"/miRNA2target.dict.pickle","rb"))
print "Search\tmiRNA\tTarget"
if os.path.isfile(f):
with open(f, 'r') as foo :
for line in foo:
if not line.startswith("hsa-"): continue
line = line.rstrip()
miRNAs = [i for i,j in miRNA2targetDict.items() if re.search(line+"\D",i,re.IGNORECASE)]
miRNAs.extend([i for i,j in miRNA2targetDict.items() if re.search(line+"$",i,re.IGNORECASE)])
if len(miRNAs) ==0:
print line,"\t","-","\t","-"
else:
for i in miRNAs:
print line,"\t",i,"\t","\t".join(miRNA2targetDict[i])
else:
inputMiRNAList = re.split(",|;",f)
for line in inputMiRNAList:
if not line.startswith("hsa-"): continue
line = line.rstrip()
miRNAs = [i for i,j in miRNA2targetDict.items() if re.search(line+"\D",i,re.IGNORECASE)]
miRNAs.extend([i for i,j in miRNA2targetDict.items() if re.search(line+"$",i,re.IGNORECASE)])
if len(miRNAs) ==0:
print line,"\t","-","\t","-"
else:
for i in miRNAs:
print line,"\t",i,"\t","\t".join(miRNA2targetDict[i])
def help():
if len(sys.argv) != 2:
print "Description:"
print "\tFind miRNA targets"
print "Input:"
print "\tPlease input miRNA list with comma or semicolon seperated"
print "\tOr input a file containing miRNA line by line"
print "Example:"
print "\t1. python %s hsa-mir-1,hsa-mir-2" % sys.argv[0]
print "\t2. python %s miRNAfile.txt" %sys.argv[0]
sys.exit(1)
def main():
help()
run(sys.argv[1])
# miRNA2target()
if __name__ == "__main__":
main()