-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcovbatScript.py
More file actions
38 lines (26 loc) · 1.11 KB
/
covbatScript.py
File metadata and controls
38 lines (26 loc) · 1.11 KB
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
38
import patsy
import time
import sys
import pandas as pd
import numpy as np
import os
import covbat as cb
# import importlib
# importlib.reload(cb)
# read data from R output
#Expects command line arguments in the following order:
#arg1: Text name of batch column variable in covariate file
#arg2: String to specify model to pass to covbat. Eg: "~ mutation + Age + income*only_child_flag"
#arg3: Text name of columns in model that are numeric rather than categorical
batchVarName = sys.argv[1]
modelStr = sys.argv[2]
numerColNameStr = sys.argv[3]
numerColName = [x.strip() for x in numerColNameStr.split(",")]
if (len(numerColName)==1) & (numerColName[0]=='none'):
numerColName = []
covTbl = pd.read_table(os.path.join('.', 'tempCovbatFiles', 'covarTbl.txt'), index_col=0)
fcDat = pd.read_table(os.path.join('.', 'tempCovbatFiles', 'tempfcData.txt'), index_col=0)
mod = patsy.dmatrix(modelStr, covTbl, return_type="dataframe")
#### CovBat test ####
ebat = cb.covbat(fcDat, covTbl[batchVarName], mod, numerColName)
ebat.to_csv(os.path.join('.', 'tempCovbatFiles', 'matlabCovBat_FC_output.txt'), sep="\t") # save Python output