gwaslab 3.4.48__py3-none-any.whl → 3.5.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of gwaslab might be problematic. Click here for more details.
- gwaslab/bd_common_data.py +3 -1
- gwaslab/data/reference.json +10 -2
- gwaslab/g_Sumstats.py +24 -2
- gwaslab/g_vchange_status.py +1 -1
- gwaslab/g_version.py +2 -2
- gwaslab/hm_harmonize_sumstats.py +23 -7
- gwaslab/io_preformat_input.py +73 -8
- gwaslab/io_to_formats.py +5 -5
- gwaslab/qc_fix_sumstats.py +106 -7
- gwaslab/util_in_fill_data.py +20 -2
- gwaslab/util_in_get_sig.py +18 -2
- gwaslab/viz_aux_annotate_plot.py +75 -242
- gwaslab/viz_aux_quickfix.py +9 -2
- gwaslab/viz_aux_save_figure.py +2 -1
- gwaslab/viz_plot_compare_effect.py +48 -20
- gwaslab/viz_plot_miamiplot2.py +5 -1
- gwaslab/viz_plot_mqqplot.py +70 -20
- gwaslab/viz_plot_phe_heatmap.py +260 -0
- gwaslab/viz_plot_stackedregional.py +11 -4
- {gwaslab-3.4.48.dist-info → gwaslab-3.5.0.dist-info}/METADATA +1 -1
- {gwaslab-3.4.48.dist-info → gwaslab-3.5.0.dist-info}/RECORD +25 -24
- {gwaslab-3.4.48.dist-info → gwaslab-3.5.0.dist-info}/WHEEL +1 -1
- {gwaslab-3.4.48.dist-info → gwaslab-3.5.0.dist-info}/LICENSE +0 -0
- {gwaslab-3.4.48.dist-info → gwaslab-3.5.0.dist-info}/LICENSE_before_v3.4.39 +0 -0
- {gwaslab-3.4.48.dist-info → gwaslab-3.5.0.dist-info}/top_level.txt +0 -0
gwaslab/viz_aux_annotate_plot.py
CHANGED
|
@@ -60,21 +60,21 @@ def annotate_single(
|
|
|
60
60
|
elif anno:
|
|
61
61
|
annotation_col=anno
|
|
62
62
|
log.write(" -Annotating using column "+annotation_col+"...", verbose=verbose)
|
|
63
|
-
|
|
63
|
+
################################################################################################################################
|
|
64
64
|
## calculate y span
|
|
65
65
|
if region is not None:
|
|
66
66
|
y_span = region[2] - region[1]
|
|
67
67
|
else:
|
|
68
68
|
y_span = sumstats["i"].max()-sumstats["i"].min()
|
|
69
|
-
|
|
70
69
|
log.write(" -Adjusting text positions with repel_force={}...".format(repel_force), verbose=verbose)
|
|
71
70
|
if anno_style == "expand" :
|
|
72
71
|
to_annotate.loc[:, "ADJUSTED_i"] = adjust_text_position(to_annotate["i"].values.copy(), y_span, repel_force,max_iter=anno_max_iter,log=log,amode=amode,verbose=verbose)
|
|
73
72
|
## iterate through variants to be annotated
|
|
73
|
+
################################################################################################################################
|
|
74
|
+
|
|
74
75
|
anno_to_adjust_list = list()
|
|
75
76
|
|
|
76
77
|
for rowi,row in to_annotate.iterrows():
|
|
77
|
-
|
|
78
78
|
# avoid text overlapping
|
|
79
79
|
## adjust x to avoid overlapping################################################################
|
|
80
80
|
if anno_style == "right" :
|
|
@@ -93,7 +93,7 @@ def annotate_single(
|
|
|
93
93
|
else:
|
|
94
94
|
pass
|
|
95
95
|
################################################################
|
|
96
|
-
#shrink or increase the arm
|
|
96
|
+
# shrink or increase the arm by a factor (arm_scale)
|
|
97
97
|
if arm_scale_d is not None:
|
|
98
98
|
if anno_count not in arm_scale_d.keys():
|
|
99
99
|
arm_scale =1
|
|
@@ -102,20 +102,32 @@ def annotate_single(
|
|
|
102
102
|
################################################################
|
|
103
103
|
|
|
104
104
|
# vertical arm length in pixels
|
|
105
|
-
#
|
|
106
|
-
#
|
|
107
|
-
#
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
105
|
+
# Annotation y : 1.15 * maxy_anno
|
|
106
|
+
# Top dot: 1 * maxy_anno
|
|
107
|
+
# armB_length_in_point_raw = 0.15 * maxy_anno -> gap_pixel
|
|
108
|
+
# Fixed Offset: 0.5 * 0.15 * gap_pixel
|
|
109
|
+
|
|
110
|
+
#Calculate armB length in pixels
|
|
111
|
+
# arm_scale: raise up the ceiling
|
|
112
|
+
|
|
113
|
+
# gap : 0.5* space between top variant and annotation text
|
|
114
|
+
gap_pixel = (ax1.transData.transform((0,1.15*maxy*arm_scale))[1]-ax1.transData.transform((0, maxy*arm_scale))[1])*0.5
|
|
115
|
+
|
|
116
|
+
# armB_length_in_pixel_raw : distance between variant to annotate and annotation text
|
|
117
|
+
armB_length_in_pixel_raw = ax1.transData.transform((0,1.15*maxy*arm_scale))[1]-ax1.transData.transform((0, row["scaled_P"]+1))[1]
|
|
118
|
+
|
|
119
|
+
armB_length_in_pixel = armB_length_in_pixel_raw - gap_pixel
|
|
120
|
+
|
|
111
121
|
################################################################
|
|
122
|
+
# armB_length_in_pixel should not be negative
|
|
112
123
|
if arm_scale>=1:
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
124
|
+
armB_length_in_pixel = max(0, armB_length_in_pixel)
|
|
125
|
+
|
|
126
|
+
################################################################
|
|
127
|
+
#if setting anno_fixed_arm_length
|
|
116
128
|
if anno_fixed_arm_length is not None:
|
|
117
|
-
|
|
118
|
-
|
|
129
|
+
armB_length_in_pixel = ax1.transData.transform((skip,anno_fixed_arm_length))[1]-ax1.transData.transform((skip,0))[1]
|
|
130
|
+
|
|
119
131
|
################################################################################################################################
|
|
120
132
|
# annotation alias
|
|
121
133
|
if anno==True:
|
|
@@ -129,26 +141,31 @@ def annotate_single(
|
|
|
129
141
|
else:
|
|
130
142
|
annotation_text=row["Annotation"]
|
|
131
143
|
|
|
132
|
-
|
|
133
|
-
#xy
|
|
144
|
+
################################################################################################################################
|
|
145
|
+
# setting arrow xy and text xy
|
|
146
|
+
# add a small space between variant and arrow head
|
|
134
147
|
xy=(row["i"],row["scaled_P"]+0.01*maxy)
|
|
135
|
-
|
|
148
|
+
|
|
149
|
+
# text xy is of the same height
|
|
150
|
+
# anno_height can be used to adjust the height of annotation text
|
|
151
|
+
xytext=(last_pos,1.15*maxy*(arm_scale + anno_height -1))
|
|
136
152
|
|
|
153
|
+
# for anno_fixed_arm_length
|
|
137
154
|
if anno_fixed_arm_length is not None:
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
155
|
+
xytext=(row["i"],row["scaled_P"] + 0.2 + anno_fixed_arm_length)
|
|
156
|
+
|
|
157
|
+
################################################################################################################################
|
|
158
|
+
# if not changing the directions of some annotation arror arms
|
|
141
159
|
if anno_count not in anno_d.keys():
|
|
142
|
-
#arrowargs = dict(arrowstyle="-|>",relpos=(0,0),color="#ebebeb",
|
|
143
|
-
# connectionstyle="arc,angleA=0,armA=0,angleB=90,armB="+str(armB_length_in_point)+",rad=0")
|
|
144
160
|
if _invert==False:
|
|
145
161
|
arrowargs = dict(arrowstyle="-|>",relpos=(0,0),color="#ebebeb",
|
|
146
|
-
connectionstyle="arc,angleA=0,armA=0,angleB=90,armB="+str(
|
|
162
|
+
connectionstyle="arc,angleA=0,armA=0,angleB=90,armB="+str(armB_length_in_pixel)+",rad=0")
|
|
147
163
|
else:
|
|
148
164
|
arrowargs = dict(arrowstyle="-|>",relpos=(0,1),color="#ebebeb",
|
|
149
|
-
connectionstyle="arc,angleA=0,armA=0,angleB=-90,armB="+str(
|
|
165
|
+
connectionstyle="arc,angleA=0,armA=0,angleB=-90,armB="+str(armB_length_in_pixel)+",rad=0")
|
|
150
166
|
else:
|
|
151
|
-
#
|
|
167
|
+
# if not changing the directions of some annotation arror arms
|
|
168
|
+
# adjust horizontal direction
|
|
152
169
|
xy=(row["i"],row["scaled_P"])
|
|
153
170
|
if anno_d[anno_count] in ["right","left","l","r"]:
|
|
154
171
|
if anno_d[anno_count]=="right" or anno_d[anno_count]=="r":
|
|
@@ -170,7 +187,7 @@ def annotate_single(
|
|
|
170
187
|
elif anno_d[anno_count]=="left" or anno_d[anno_count]=="l":
|
|
171
188
|
arrowargs = dict(arrowstyle="-|>",relpos=(0,0),color="#ebebeb",
|
|
172
189
|
connectionstyle="arc,angleA=-135,armA="+str( anno_d[anno_count][1])+",angleB=135,armB="+str( anno_d[anno_count][1])+",rad=0")
|
|
173
|
-
|
|
190
|
+
################################################################################################################################
|
|
174
191
|
|
|
175
192
|
if "r" in mode:
|
|
176
193
|
arrowargs["color"] = "black"
|
|
@@ -179,16 +196,19 @@ def annotate_single(
|
|
|
179
196
|
bbox_para[key]=value
|
|
180
197
|
else:
|
|
181
198
|
bbox_para=None
|
|
182
|
-
|
|
199
|
+
|
|
200
|
+
################################################################################################################################
|
|
183
201
|
if _invert==False:
|
|
184
|
-
anno_default = {"rotation":40,"fontstyle":"italic","ha":"left","va":"bottom","fontsize":anno_fontsize,"fontweight":"normal","fontfamily":font_family}
|
|
202
|
+
anno_default = {"rotation":40, "fontstyle":"italic","ha":"left","va":"bottom","fontsize":anno_fontsize,"fontweight":"normal","fontfamily":font_family}
|
|
185
203
|
else:
|
|
186
|
-
anno_default = {"rotation":-40,"fontstyle":"italic","ha":"left","va":"top","fontsize":anno_fontsize,"fontweight":"normal","fontfamily":font_family}
|
|
204
|
+
anno_default = {"rotation":-40,"fontstyle":"italic","ha":"left","va":"top", "fontsize":anno_fontsize,"fontweight":"normal","fontfamily":font_family}
|
|
187
205
|
|
|
206
|
+
################################################################################################################################
|
|
188
207
|
if anno_style == "expand" :
|
|
189
208
|
anno_default["rotation"] = 90
|
|
190
209
|
if anno_style == "tight" :
|
|
191
210
|
anno_default["rotation"] = 90
|
|
211
|
+
################################################################################################################################
|
|
192
212
|
|
|
193
213
|
for key,value in anno_args.items():
|
|
194
214
|
anno_default[key]=value
|
|
@@ -196,12 +216,13 @@ def annotate_single(
|
|
|
196
216
|
if row["i"] in highlight_i:
|
|
197
217
|
for key,value in highlight_anno_args.items():
|
|
198
218
|
anno_default[key]=value
|
|
199
|
-
|
|
219
|
+
################################################################################################################################
|
|
200
220
|
if anno_adjust==True:
|
|
201
221
|
if _invert==False:
|
|
202
222
|
arrowargs=dict(arrowstyle='-|>', color='grey', shrinkA=10, linewidth=0.1, relpos=(0,0.5))
|
|
203
223
|
else:
|
|
204
224
|
arrowargs=dict(arrowstyle='-|>', color='grey', shrinkA=10, linewidth=0.1, relpos=(1,0.5))
|
|
225
|
+
################################################################################################################################
|
|
205
226
|
|
|
206
227
|
anno_to_adjust = ax1.annotate(annotation_text,
|
|
207
228
|
xy=xy,
|
|
@@ -213,6 +234,8 @@ def annotate_single(
|
|
|
213
234
|
)
|
|
214
235
|
anno_to_adjust_list.append(anno_to_adjust)
|
|
215
236
|
anno_count +=1
|
|
237
|
+
################################################################################################################################
|
|
238
|
+
|
|
216
239
|
#anno_adjust_keyargs = {"arrowprops":dict(arrowstyle='->', color='grey', linewidth=0.1,relpos=(0.5,0.5))}
|
|
217
240
|
if anno_adjust==True:
|
|
218
241
|
log.write(" -Auto-adjusting text positions...", verbose=verbose)
|
|
@@ -354,15 +377,25 @@ def annotate_pair(
|
|
|
354
377
|
arm_scale = arm_scale_d[anno_count]
|
|
355
378
|
|
|
356
379
|
# vertical arm length in pixels
|
|
357
|
-
|
|
358
|
-
#
|
|
359
|
-
|
|
380
|
+
# Annotation y : 1.15 * maxy_anno
|
|
381
|
+
# Top dot: 1 * maxy_anno
|
|
382
|
+
# armB_length_in_point_raw = 0.15 * maxy_anno -> gap_pixel
|
|
383
|
+
# Fixed Offset: 0.5 * 0.15 * gap_pixel
|
|
384
|
+
|
|
385
|
+
#Calculate armB length in pixels
|
|
386
|
+
# arm_scale: raise up the ceiling
|
|
387
|
+
gap_pixel = (ax1.transData.transform((0,1.15*maxy_anno*arm_scale))[1]-ax1.transData.transform((0, maxy_anno*arm_scale))[1])*0.5
|
|
388
|
+
|
|
389
|
+
armB_length_in_pixel_raw = ax1.transData.transform((0,1.15*maxy_anno*arm_scale))[1]-ax1.transData.transform((0, row["scaled_P"]+1))[1]
|
|
390
|
+
|
|
391
|
+
armB_length_in_pixel = armB_length_in_pixel_raw - gap_pixel
|
|
360
392
|
|
|
361
393
|
if arm_scale>=1:
|
|
362
|
-
|
|
394
|
+
armB_length_in_pixel= armB_length_in_pixel if armB_length_in_pixel>0 else 0
|
|
395
|
+
|
|
363
396
|
if anno_fixed_arm_length is not None:
|
|
364
397
|
anno_fixed_arm_length_factor = ax.transData.transform((skip,anno_fixed_arm_length))[1]-ax.transData.transform((skip,0))[1]
|
|
365
|
-
|
|
398
|
+
armB_length_in_pixel = anno_fixed_arm_length_factor
|
|
366
399
|
|
|
367
400
|
if anno==True:
|
|
368
401
|
if row[snpid] in anno_alias.keys():
|
|
@@ -383,24 +416,24 @@ def annotate_pair(
|
|
|
383
416
|
xytext=(last_pos,1.15*maxy_anno*arm_scale)
|
|
384
417
|
|
|
385
418
|
if anno_fixed_arm_length is not None:
|
|
386
|
-
|
|
419
|
+
armB_length_in_pixel = anno_fixed_arm_length
|
|
387
420
|
xytext=(row["i"],row["scaled_P"]+0.2+anno_fixed_arm_length)
|
|
388
421
|
|
|
389
422
|
if anno_count not in anno_d.keys():
|
|
390
423
|
if index==0:
|
|
391
424
|
#upper panel
|
|
392
|
-
if
|
|
425
|
+
if armB_length_in_pixel <5:
|
|
393
426
|
arrowargs = dict(arrowstyle="-|>",relpos=(0,0),color="#ebebeb",connectionstyle="arc,armA=0,armB=0,rad=0.")
|
|
394
427
|
else:
|
|
395
428
|
arrowargs = dict(arrowstyle="-|>",relpos=(0,0),color="#ebebeb",
|
|
396
|
-
connectionstyle="arc,angleA=0,armA=0,angleB=90,armB="+str(
|
|
429
|
+
connectionstyle="arc,angleA=0,armA=0,angleB=90,armB="+str(armB_length_in_pixel)+",rad=0")
|
|
397
430
|
else:
|
|
398
431
|
#lower panel
|
|
399
|
-
if
|
|
432
|
+
if armB_length_in_pixel <5:
|
|
400
433
|
arrowargs = dict(arrowstyle="-|>",relpos=(0,0),color="#ebebeb",connectionstyle="arc,armA=0,armB=0,rad=0.")
|
|
401
434
|
else:
|
|
402
435
|
arrowargs = dict(arrowstyle="-|>",relpos=(0,1),color="#ebebeb",
|
|
403
|
-
connectionstyle="arc,angleA=0,armA=0,angleB=-90,armB="+str(
|
|
436
|
+
connectionstyle="arc,angleA=0,armA=0,angleB=-90,armB="+str(armB_length_in_pixel)+",rad=0")
|
|
404
437
|
|
|
405
438
|
else:
|
|
406
439
|
xy=(row["i"],row["scaled_P"])
|
|
@@ -478,204 +511,4 @@ def annotate_pair(
|
|
|
478
511
|
)
|
|
479
512
|
else:
|
|
480
513
|
log.write(" -Skip annotating", verbose=verbose)
|
|
481
|
-
return ax1,ax5
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
# subtype plot
|
|
485
|
-
def annotate_subtype(
|
|
486
|
-
sumstats,
|
|
487
|
-
anno,
|
|
488
|
-
mode,
|
|
489
|
-
ax1,
|
|
490
|
-
highlight_i,
|
|
491
|
-
to_annotate,
|
|
492
|
-
anno_d,
|
|
493
|
-
anno_alias,
|
|
494
|
-
anno_style,
|
|
495
|
-
anno_args,
|
|
496
|
-
arm_scale,
|
|
497
|
-
anno_max_iter,
|
|
498
|
-
arm_scale_d,
|
|
499
|
-
arm_offset,
|
|
500
|
-
anno_adjust,
|
|
501
|
-
anno_fixed_arm_length,
|
|
502
|
-
maxy,
|
|
503
|
-
anno_fontsize,
|
|
504
|
-
region,
|
|
505
|
-
region_anno_bbox_args,
|
|
506
|
-
skip,
|
|
507
|
-
snpid="SNPID",
|
|
508
|
-
chrom="CHR",
|
|
509
|
-
pos="POS",
|
|
510
|
-
repel_force=0.02,
|
|
511
|
-
verbose=True,
|
|
512
|
-
log=Log()
|
|
513
|
-
):
|
|
514
|
-
if anno and (to_annotate.empty is not True):
|
|
515
|
-
#initiate a list for text and a starting position
|
|
516
|
-
text = []
|
|
517
|
-
last_pos=0
|
|
518
|
-
anno_count=0
|
|
519
|
-
to_annotate = to_annotate.sort_values(by=[chrom,pos])
|
|
520
|
-
## log : annotation column
|
|
521
|
-
if anno==True:
|
|
522
|
-
annotation_col="CHR:POS"
|
|
523
|
-
elif anno:
|
|
524
|
-
annotation_col=anno
|
|
525
|
-
log.write(" -Annotating using column "+annotation_col+"...", verbose=verbose)
|
|
526
|
-
|
|
527
|
-
## calculate y span
|
|
528
|
-
if region is not None:
|
|
529
|
-
y_span = region[2] - region[1]
|
|
530
|
-
else:
|
|
531
|
-
y_span = sumstats["i"].max()-sumstats["i"].min()
|
|
532
|
-
|
|
533
|
-
log.write(" -Adjusting text positions with repel_force={}...".format(repel_force), verbose=verbose)
|
|
534
|
-
if anno_style == "expand" :
|
|
535
|
-
to_annotate.loc[:, "ADJUSTED_i"] = adjust_text_position(to_annotate["i"].values.copy(), y_span, repel_force,max_iter=anno_max_iter,log=log,verbose=verbose)
|
|
536
|
-
## iterate through variants to be annotated
|
|
537
|
-
anno_to_adjust_list = list()
|
|
538
|
-
|
|
539
|
-
for rowi,row in to_annotate.iterrows():
|
|
540
|
-
|
|
541
|
-
# avoid text overlapping
|
|
542
|
-
## adjust x to avoid overlapping################################################################
|
|
543
|
-
if anno_style == "right" :
|
|
544
|
-
#right style
|
|
545
|
-
if row["i"]>last_pos+repel_force*y_span:
|
|
546
|
-
last_pos=row["i"]
|
|
547
|
-
else:
|
|
548
|
-
last_pos+=repel_force*y_span
|
|
549
|
-
elif anno_style == "expand" :
|
|
550
|
-
#expand style
|
|
551
|
-
last_pos = row["ADJUSTED_i"]
|
|
552
|
-
anno_args["rotation"] = 90
|
|
553
|
-
elif anno_style == "tight" :
|
|
554
|
-
#tight style
|
|
555
|
-
anno_fixed_arm_length = 1
|
|
556
|
-
anno_adjust = True
|
|
557
|
-
anno_args["rotation"] = 90
|
|
558
|
-
else:
|
|
559
|
-
pass
|
|
560
|
-
################################################################
|
|
561
|
-
#shrink or increase the arm
|
|
562
|
-
if arm_scale_d is not None:
|
|
563
|
-
if anno_count not in arm_scale_d.keys():
|
|
564
|
-
arm_scale =1
|
|
565
|
-
else:
|
|
566
|
-
arm_scale = arm_scale_d[anno_count]
|
|
567
|
-
################################################################
|
|
568
|
-
|
|
569
|
-
# vertical arm length in pixels
|
|
570
|
-
armB_length_in_point = ax1.transData.transform((skip,1.15*maxy))[1]-ax1.transData.transform((skip, row["scaled_P"]+1))[1]-arm_offset/2
|
|
571
|
-
# scale if needed
|
|
572
|
-
armB_length_in_point = armB_length_in_point*arm_scale
|
|
573
|
-
################################################################
|
|
574
|
-
if arm_scale>=1:
|
|
575
|
-
armB_length_in_point= armB_length_in_point if armB_length_in_point>0 else ax1.transData.transform((skip, maxy+2))[1]-ax1.transData.transform((skip, row["scaled_P"]+1))[1]
|
|
576
|
-
###if anno_fixed_arm_length #############################################################
|
|
577
|
-
if anno_fixed_arm_length is not None:
|
|
578
|
-
anno_fixed_arm_length_factor = ax1.transData.transform((skip,anno_fixed_arm_length))[1]-ax1.transData.transform((skip,0))[1]
|
|
579
|
-
armB_length_in_point = anno_fixed_arm_length_factor
|
|
580
|
-
################################################################################################################################
|
|
581
|
-
# annotation alias
|
|
582
|
-
if anno==True:
|
|
583
|
-
if row[snpid] in anno_alias.keys():
|
|
584
|
-
annotation_text = anno_alias[row[snpid]]
|
|
585
|
-
else:
|
|
586
|
-
annotation_text="Chr"+ str(row[chrom]) +":"+ str(int(row[pos]))
|
|
587
|
-
elif anno:
|
|
588
|
-
annotation_text=row["Annotation"]
|
|
589
|
-
|
|
590
|
-
#
|
|
591
|
-
fontweight = "normal"
|
|
592
|
-
if len(highlight_i) >0:
|
|
593
|
-
if row["i"] in highlight_i:
|
|
594
|
-
fontweight = "bold"
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
xy=(row["i"],row["scaled_P"]+0.2)
|
|
598
|
-
xytext=(last_pos, 1.15*maxy*arm_scale)
|
|
599
|
-
|
|
600
|
-
if anno_fixed_arm_length is not None:
|
|
601
|
-
armB_length_in_point = anno_fixed_arm_length
|
|
602
|
-
xytext=(row["i"],row["scaled_P"]+0.2+anno_fixed_arm_length)
|
|
603
|
-
|
|
604
|
-
if anno_count not in anno_d.keys():
|
|
605
|
-
#arrowargs = dict(arrowstyle="-|>",relpos=(0,0),color="#ebebeb",
|
|
606
|
-
# connectionstyle="arc,angleA=0,armA=0,angleB=90,armB="+str(armB_length_in_point)+",rad=0")
|
|
607
|
-
arrowargs = dict(arrowstyle="-|>",relpos=(0,0),color="#ebebeb",
|
|
608
|
-
connectionstyle="arc,angleA=0,armA=0,angleB=90,armB="+str(armB_length_in_point)+",rad=0")
|
|
609
|
-
else:
|
|
610
|
-
# adjuest direction
|
|
611
|
-
xy=(row["i"],row["scaled_P"])
|
|
612
|
-
if anno_d[anno_count] in ["right","left","l","r"]:
|
|
613
|
-
if anno_d[anno_count]=="right" or anno_d[anno_count]=="r":
|
|
614
|
-
armoffsetall = (ax1.transData.transform(xytext)[0]-ax1.transData.transform(xy)[0])*np.sqrt(2)
|
|
615
|
-
armoffsetb = arm_offset
|
|
616
|
-
armoffseta = armoffsetall - armoffsetb
|
|
617
|
-
arrowargs = dict(arrowstyle="-|>",relpos=(0,0),color="#ebebeb",
|
|
618
|
-
connectionstyle="arc,angleA=-135,armA="+str(armoffseta)+",angleB=45,armB="+str(armoffsetb)+",rad=0")
|
|
619
|
-
elif anno_d[anno_count]=="left" or anno_d[anno_count]=="l":
|
|
620
|
-
arrowargs = dict(arrowstyle="-|>",relpos=(0,0),color="#ebebeb",
|
|
621
|
-
connectionstyle="arc,angleA=-135,armA="+str(arm_offset)+",angleB=135,armB="+str(arm_offset)+",rad=0")
|
|
622
|
-
else:
|
|
623
|
-
if anno_d[anno_count][0]=="right" or anno_d[anno_count][0]=="r":
|
|
624
|
-
armoffsetall = (ax1.transData.transform(xytext)[0]-ax1.transData.transform(xy)[0])*np.sqrt(2)
|
|
625
|
-
armoffsetb = anno_d[anno_count][1]
|
|
626
|
-
armoffseta = armoffsetall - armoffsetb
|
|
627
|
-
arrowargs = dict(arrowstyle="-|>",relpos=(0,0),color="#ebebeb",
|
|
628
|
-
connectionstyle="arc,angleA=-135,armA="+str(armoffseta)+",angleB=45,armB="+str(armoffsetb)+",rad=0")
|
|
629
|
-
elif anno_d[anno_count]=="left" or anno_d[anno_count]=="l":
|
|
630
|
-
arrowargs = dict(arrowstyle="-|>",relpos=(0,0),color="#ebebeb",
|
|
631
|
-
connectionstyle="arc,angleA=-135,armA="+str( anno_d[anno_count][1])+",angleB=135,armB="+str( anno_d[anno_count][1])+",rad=0")
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
if "r" in mode:
|
|
635
|
-
arrowargs["color"] = "black"
|
|
636
|
-
bbox_para=dict(boxstyle="round", fc="white",zorder=3)
|
|
637
|
-
for key,value in region_anno_bbox_args.items():
|
|
638
|
-
bbox_para[key]=value
|
|
639
|
-
else:
|
|
640
|
-
bbox_para=None
|
|
641
|
-
|
|
642
|
-
anno_default = {"rotation":40,"style":"italic","ha":"left","va":"bottom","fontsize":anno_fontsize,"fontweight":fontweight}
|
|
643
|
-
for key,value in anno_args.items():
|
|
644
|
-
anno_default[key]=value
|
|
645
|
-
|
|
646
|
-
if anno_adjust==True:
|
|
647
|
-
arrowargs=dict(arrowstyle='-|>', color='grey', shrinkA=10, linewidth=0.1, relpos=(0,0.5))
|
|
648
|
-
anno_to_adjust = ax1.annotate(annotation_text,
|
|
649
|
-
xy=xy,
|
|
650
|
-
xytext=xytext,
|
|
651
|
-
bbox=bbox_para,
|
|
652
|
-
arrowprops=arrowargs,
|
|
653
|
-
zorder=100,
|
|
654
|
-
**anno_default
|
|
655
|
-
)
|
|
656
|
-
anno_to_adjust_list.append(anno_to_adjust)
|
|
657
|
-
anno_count +=1
|
|
658
|
-
#anno_adjust_keyargs = {"arrowprops":dict(arrowstyle='->', color='grey', linewidth=0.1,relpos=(0.5,0.5))}
|
|
659
|
-
if anno_adjust==True:
|
|
660
|
-
log.write(" -Auto-adjusting text positions...", verbose=verbose)
|
|
661
|
-
adjust_text(texts = anno_to_adjust_list,
|
|
662
|
-
autoalign=False,
|
|
663
|
-
only_move={'points':'x', 'text':'x', 'objects':'x'},
|
|
664
|
-
ax=ax1,
|
|
665
|
-
precision=0.02,
|
|
666
|
-
force_text=(repel_force,repel_force),
|
|
667
|
-
expand_text=(1,1),
|
|
668
|
-
expand_objects=(0,0),
|
|
669
|
-
expand_points=(0,0),
|
|
670
|
-
va="bottom",
|
|
671
|
-
ha='left',
|
|
672
|
-
avoid_points=False,
|
|
673
|
-
lim =100
|
|
674
|
-
#kwargs = anno_adjust_keyargs
|
|
675
|
-
)
|
|
676
|
-
|
|
677
|
-
else:
|
|
678
|
-
log.write(" -Skip annotating", verbose=verbose)
|
|
679
|
-
|
|
680
|
-
return ax1
|
|
681
|
-
|
|
514
|
+
return ax1,ax5
|
gwaslab/viz_aux_quickfix.py
CHANGED
|
@@ -80,6 +80,7 @@ def _quick_fix_chr(seires, chr_dict,log=Log(), verbose=True):
|
|
|
80
80
|
'''
|
|
81
81
|
if pd.api.types.is_string_dtype(seires) == True:
|
|
82
82
|
# if chr is string dtype: convert using chr_dict
|
|
83
|
+
seires = seires.astype("string")
|
|
83
84
|
seires = seires.map(chr_dict, na_action="ignore")
|
|
84
85
|
seires = np.floor(pd.to_numeric(seires, errors='coerce')).astype('Int64')
|
|
85
86
|
return seires
|
|
@@ -93,6 +94,12 @@ def _quick_fix_pos(seires,log=Log(), verbose=True):
|
|
|
93
94
|
return seires
|
|
94
95
|
|
|
95
96
|
|
|
97
|
+
def _dropna_in_cols(sumstats, cols, log=Log(), verbose=True):
|
|
98
|
+
to_drop = sumstats[cols].isna().any(axis=1)
|
|
99
|
+
log.write(" -Dropping {} variants due to missing values in {}.".format(sum(to_drop),cols))
|
|
100
|
+
return sumstats.loc[~to_drop,:]
|
|
101
|
+
|
|
102
|
+
|
|
96
103
|
def _get_largenumber(*args,log=Log(), verbose=True):
|
|
97
104
|
'''
|
|
98
105
|
get a helper large number, >> max(pos)
|
|
@@ -330,7 +337,7 @@ def _cut(series, mode,cutfactor,cut,skip, ylabels, cut_log, verbose, lines_to_pl
|
|
|
330
337
|
if "b" not in mode:
|
|
331
338
|
log.write(" -Minus log10(P) values above " + str(cut)+" will be shrunk with a shrinkage factor of " + str(cutfactor)+"...", verbose=verbose)
|
|
332
339
|
else:
|
|
333
|
-
log.write(" -
|
|
340
|
+
log.write(" -DENSITY values above " + str(cut)+" will be shrunk with a shrinkage factor of " + str(cutfactor)+"...", verbose=verbose)
|
|
334
341
|
|
|
335
342
|
maxticker=int(np.round(series.max(skipna=True)))
|
|
336
343
|
|
|
@@ -448,4 +455,4 @@ def _jagged_y(cut,skip,ax1,mode,mqqratio,jagged_len,jagged_wid, log=Log(), verbo
|
|
|
448
455
|
ax1.plot((x0,-dx), (tycut,tycut+dy), zorder=1001, **kwargs)
|
|
449
456
|
ax1.plot((-dx,+dx), (tycut+dy,tycut+3*dy), zorder=1001, **kwargs)
|
|
450
457
|
ax1.plot((+dx,x0), (tycut+3*dy,tycut+4*dy), zorder=1001, **kwargs)
|
|
451
|
-
return ax1
|
|
458
|
+
return ax1
|
gwaslab/viz_aux_save_figure.py
CHANGED
|
@@ -50,7 +50,8 @@ def get_default_path(keyword,fmt="png"):
|
|
|
50
50
|
"ldscrg":"ldscrg_heatmap",
|
|
51
51
|
"miami":"miami",
|
|
52
52
|
"esc":"effect_size_comparision",
|
|
53
|
-
"afc":"allele_frequency_comparision"
|
|
53
|
+
"afc":"allele_frequency_comparision",
|
|
54
|
+
"gwheatmap":"genome_wide_heatmap"
|
|
54
55
|
}
|
|
55
56
|
prefix = path_dictionary[keyword]
|
|
56
57
|
count = 1
|