From 338159b2778c9d9cf2ceefd6e621e99cebdbc483 Mon Sep 17 00:00:00 2001 From: chaopower Date: Tue, 2 Jan 2024 13:53:43 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AE=A1=E6=95=B0=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- T7_client.py | 19 ++++++++++--------- T7_server.py | 8 ++++---- client.py | 4 ++-- tools/t7.py | 50 +++++++++++++++++++++++++++++++++++++++++--------- 4 files changed, 57 insertions(+), 24 deletions(-) diff --git a/T7_client.py b/T7_client.py index a696540..52005cf 100644 --- a/T7_client.py +++ b/T7_client.py @@ -23,7 +23,7 @@ def recvdata(conn, filepath): recv_len += len(correntrecv) -def senddata(conn, path, chipum): +def senddata(conn, path, librarynum): name = os.path.basename(os.path.realpath(path)) try: with open(path, 'rb') as file: @@ -31,7 +31,7 @@ def senddata(conn, path, chipum): headerdic = dict( contentlen=len(content), contentname=name, - chipum=chipum + librarynum=librarynum ) headerjson = json.dumps(headerdic) headerbytes = headerjson.encode('utf-8') @@ -51,9 +51,9 @@ def connect(): return client -def transclient(sendfile, resfile, chipnum): +def transclient(sendfile, resfile, librarynum): conn = connect() - senddata(conn, sendfile, chipnum) + senddata(conn, sendfile, librarynum) recvdata(conn, resfile) @@ -61,7 +61,7 @@ def make_gui(): sg.theme('DarkBlack1') layout = [ - [sg.Text('排样芯片数'), sg.Spin([i for i in range(20)], initial_value=5, size=(3, 1), key='_CHIPNUM_')], + [sg.Text('排样管数'), sg.Spin([i for i in range(150)], initial_value=130, size=(3, 1), key='_LIBRARYNUM_')], [sg.Text()], [ sg.Text('导入排样excel')], @@ -75,16 +75,17 @@ def make_gui(): [sg.Text()], [ sg.OK('生成'), sg.Cancel('取消')]] - # iconpath = os.path.join(os.path.abspath(sys.path[0]), 'other', 'icon.ico') - window = sg.Window('解码排样T7程序', layout, font='Helvetica 11') + iconpath = os.path.join(os.path.abspath(sys.path[0]), 'other', 'icon.ico') + print(iconpath) + window = sg.Window('解码排样T7程序', layout, font='Helvetica 11', icon=r'D:\project\autulayout\other\icon.ico') while True: - event, values = window.Read() + event, values = window.read() if event == '生成': if not values['_FILE1_'] or not values['_FILE2_']: sg.popup_non_blocking('请正确提供参数') else: - transclient(values['_FILE1_'], os.path.join(values['_FILE2_']), values['_CHIPNUM_']) + transclient(values['_FILE1_'], os.path.join(values['_FILE2_']), values['_LIBRARYNUM_']) sg.Popup('排样成功!') window.Close() else: diff --git a/T7_server.py b/T7_server.py index 41a8940..12b87ca 100644 --- a/T7_server.py +++ b/T7_server.py @@ -22,7 +22,7 @@ def recvdata(conn, path): header_dic = json.loads(header_json) content_len = header_dic['contentlen'] content_name = header_dic['contentname'] - chipnum = header_dic['chipnum'] + librarynum = header_dic['librarynum'] recv_len = 0 fielpath = os.path.join(path, '%s_%s' % (datetime.now().strftime("%m%d%H%M"), content_name)) file = open(fielpath, 'wb') @@ -31,7 +31,7 @@ def recvdata(conn, path): file.write(correntrecv) recv_len += len(correntrecv) file.close() - return fielpath, chipnum + return fielpath, librarynum def senddata(conn, path, message=None): @@ -77,8 +77,8 @@ def server(): while True: try: myclient, adddr = myserver.accept() - recv_content, chipnum = recvdata(myclient, os.path.join(basedir, 'example')) - layout = T7(recv_content, chipnum) + recv_content, librarynum = recvdata(myclient, os.path.join(basedir, 'example')) + layout = T7(recv_content, librarynum) outputpath = layout.run() senddata(myclient, outputpath) except Exception as e: diff --git a/client.py b/client.py index c6a23d9..471e4ac 100644 --- a/client.py +++ b/client.py @@ -44,7 +44,7 @@ def senddata(conn, path, select_type): def connect(): client = socket.socket(socket.AF_INET, socket.SOCK_STREAM) dest_ip = '192.168.11.121' - dest_port = int(8190) + dest_port = int(8191) client.connect((dest_ip, dest_port)) return client @@ -80,7 +80,7 @@ def make_gui(): select_type = 'xplus' else: select_type = 't7' - transclient(values['_FILE1_'], os.path.join(values['_FILE2_'], select_type)) + transclient(values['_FILE1_'], os.path.join(values['_FILE2_']), select_type) sg.Popup('排样成功!') else: window.Close() diff --git a/tools/t7.py b/tools/t7.py index e3697cb..766e887 100644 --- a/tools/t7.py +++ b/tools/t7.py @@ -14,10 +14,10 @@ class AutoLayout: 自动化派样 """ - def __init__(self, path, chipnum, output=basedir, data_limit=1750): + def __init__(self, path, librarynum, output=basedir, data_limit=1750): self.path = path self.output = output - self.chipnum = int(chipnum) + self.librarynum = int(librarynum) self.data_limit = data_limit self.index_assignments = defaultdict(list) @@ -67,13 +67,14 @@ class AutoLayout: if newer: self.chip_size[chipname] = library_data['size'] - if library_data['classification'] in ['扩增子', '不平衡文库', '单细胞文库以及甲基化']: + # if library_data['classification'] in ['扩增子', '不平衡文库', '单细胞文库以及甲基化']: + if library_data['is_balance_lib'] == '否': self.chip_speciallib_size[chipname] = library_data['size'] else: self.chip_speciallib_size[chipname] = 0 else: self.chip_size[chipname] += library_data['size'] - if library_data['classification'] in ['扩增子', '不平衡文库', '单细胞文库', '甲基化']: + if library_data['is_balance_lib'] == '否': self.chip_speciallib_size[chipname] += library_data['size'] self.chip_customer[chipname].add(library_data['customer']) @@ -182,6 +183,7 @@ class AutoLayout: # customer = library_data['customer'] library = library_data['library'] classification = library_data['classification'] + is_balance_lib = library_data['is_balance_lib'] # 芯片大小不能超过设定限制 sizelimit = True @@ -198,10 +200,9 @@ class AutoLayout: if self.use_rule(chipname, classification): exclusive_classific = False - # 不平衡文库大于200G 不能添加 + # 不平衡文库大于250G 不能添加 splibrary = True - if classification in ['扩增子', '不平衡文库', '单细胞文库', '甲基化'] \ - and self.chip_speciallib_size[chipname] + size > 250: + if is_balance_lib == '否' and self.chip_speciallib_size[chipname] + size > 250: splibrary = False # 碱基不平衡不过不添加,保证前面的数据, 在数据达到1200G的时候开始 @@ -226,7 +227,7 @@ class AutoLayout: ori_library_df = pd.DataFrame(self.ori_data['未测']) need_col = ['#library', 'sublibrary', 'i5', 'i7', 'data_needed', 'real_data', 'customer', - 'classification', 'priority', 'time', '拆分方式', 'barcode' + 'classification', 'priority', 'time', '拆分方式', 'barcode', 'is_balance_lib' ] get_col = set(ori_library_df.columns) unhave_col = set(need_col) - get_col @@ -250,9 +251,24 @@ class AutoLayout: # 使用布尔索引筛选出不是数字和非日期的行 ori_library_df = ori_library_df[(numeric_mask & time_mask)] ori_library_df['level'] = ori_library_df.apply(self.level, axis=1) + + # 极致客户有重复的,把等级调到0,防止放到了最后,到了未测里 + duplicate_name = ori_library_df[ori_library_df['level'] == 2].duplicated(subset='barcode', keep=False) + # 将 'level' 列的值改为 0 + ori_library_df.loc[duplicate_name, 'level'] = 0 + for library, library_df in ori_library_df.groupby('#library'): + + size = library_df['data_needed'].sum() + + flag = False + if size > (self.data_limit) / 2: + library_df['data_needed'] = library_df['data_needed'] / 2 + flag = True + ori_library_data.append(dict( library=library, + is_balance_lib=library_df['is_balance_lib'].values[0], size=library_df['data_needed'].sum(), split_method=library_df['拆分方式'].values[0], time=library_df['time'].values[0], @@ -261,6 +277,20 @@ class AutoLayout: classification=library_df['classification'].values[0], data=library_df[need_col].to_dict('records') )) + + if flag: + self.return_log.append(f'文库{library} 已做拆分处理, 请注意!!! ') + ori_library_data.append(dict( + library=library, + is_balance_lib=library_df['is_balance_lib'].values[0], + size=library_df['data_needed'].sum(), + split_method=library_df['拆分方式'].values[0], + time=library_df['time'].values[0], + level=library_df['level'].values[0], + customer=library_df['customer'].values[0], + classification=library_df['classification'].values[0], + data=library_df[need_col].to_dict('records') + )) ori_sort_data = sorted(ori_library_data, key=lambda x: (x['level'], x['time'])) i = 0 @@ -309,12 +339,14 @@ class AutoLayout: writer = pd.ExcelWriter(outputpath) chip_loc = 1 + librarynum = 0 for chip_idx, chip_assignments in self.index_assignments.items(): df = pd.DataFrame(chip_assignments) df['time'] = df['time'].dt.strftime('%Y-%m-%d') - if df['data_needed'].sum() < 1500 or chip_loc > self.chipnum: + if df['data_needed'].sum() < 1600 or librarynum > self.librarynum: self.no_assign_data.extend(df.to_dict('records')) continue + librarynum += len(set(df['#library'].values)) if [method for method in df['拆分方式'].values if '极致' in method]: addname = 'X' else: