bug 更新

main
chaopower 2023-12-14 10:26:34 +08:00
parent 1bffac2029
commit c60d5fe6cc
2 changed files with 68 additions and 60 deletions

View File

@ -67,16 +67,23 @@ def server():
adrss = ("", 8191)
myserver.bind(adrss)
myserver.listen(5)
while True:
try:
myclient, adddr = myserver.accept()
recv_content, chipnum = recvdata(myclient, os.path.join(basedir, 'example'))
layout = T7(recv_content, chipnum)
outputpath = layout.run()
senddata(myclient, outputpath)
except Exception as e:
print(e)
continue
# while True:
# try:
# myclient, adddr = myserver.accept()
# recv_content, chipnum = recvdata(myclient, os.path.join(basedir, 'example'))
# layout = T7(recv_content, chipnum)
# outputpath = layout.run()
# senddata(myclient, outputpath)
# except Exception as e:
# print(e)
# continue
if __name__ == '__main__':

View File

@ -13,7 +13,7 @@ class AutoLayout:
自动化派样
"""
def __init__(self, path, chipnum, output=basedir, data_limit=1520):
def __init__(self, path, chipnum, output=basedir, data_limit=1800):
self.path = path
self.output = output
self.chipnum = int(chipnum)
@ -78,39 +78,39 @@ class AutoLayout:
self.chip_customer[chipname].add(library_data['customer'])
self.chip_classification[chipname].add(library_data['classification'])
def add_new_chip(self, library_data):
"""
要新增到芯片上的数据
:param library_data:
:return:
"""
chip_num_tmp = self.loc_chip_num
while True:
chip_num_tmp += 1
chipname_tmp = f'chip{chip_num_tmp}'
library = library_data['library']
if chipname_tmp not in self.index_assignments:
self.logger.error(f'{library} {chipname_tmp} 常规添加')
self.add_new_data(chipname_tmp, library_data)
break
else:
is_same_barcode = self.chip_barcode_recode[chipname_tmp].intersection(
{item['barcode'] for item in library_data['data']})
# 没有从重复的index,并且也不互斥的
if ((self.chip_size[chipname_tmp] + library_data['size']) > self.data_limit):
self.logger.error(f'{library} {chipname_tmp} 文库相加大于设定限制')
if ((self.chip_speciallib_size[chipname_tmp] + library_data['size']) >= 200):
self.logger.error(f'{library} {chipname_tmp} 不平衡文库相加大于设定限制')
if is_same_barcode:
self.logger.error(f'{library} {chipname_tmp} 文库有barcode重复')
if self.use_rule(chipname_tmp, library_data['customer']):
self.logger.error(f'{library} {chipname_tmp} 有互斥单位')
if ((self.chip_size[chipname_tmp] + library_data['size']) <= self.data_limit) \
and ((self.chip_speciallib_size[chipname_tmp] + library_data['size']) < 200) \
and (not is_same_barcode) \
and (not self.use_rule(chipname_tmp, library_data['customer'])):
self.add_new_data(chipname_tmp, library_data, newer=False)
break
# def add_new_chip(self, library_data):
# """
# 要新增到芯片上的数据
# :param library_data:
# :return:
# """
# chip_num_tmp = self.loc_chip_num
# while True:
# chip_num_tmp += 1
# chipname_tmp = f'chip{chip_num_tmp}'
# library = library_data['library']
# if chipname_tmp not in self.index_assignments:
# self.logger.error(f'{library} {chipname_tmp} 常规添加')
# self.add_new_data(chipname_tmp, library_data)
# break
# else:
# is_same_barcode = self.chip_barcode_recode[chipname_tmp].intersection(
# {item['barcode'] for item in library_data['data']})
# # 没有从重复的index,并且也不互斥的
# if ((self.chip_size[chipname_tmp] + library_data['size']) > self.data_limit):
# self.logger.error(f'{library} {chipname_tmp} 文库相加大于设定限制')
# if ((self.chip_speciallib_size[chipname_tmp] + library_data['size']) >= 200):
# self.logger.error(f'{library} {chipname_tmp} 不平衡文库相加大于设定限制')
# if is_same_barcode:
# self.logger.error(f'{library} {chipname_tmp} 文库有barcode重复')
# if self.use_rule(chipname_tmp, library_data['customer']):
# self.logger.error(f'{library} {chipname_tmp} 有互斥单位')
# if ((self.chip_size[chipname_tmp] + library_data['size']) <= self.data_limit) \
# and ((self.chip_speciallib_size[chipname_tmp] + library_data['size']) < 200) \
# and (not is_same_barcode) \
# and (not self.use_rule(chipname_tmp, library_data['customer'])):
# self.add_new_data(chipname_tmp, library_data, newer=False)
# break
def dec_barcode_radio(self, chipname):
data = self.index_assignments[chipname]
@ -134,8 +134,6 @@ class AutoLayout:
# is_need_base = col_df.index[col_df['ratio'] < 0.088]
A, B, C, D = list(), list(), list(), list(),
need_base_list = list()
ratio = col_df['ratio'].to_dict()
for decbase in ['A', 'T', 'C', 'G']:
if decbase not in ratio:
@ -153,7 +151,7 @@ class AutoLayout:
'%s%s位置,有碱基不平衡,算出结果为 %s' % (chipname, i, ratio)
)
if len(is_not_balance_list) > 2:
if len(is_not_balance_list):
self.return_log.append('有碱基不平衡性!')
self.return_log.extend(is_not_balance_list)
print('有碱基不平衡性!\n', '\n'.join(is_not_balance_list))
@ -229,7 +227,7 @@ class AutoLayout:
# 不平衡文库大于200G 不能添加
splibrary = True
if classification in ['扩增子', '不平衡文库', '单细胞文库', '甲基化'] \
and self.chip_speciallib_size[chipname] + size > 200:
and self.chip_speciallib_size[chipname] + size > 250:
splibrary = False
self.logger.error(f'{library} {chipname} 不平衡文库相加大于设定限制')
if sizelimit and notrepeatbarcode and exclusive_classific and splibrary:
@ -262,11 +260,12 @@ class AutoLayout:
need_col.append('note')
self.no_assign_data.extend(ori_library_df[~(numeric_mask & time_mask)].to_dict('records'))
# 使用布尔索引筛选出不是数字和非日期的行
ori_library_df = ori_library_df[numeric_mask & time_mask]
ori_library_df['level'] = ori_library_df.apply(self.level, axis=1)
no_ori_data = ori_library_df[~(numeric_mask & time_mask)]
self.no_assign_data.extend(no_ori_data.to_dict('records'))
# 使用布尔索引筛选出不是数字和非日期的行
ori_library_df = ori_library_df[(numeric_mask & time_mask)]
ori_library_df['level'] = ori_library_df.apply(self.level, axis=1)
for library, library_df in ori_library_df.groupby('#library'):
ori_library_data.append(dict(
library=library,
@ -308,14 +307,13 @@ class AutoLayout:
j += 1
else:
self.loc_chip_num += 1
if self.chip_size[chipname] > 1500:
if self.chip_size[chipname] > self.data_limit:
self.loc_chip_num += 1
def assign_again(self):
pass
def run(self):
self.assign_samples()
try:
self.assign_samples()
except Exception as e:
@ -328,17 +326,20 @@ class AutoLayout:
chip_loc = 1
for chip_idx, chip_assignments in self.index_assignments.items():
df = pd.DataFrame(chip_assignments)
if df['data_needed'].sum() < 1400 or chip_loc > self.chipnum:
df['time'] = df['time'].dt.strftime('%Y-%m-%d')
if df['data_needed'].sum() < 1500 or chip_loc > self.chipnum:
self.no_assign_data.extend(chip_assignments)
continue
if '极致' in df['拆分方式'].values:
if [method for method in df['拆分方式'].values if '极致' in method]:
addname = 'X'
else:
addname = ''
self.dec_barcode_radio(chip_idx)
df.to_excel(writer, sheet_name=addname + chip_idx, index=False)
chip_loc += 1
pd.DataFrame(self.no_assign_data).to_excel(writer, sheet_name='未测', index=False)
no_assign_df = pd.DataFrame(self.no_assign_data)
# no_assign_df['time'] = no_assign_df['time'].dt.strftime('%Y-%m-%d')
no_assign_df.to_excel(writer, sheet_name='未测', index=False)
if self.return_log:
pd.DataFrame(self.return_log).to_excel(writer, sheet_name='log', index=False)
writer.close()