annotate viz.py @ 8:fa26ea53c055 draft

Uploaded
author glogobyte
date Wed, 13 Oct 2021 11:20:06 +0000
parents 4d59ac081282
children 0a4d6c483ff0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5
4d59ac081282 Uploaded
glogobyte
parents:
diff changeset
1 from viz_graphs import *
4d59ac081282 Uploaded
glogobyte
parents:
diff changeset
2 from viz_functions import *
4d59ac081282 Uploaded
glogobyte
parents:
diff changeset
3 import argparse
4d59ac081282 Uploaded
glogobyte
parents:
diff changeset
4 import time
4d59ac081282 Uploaded
glogobyte
parents:
diff changeset
5 from multiprocessing import Process, Lock, Manager
4d59ac081282 Uploaded
glogobyte
parents:
diff changeset
6
4d59ac081282 Uploaded
glogobyte
parents:
diff changeset
7 ##################################################################################################################################################################################################################################################################
4d59ac081282 Uploaded
glogobyte
parents:
diff changeset
8 starttime = time.time()
4d59ac081282 Uploaded
glogobyte
parents:
diff changeset
9
4d59ac081282 Uploaded
glogobyte
parents:
diff changeset
10 parser = argparse.ArgumentParser()
4d59ac081282 Uploaded
glogobyte
parents:
diff changeset
11 parser.add_argument("-in", "--input", help="choose type of analysis", action="store")
4d59ac081282 Uploaded
glogobyte
parents:
diff changeset
12 parser.add_argument("-p_value", "--pval", help="choose type of analysis", action="store")
4d59ac081282 Uploaded
glogobyte
parents:
diff changeset
13 parser.add_argument("-fc", "--log2fc", help="choose type of analysis", action="store")
4d59ac081282 Uploaded
glogobyte
parents:
diff changeset
14 parser.add_argument("-top", "--top_mirnas", help="choose type of analysis", action="store")
4d59ac081282 Uploaded
glogobyte
parents:
diff changeset
15 parser.add_argument("-tool_dir", "--tool_directory", help="tool directory path", action="store")
4d59ac081282 Uploaded
glogobyte
parents:
diff changeset
16 parser.add_argument("-statistic", "--stat", help="tool directory path", action="store")
4d59ac081282 Uploaded
glogobyte
parents:
diff changeset
17 parser.add_argument("-diff_tool", "--tool", help="tool directory path", action="store")
4d59ac081282 Uploaded
glogobyte
parents:
diff changeset
18
4d59ac081282 Uploaded
glogobyte
parents:
diff changeset
19 args = parser.parse_args()
4d59ac081282 Uploaded
glogobyte
parents:
diff changeset
20
4d59ac081282 Uploaded
glogobyte
parents:
diff changeset
21 l=Lock()
4d59ac081282 Uploaded
glogobyte
parents:
diff changeset
22 number = int(args.top_mirnas)
4d59ac081282 Uploaded
glogobyte
parents:
diff changeset
23 log2fc = float(args.log2fc)
4d59ac081282 Uploaded
glogobyte
parents:
diff changeset
24 pval = float(args.pval)
4d59ac081282 Uploaded
glogobyte
parents:
diff changeset
25 iso_star_flag=0
4d59ac081282 Uploaded
glogobyte
parents:
diff changeset
26 non_star_flag=0
4d59ac081282 Uploaded
glogobyte
parents:
diff changeset
27
4d59ac081282 Uploaded
glogobyte
parents:
diff changeset
28 if args.tool=="2":
4d59ac081282 Uploaded
glogobyte
parents:
diff changeset
29
4d59ac081282 Uploaded
glogobyte
parents:
diff changeset
30 raw_EdgeR = read(args.input,0)
4d59ac081282 Uploaded
glogobyte
parents:
diff changeset
31 EdgeR = [x.rstrip("\n").split("\t") for x in raw_EdgeR]
4d59ac081282 Uploaded
glogobyte
parents:
diff changeset
32 del EdgeR[0]
4d59ac081282 Uploaded
glogobyte
parents:
diff changeset
33 for x in EdgeR:
4d59ac081282 Uploaded
glogobyte
parents:
diff changeset
34 if "/" in x[0]:
4d59ac081282 Uploaded
glogobyte
parents:
diff changeset
35 x[0]=x[0].split("/")[0]+"★"
4d59ac081282 Uploaded
glogobyte
parents:
diff changeset
36
4d59ac081282 Uploaded
glogobyte
parents:
diff changeset
37 if args.stat=="1":
4d59ac081282 Uploaded
glogobyte
parents:
diff changeset
38 non_templated = [[x[0],x[1],x[4]] for x in EdgeR if "nt" in x[0] and x[1]!="NA" and x[4]!="NA"]
4d59ac081282 Uploaded
glogobyte
parents:
diff changeset
39 matures = [[x[0],x[1],x[4]] for x in EdgeR if 'chr' in x[0].split("_")[-1] and "nt" not in x[0] and x[1]!="NA" and x[4]!="NA"]
4d59ac081282 Uploaded
glogobyte
parents:
diff changeset
40 isoforms = [[x[0],x[1],x[4]] for x in EdgeR if 'chr' not in x[0].split("_")[-1] and "nt" not in x[0] and x[1]!="NA" and x[4]!="NA"]
4d59ac081282 Uploaded
glogobyte
parents:
diff changeset
41 else:
4d59ac081282 Uploaded
glogobyte
parents:
diff changeset
42 non_templated = [[x[0],x[1],x[5]] for x in EdgeR if "nt" in x[0] and x[1]!="NA" and x[5]!="NA"]
4d59ac081282 Uploaded
glogobyte
parents:
diff changeset
43 matures = [[x[0],x[1],x[5]] for x in EdgeR if 'chr' in x[0].split("_")[-1] and "nt" not in x[0] and x[1]!="NA" and x[5]!="NA"]
4d59ac081282 Uploaded
glogobyte
parents:
diff changeset
44 isoforms = [[x[0],x[1],x[5]] for x in EdgeR if 'chr' not in x[0].split("_")[-1] and "nt" not in x[0] and x[1]!="NA" and x[5]!="NA"]
4d59ac081282 Uploaded
glogobyte
parents:
diff changeset
45
4d59ac081282 Uploaded
glogobyte
parents:
diff changeset
46 if args.tool=="1":
4d59ac081282 Uploaded
glogobyte
parents:
diff changeset
47
4d59ac081282 Uploaded
glogobyte
parents:
diff changeset
48 raw_Deseq = read(args.input,0)
4d59ac081282 Uploaded
glogobyte
parents:
diff changeset
49 Deseq = [x.rstrip("\n").split("\t") for x in raw_Deseq]
4d59ac081282 Uploaded
glogobyte
parents:
diff changeset
50 for x in Deseq:
4d59ac081282 Uploaded
glogobyte
parents:
diff changeset
51 if "/" in x[0]:
4d59ac081282 Uploaded
glogobyte
parents:
diff changeset
52 x[0]=x[0].split("/")[0]+"★"
4d59ac081282 Uploaded
glogobyte
parents:
diff changeset
53
4d59ac081282 Uploaded
glogobyte
parents:
diff changeset
54 if args.stat=="1":
4d59ac081282 Uploaded
glogobyte
parents:
diff changeset
55 non_templated = [[x[0],x[2],x[5]] for x in Deseq if "nt" in x[0] and x[2]!="NA" and x[5]!="NA"]
4d59ac081282 Uploaded
glogobyte
parents:
diff changeset
56 matures = [[x[0],x[2],x[5]] for x in Deseq if 'chr' in x[0].split("_")[-1] and "nt" not in x[0] and x[2]!="NA" and x[5]!="NA"]
4d59ac081282 Uploaded
glogobyte
parents:
diff changeset
57 isoforms = [[x[0],x[2],x[5]] for x in Deseq if 'chr' not in x[0].split("_")[-1] and "nt" not in x[0] and x[2]!="NA" and x[5]!="NA"]
4d59ac081282 Uploaded
glogobyte
parents:
diff changeset
58 elif args.stat=="2":
4d59ac081282 Uploaded
glogobyte
parents:
diff changeset
59 non_templated = [[x[0],x[2],x[6]] for x in Deseq if "nt" in x[0] and x[2]!="NA" and x[6]!="NA"]
4d59ac081282 Uploaded
glogobyte
parents:
diff changeset
60 matures = [[x[0],x[2],x[6]] for x in Deseq if 'chr' in x[0].split("_")[-1] and "nt" not in x[0] and x[2]!="NA" and x[6]!="NA"]
4d59ac081282 Uploaded
glogobyte
parents:
diff changeset
61 isoforms = [[x[0],x[2],x[6]] for x in Deseq if 'chr' not in x[0].split("_")[-1] and "nt" not in x[0] and x[2]!="NA" and x[6]!="NA"]
4d59ac081282 Uploaded
glogobyte
parents:
diff changeset
62 else:
4d59ac081282 Uploaded
glogobyte
parents:
diff changeset
63 non_templated = [[x[0],x[2],x[1]] for x in Deseq if "nt" in x[0] and x[2]!="NA" and x[1]!="NA"]
4d59ac081282 Uploaded
glogobyte
parents:
diff changeset
64 matures = [[x[0],x[2],x[1]] for x in Deseq if 'chr' in x[0].split("_")[-1] and "nt" not in x[0] and x[2]!="NA" and x[1]!="NA"]
4d59ac081282 Uploaded
glogobyte
parents:
diff changeset
65 isoforms = [[x[0],x[2],x[1]] for x in Deseq if 'chr' not in x[0].split("_")[-1] and "nt" not in x[0] and x[2]!="NA" and x[1]!="NA"]
4d59ac081282 Uploaded
glogobyte
parents:
diff changeset
66
4d59ac081282 Uploaded
glogobyte
parents:
diff changeset
67
4d59ac081282 Uploaded
glogobyte
parents:
diff changeset
68 diff_matures,diff_isoforms,diff_non_templated,names,non_temp,mat_iso = preproccess(non_templated,matures,isoforms,log2fc,pval,args.stat)
4d59ac081282 Uploaded
glogobyte
parents:
diff changeset
69 for x in mat_iso[:number]:
4d59ac081282 Uploaded
glogobyte
parents:
diff changeset
70 if "★" in x[0]:
4d59ac081282 Uploaded
glogobyte
parents:
diff changeset
71 iso_star_flag=1
4d59ac081282 Uploaded
glogobyte
parents:
diff changeset
72 break
4d59ac081282 Uploaded
glogobyte
parents:
diff changeset
73 for x in non_temp[:number]:
4d59ac081282 Uploaded
glogobyte
parents:
diff changeset
74 if "★" in x[0]:
4d59ac081282 Uploaded
glogobyte
parents:
diff changeset
75 non_star_flag=1
4d59ac081282 Uploaded
glogobyte
parents:
diff changeset
76 break
4d59ac081282 Uploaded
glogobyte
parents:
diff changeset
77
4d59ac081282 Uploaded
glogobyte
parents:
diff changeset
78
4d59ac081282 Uploaded
glogobyte
parents:
diff changeset
79 if non_templated!=[]:
4d59ac081282 Uploaded
glogobyte
parents:
diff changeset
80 analysis="2"
4d59ac081282 Uploaded
glogobyte
parents:
diff changeset
81 p=[Process(target=top_diff,args=(non_temp,number,"nt",l))]
4d59ac081282 Uploaded
glogobyte
parents:
diff changeset
82 p.extend([Process(target=top_diff,args=(mat_iso,number,"t",l))])
4d59ac081282 Uploaded
glogobyte
parents:
diff changeset
83 p.extend([Process(target=top_scatter_non,args=(diff_matures,diff_isoforms,diff_non_templated,names,number))])
4d59ac081282 Uploaded
glogobyte
parents:
diff changeset
84
4d59ac081282 Uploaded
glogobyte
parents:
diff changeset
85 else:
4d59ac081282 Uploaded
glogobyte
parents:
diff changeset
86 analysis="1"
4d59ac081282 Uploaded
glogobyte
parents:
diff changeset
87 p=[Process(target=top_diff,args=(mat_iso,number,"t",l))]
4d59ac081282 Uploaded
glogobyte
parents:
diff changeset
88 p.extend([Process(target=top_scatter_tem,args=(diff_matures,diff_isoforms,names,number))])
4d59ac081282 Uploaded
glogobyte
parents:
diff changeset
89
4d59ac081282 Uploaded
glogobyte
parents:
diff changeset
90 [x.start() for x in p]
4d59ac081282 Uploaded
glogobyte
parents:
diff changeset
91 [x.join() for x in p]
4d59ac081282 Uploaded
glogobyte
parents:
diff changeset
92
4d59ac081282 Uploaded
glogobyte
parents:
diff changeset
93 pdf_after_DE(analysis,args.top_mirnas,args.tool_directory,iso_star_flag,non_star_flag)
4d59ac081282 Uploaded
glogobyte
parents:
diff changeset
94
4d59ac081282 Uploaded
glogobyte
parents:
diff changeset
95 print('That took {} seconds'.format(time.time() - starttime))
4d59ac081282 Uploaded
glogobyte
parents:
diff changeset
96