gwaslab 3.5.0__py3-none-any.whl → 3.5.2__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/__init__.py +1 -0
- gwaslab/bd_get_hapmap3.py +3 -1
- gwaslab/g_Sumstats.py +15 -9
- gwaslab/g_version.py +2 -2
- gwaslab/io_process_args.py +28 -0
- gwaslab/qc_fix_sumstats.py +9 -5
- gwaslab/vis_plot_credible sets.py +0 -0
- gwaslab/viz_aux_annotate_plot.py +8 -0
- gwaslab/viz_aux_property.py +2 -0
- gwaslab/viz_aux_quickfix.py +8 -6
- gwaslab/viz_aux_save_figure.py +2 -1
- gwaslab/viz_plot_compare_effect.py +787 -468
- gwaslab/viz_plot_mqqplot.py +27 -9
- gwaslab/viz_plot_phe_heatmap.py +1 -1
- gwaslab/viz_plot_regional2.py +44 -9
- gwaslab/viz_plot_scatter_with_reg.py +229 -0
- gwaslab/viz_plot_stackedregional.py +1 -1
- gwaslab/viz_plot_trumpetplot.py +1 -1
- {gwaslab-3.5.0.dist-info → gwaslab-3.5.2.dist-info}/METADATA +3 -3
- {gwaslab-3.5.0.dist-info → gwaslab-3.5.2.dist-info}/RECORD +24 -20
- {gwaslab-3.5.0.dist-info → gwaslab-3.5.2.dist-info}/WHEEL +1 -1
- {gwaslab-3.5.0.dist-info → gwaslab-3.5.2.dist-info}/LICENSE +0 -0
- {gwaslab-3.5.0.dist-info → gwaslab-3.5.2.dist-info}/LICENSE_before_v3.4.39 +0 -0
- {gwaslab-3.5.0.dist-info → gwaslab-3.5.2.dist-info}/top_level.txt +0 -0
gwaslab/__init__.py
CHANGED
|
@@ -46,3 +46,4 @@ from gwaslab.util_ex_process_h5 import process_vcf_to_hfd5
|
|
|
46
46
|
from gwaslab.util_ex_run_susie import _run_susie_rss as run_susie_rss
|
|
47
47
|
from gwaslab.io_read_tabular import _read_tabular as read_tabular
|
|
48
48
|
from gwaslab.util_in_meta import meta_analyze
|
|
49
|
+
from gwaslab.viz_plot_scatter_with_reg import scatter
|
gwaslab/bd_get_hapmap3.py
CHANGED
|
@@ -47,8 +47,10 @@ def gethapmap3(sumstats,rsid="rsID",chrom="CHR", pos="POS", ea="EA", nea="NEA",b
|
|
|
47
47
|
#rsid A1 A2 #CHROM POS
|
|
48
48
|
#rs3094315 G A 1 752566
|
|
49
49
|
|
|
50
|
-
if rsid in sumstats.columns
|
|
50
|
+
if rsid in sumstats.columns:
|
|
51
|
+
log.write(" -rsID will be used for matching...", verbose=verbose)
|
|
51
52
|
output = sumstats.loc[sumstats[rsid].isin(hapmap3_ref["rsid"].values),:].copy()
|
|
53
|
+
log.write(" -Raw input contains "+str(len(output))+" Hapmap3 variants based on rsID...", verbose=verbose)
|
|
52
54
|
return output
|
|
53
55
|
|
|
54
56
|
elif chrom in sumstats.columns and pos in sumstats.columns:
|
gwaslab/g_Sumstats.py
CHANGED
|
@@ -389,6 +389,12 @@ class Sumstats():
|
|
|
389
389
|
self.data =flipallelestats(self.data,log=self.log,**flipallelestats_args)
|
|
390
390
|
|
|
391
391
|
gc.collect()
|
|
392
|
+
|
|
393
|
+
if (ref_seq is not None or ref_infer is not None) and (ref_rsid_tsv is not None or ref_rsid_vcf is not None):
|
|
394
|
+
|
|
395
|
+
self.data = fixID(self.data, log=self.log, **{"fixid":True, "fixsep":True, "overwrite":True})
|
|
396
|
+
|
|
397
|
+
gc.collect()
|
|
392
398
|
|
|
393
399
|
#####################################################
|
|
394
400
|
if ref_rsid_tsv is not None:
|
|
@@ -790,28 +796,28 @@ class Sumstats():
|
|
|
790
796
|
|
|
791
797
|
|
|
792
798
|
## LDSC ##############################################################################################
|
|
793
|
-
def estimate_h2_by_ldsc(self, build=None, verbose=True, match_allele=True, **kwargs):
|
|
799
|
+
def estimate_h2_by_ldsc(self, build=None, verbose=True, match_allele=True, how="right", **kwargs):
|
|
794
800
|
if build is None:
|
|
795
801
|
build = self.meta["gwaslab"]["genome_build"]
|
|
796
|
-
insumstats = gethapmap3(self.data.copy(), build=build, verbose=verbose , match_allele=
|
|
802
|
+
insumstats = gethapmap3(self.data.copy(), build=build, verbose=verbose , match_allele=match_allele, how=how )
|
|
797
803
|
self.ldsc_h2, self.ldsc_h2_results = _estimate_h2_by_ldsc(insumstats=insumstats, log=self.log, verbose=verbose, **kwargs)
|
|
798
804
|
|
|
799
|
-
def estimate_rg_by_ldsc(self, build=None, verbose=True, match_allele=True,
|
|
805
|
+
def estimate_rg_by_ldsc(self, build=None, verbose=True, match_allele=True, how="right",**kwargs):
|
|
800
806
|
if build is None:
|
|
801
807
|
build = self.meta["gwaslab"]["genome_build"]
|
|
802
|
-
insumstats = gethapmap3(self.data.copy(), build=build, verbose=verbose , match_allele=
|
|
808
|
+
insumstats = gethapmap3(self.data.copy(), build=build, verbose=verbose , match_allele=match_allele, how=how )
|
|
803
809
|
self.ldsc_rg = _estimate_rg_by_ldsc(insumstats=insumstats, log=self.log, verbose=verbose, **kwargs)
|
|
804
810
|
|
|
805
|
-
def estimate_h2_cts_by_ldsc(self, build=None, verbose=True, match_allele=True,
|
|
811
|
+
def estimate_h2_cts_by_ldsc(self, build=None, verbose=True, match_allele=True, how="right",**kwargs):
|
|
806
812
|
if build is None:
|
|
807
813
|
build = self.meta["gwaslab"]["genome_build"]
|
|
808
|
-
insumstats = gethapmap3(self.data.copy(), build=build, verbose=verbose , match_allele=
|
|
814
|
+
insumstats = gethapmap3(self.data.copy(), build=build, verbose=verbose , match_allele=match_allele, how=how )
|
|
809
815
|
self.ldsc_h2_cts = _estimate_h2_cts_by_ldsc(insumstats=insumstats, log=self.log, verbose=verbose, **kwargs)
|
|
810
816
|
|
|
811
|
-
def estimate_partitioned_h2_by_ldsc(self, build=None, verbose=True, match_allele=True,
|
|
817
|
+
def estimate_partitioned_h2_by_ldsc(self, build=None, verbose=True, match_allele=True, how="right",**kwargs):
|
|
812
818
|
if build is None:
|
|
813
819
|
build = self.meta["gwaslab"]["genome_build"]
|
|
814
|
-
insumstats = gethapmap3(self.data.copy(), build=build, verbose=verbose , match_allele=
|
|
820
|
+
insumstats = gethapmap3(self.data.copy(), build=build, verbose=verbose , match_allele=match_allele, how=how )
|
|
815
821
|
self.ldsc_partitioned_h2_summary, self.ldsc_partitioned_h2_results = _estimate_partitioned_h2_by_ldsc(insumstats=insumstats, log=self.log, verbose=verbose, **kwargs)
|
|
816
822
|
# external ################################################################################################
|
|
817
823
|
|
|
@@ -833,4 +839,4 @@ class Sumstats():
|
|
|
833
839
|
def to_format(self, path, build=None, verbose=True, **kwargs):
|
|
834
840
|
if build is None:
|
|
835
841
|
build = self.meta["gwaslab"]["genome_build"]
|
|
836
|
-
_to_format(self.data, path, log=self.log, verbose=verbose, meta=self.meta, build=build, **kwargs)
|
|
842
|
+
_to_format(self.data, path, log=self.log, verbose=verbose, meta=self.meta, build=build, **kwargs)
|
gwaslab/g_version.py
CHANGED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import copy
|
|
2
|
+
|
|
3
|
+
def _list_func_args(func):
|
|
4
|
+
return func.__code__.co_varnames
|
|
5
|
+
|
|
6
|
+
def _extract_kwargs(prefix:str, default:dict, kwargs:dict) -> dict:
|
|
7
|
+
# prefix: keyword
|
|
8
|
+
# default: default dict
|
|
9
|
+
# kwargs: all local kwargs + args + kwargs
|
|
10
|
+
|
|
11
|
+
extracted = []
|
|
12
|
+
for key,value in kwargs.items():
|
|
13
|
+
if key=="kwargs" or key=="args":
|
|
14
|
+
for key_nested,value_nested in kwargs[key].items():
|
|
15
|
+
if prefix in key_nested and "arg" in key_nested:
|
|
16
|
+
extracted.append(value_nested)
|
|
17
|
+
else:
|
|
18
|
+
if prefix in key and "arg" in key:
|
|
19
|
+
extracted.append(value)
|
|
20
|
+
merged_arg = _merge_and_sync_dic(extracted, default)
|
|
21
|
+
return merged_arg
|
|
22
|
+
|
|
23
|
+
def _merge_and_sync_dic(list_of_dics:list, default:dict) -> dict:
|
|
24
|
+
temp = copy.copy(default)
|
|
25
|
+
for dic in list_of_dics:
|
|
26
|
+
if isinstance(dic, dict):
|
|
27
|
+
temp.update(dic)
|
|
28
|
+
return temp
|
gwaslab/qc_fix_sumstats.py
CHANGED
|
@@ -1579,14 +1579,14 @@ def liftover_variant(sumstats,
|
|
|
1579
1579
|
|
|
1580
1580
|
try:
|
|
1581
1581
|
if chain is None:
|
|
1582
|
-
converter = get_lifter(from_build,to_build,one_based=True)
|
|
1582
|
+
converter = get_lifter("hg{}".format(from_build),"hg{}".format(to_build),one_based=True)
|
|
1583
1583
|
else:
|
|
1584
|
-
converter = ChainFile(chain, one_based=True)
|
|
1584
|
+
converter = ChainFile(chain,target="",query="", one_based=True)
|
|
1585
1585
|
except:
|
|
1586
1586
|
if chain is None:
|
|
1587
|
-
converter = get_lifter(from_build,to_build)
|
|
1587
|
+
converter = get_lifter("hg{}".format(from_build),"hg{}".format(to_build))
|
|
1588
1588
|
else:
|
|
1589
|
-
converter = ChainFile(chain)
|
|
1589
|
+
converter = ChainFile(chain, target="",query="")
|
|
1590
1590
|
|
|
1591
1591
|
dic= get_number_to_chr(in_chr=False,xymt=["X","Y","M"])
|
|
1592
1592
|
dic2= get_chr_to_number(out_chr=False)
|
|
@@ -1627,11 +1627,15 @@ def parallelizeliftovervariant(sumstats,n_cores=1,chrom="CHR", pos="POS", from_b
|
|
|
1627
1627
|
else:
|
|
1628
1628
|
try:
|
|
1629
1629
|
chain = get_chain(from_build=from_build, to_build=to_build)
|
|
1630
|
-
|
|
1630
|
+
if chain is None or chain==False:
|
|
1631
|
+
raise ValueError("")
|
|
1632
|
+
log.write(" -Creating converter using provided ChainFile: {}".format(chain), verbose=verbose)
|
|
1631
1633
|
except:
|
|
1632
1634
|
chain = None
|
|
1633
1635
|
lifter_from_build=from_build
|
|
1634
1636
|
lifter_to_build=to_build
|
|
1637
|
+
log.write(" -Try creating converter using liftover package", verbose=verbose)
|
|
1638
|
+
|
|
1635
1639
|
log.write(" -Creating converter : {} -> {}".format(lifter_from_build, lifter_to_build), verbose=verbose)
|
|
1636
1640
|
# valid chr and pos
|
|
1637
1641
|
pattern = r"\w\w\w0\w\w\w"
|
|
File without changes
|
gwaslab/viz_aux_annotate_plot.py
CHANGED
|
@@ -38,6 +38,7 @@ def annotate_single(
|
|
|
38
38
|
region,
|
|
39
39
|
region_anno_bbox_args,
|
|
40
40
|
skip,
|
|
41
|
+
arrow_kwargs=None,
|
|
41
42
|
anno_height=1,
|
|
42
43
|
amode="int",
|
|
43
44
|
snpid="SNPID",
|
|
@@ -48,6 +49,9 @@ def annotate_single(
|
|
|
48
49
|
_invert=False,
|
|
49
50
|
log=Log()
|
|
50
51
|
):
|
|
52
|
+
if arrow_kwargs is None:
|
|
53
|
+
arrow_kwargs=dict()
|
|
54
|
+
|
|
51
55
|
if anno and (to_annotate.empty is not True):
|
|
52
56
|
#initiate a list for text and a starting position
|
|
53
57
|
text = []
|
|
@@ -223,6 +227,8 @@ def annotate_single(
|
|
|
223
227
|
else:
|
|
224
228
|
arrowargs=dict(arrowstyle='-|>', color='grey', shrinkA=10, linewidth=0.1, relpos=(1,0.5))
|
|
225
229
|
################################################################################################################################
|
|
230
|
+
for key,value in arrow_kwargs.items():
|
|
231
|
+
arrowargs[key]=value
|
|
226
232
|
|
|
227
233
|
anno_to_adjust = ax1.annotate(annotation_text,
|
|
228
234
|
xy=xy,
|
|
@@ -293,6 +299,7 @@ def annotate_pair(
|
|
|
293
299
|
pos="POS",
|
|
294
300
|
repel_force=0.02,
|
|
295
301
|
verbose=True,
|
|
302
|
+
arrow_kwargs=None,
|
|
296
303
|
log=Log()
|
|
297
304
|
):
|
|
298
305
|
if anno is not None:
|
|
@@ -474,6 +481,7 @@ def annotate_pair(
|
|
|
474
481
|
arrowargs=dict(arrowstyle='-|>', color='grey', shrinkA=10, linewidth=0.1, relpos=(0,0.5))
|
|
475
482
|
else:
|
|
476
483
|
arrowargs=dict(arrowstyle='-|>', color='grey', shrinkA=10, linewidth=0.1, relpos=(1,0.5))
|
|
484
|
+
|
|
477
485
|
|
|
478
486
|
anno_to_adjust = ax.annotate(annotation_text,
|
|
479
487
|
xy=xy,
|
gwaslab/viz_aux_quickfix.py
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import pandas as pd
|
|
2
2
|
import numpy as np
|
|
3
3
|
from gwaslab.g_Log import Log
|
|
4
|
+
from matplotlib import ticker
|
|
5
|
+
import matplotlib.pyplot as plt
|
|
4
6
|
from gwaslab.bd_common_data import get_chr_to_number
|
|
5
7
|
from gwaslab.bd_common_data import get_number_to_chr
|
|
6
8
|
from math import ceil
|
|
@@ -350,7 +352,7 @@ def _cut(series, mode,cutfactor,cut,skip, ylabels, cut_log, verbose, lines_to_pl
|
|
|
350
352
|
#sumstats.loc[sumstats["scaled_P"]>cut,"scaled_P"] = (sumstats.loc[sumstats["scaled_P"]>cut,"scaled_P"]-cut)/cutfactor + cut
|
|
351
353
|
|
|
352
354
|
maxy = (maxticker-cut)/cutfactor + cut
|
|
353
|
-
|
|
355
|
+
|
|
354
356
|
return series, maxy, maxticker, cut, cutfactor,ylabels,lines_to_plot
|
|
355
357
|
|
|
356
358
|
#def _cut_line(level, mode,cutfactor,cut,skip, ylabels, cut_log, verbose, log):
|
|
@@ -379,10 +381,9 @@ def _set_yticklabels(cut,
|
|
|
379
381
|
log.write(" -Processing Y tick lables...",verbose=verbose)
|
|
380
382
|
# if no cut
|
|
381
383
|
if cut == 0:
|
|
382
|
-
ax1.set_ylim(skip, ceil(maxy*1.2) )
|
|
383
|
-
|
|
384
|
+
ax1.set_ylim((skip, ceil(maxy*1.2)) )
|
|
384
385
|
# if cut
|
|
385
|
-
if cut:
|
|
386
|
+
if cut!=0:
|
|
386
387
|
# add cut line
|
|
387
388
|
|
|
388
389
|
cutline = ax1.axhline(y=cut, linewidth = sc_linewidth,linestyle="--",color=cut_line_color,zorder=1)
|
|
@@ -432,14 +433,15 @@ def _set_yticklabels(cut,
|
|
|
432
433
|
else:
|
|
433
434
|
ax1.set_yticks(ticks1+ticks2)
|
|
434
435
|
ax1.set_yticklabels(tickslabel1+tickslabel2,fontsize=fontsize,family=font_family)
|
|
435
|
-
ax1.set_ylim(bottom = skip)
|
|
436
436
|
|
|
437
437
|
if ylabels is not None:
|
|
438
438
|
ax1.set_yticks(ylabels_converted)
|
|
439
439
|
ax1.set_yticklabels(ylabels,fontsize=fontsize,family=font_family)
|
|
440
440
|
|
|
441
|
+
ylim_top = ax1.get_ylim()[1]
|
|
442
|
+
ax1.set_ybound(lower=skip,upper=ylim_top)
|
|
441
443
|
ax1.tick_params(axis='y', labelsize=fontsize)
|
|
442
|
-
|
|
444
|
+
|
|
443
445
|
return ax1
|
|
444
446
|
|
|
445
447
|
def _jagged_y(cut,skip,ax1,mode,mqqratio,jagged_len,jagged_wid, log=Log(), verbose=True):
|
gwaslab/viz_aux_save_figure.py
CHANGED
|
@@ -51,7 +51,8 @@ def get_default_path(keyword,fmt="png"):
|
|
|
51
51
|
"miami":"miami",
|
|
52
52
|
"esc":"effect_size_comparision",
|
|
53
53
|
"afc":"allele_frequency_comparision",
|
|
54
|
-
"gwheatmap":"genome_wide_heatmap"
|
|
54
|
+
"gwheatmap":"genome_wide_heatmap",
|
|
55
|
+
"scatter":"scatter"
|
|
55
56
|
}
|
|
56
57
|
prefix = path_dictionary[keyword]
|
|
57
58
|
count = 1
|