-
Notifications
You must be signed in to change notification settings - Fork 33
/
find-gene-miRNA-by-symbol.py
executable file
·78 lines (65 loc) · 2.03 KB
/
find-gene-miRNA-by-symbol.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
#!/usr/bin/python
#-*- coding:utf-8 -*-
################################################
#File Name: find_gene_miRNA_by_symbol.py
#Author: C.J. Liu
#Mail: samliu@hust.edu.cn
#Created Time: Wed 30 Mar 2016 02:25:50 PM CST
################################################
import sys, os
import pickle
import pprint
import re
def help():
if len(sys.argv) != 2:
print "Description:"
print "\tFind gene regulated by miRNAs"
print "Input:"
print "\tPlease input gene list with comma or semicolon seperated"
print "\tOr input a file containing gene line by line"
print "Example:"
print "\t1. python %s NR3C1" % sys.argv[0]
print "\t2. python %s genelistfile.txt" %sys.argv[0]
sys.exit(1)
def target2mirna():
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[1]].append(arr[0])
except:
miRNA2targetDict.setdefault(arr[1],[arr[0]])
pickle.dump(miRNA2targetDict, open("target2miRNA.dict.pickle","wb"))
# pprint.pprint(miRNA2targetDict)
def run(f):
miRNA2targetDict = pickle.load(open(os.path.dirname(os.path.realpath(__file__))+"/target2miRNA.dict.pickle","rb"))
print "Search\tGene\tmiRNA"
if os.path.isfile(f):
with open(f, 'r') as foo :
for line in foo:
line = line.rstrip()
genes = [i for i,j in miRNA2targetDict.items() if re.search(line,i,re.IGNORECASE)]
if len(genes) ==0:
print line,"\t","-","\t","-"
else:
for i in genes:
print line,"\t",i,"\t","\t".join(miRNA2targetDict[i])
else:
inputMiRNAList = re.split(",|;",f)
for line in inputMiRNAList:
line = line.rstrip()
genes = [i for i,j in miRNA2targetDict.items() if re.search(line,i,re.IGNORECASE)]
if len(genes) ==0:
print line,"\t","-","\t","-"
else:
for i in genes:
print line,"\t",i,"\t","\t".join(miRNA2targetDict[i])
def main():
help()
# target2mirna()
run(sys.argv[1])
if __name__ == "__main__":
main()