gwaslab 3.4.49__py3-none-any.whl → 3.5.1__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_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 and how=="inner":
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
@@ -81,6 +81,7 @@ from gwaslab.bd_get_hapmap3 import gethapmap3
81
81
  from gwaslab.util_abf_finemapping import abf_finemapping
82
82
  from gwaslab.util_abf_finemapping import make_cs
83
83
  import gc
84
+ from gwaslab.viz_plot_phe_heatmap import _gwheatmap
84
85
 
85
86
  #20220309
86
87
  class Sumstats():
@@ -602,6 +603,11 @@ class Sumstats():
602
603
  def plot_daf(self, **kwargs):
603
604
  fig,outliers = plotdaf(self.data, **kwargs)
604
605
  return fig, outliers
606
+
607
+ def plot_gwheatmap(self, **kwargs):
608
+ fig = _gwheatmap(self.data, **kwargs)
609
+ return fig
610
+
605
611
  def plot_mqq(self, build=None, **kwargs):
606
612
 
607
613
  chrom="CHR"
@@ -705,7 +711,7 @@ class Sumstats():
705
711
  # return sumstats object
706
712
  return output
707
713
 
708
- def check_cis(self, **kwargs):
714
+ def check_cis(self, gls=False, **kwargs):
709
715
  if "SNPID" in self.data.columns:
710
716
  id_to_use = "SNPID"
711
717
  else:
@@ -717,7 +723,13 @@ class Sumstats():
717
723
  p="P",
718
724
  log=self.log,
719
725
  **kwargs)
720
- # return sumstats object
726
+
727
+ # return sumstats object
728
+ if gls == True:
729
+ new_Sumstats_object = copy.deepcopy(self)
730
+ new_Sumstats_object.data = output
731
+ gc.collect()
732
+ return new_Sumstats_object
721
733
  return output
722
734
 
723
735
  def check_novel_set(self, **kwargs):
@@ -778,28 +790,28 @@ class Sumstats():
778
790
 
779
791
 
780
792
  ## LDSC ##############################################################################################
781
- def estimate_h2_by_ldsc(self, build=None, verbose=True, match_allele=True, **kwargs):
793
+ def estimate_h2_by_ldsc(self, build=None, verbose=True, match_allele=True, how="right", **kwargs):
782
794
  if build is None:
783
795
  build = self.meta["gwaslab"]["genome_build"]
784
- insumstats = gethapmap3(self.data.copy(), build=build, verbose=verbose , match_allele=True, how="right" )
796
+ insumstats = gethapmap3(self.data.copy(), build=build, verbose=verbose , match_allele=match_allele, how=how )
785
797
  self.ldsc_h2, self.ldsc_h2_results = _estimate_h2_by_ldsc(insumstats=insumstats, log=self.log, verbose=verbose, **kwargs)
786
798
 
787
- def estimate_rg_by_ldsc(self, build=None, verbose=True, match_allele=True, **kwargs):
799
+ def estimate_rg_by_ldsc(self, build=None, verbose=True, match_allele=True, how="right",**kwargs):
788
800
  if build is None:
789
801
  build = self.meta["gwaslab"]["genome_build"]
790
- insumstats = gethapmap3(self.data.copy(), build=build, verbose=verbose , match_allele=True, how="right" )
802
+ insumstats = gethapmap3(self.data.copy(), build=build, verbose=verbose , match_allele=match_allele, how=how )
791
803
  self.ldsc_rg = _estimate_rg_by_ldsc(insumstats=insumstats, log=self.log, verbose=verbose, **kwargs)
792
804
 
793
- def estimate_h2_cts_by_ldsc(self, build=None, verbose=True, match_allele=True, **kwargs):
805
+ def estimate_h2_cts_by_ldsc(self, build=None, verbose=True, match_allele=True, how="right",**kwargs):
794
806
  if build is None:
795
807
  build = self.meta["gwaslab"]["genome_build"]
796
- insumstats = gethapmap3(self.data.copy(), build=build, verbose=verbose , match_allele=True, how="right" )
808
+ insumstats = gethapmap3(self.data.copy(), build=build, verbose=verbose , match_allele=match_allele, how=how )
797
809
  self.ldsc_h2_cts = _estimate_h2_cts_by_ldsc(insumstats=insumstats, log=self.log, verbose=verbose, **kwargs)
798
810
 
799
- def estimate_partitioned_h2_by_ldsc(self, build=None, verbose=True, match_allele=True, **kwargs):
811
+ def estimate_partitioned_h2_by_ldsc(self, build=None, verbose=True, match_allele=True, how="right",**kwargs):
800
812
  if build is None:
