-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdnameth.py
64 lines (55 loc) · 2.12 KB
/
dnameth.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# PROTOTYPE FOR DNAmeth
import sys
from os import walk, path, sep, makedirs
import subprocess
import logging
import argparse
COMMAND_R = "Rscript"
PROGRAM = "DNAmeth"
LOG_PATH = '/pfs/out'
logging.basicConfig(filename = f"{LOG_PATH}/{PROGRAM}.log",
level = logging.DEBUG,
format = "%(levelname)s : %(asctime)s - %(message)s")
logger = logging.getLogger()
try:
parser = argparse.ArgumentParser()
parser.add_argument("-i", "--input", help="", required=True)
parser.add_argument("-o", "--output", help="Output folder", default=LOG_PATH)
parser.add_argument("-s", "--step", help="DNA methylation step (R script name) \
(00_load_data, 01_clean_data, 02_bmiq, 03_cnv, 04_sva, 05_qc, 06_make_cg_gene)", required=True)
parser.add_argument("-a", "--anno", help="Annotation file folder", default="")
parser.add_argument("-c", "--cross", help="CrossHybrid file folder", default="")
parser.add_argument("-p", "--pheno", help="Phenotype file folder", default="")
parser.add_argument("-e", "--ehub", help="Path to ehub", default="")
args = parser.parse_args()
except Exception as e:
logger.error(e)
sys.exit(1)
# Declare variables
# POSTFIX = "_dnameth"
SCRIPT_NAME = args.step + '.R'
INPUTF = path.normpath(args.input) + sep
OUTPUTF = path.normpath(args.output) + sep
ANNO = args.anno
CROSS = args.cross
PHENO = args.pheno
EHUB = args.ehub
# Ensure about output folder
if not path.exists(OUTPUTF):
# OUTPUTF = OUTPUTF + '_' + PROGRAM + sep
makedirs(OUTPUTF)
logger.info(f"""Preparing DNA methylation pipeline script with
step - {args.step}
input folder - {INPUTF}
output folder - {OUTPUTF}
additional agrs - {ANNO} {CROSS} {PHENO} {EHUB}""")
if (path.exists(INPUTF) and path.exists(OUTPUTF)):
cmd = f"{COMMAND_R} {SCRIPT_NAME} {INPUTF} {OUTPUTF} {ANNO} {CROSS} {PHENO} {EHUB}"
# Rscript 00_load_data.R {input_folder} {output_folder}
logger.info(f"Executing: {str((cmd.strip()).split())}")
subprocess.call((cmd.strip()).split())
else:
logger.warning(f"Check the existence of the provided input folder: {args.input}")
sys.exit()
logger.info("Done current datum")
logging.shutdown()