Mercurial > repos > glogobyte > armdb
comparison armdb_mirgene.py @ 1:d133caf020a7 draft
Uploaded
author | glogobyte |
---|---|
date | Wed, 13 Oct 2021 16:23:13 +0000 |
parents | |
children | 41f5a0616dbb |
comparison
equal
deleted
inserted
replaced
0:6c267b9256fa | 1:d133caf020a7 |
---|---|
1 import subprocess | |
2 import argparse | |
3 import time | |
4 import urllib.request | |
5 from multiprocessing import Process, Queue | |
6 | |
7 #--------------------------------------------Arguments----------------------------------------------- | |
8 subprocess.call(['mkdir', 'out']) | |
9 parser = argparse.ArgumentParser() | |
10 parser.add_argument("-pos", "--positions", help="", action="store") | |
11 parser.add_argument("-tool_dir", "--tool_directory", help="tool directory path", action="store") | |
12 parser.add_argument("-sym", "--symbol", help="",action="store") | |
13 args = parser.parse_args() | |
14 | |
15 #------------------------------------Read Fasta files from MirGene----------------------------------- | |
16 | |
17 def read_url(path): | |
18 | |
19 data = urllib.request.urlopen(path).read() | |
20 data1 = data.decode('utf-8') | |
21 data1 = data1.split("\n") | |
22 del data1[-1] | |
23 q.put(data1) | |
24 | |
25 #-------------------------------------Generation of Custom Arms-------------------------------------- | |
26 | |
27 def custom_arms_mirgene(mat_mirna,pri_mirna): | |
28 mat_ext=[] | |
29 for i in range(0,len(mat_mirna),2): | |
30 if args.symbol in mat_mirna[i]: | |
31 mat_seq=mat_mirna[i+1] | |
32 | |
33 for j in range(0,len(pri_mirna),2): | |
34 if mat_mirna[i].split("_")[0] == pri_mirna[j].split("_")[0]: | |
35 temp_ext = pri_mirna[j+1].split(mat_seq) | |
36 mat_ext.append([mat_mirna[i],temp_ext[0][-int(args.positions):]+mat_seq+temp_ext[1][0:int(args.positions)]]) | |
37 | |
38 print(str(args.positions)+" positions shifted") | |
39 return(mat_ext) | |
40 | |
41 #----------------------------------------Export of Fasta files --------------------------------------- | |
42 | |
43 def write_custom_arms(list,name,c): | |
44 | |
45 f = open(name, "w") | |
46 for x in list: | |
47 if c==1: | |
48 f.write(x[0]+'\n') | |
49 f.write(x[1]+'\n') | |
50 else: | |
51 f.write(x+'\n') | |
52 | |
53 #================================================================================================================================== | |
54 | |
55 if __name__=='__main__': | |
56 | |
57 starttime = time.time() | |
58 print(args.symbol) | |
59 q = Queue() | |
60 | |
61 # Read of all Fasta files | |
62 mat_url = 'https://mirgenedb.org/fasta/ALL?mat=1' | |
63 p = [Process(target=read_url(mat_url))] | |
64 star_url = 'https://mirgenedb.org/fasta/ALL?star=1' | |
65 p.extend([Process(target=read_url(star_url))]) | |
66 pri_url = 'https://mirgenedb.org/static/data/ALL/ALL--pri-30-30.fas' | |
67 p.extend([Process(target=read_url(pri_url))]) | |
68 [x.start() for x in p] | |
69 [x.join() for x in p] | |
70 | |
71 mat_mirna=q.get() | |
72 star_mirna=q.get() | |
73 pri_mirna=q.get() | |
74 | |
75 # Replace U with T in seqeunces | |
76 mat_mirna.extend(star_mirna) | |
77 for i in range(1,len(mat_mirna),2): | |
78 mat_mirna[i]=mat_mirna[i].replace("U","T") | |
79 | |
80 #Generation of Custom Arms | |
81 mat_ext=custom_arms_mirgene(mat_mirna,pri_mirna) | |
82 | |
83 #Export of all Fasta files | |
84 p1 = [Process(target=write_custom_arms(mat_mirna,"shifted_mirnas.bed",0))] | |
85 p1.extend([Process(target=write_custom_arms(pri_mirna,"original_mirnas.bed",0))]) | |
86 p1.extend([Process(target=write_custom_arms(mat_ext,"new_ref.fa",1))]) | |
87 [x.start() for x in p1] | |
88 [x.join() for x in p1] | |
89 | |
90 print('That runtime was {} seconds'.format(time.time() - starttime)) |