bug修复
parent
967ad45cb4
commit
8244373e21
Binary file not shown.
|
|
@ -19,7 +19,7 @@ class BaseAssignment:
|
||||||
self.result = tree() # 报告结果
|
self.result = tree() # 报告结果
|
||||||
self.signtb = set() # 具有明确或潜在临床意义的基因变异
|
self.signtb = set() # 具有明确或潜在临床意义的基因变异
|
||||||
self.signdurg = set() # 潜在临床获益的治疗药物
|
self.signdurg = set() # 潜在临床获益的治疗药物
|
||||||
|
self.sign_from_type = defaultdict(dict) # 不同来源有意义突变记录,NCCN使用
|
||||||
self.drugs_type = dict()
|
self.drugs_type = dict()
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -37,7 +37,8 @@ class Parse(BaseAssignment):
|
||||||
if data.empty:
|
if data.empty:
|
||||||
raise UserWarning('sample_info表为空,生成报告失败!')
|
raise UserWarning('sample_info表为空,生成报告失败!')
|
||||||
data = data.applymap(
|
data = data.applymap(
|
||||||
lambda x: str(x).replace('.', '/').replace('-', '/').replace('——', '/') if str(x) in ['.', '-', '——'] else x)
|
lambda x: str(x).replace('.', '/').replace('-', '/').replace('——', '/') if str(x) in ['.', '-',
|
||||||
|
'——'] else x)
|
||||||
data_dict = data.to_dict('index')[0]
|
data_dict = data.to_dict('index')[0]
|
||||||
data_dict['receiveTime'] = re.split(' ', data_dict['receiveTime'])[0]
|
data_dict['receiveTime'] = re.split(' ', data_dict['receiveTime'])[0]
|
||||||
data_dict['reportTime'] = time.strftime("%Y-%m-%d", time.localtime())
|
data_dict['reportTime'] = time.strftime("%Y-%m-%d", time.localtime())
|
||||||
|
|
@ -60,7 +61,8 @@ class Parse(BaseAssignment):
|
||||||
# 拆分hgvs
|
# 拆分hgvs
|
||||||
data[['gene', 'transcript', 'exon', 'nacid', 'aacid']] = data['AAChange.refGene'].str.split(':', expand=True)
|
data[['gene', 'transcript', 'exon', 'nacid', 'aacid']] = data['AAChange.refGene'].str.split(':', expand=True)
|
||||||
# 没有氨基酸改变用核苷酸改变代替
|
# 没有氨基酸改变用核苷酸改变代替
|
||||||
data['aacid'] = data['aacid'].fillna(data['nacid'])
|
# data['aacid'] = data['aacid'].fillna(data['nacid'])
|
||||||
|
data['aacid'] = data['aacid'].fillna('/')
|
||||||
|
|
||||||
for alter, alter_data in data.groupby('AAChange.refGene'):
|
for alter, alter_data in data.groupby('AAChange.refGene'):
|
||||||
alter_data_need = alter_data[['gene', 'transcript', 'exon', 'nacid', 'aacid', 'mutant_frequency',
|
alter_data_need = alter_data[['gene', 'transcript', 'exon', 'nacid', 'aacid', 'mutant_frequency',
|
||||||
|
|
@ -77,6 +79,7 @@ class Parse(BaseAssignment):
|
||||||
# 汇总
|
# 汇总
|
||||||
if alter_res['AMP_mut_level'] in ['I', 'II']:
|
if alter_res['AMP_mut_level'] in ['I', 'II']:
|
||||||
self.signtb.add(alter)
|
self.signtb.add(alter)
|
||||||
|
self.sign_from_type['target'][alter_res['gene']] = '%s %s' % (alter_res['gene'], alter_res['nacid'])
|
||||||
|
|
||||||
self.result['snvindel'] = res
|
self.result['snvindel'] = res
|
||||||
|
|
||||||
|
|
@ -88,19 +91,21 @@ class Parse(BaseAssignment):
|
||||||
return
|
return
|
||||||
data = data[data['Validated'] == 1].reset_index()
|
data = data[data['Validated'] == 1].reset_index()
|
||||||
for alter, alter_data in data.groupby('FUSION'):
|
for alter, alter_data in data.groupby('FUSION'):
|
||||||
alter_data_need = alter_data[['FUSION', 'FREQ1', 'AMP_mut_level', 'Gene_function']]
|
alter_data_need = alter_data[['FUSION', 'FREQ1', 'AMP_mut_level', 'Gene_function', 'Gene_Symbol']]
|
||||||
alter_res = alter_data_need.iloc[0].to_dict()
|
alter_res = alter_data_need.iloc[0].to_dict()
|
||||||
alter_res['drug_category'] = self._drug_category(alter_data)
|
alter_res['drug_category'] = self._drug_category(alter_data)
|
||||||
drug_content = alter_data[
|
drug_content = alter_data[
|
||||||
['DrugCn', 'Response_Type', 'Indication', 'Evidence_Source', 'Efficacy_Evidence']]
|
['DrugCn', 'Response_Type', 'Indication', 'Evidence_Source', 'Efficacy_Evidence']]
|
||||||
drug_content = drug_content[drug_content['DrugCn'] != '.']
|
drug_content = drug_content[drug_content['DrugCn'] != '.']
|
||||||
alter_res['drug_content'] = drug_content.reset_index().to_dict('records')
|
alter_res['drug_content'] = drug_content.reset_index().to_dict('records')
|
||||||
alter_res['alter'] = '%s 融合' % (alter_res['FUSION'].replace('-', ':'))
|
des = '%s 融合' % (alter_res['FUSION'].replace('-', '::'))
|
||||||
|
alter_res['alter'] = des
|
||||||
res.append(alter_res)
|
res.append(alter_res)
|
||||||
|
|
||||||
# 汇总
|
# 汇总
|
||||||
if alter_res['AMP_mut_level'] in ['I', 'II']:
|
if alter_res['AMP_mut_level'] in ['I', 'II']:
|
||||||
self.signtb.add(alter)
|
self.signtb.add(alter)
|
||||||
|
self.sign_from_type['fusion'][alter_res['Gene_Symbol']] = des
|
||||||
|
|
||||||
self.result['fusion'] = res
|
self.result['fusion'] = res
|
||||||
|
|
||||||
|
|
@ -121,12 +126,14 @@ class Parse(BaseAssignment):
|
||||||
['DrugCn', 'Response_Type', 'Indication', 'Evidence_Source', 'Efficacy_Evidence']]
|
['DrugCn', 'Response_Type', 'Indication', 'Evidence_Source', 'Efficacy_Evidence']]
|
||||||
drug_content = drug_content[drug_content['DrugCn'] != '.']
|
drug_content = drug_content[drug_content['DrugCn'] != '.']
|
||||||
alter_res['drug_content'] = drug_content.reset_index().to_dict('records')
|
alter_res['drug_content'] = drug_content.reset_index().to_dict('records')
|
||||||
|
des = '%s %s' % (alter, alter_res['muttype'])
|
||||||
alter_res['alter'] = '%s %s' % (alter, alter_res['muttype'])
|
alter_res['alter'] = '%s %s' % (alter, alter_res['muttype'])
|
||||||
res.append(alter_res)
|
res.append(alter_res)
|
||||||
|
|
||||||
# 汇总
|
# 汇总
|
||||||
if alter_res['AMP_mut_level'] in ['I', 'II']:
|
if alter_res['AMP_mut_level'] in ['I', 'II']:
|
||||||
self.signtb.add(alter)
|
self.signtb.add(alter)
|
||||||
|
self.sign_from_type['cnv'][alter_res['Gene_Symbol']] = des
|
||||||
self.result['cnv'] = res
|
self.result['cnv'] = res
|
||||||
|
|
||||||
def hotspot(self):
|
def hotspot(self):
|
||||||
|
|
@ -268,13 +275,21 @@ class Parse(BaseAssignment):
|
||||||
|
|
||||||
def chemo(self):
|
def chemo(self):
|
||||||
chemo_res = self._to_records('chemo_res', need=True)
|
chemo_res = self._to_records('chemo_res', need=True)
|
||||||
chemo_res_df = pd.DataFrame(chemo_res)
|
|
||||||
chemo_res_df.index = chemo_res_df.index + 1
|
chemo_res_list = []
|
||||||
chemo_res_df = chemo_res_df.reset_index()
|
chemo_sign_drug_num = 0
|
||||||
self.result['chemo']['chemo_res'] = chemo_res_df.to_dict('records')
|
chemo_drug_category = dict()
|
||||||
self.result['sum']['chemo']['drug_num'] = len(chemo_res)
|
if chemo_res:
|
||||||
self.result['sum']['chemo']['drug_category'] = pd.DataFrame(chemo_res).groupby('推荐程度')['药物名称'].apply(
|
chemo_res_df = pd.DataFrame(chemo_res)
|
||||||
','.join).to_dict()
|
chemo_res_df.index = chemo_res_df.index + 1
|
||||||
|
chemo_res_df = chemo_res_df.reset_index()
|
||||||
|
chemo_res_list = chemo_res_df.to_dict('records')
|
||||||
|
chemo_sign_drug_num = len(chemo_res_df[chemo_res_df['推荐程度'] == '推荐'])
|
||||||
|
chemo_drug_category = chemo_res_df.groupby('推荐程度')['药物名称'].apply(
|
||||||
|
','.join).to_dict()
|
||||||
|
self.result['chemo']['chemo_res'] = chemo_res_list
|
||||||
|
self.result['sum']['chemo']['drug_num'] = chemo_sign_drug_num
|
||||||
|
self.result['sum']['chemo']['drug_category'] = chemo_drug_category
|
||||||
|
|
||||||
chemo_comb = self._to_records('chemo_comb', need=True)
|
chemo_comb = self._to_records('chemo_comb', need=True)
|
||||||
chemo_comb_res = dict()
|
chemo_comb_res = dict()
|
||||||
|
|
@ -309,13 +324,15 @@ class Parse(BaseAssignment):
|
||||||
|
|
||||||
hereditary_risk = pd.DataFrame(self.sampledata['hereditary_risk'])
|
hereditary_risk = pd.DataFrame(self.sampledata['hereditary_risk'])
|
||||||
if not hereditary_risk.empty:
|
if not hereditary_risk.empty:
|
||||||
risk = ','.join(hereditary_risk[hereditary_risk['风险值'] == '偏高']['肿瘤类型'].to_list())
|
risk = ','.join(hereditary_risk[hereditary_risk['风险值'] == '偏高']['肿瘤类型'].to_list()) + '风险可能较高'
|
||||||
|
|
||||||
self.result['hereditary'] = hereditary.to_dict('records')
|
self.result['hereditary'] = hereditary.to_dict('records')
|
||||||
self.result['sum']['hereditary']['result'] = result
|
self.result['sum']['hereditary']['result'] = result
|
||||||
self.result['sum']['hereditary']['disease'] = disease
|
self.result['sum']['hereditary']['disease'] = disease
|
||||||
self.result['sum']['hereditary']['risk'] = risk
|
self.result['sum']['hereditary']['risk'] = risk
|
||||||
|
|
||||||
|
self.result['sum']['hereditary']['num'] = len(hereditary.index)
|
||||||
|
|
||||||
def qc(self):
|
def qc(self):
|
||||||
# self._to_dicts('qc')
|
# self._to_dicts('qc')
|
||||||
data = pd.DataFrame(self.sampledata['qc'])
|
data = pd.DataFrame(self.sampledata['qc'])
|
||||||
|
|
@ -335,11 +352,35 @@ class Parse(BaseAssignment):
|
||||||
if not data.empty:
|
if not data.empty:
|
||||||
data = data.dropna()
|
data = data.dropna()
|
||||||
data = data[data['drug_detail'] != '.']
|
data = data[data['drug_detail'] != '.']
|
||||||
|
data = data.applymap(lambda x: str(x).replace('\\\\', '\n') if ' \\\\' in str(x) else x)
|
||||||
res = data.set_index('drug_name')['drug_detail'].to_dict()
|
res = data.set_index('drug_name')['drug_detail'].to_dict()
|
||||||
self.result['drugs']['drugs_detail'] = res
|
self.result['drugs']['drugs_detail'] = res
|
||||||
|
|
||||||
def indication(self):
|
def indication(self):
|
||||||
self._to_records('indication')
|
indication_res = self._to_records('indication', need=True)
|
||||||
|
trans = dict(
|
||||||
|
突变='target',
|
||||||
|
融合='fusion',
|
||||||
|
扩增='cnv'
|
||||||
|
)
|
||||||
|
res = list()
|
||||||
|
if indication_res:
|
||||||
|
# indication_res_df = pd.DataFrame(indication_res)
|
||||||
|
# indication_res_df['变异'] = indication_res_df.apply(
|
||||||
|
# lambda x: self.sign_from_type.get(trans.get(tbtype, ''), '') for tbtype in x['检测内容'].split('/'))
|
||||||
|
for indication_sp in indication_res:
|
||||||
|
gene_tbtype_res = list()
|
||||||
|
for tbtype in indication_sp['检测内容'].split('/'):
|
||||||
|
if tbtype not in trans:
|
||||||
|
continue
|
||||||
|
if trans[tbtype] not in self.sign_from_type:
|
||||||
|
continue
|
||||||
|
if indication_sp['基因'] not in self.sign_from_type[trans[tbtype]]:
|
||||||
|
continue
|
||||||
|
gene_tbtype_res.append(self.sign_from_type[trans[tbtype]][indication_sp['基因']])
|
||||||
|
indication_sp['检测情况'] = '\n'.join(gene_tbtype_res)
|
||||||
|
res.append(indication_sp)
|
||||||
|
self.result['indication'] = res
|
||||||
|
|
||||||
def _to_records(self, sheetname, need=False):
|
def _to_records(self, sheetname, need=False):
|
||||||
"""
|
"""
|
||||||
|
|
@ -376,17 +417,21 @@ class Parse(BaseAssignment):
|
||||||
for drug_category, drug_category_alter_data in groupdata.groupby('Drug_Category'):
|
for drug_category, drug_category_alter_data in groupdata.groupby('Drug_Category'):
|
||||||
if drug_category == '.':
|
if drug_category == '.':
|
||||||
continue
|
continue
|
||||||
|
drug_category_alter_data['drug_split'] = drug_category_alter_data['DrugCn'].str.split(',')
|
||||||
|
drug_category_alter_data_split = drug_category_alter_data.explode('drug_split').reset_index()
|
||||||
# 敏感,可能敏感药物统计
|
# 敏感,可能敏感药物统计
|
||||||
if drug_category in ['a', 'b', 'c']:
|
if drug_category in ['a', 'b', 'c']:
|
||||||
self.signdurg.update(set(drug_category_alter_data['DrugCn'].str.split(',').explode().tolist()))
|
self.signdurg.update(set(drug_category_alter_data_split['drug_split'].tolist()))
|
||||||
drug_category_alter_data['drugdes'] = drug_category_alter_data.apply(
|
drug_category_alter_data_split['drugdes'] = drug_category_alter_data_split.apply(
|
||||||
lambda x: '%s 【%s 级】' % (x['DrugCn'], x['AMP_evidence_level']), axis=1)
|
lambda x: '%s 【%s 级】' % (x['drug_split'], x['AMP_evidence_level']), axis=1)
|
||||||
drug_category_res[drug_category] = '\n'.join(drug_category_alter_data['drugdes'].to_list())
|
drug_category_res[drug_category] = '\n'.join(drug_category_alter_data_split['drugdes'].to_list())
|
||||||
|
|
||||||
# 所有药物信息
|
# 所有药物信息
|
||||||
groupdata['list_col'] = groupdata['DrugCn'].str.replace(' + ', '+').str.split(r'[+,]')
|
groupdata['list_col'] = groupdata['DrugCn'].str.replace(' + ', '+').str.split(r'[+,]')
|
||||||
exploded_df = groupdata.explode('list_col').reset_index()
|
exploded_df = groupdata.explode('list_col').reset_index()
|
||||||
exploded_df = exploded_df[(exploded_df['list_col'] != '.') & (exploded_df['list_col'] != '')]
|
exploded_df = exploded_df[(exploded_df['list_col'] != '.') & (exploded_df['list_col'] != '')]
|
||||||
|
exploded_df.loc[exploded_df['Response_Type'].str.contains('敏感'), 'Response_Type'] = '可能敏感'
|
||||||
|
exploded_df.loc[exploded_df['Response_Type'].str.contains('耐药'), 'Response_Type'] = '可能耐药'
|
||||||
exploded_dict = exploded_df.groupby('Response_Type')['list_col'].agg(lambda x: list(set(x))).to_dict()
|
exploded_dict = exploded_df.groupby('Response_Type')['list_col'].agg(lambda x: list(set(x))).to_dict()
|
||||||
|
|
||||||
for drug_type in exploded_dict:
|
for drug_type in exploded_dict:
|
||||||
|
|
@ -448,8 +493,8 @@ def run(path):
|
||||||
parse = Parse(read(path))
|
parse = Parse(read(path))
|
||||||
res = parse.collect()
|
res = parse.collect()
|
||||||
resjson = json.dumps(res, indent=4, ensure_ascii=False)
|
resjson = json.dumps(res, indent=4, ensure_ascii=False)
|
||||||
with open('t.json', 'w') as f:
|
# with open('t.json', 'w') as f:
|
||||||
f.write(resjson)
|
# f.write(resjson)
|
||||||
return resjson
|
return resjson
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue