From cb89ec1ef9e39e9b8f5594f19e7f33b497bad047 Mon Sep 17 00:00:00 2001 From: chaopower Date: Thu, 22 Feb 2024 16:45:19 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0qcfail?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- codes/postprocess.py | 4 +++- codes/run_wdl.py | 23 +++++++++++++++++------ wdl/postprocess.wdl | 1 + 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/codes/postprocess.py b/codes/postprocess.py index 0ea1333..2a8be2a 100755 --- a/codes/postprocess.py +++ b/codes/postprocess.py @@ -91,6 +91,7 @@ class PostProcess: # 突变的等级分类 if '证据等级' in df.columns: df['AMP_mut_level'] = df['证据等级'].replace(['A', 'B', 'C', 'D'], ['I', 'I', 'II', 'II']) + # df['NCCN_mut_level'] = df['证据等级'].replace(['A', 'B', 'C', 'D'], ['I', 'II', 'II', 'II']) # 药物等级划分 if 'Response_Type_C' in df.columns and '证据等级' in df.columns: @@ -527,7 +528,8 @@ class PostProcess: if qc_files: if os.path.getsize(qc_files[0]) > 0: qc = pd.read_csv(qc_files[0], sep='\t', header=None) - qc_res = [qc.set_index(0)[1].to_dict()] + qc_content = qc.set_index(0)[1].to_dict() + qc_res = [qc_content] self.sheet['qc'] = qc_res def drugs(self): diff --git a/codes/run_wdl.py b/codes/run_wdl.py index c554bbb..1e99ea8 100755 --- a/codes/run_wdl.py +++ b/codes/run_wdl.py @@ -66,12 +66,13 @@ def get_catecode(project, start_node='addQc'): return cate_dict -def send_ding(msg): +def send_ding(msg, isat=True): ''' 发送钉钉消息功能 ''' url = 'https://oapi.dingtalk.com/robot/send?access_token=0c4b2dc1b6a1b459826512cc27adbd14e4f6aa2e661b7a7c284669065bbccfc5' - data = {"msgtype": "text", "text": {"content": "pipeline:" + str(msg)}, "at": {"isAtAll": True}} + # url = 'https://oapi.dingtalk.com/robot/send?access_token=d4a0749cc7ff87bd12079a79dd74ca3423becb1ce161c3088acc6628a7a188dd' + data = {"msgtype": "text", "text": {"content": "pipeline:" + str(msg)}, "at": {"isAtAll": isat}} headers = {'Content-Type': 'application/json;charset=UTF-8'} send_data = json.dumps(data).encode('utf-8') session.post(url=url, data=send_data, headers=headers) @@ -116,7 +117,7 @@ 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 开始分析') + send_ding(msg=f'\n样本: {barcode}\n分析地址: \n{output_dir} \n 开始分析', isat=False) 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: @@ -163,12 +164,12 @@ def run(barcode, normal, umi, input_dir, output_dir, project, cancer, probe, wdl # 按照文件的修改时间倒序排序 sorted_stdout_files = sorted(stdout_files, key=lambda x: os.path.getmtime(x), reverse=True) sorted_stderr_files = sorted(stderr_files, key=lambda x: os.path.getmtime(x), reverse=True) - for file_path in sorted_stdout_files: with open(file_path, 'r') as f: stdout.write('#' * 50 + '\n') stdout.write(file_path + '\n') - stdout.write(f.read()) + f_read = f.read() + stdout.write(f_read) stdout.write('\n\n') for file_path in sorted_stderr_files: @@ -177,8 +178,18 @@ 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') + + qcfail_f = os.path.join(output_dir, 'report', f'{barcode}_qcfail.txt') + if os.path.exists(qcfail_f): + with open(qcfail_f, "r") as qcfail_f_out: + qcfail = qcfail_f_out.read() + else: + qcfail = '流程失败,请核查!!!' + if not qcfail: + qcfail = '合格' if not debug: - send_ding(msg=f'\n样本: {barcode}\n分析地址: \n{output_dir} \n 分析完成,请查看!') + send_ding(msg=f'\n样本: {barcode}\n分析地址: \n{output_dir} \n 分析完成,请查看!\n\n qcfail: \n {qcfail}\n') + stdout.close() stderr.close() diff --git a/wdl/postprocess.wdl b/wdl/postprocess.wdl index 033dd66..8898872 100755 --- a/wdl/postprocess.wdl +++ b/wdl/postprocess.wdl @@ -22,6 +22,7 @@ task run_post { fi indication.pl ${output_dir} ${cancer} ${project} sample_post.py -s ${name} -o ${output_dir} + qc_check.py -n ${output_dir}/qc/${name}_qc.txt -s ${output_dir}/qc/${normal}_qc.txt -p ${output_dir}/pollution/${name}_gender_res.txt -c ${output_dir}/qc/${name}_post.json -o ${output_dir}/report/${name}_qcfail.txt postprocess.py -n ${name} -s ${normal} -c ${output_dir} -o ${output_dir}/report/${name}.merged_file.xlsx }