diff --git a/codes/run_pipeline.py b/codes/run_pipeline.py index ece6257..332cdcd 100755 --- a/codes/run_pipeline.py +++ b/codes/run_pipeline.py @@ -34,6 +34,7 @@ if __name__ == '__main__': "and also run more than one " "node ,like this 'addTarget,addFusion'", default='addQc') + parser.add_argument('-d', '--debug', action='store_true', help="debug", default=False) args = parser.parse_args() environ_test() @@ -48,7 +49,7 @@ if __name__ == '__main__': cmd = f'nohup python3 ' \ f'{run_wdl_path} -n {args.barcode} -s {args.normal} ' \ f'{"-u " if args.umi else ""} -i {args.input_dir} ' \ - f'-node {args.start_node} ' \ + f'-node {args.start_node} {"-d " if args.debug else ""}' \ f'-o {res_path} -b {args.probe} -p {args.project} -c {args.cancer} -w {args.wdl} ' \ f'> {res_path}/{args.barcode}_{logname}_run.log ' \ f'2>> {res_path}/{args.barcode}_{logname}_run.log &' diff --git a/codes/run_wdl.py b/codes/run_wdl.py index 95e9e39..c554bbb 100755 --- a/codes/run_wdl.py +++ b/codes/run_wdl.py @@ -11,6 +11,9 @@ from datetime import datetime import pandas as pd import requests +# 创建全局的 Session 对象 +session = requests.Session() + def get_branch_nodes(graph, start_node): def dfs(node): @@ -67,14 +70,15 @@ def send_ding(msg): ''' 发送钉钉消息功能 ''' - url = 'https://oapi.dingtalk.com/robot/send?access_token=d4a0749cc7ff87bd12079a79dd74ca3423becb1ce161c3088acc6628a7a188dd' + url = 'https://oapi.dingtalk.com/robot/send?access_token=0c4b2dc1b6a1b459826512cc27adbd14e4f6aa2e661b7a7c284669065bbccfc5' data = {"msgtype": "text", "text": {"content": "pipeline:" + str(msg)}, "at": {"isAtAll": True}} headers = {'Content-Type': 'application/json;charset=UTF-8'} send_data = json.dumps(data).encode('utf-8') - ret = requests.post(url=url, data=send_data, headers=headers) + session.post(url=url, data=send_data, headers=headers) + print(msg) -def run(barcode, normal, umi, input_dir, output_dir, project, cancer, probe, wdl, start_node): +def run(barcode, normal, umi, input_dir, output_dir, project, cancer, probe, wdl, start_node, debug): input_dir = os.path.realpath(input_dir) output_dir = os.path.realpath(output_dir) wdl = os.path.realpath(wdl) @@ -111,6 +115,8 @@ def run(barcode, normal, umi, input_dir, output_dir, project, cancer, probe, wdl # 记录开始时间 start_time = time.time() + if not debug: + send_ding(msg=f'\n样本: {barcode}\n分析地址: \n{output_dir} \n 开始分析') 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: @@ -120,8 +126,6 @@ def run(barcode, normal, umi, input_dir, output_dir, project, cancer, probe, wdl output, error = ret.communicate() print(output, error) - send_ding(msg=f'样本{barcode}已开始分析,分析地址\n{output_dir}') - stdout = open(os.path.join(output_dir, f'{args.barcode}_{logname}_stdout.log'), 'w') stderr = open(os.path.join(output_dir, f'{args.barcode}_{logname}_stderr.log'), 'w') @@ -173,7 +177,8 @@ def run(barcode, normal, umi, input_dir, output_dir, project, cancer, probe, wdl stderr.write(file_path + '\n') stderr.write(f.read()) stderr.write('\n\n') - send_ding(msg=f'样本{barcode}已分析完成,分析地址\n{output_dir}, 请查看!') + if not debug: + send_ding(msg=f'\n样本: {barcode}\n分析地址: \n{output_dir} \n 分析完成,请查看!') stdout.close() stderr.close() @@ -197,7 +202,9 @@ if __name__ == '__main__': "and also run more than one node ," "like this 'addTarget,addFusion'", default='addQc') + parser.add_argument('-d', '--debug', action='store_true', help="debug", default=False) args = parser.parse_args() run(args.barcode, args.normal, args.umi, args.input_dir, args.output_dir, - args.project, args.cancer, args.probe, args.wdl, args.start_node) + args.project, args.cancer, args.probe, args.wdl, args.start_node, args.debug) + session.close()