801
813
  build = self.meta["gwaslab"]["genome_build"]
802
- insumstats = gethapmap3(self.data.copy(), build=build, verbose=verbose , match_allele=True, how="right" )
814
+ insumstats = gethapmap3(self.data.copy(), build=build, verbose=verbose , match_allele=match_allele, how=how )
803
815
  self.ldsc_partitioned_h2_summary, self.ldsc_partitioned_h2_results = _estimate_partitioned_h2_by_ldsc(insumstats=insumstats, log=self.log, verbose=verbose, **kwargs)
804
816
  # external ################################################################################################
805
817
 
gwaslab/g_version.py CHANGED
@@ -15,8 +15,8 @@ def _get_version():
15
15
  def gwaslab_info():
16
16
  # version meta information
17
17
  dic={
18
- "version":"3.4.49",
19
- "release_date":"20241019"
18
+ "version":"3.5.1",
19
+ "release_date":"20241120"
20
20
  }
21
21
  return dic
22
22
 
@@ -0,0 +1,23 @@
1
+ import copy
2
+ def _merge_and_sync_dic(list_of_dics:list, default:dict) -> dict:
3
+ temp = copy.copy(default)
4
+ for dic in list_of_dics:
5
+ if isinstance(dic, dict):
6
+ temp.update(dic)
7
+ return temp
8
+
9
+ def _list_func_args(func):
10
+ return func.__code__.co_varnames
11
+
12
+ def _extract_kwargs(prefix:str, default:dict, kwargs:dict) -> dict:
13
+ extracted = []
14
+ for key,value in kwargs.items():
15
+ if key=="kwargs" or key=="args":
16
+ for key_nested,value_nested in kwargs[key].items():
17
+ if prefix in key_nested and "arg" in key_nested:
18
+ extracted.append(value_nested)
19
+ else:
20
+ if prefix in key and "arg" in key:
21
+ extracted.append(value)
22
+ merged_arg = _merge_and_sync_dic(extracted, default)
23
+ return merged_arg
@@ -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
- log.write(" -Creating converter using ChainFile: {}".format(chain), verbose=verbose)
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"
@@ -619,8 +619,10 @@ def _check_cis(insumstats,
619
619
  except:
620
620
  pass
621
621
 
622
- allsig["CIS/TRANS"] = allsig.apply(lambda x: determine_if_cis(x, group_key,windowsizekb, reference_dict), axis=1)
623
-
622
+ #allsig["CIS/TRANS"] = allsig.apply(lambda x: determine_if_cis(x, group_key,windowsizekb, reference_dict), axis=1)
623
+ cis_tuples = allsig.apply(lambda x: determine_if_cis2(x, group_key,windowsizekb, reference_dict), axis=1)
624
+ allsig[["CIS/TRANS","REF_CHR","REF_START","REF_END"]] = pd.DataFrame(cis_tuples.tolist(), index=allsig.index)
625
+
624
626
  try:
625
627
  allsig = allsig.where(~pd.isna(allsig), pd.NA)
626
628
  except:
@@ -689,6 +691,20 @@ def determine_if_cis(x, group_key,windowsizekb, reference_dict):
689
691
  else:
690
692
  return "NoReference"
691
693
 
694
+ def determine_if_cis2(x, group_key,windowsizekb, reference_dict):
695
+ if x[group_key] in reference_dict.keys():
696
+ is_same_chr = str(reference_dict[x[group_key]][0]) == str(x["CHR"])
697
+ is_large_than_start = int(reference_dict[x[group_key]][1]) - windowsizekb*1000 <= x["POS"]
698
+ is_smaller_than_end = int(reference_dict[x[group_key]][2]) + windowsizekb*1000 >= x["POS"]
699
+
700
+ if is_same_chr and is_large_than_start and is_smaller_than_end:
701
+ return "Cis", int(reference_dict[x[group_key]][0]), int(reference_dict[x[group_key]][1]), int(reference_dict[x[group_key]][2])
702
+ else:
703
+ return "Trans", int(reference_dict[x[group_key]][0]), int(reference_dict[x[group_key]][1]), int(reference_dict[x[group_key]][2])
704
+ else:
705
+ return "NoReference", pd.NA, pd.NA, pd.NA
706
+
707
+
692
708
  def determine_distance(allsig, knownsig):
693
709
  if len(allsig)==0:
694
710
  return allsig
File without changes