gwaslab 3.4.41__py3-none-any.whl → 3.4.43__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 CHANGED
@@ -298,9 +298,22 @@ def gtf_to_protein_coding(gtfpath,log=Log(),verbose=True):
298
298
 
299
299
  return protein_coding_path
300
300
 
301
+ ####################################################################################################################
302
+ # From BioPython: https://github.com/biopython/biopython/blob/c5a6b1374267d769b19c1022b4b45472316e78b4/Bio/Seq.py#L36
303
+ def _maketrans(complement_mapping):
304
+ """Make a python string translation table.
305
+
306
+ Arguments:
307
+ - complement_mapping - a dictionary.
301
308
 
302
-
309
+ Returns a translation table (a bytes object of length 256) for use with
310
+ the python string's translate method.
303
311
 
312
+ Compatible with lower case and upper case sequences.
313
+ """
314
+ keys = "".join(complement_mapping.keys()).encode("ASCII")
315
+ values = "".join(complement_mapping.values()).encode("ASCII")
316
+ return bytes.maketrans(keys + keys.lower(), values + values.lower())
304
317
 
305
318
  ####################################################################################################################
306
319
 
gwaslab/bd_get_hapmap3.py CHANGED
@@ -12,7 +12,7 @@ from gwaslab.qc_fix_sumstats import finished
12
12
  #A P-value
13
13
  #A signed summary statistic (beta, OR, log odds, Z-score, etc)
14
14
 
15
- def gethapmap3(sumstats,rsid="rsID",chrom="CHR", pos="POS", ea="EA", nea="NEA",build="19", verbose=True, match_allele= True, log=Log()):
15
+ def gethapmap3(sumstats,rsid="rsID",chrom="CHR", pos="POS", ea="EA", nea="NEA",build="19", verbose=True, match_allele= True, how="inner", log=Log()):
16
16
  ##start function with col checking##########################################################
17
17
  _start_line = "extract HapMap3 SNPs"
18
18
  _end_line = "extracting HapMap3 SNPs"
@@ -47,7 +47,7 @@ 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 and how=="inner":
51
51
  output = sumstats.loc[sumstats[rsid].isin(hapmap3_ref["rsid"].values),:].copy()
52
52
  return output
53
53
 
@@ -56,11 +56,15 @@ def gethapmap3(sumstats,rsid="rsID",chrom="CHR", pos="POS", ea="EA", nea="NEA",b
56
56
  sumstats ["chr:pos"] = sumstats[chrom].astype("string")+":"+sumstats[pos].astype("string")
57
57
  hapmap3_ref["chr:pos"] = hapmap3_ref["#CHROM"]+":"+hapmap3_ref["POS"]
58
58
  hapmap3_ref = hapmap3_ref.rename(columns={"rsid":"rsID"})
59
- output = pd.merge(sumstats,hapmap3_ref.loc[:,["chr:pos","rsID"]+additional_cols],left_on="chr:pos",right_on="chr:pos",how="inner",suffixes=('', '_hapmap3')).copy()
59
+ output = pd.merge(sumstats,hapmap3_ref.loc[:,["chr:pos","rsID"]+additional_cols],left_on="chr:pos",right_on="chr:pos",how=how,suffixes=('', '_hapmap3')).copy()
60
60
  if match_allele:
61
61
  log.write(" -Checking if alleles are same...")
62
62
  is_matched = ((output[ea].astype("string") == output["A1"]) & (output[nea].astype("string") == output["A2"])) \
63
63
  | ((output[ea].astype("string") == output["A2"]) & (output[nea].astype("string") == output["A1"]))
64
+ if how=="right":
65
+ is_matched = ((output[ea].astype("string") == output["A1"]) & (output[nea].astype("string") == output["A2"])) \
66
+ | ((output[ea].astype("string") == output["A2"]) & (output[nea].astype("string") == output["A1"])) | output[ea].isna()
67
+
64
68
  log.write(" -Variants with macthed alleles: {}".format(sum(is_matched)))
65
69
  output = output.loc[is_matched,:]
66
70
  output = output.drop(columns=["chr:pos"]+additional_cols)