forked from TyckoLab/CloudASM
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathasm_single_cpg.py
executable file
·37 lines (30 loc) · 999 Bytes
/
asm_single_cpg.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/env python
import os
import scipy.stats as stats
import numpy as np
import pandas as pd
# The schema of the cpg genotype file is the following and the header is included
# chr STRING
# pos INTEGER
# snp_id STRING
# snp_pos INT
# ref_cov INTEGER
# ref_meth INTEGER
# alt_cov INTEGER
# alt_meth INTEGER
CPG_GENOTYPE = os.environ['CPG_GENOTYPE']
OUTPUT_FILE = os.environ['CPG_ASM']
# Import CpG file into Python
df = pd.read_csv(CPG_GENOTYPE)
# Function to extract Fisher p-value (5-digit rounding)
def fisher_pvalue(row):
_, pvalue = stats.fisher_exact([[row['ref_meth'], \
row['alt_meth']], \
[row['ref_cov']-row['ref_meth'], \
row['alt_cov']-row['alt_meth'] \
]])
return round(pvalue,5)
# Create a column with the Fisher p-value
df['fisher_pvalue'] = df.apply(fisher_pvalue, axis = 1)
# Save to CSV
df.to_csv (OUTPUT_FILE, index = None, header = False)