71 lines
2.7 KiB
Python
Executable File
71 lines
2.7 KiB
Python
Executable File
import argparse
|
|
import json
|
|
import os
|
|
import subprocess
|
|
import time
|
|
|
|
|
|
def run(barcode, normal, umi, input_dir, output_dir, project, bed, wdl):
|
|
input_dir = os.path.realpath(input_dir)
|
|
output_dir = os.path.realpath(output_dir)
|
|
wdl = os.path.realpath(wdl)
|
|
arg = {
|
|
"pipeline.tumor": barcode,
|
|
"pipeline.normal": normal,
|
|
"pipeline.umi": umi,
|
|
"pipeline.input_dir": input_dir,
|
|
"pipeline.output_dir": output_dir,
|
|
"pipeline.project": project,
|
|
"pipeline.bed": bed
|
|
}
|
|
|
|
arg = {key: value for key, value in arg.items() if value not in (None, '', False)}
|
|
|
|
# generate json
|
|
jsfile_path = os.path.join(output_dir, f'{barcode}.json')
|
|
with open(jsfile_path, 'w') as jsfile:
|
|
jsfile.write(json.dumps(arg, indent=4, ensure_ascii=False))
|
|
|
|
# run pipeline
|
|
cmd1 = 'export PATH=/home/zhangchao/project/pipeline/workflow/script:$PATH'
|
|
cmd2 = 'export PUBLIC=/home/zhangchao/project/pipeline/workflow/script/public/'
|
|
cmd3 = f'cd {output_dir}'
|
|
cmd4 = f'/home/zhangchao/soft/jdk-17.0.7+7/bin/java -jar /home/zhangchao/soft/cromwell-85.jar run --inputs {jsfile_path} {wdl}'
|
|
cmd = f'{cmd1}; {cmd2}; {cmd3}; {cmd4}'
|
|
|
|
# 记录开始时间
|
|
start_time = time.time()
|
|
print(cmd)
|
|
ret = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, encoding="utf-8")
|
|
pidnum = ret.pid
|
|
with open(os.path.join(output_dir, 'pid'), 'w') as pidfile:
|
|
pidfile.write(str(pidnum))
|
|
ret.wait()
|
|
# 记录结束时间
|
|
end_time = time.time()
|
|
# 计算运行时间
|
|
elapsed_time = end_time - start_time
|
|
|
|
print("\n运行时间:{:.2f} 秒".format(elapsed_time))
|
|
|
|
print(ret.stdout.read(), ret.stderr.read())
|
|
print('#' * 50)
|
|
print('读取日志')
|
|
|
|
|
|
if __name__ == '__main__':
|
|
parser = argparse.ArgumentParser(description="JM to run pipeline")
|
|
|
|
parser.add_argument('-n', '--barcode', help="sample's barcode", required=True)
|
|
parser.add_argument('-s', '--normal', help="sample's normal", default='', required=False, nargs='?')
|
|
parser.add_argument('-u', '--umi', action='store_true', help="is umi sample", default=False)
|
|
parser.add_argument('-i', '--input_dir', help="sample's input_dir/workdir", required=True)
|
|
parser.add_argument('-o', '--output_dir', help="Output directory, default ./", default='./')
|
|
parser.add_argument('-p', '--project', help="project", required=True)
|
|
parser.add_argument('-b', '--bed', help="bed", required=True)
|
|
parser.add_argument('-w', '--wdl', help="wdl")
|
|
|
|
args = parser.parse_args()
|
|
|
|
run(args.barcode, args.normal, args.umi, args.input_dir, args.output_dir, args.project, args.bed, args.wdl)
|