def file_btn_click_event(self, clicked_btn): name = self.info_table.item(0, 0) if name is None: QMessageBox.about(self, "Error", "There is no searching history") return # search information searched_type = str(self.search_type_list.currentText()) searched_input = self.search_line.text() selected_species = [] if self.species_all.isChecked(): selected_species.append('all') else: if self.species_btn1.isChecked(): selected_species.append('zebra fish') if self.species_btn2.isChecked(): selected_species.append('fathead minnow') if self.species_btn3.isChecked(): selected_species.append('medaka') if self.species_btn4.isChecked(): selected_species.append('daphnia') if self.species_others.isChecked(): selected_species.append('others') selected_species = ', '.join(selected_species) selected_ep = [] if self.ep_all.isChecked(): selected_ep.append('all') else: if self.ep_lc_btn.isChecked(): selected_ep.append('LC50') if self.ep_ec_btn.isChecked(): selected_ep.append('EC50') if self.ep_others.isChecked(): selected_ep.append('others') selected_ep = ', '.join(selected_ep) # chemical information name = self.info_table.item(0, 0).text() iupac_name = self.info_table.item(1, 0).text() cas = self.info_table.item(2, 0).text() smiles = self.info_table.item(3, 0).text() # toxic information poison_text = self.poison_text.toPlainText() # mass spectrum try: self.msms_db[smiles] fig, ax = utils.plot_mass(self.mz_array, self.intensity_array, save=True) reference = self.reference_line.text() except: pass # Make the entire text edit for save/print entire_text = QTextEdit('') entire_text.append('\n' + '=' * 10 + 'Search Information' + '=' * 10 + '\n') entire_text.append('Searched type: {}'.format(searched_type)) entire_text.append('Searched input: {}'.format(searched_input)) entire_text.append('Selected species: {}'.format(selected_species)) entire_text.append('Selected end point: {}'.format(selected_ep)) entire_text.append('\n' + '=' * 10 + 'Chemical Information' + '=' * 10 + '\n') entire_text.append('Name: {}'.format(name)) entire_text.append('IUPAC name: {}'.format(iupac_name)) entire_text.append('CAS number: {}'.format(cas)) entire_text.append('SMILES: {}'.format(smiles)) entire_text.append('\n' + '=' * 10 + 'Toxic Information' + '=' * 10 + '\n') entire_text.append(poison_text) try: self.msms_db[smiles] entire_text.append('\n' + '=' * 10 + 'Mass Spectrum' + '=' * 10 + '\n') entire_text.append('reference: {}'.format(reference) + '\n') cursor = entire_text.textCursor() entire_text.moveCursor(QTextCursor.End) cursor.insertImage('mass_fig.jpg') except: pass if clicked_btn == 'save': fn, _ = QFileDialog.getSaveFileName( self, 'Export PDF', None, 'PDF files (.pdf);;All Files()') if fn != '': if QFileInfo(fn).suffix() == "": fn += '.pdf' printer = QPrinter(QPrinter.HighResolution) printer.setOutputFormat(QPrinter.PdfFormat) printer.setOutputFileName(fn) entire_text.document().print_(printer) try: os.remove('mass_fig.jpg') except: pass elif clicked_btn == 'print': printer = QPrinter(QPrinter.HighResolution) dialog = QPrintDialog(printer, self) if dialog.exec_() == QPrintDialog.Accepted: entire_text.print_(printer) try: os.remove('mass_fig.jpg') except: pass
def search_btn_click_event(self): ### related to search grid ### df = self.toxic_db searched_type = str(self.search_type_list.currentText()) searched_input = self.search_line.text().replace(' ', '') if searched_type == 'CAS': try: searched_cid = df[list( map(lambda f: searched_input in f, df['CAS']))]['cid'].item() except: QMessageBox.about(self, "Error", "Please enter the correct CAS.") return elif searched_type == 'IUPAC': try: searched_cid = df[df['IUPAC'] == searched_input]['cid'].item() except: QMessageBox.about(self, "Error", "Please enter the correct IUPAC_NAME.") return elif searched_type == 'SMILES': try: searched_cid = df[df['SMILES'] == searched_input]['cid'].item() except: QMessageBox.about(self, "Error", "Please enter the correct SMILES.") return else: QMessageBox.about( self, "Error", "Please select search type (CAS, IUPAC, or SMILES)") return ### related to info grid ### searched_data = self.toxic_db[self.toxic_db['cid'] == searched_cid] cas = searched_data['CAS'].item() iupac_name = searched_data['IUPAC'].item() smiles = searched_data['SMILES'].item() name, all_poison_list = utils.load_poison_info(searched_cid) self.info_table.setItem(0, 0, QTableWidgetItem(name)) self.info_table.setItem(1, 0, QTableWidgetItem(iupac_name)) self.info_table.setItem(2, 0, QTableWidgetItem(', '.join(cas))) self.info_table.setItem(3, 0, QTableWidgetItem(smiles)) self.info_table.resizeColumnsToContents() ### related to poison grid ### if not self.species_all.isChecked() \ and not self.species_btn1.isChecked() \ and not self.species_btn2.isChecked() \ and not self.species_btn3.isChecked() \ and not self.species_btn4.isChecked() \ and not self.species_others.isChecked(): self.species_all.setChecked(True) if not self.ep_all.isChecked() \ and not self.ep_lc_btn.isChecked() \ and not self.ep_ec_btn.isChecked() \ and not self.ep_others.isChecked(): self.ep_all.setChecked(True) filtered_poison_list = [] if self.species_all.isChecked() and self.ep_all.isChecked(): filtered_poison_list = all_poison_list elif self.species_all.isChecked() and not self.ep_all.isChecked(): if self.ep_lc_btn.isChecked(): filtered_poison_list += [ p for p in all_poison_list if 'LC50' in p ] if self.ep_ec_btn.isChecked(): filtered_poison_list += [ p for p in all_poison_list if 'EC50' in p ] if self.ep_others.isChecked(): filtered_poison_list += [ p for p in all_poison_list if not 'LC50' in p and not 'EC50' in p ] elif not self.species_all.isChecked() and self.ep_all.isChecked(): if self.species_btn1.isChecked(): filtered_poison_list += [p for p in all_poison_list if 'zebra fish' in p.lower() or \ 'zebrafish' in p.lower() or \ 'danio rerio' in p.lower()] if self.species_btn2.isChecked(): filtered_poison_list += [p for p in all_poison_list if 'fathead minnow' in p.lower() or \ 'pimephales promelas' in p.lower()] if self.species_btn3.isChecked(): filtered_poison_list += [p for p in all_poison_list if 'medaka' in p.lower() or \ 'oryzias latipes' in p.lower()] if self.species_btn4.isChecked(): filtered_poison_list += [ p for p in all_poison_list if 'daphnia' in p.lower() ] if self.species_others.isChecked(): filtered_poison_list += [p for p in all_poison_list if 'zebra fish' not in p.lower() and \ 'zebrafish' not in p.lower() and \ 'danio rerio' not in p.lower() and \ 'fathead minnow' not in p.lower() and \ 'pimephales promelas' not in p.lower() and \ 'medaka' not in p.lower() and \ 'oryzias latipes' not in p.lower() and \ 'daphnia' not in p.lower()] else: ep_filtered_poison_list = [] if self.ep_lc_btn.isChecked(): ep_filtered_poison_list += [ p for p in all_poison_list if 'LC50' in p ] if self.ep_ec_btn.isChecked(): ep_filtered_poison_list += [ p for p in all_poison_list if 'EC50' in p ] if self.ep_others.isChecked(): ep_filtered_poison_list += [ p for p in all_poison_list if not 'LC50' in p and not 'EC50' in p ] if self.species_btn1.isChecked(): filtered_poison_list += [p for p in ep_filtered_poison_list if 'zebra fish' in p.lower() or \ 'zebrafish' in p.lower() or \ 'danio rerio' in p.lower()] if self.species_btn2.isChecked(): filtered_poison_list += [p for p in ep_filtered_poison_list if 'fathead minnow' in p.lower() or \ 'pimephales promelas' in p.lower()] if self.species_btn3.isChecked(): filtered_poison_list += [p for p in ep_filtered_poison_list if 'medaka' in p.lower() or \ 'oryzias latipes' in p.lower()] if self.species_btn4.isChecked(): filtered_poison_list += [ p for p in ep_filtered_poison_list if 'daphnia' in p.lower() ] if self.species_others.isChecked(): filtered_poison_list += [p for p in ep_filtered_poison_list if 'zebra fish' not in p.lower() and \ 'zebrafish' not in p.lower() and \ 'danio rerio' not in p.lower() and \ 'fathead minnow' not in p.lower() and \ 'pimephales promelas' not in p.lower() and \ 'medaka' not in p.lower() and \ 'oryzias latipes' not in p.lower() and \ 'daphnia' not in p.lower()] poison_text = '\n\n'.join(filtered_poison_list) self.poison_text.setText(poison_text) ### related to mass grid ### try: searched_msms_data = self.msms_db[smiles][0]['spectrum'] self.mz_array = [ float(d.split(':')[0]) for d in searched_msms_data.split(' ') ] self.intensity_array = [ float(d.split(':')[1]) for d in searched_msms_data.split(' ') ] fig, ax = utils.plot_mass(self.mz_array, self.intensity_array) reference = self.msms_db[smiles][0]['library']['link'] self.mass_fig.clear() self.mass_layout.removeWidget(self.mass_canvas) self.mass_fig = fig self.mass_canvas = FigureCanvas(self.mass_fig) self.reference_line.setText(reference) self.mass_canvas.draw() self.mass_layout.addWidget(self.mass_canvas) self.mass_layout.addWidget(self.reference_line) self.mass_layout.addWidget(self.save_print_group) self.mass_grid.setLayout(self.mass_layout) self.mass_canvas.show() except: self.mass_fig.clear() self.mass_layout.removeWidget(self.mass_canvas) self.mass_canvas = FigureCanvas(self.mass_fig) self.reference_line.setText('') self.mass_canvas.draw() self.mass_layout.addWidget(self.mass_canvas) self.mass_layout.addWidget(self.reference_line) self.mass_layout.addWidget(self.save_print_group) QMessageBox.about( self, "Error", "There is no database corresponding to the {} in the mass spectrum DB" .format(smiles)) return
def search_btn_click_event(self): ### related to search grid ### df = self.toxic_db searched_type = str(self.search_type_list.currentText()) searched_input = self.search_line.text().replace(' ', '') if searched_type == 'CAS': try: searched_cid = df[list( map(lambda f: searched_input in f, df['CAS']))]['cid'].item() except: QMessageBox.about( self, "No results found.", "We do not have any datas for \"{}\"".format( searched_input)) return elif searched_type == 'IUPAC': try: searched_cid = df[df['IUPAC'] == searched_input]['cid'].item() except: QMessageBox.about( self, "No results found.", "We do not have any datas for \"{}\"".format( searched_input)) return elif searched_type == 'SMILES': try: searched_cid = df[df['SMILES'] == searched_input]['cid'].item() except: QMessageBox.about( self, "No results found.", "We do not have any datas for \"{}\"".format( searched_input)) return else: QMessageBox.about( self, "Error", "Please select search type (CAS, IUPAC, or SMILES)") return ### related to info grid ### searched_data = df[df['cid'] == searched_cid] cas = searched_data['CAS'].item() iupac_name = searched_data['IUPAC'].item() smiles = searched_data['SMILES'].item() name, all_poison_list = utils.load_poison_info(searched_cid) self.info_table.setItem(0, 0, QTableWidgetItem(name)) self.info_table.setItem(1, 0, QTableWidgetItem(iupac_name)) self.info_table.setItem(2, 0, QTableWidgetItem(', '.join(cas))) self.info_table.setItem(3, 0, QTableWidgetItem(smiles)) self.info_table.resizeColumnsToContents() ### related to poison grid ### if not self.species_all.isChecked() \ and not self.species_btn1.isChecked() \ and not self.species_btn2.isChecked() \ and not self.species_btn3.isChecked() \ and not self.species_btn4.isChecked() \ and not self.species_others.isChecked(): self.species_all.setChecked(True) if not self.ep_all.isChecked() \ and not self.ep_lc_btn.isChecked() \ and not self.ep_ec_btn.isChecked() \ and not self.ep_others.isChecked(): self.ep_all.setChecked(True) filtered_poison_list = [] if self.species_all.isChecked() and self.ep_all.isChecked(): filtered_poison_list = all_poison_list elif self.species_all.isChecked() and not self.ep_all.isChecked(): if self.ep_lc_btn.isChecked(): filtered_poison_list += [ p for p in all_poison_list if 'LC50' in p ] if self.ep_ec_btn.isChecked(): filtered_poison_list += [ p for p in all_poison_list if 'EC50' in p ] if self.ep_others.isChecked(): filtered_poison_list += [ p for p in all_poison_list if not 'LC50' in p and not 'EC50' in p ] elif not self.species_all.isChecked() and self.ep_all.isChecked(): if self.species_btn1.isChecked(): filtered_poison_list += [p for p in all_poison_list if 'zebra fish' in p.lower() or \ 'zebrafish' in p.lower() or \ 'danio rerio' in p.lower()] if self.species_btn2.isChecked(): filtered_poison_list += [p for p in all_poison_list if 'fathead minnow' in p.lower() or \ 'pimephales promelas' in p.lower()] if self.species_btn3.isChecked(): filtered_poison_list += [p for p in all_poison_list if 'medaka' in p.lower() or \ 'oryzias latipes' in p.lower()] if self.species_btn4.isChecked(): filtered_poison_list += [ p for p in all_poison_list if 'daphnia' in p.lower() ] if self.species_others.isChecked(): filtered_poison_list += [p for p in all_poison_list if 'zebra fish' not in p.lower() and \ 'zebrafish' not in p.lower() and \ 'danio rerio' not in p.lower() and \ 'fathead minnow' not in p.lower() and \ 'pimephales promelas' not in p.lower() and \ 'medaka' not in p.lower() and \ 'oryzias latipes' not in p.lower() and \ 'daphnia' not in p.lower()] else: ep_filtered_poison_list = [] if self.ep_lc_btn.isChecked(): ep_filtered_poison_list += [ p for p in all_poison_list if 'LC50' in p ] if self.ep_ec_btn.isChecked(): ep_filtered_poison_list += [ p for p in all_poison_list if 'EC50' in p ] if self.ep_others.isChecked(): ep_filtered_poison_list += [ p for p in all_poison_list if not 'LC50' in p and not 'EC50' in p ] if self.species_btn1.isChecked(): filtered_poison_list += [p for p in ep_filtered_poison_list if 'zebra fish' in p.lower() or \ 'zebrafish' in p.lower() or \ 'danio rerio' in p.lower()] if self.species_btn2.isChecked(): filtered_poison_list += [p for p in ep_filtered_poison_list if 'fathead minnow' in p.lower() or \ 'pimephales promelas' in p.lower()] if self.species_btn3.isChecked(): filtered_poison_list += [p for p in ep_filtered_poison_list if 'medaka' in p.lower() or \ 'oryzias latipes' in p.lower()] if self.species_btn4.isChecked(): filtered_poison_list += [ p for p in ep_filtered_poison_list if 'daphnia' in p.lower() ] if self.species_others.isChecked(): filtered_poison_list += [p for p in ep_filtered_poison_list if 'zebra fish' not in p.lower() and \ 'zebrafish' not in p.lower() and \ 'danio rerio' not in p.lower() and \ 'fathead minnow' not in p.lower() and \ 'pimephales promelas' not in p.lower() and \ 'medaka' not in p.lower() and \ 'oryzias latipes' not in p.lower() and \ 'daphnia' not in p.lower()] filtered_poison_list = [' ● ' + f for f in filtered_poison_list] poison_text = 'pubchem.{}'.format(searched_cid) + '\n\n' + '\n\n'.join( filtered_poison_list) self.poison_text.setText(poison_text) ### related to mass grid ### try: searched_msms_data = self.msms_db[smiles][0]['spectrum'] self.mz_array = [ float(d.split(':')[0]) for d in searched_msms_data.split(' ') ] self.intensity_array = [ float(d.split(':')[1]) for d in searched_msms_data.split(' ') ] self.mass_fig.clear() ax = self.mass_fig.add_subplot(111) ax = utils.plot_mass(ax, self.mz_array, self.intensity_array) self.mass_canvas.draw() reference = self.msms_db[smiles][0]['library']['link'] self.reference_line.setText(reference) # +Added) Set Item and Lable of msinfo_table idx_ms = 0 self.msinfo_table.setRowCount( len(self.msms_db[smiles][0]['metaData'])) meta_n = [] meta_v = [] for ms_dict in self.msms_db[smiles][0]['metaData']: self.header_list.append(ms_dict['name']) meta_n.append(ms_dict['name']) self.msinfo_table.setItem( idx_ms, 0, QTableWidgetItem(str(ms_dict['value']))) meta_v.append(ms_dict['value']) idx_ms += 1 meta = str() meta_all = str() meta_all = "[MS spectrum metadata]\n\n" for i in range(0, len(meta_n)): meta = "►{} \n : {}".format(meta_n[i], meta_v[i]) meta_all += '{}\n'.format(meta) print(meta_all) self.meta_all.setText(meta_all) print("up", meta_n) print("up", meta_v) self.msinfo_table.setVerticalHeaderLabels(self.header_list) # self.msinfo_fig.clear() # bx=self.msinfo_fig.add_subplot(111) self.mass_canvas.draw() self.mass_layout.addWidget(self.mass_canvas) self.mass_layout.addWidget(self.reference_line) self.mass_layout.addWidget(self.save_print_group) self.mass_grid.setLayout(self.mass_layout) self.mass_canvas.show() #ADDED mass metadata png # lis = [] # lis.append(utils.ms_name()) # print(utils.ms_name()) # print(lis) # l10=[] # for i in range (0,len(meta_n)): # l1=(lis[0][0][i],lis[0][1][i]) # l10.append(l1) # print(l10) # fig = plt.figure() # ax = fig.add_subplot(111) # table_vals = l10 #Draw table # the_table = plt.table(cellText=table_vals) # the_table.auto_set_font_size(False) # the_table.set_fontsize(24) # the_table.scale(4, 4) # plt.tick_params(axis='x', which='both', bottom=False, top=False, labelbottom=False) # plt.tick_params(axis='y', which='both', right=False, left=False, labelleft=False) # for pos in ['right','top','bottom','left']: # plt.gca().spines[pos].set_visible(False) # plt.savefig('msinfo.png', bbox_inches='tight', pad_inches=0.05) # self.msinfo_table.setVerticalHeaderLabels(self.header_list) # self.msinfo_fig.savefig('mass_info.png', # bbox_inches='tight', # dpi=150 # ) #ADDED MASS METADATA TABLE #idx_ms2=0 #fig=plt.figure() #ax=fig.add_subplot(111) #for ms_dict in self.msms_db[smiles][0]['metaData']: # rows= except: self.clear() ax = self.mass_fig.add_subplot(111) ax.set_yticks([0, 20, 40, 60, 80, 100]) ax.set_xlabel('m/z') ax.set_ylabel('Intensity') plt.tight_layout() self.mass_canvas.draw() self.reference_line.setText('') QMessageBox.about( self, "Error", "There is no database corresponding to the {} in the mass spectrum DB" .format(smiles)) # +Added) Clear Table self.msinfo_table.clear() self.msinfo_table.setRowCount(4) self.msinfo_table.setVerticalHeaderLabels( [" ", " ", " ", " "]) return
def search_btn_click_event(self): ### related to search grid ### df = self.toxic_db searched_type = str(self.search_type_list.currentText()) searched_input = self.search_line.text() if searched_type == 'CAS': try: searched_input = searched_input.replace(' ', '') searched_result = list( map(lambda f: searched_input in f, df['CAS'])) # if there are more than one results , print first "True" cid number searched_result = np.array(searched_result) # print(searched_result) if len(np.where(searched_result == True)[0]) != 1: print("Searche results > 1") # searched_cid = df.values[np.where(searched_result==True)[0][1]][0] searched_cid = df.values[np.where( searched_result == True)[0][0]][0] else: # searched_cid = df[list(map(lambda f: searched_input in f, df['CAS']))]['cid'].item() searched_cid = df[searched_result]['cid'].item() except: QMessageBox.about( self, "No results found.", "We do not have any datas for \"{}\"".format( searched_input)) return elif searched_type == 'IUPAC': try: searched_input = searched_input.strip() searched_result = df['IUPAC'] == searched_input if len(np.where(searched_result == True)[0]) != 1: print("Searche results > 1") searched_cid = df.values[np.where( searched_result == True)[0][0]][0] else: searched_cid = df[df['IUPAC'] == searched_input]['cid'].item() # searched_cid = df[df['IUPAC']==searched_input]['cid'].item() except: QMessageBox.about( self, "No results found.", "We do not have any datas for \"{}\"".format( searched_input)) return elif searched_type == 'SMILES': try: searched_input = searched_input.replace(' ', '') searched_result = df['SMILES'] == searched_input if len(np.where(searched_result == True)[0]) != 1: print("Searche results > 1") searched_cid = df.values[np.where( searched_result == True)[0][0]][0] else: searched_cid = df[df['SMILES'] == searched_input]['cid'].item() # searched_cid = df[df['SMILES']==searched_input]['cid'].item() except: QMessageBox.about( self, "No results found.", "We do not have any datas for \"{}\"".format( searched_input)) return else: QMessageBox.about( self, "Error", "Please select search type (CAS, IUPAC, or SMILES)") return ### related to info grid ### searched_data = df[df['cid'] == searched_cid] cas = searched_data['CAS'].item() iupac_name = searched_data['IUPAC'].item() smiles = searched_data['SMILES'].item() ##########################set poison text module start################################### DBid = 1 name, all_poison_list = utils.load_poison_info(searched_cid, DBid) # self.info_table.horizontalScrollBar().setValue(0) self.info_table.setItem(0, 0, QTableWidgetItem(name)) self.info_table.setItem(1, 0, QTableWidgetItem(iupac_name)) self.info_table.setItem(2, 0, QTableWidgetItem(', '.join(cas))) self.info_table.setItem(3, 0, QTableWidgetItem(smiles)) self.info_table.resizeColumnsToContents() # self.info_table.scrollToItem() # self.info_table.setHorizontalScrollMode('mode : ScrollMode') # self.info_table.horizontalScrollBar().setValue(0) ### related to poison grid ### if not self.species_all.isChecked() \ and not self.species_btn1.isChecked() \ and not self.species_btn2.isChecked() \ and not self.species_btn3.isChecked() \ and not self.species_btn4.isChecked() \ and not self.species_others.isChecked(): self.species_all.setChecked(True) if not self.ep_all.isChecked() \ and not self.ep_lc_btn.isChecked() \ and not self.ep_ec_btn.isChecked() \ and not self.ep_others.isChecked(): self.ep_all.setChecked(True) filtered_poison_list = [] if self.species_all.isChecked() and self.ep_all.isChecked(): filtered_poison_list = all_poison_list elif self.species_all.isChecked() and not self.ep_all.isChecked(): if self.ep_lc_btn.isChecked(): filtered_poison_list += [ p for p in all_poison_list if 'LC50' in p ] if self.ep_ec_btn.isChecked(): filtered_poison_list += [ p for p in all_poison_list if 'EC50' in p ] if self.ep_others.isChecked(): filtered_poison_list += [ p for p in all_poison_list if not 'LC50' in p and not 'EC50' in p ] elif not self.species_all.isChecked() and self.ep_all.isChecked(): if self.species_btn1.isChecked(): filtered_poison_list += [p for p in all_poison_list if 'zebra fish' in p.lower() or \ 'zebrafish' in p.lower() or \ 'danio rerio' in p.lower()] if self.species_btn2.isChecked(): filtered_poison_list += [p for p in all_poison_list if 'fathead minnow' in p.lower() or \ 'pimephales promelas' in p.lower()] if self.species_btn3.isChecked(): filtered_poison_list += [p for p in all_poison_list if 'medaka' in p.lower() or \ 'oryzias latipes' in p.lower()] if self.species_btn4.isChecked(): filtered_poison_list += [ p for p in all_poison_list if 'daphnia' in p.lower() ] if self.species_others.isChecked(): filtered_poison_list += [p for p in all_poison_list if 'zebra fish' not in p.lower() and \ 'zebrafish' not in p.lower() and \ 'danio rerio' not in p.lower() and \ 'fathead minnow' not in p.lower() and \ 'pimephales promelas' not in p.lower() and \ 'medaka' not in p.lower() and \ 'oryzias latipes' not in p.lower() and \ 'daphnia' not in p.lower()] else: ep_filtered_poison_list = [] if self.ep_lc_btn.isChecked(): ep_filtered_poison_list += [ p for p in all_poison_list if 'LC50' in p ] if self.ep_ec_btn.isChecked(): ep_filtered_poison_list += [ p for p in all_poison_list if 'EC50' in p ] if self.ep_others.isChecked(): ep_filtered_poison_list += [ p for p in all_poison_list if not 'LC50' in p and not 'EC50' in p ] if self.species_btn1.isChecked(): filtered_poison_list += [p for p in ep_filtered_poison_list if 'zebra fish' in p.lower() or \ 'zebrafish' in p.lower() or \ 'danio rerio' in p.lower()] if self.species_btn2.isChecked(): filtered_poison_list += [p for p in ep_filtered_poison_list if 'fathead minnow' in p.lower() or \ 'pimephales promelas' in p.lower()] if self.species_btn3.isChecked(): filtered_poison_list += [p for p in ep_filtered_poison_list if 'medaka' in p.lower() or \ 'oryzias latipes' in p.lower()] if self.species_btn4.isChecked(): filtered_poison_list += [ p for p in ep_filtered_poison_list if 'daphnia' in p.lower() ] if self.species_others.isChecked(): filtered_poison_list += [p for p in ep_filtered_poison_list if 'zebra fish' not in p.lower() and \ 'zebrafish' not in p.lower() and \ 'danio rerio' not in p.lower() and \ 'fathead minnow' not in p.lower() and \ 'pimephales promelas' not in p.lower() and \ 'medaka' not in p.lower() and \ 'oryzias latipes' not in p.lower() and \ 'daphnia' not in p.lower()] filtered_poison_list = [ ' ▶︎ ' + f for f in filtered_poison_list ] poison_text = '<p style="font-size: 40px"><b>Ecotoxicity data form pubchem</b></p>' + '<br>' + '<br><br>'.join( filtered_poison_list) ##########################set poison text module end################################### ##########################set poison text module start################################### DBid = 2 all_poison_list = utils.load_poison_info(searched_cid, DBid) ### related to poison grid ### if not self.species_all.isChecked() \ and not self.species_btn1.isChecked() \ and not self.species_btn2.isChecked() \ and not self.species_btn3.isChecked() \ and not self.species_btn4.isChecked() \ and not self.species_others.isChecked(): self.species_all.setChecked(True) if not self.ep_all.isChecked() \ and not self.ep_lc_btn.isChecked() \ and not self.ep_ec_btn.isChecked() \ and not self.ep_others.isChecked(): self.ep_all.setChecked(True) filtered_poison_list = [] if self.species_all.isChecked() and self.ep_all.isChecked(): filtered_poison_list = all_poison_list elif self.species_all.isChecked() and not self.ep_all.isChecked(): if self.ep_lc_btn.isChecked(): filtered_poison_list += [ p for p in all_poison_list if 'LC50' in p ] if self.ep_ec_btn.isChecked(): filtered_poison_list += [ p for p in all_poison_list if 'EC50' in p ] if self.ep_others.isChecked(): filtered_poison_list += [ p for p in all_poison_list if not 'LC50' in p and not 'EC50' in p ] elif not self.species_all.isChecked() and self.ep_all.isChecked(): if self.species_btn1.isChecked(): filtered_poison_list += [p for p in all_poison_list if 'zebra fish' in p.lower() or \ 'zebrafish' in p.lower() or \ 'danio rerio' in p.lower()] if self.species_btn2.isChecked(): filtered_poison_list += [p for p in all_poison_list if 'fathead minnow' in p.lower() or \ 'pimephales promelas' in p.lower()] if self.species_btn3.isChecked(): filtered_poison_list += [p for p in all_poison_list if 'medaka' in p.lower() or \ 'oryzias latipes' in p.lower()] if self.species_btn4.isChecked(): filtered_poison_list += [ p for p in all_poison_list if 'daphnia' in p.lower() ] if self.species_others.isChecked(): filtered_poison_list += [p for p in all_poison_list if 'zebra fish' not in p.lower() and \ 'zebrafish' not in p.lower() and \ 'danio rerio' not in p.lower() and \ 'fathead minnow' not in p.lower() and \ 'pimephales promelas' not in p.lower() and \ 'medaka' not in p.lower() and \ 'oryzias latipes' not in p.lower() and \ 'daphnia' not in p.lower()] else: ep_filtered_poison_list = [] if self.ep_lc_btn.isChecked(): ep_filtered_poison_list += [ p for p in all_poison_list if 'LC50' in p ] if self.ep_ec_btn.isChecked(): ep_filtered_poison_list += [ p for p in all_poison_list if 'EC50' in p ] if self.ep_others.isChecked(): ep_filtered_poison_list += [ p for p in all_poison_list if not 'LC50' in p and not 'EC50' in p ] if self.species_btn1.isChecked(): filtered_poison_list += [p for p in ep_filtered_poison_list if 'zebra fish' in p.lower() or \ 'zebrafish' in p.lower() or \ 'danio rerio' in p.lower()] if self.species_btn2.isChecked(): filtered_poison_list += [p for p in ep_filtered_poison_list if 'fathead minnow' in p.lower() or \ 'pimephales promelas' in p.lower()] if self.species_btn3.isChecked(): filtered_poison_list += [p for p in ep_filtered_poison_list if 'medaka' in p.lower() or \ 'oryzias latipes' in p.lower()] if self.species_btn4.isChecked(): filtered_poison_list += [ p for p in ep_filtered_poison_list if 'daphnia' in p.lower() ] if self.species_others.isChecked(): filtered_poison_list += [p for p in ep_filtered_poison_list if 'zebra fish' not in p.lower() and \ 'zebrafish' not in p.lower() and \ 'danio rerio' not in p.lower() and \ 'fathead minnow' not in p.lower() and \ 'pimephales promelas' not in p.lower() and \ 'medaka' not in p.lower() and \ 'oryzias latipes' not in p.lower() and \ 'daphnia' not in p.lower()] filtered_poison_list = [ ' ▶︎ ' + f for f in filtered_poison_list ] poison_text = poison_text + '<br><br>' + '<p style="font-size: 40px"><b>Ecotoxicity data of 생활화학제품 from various DBs</b></p>' + '<br>' + '<br><br>'.join( filtered_poison_list) ##########################set poison text module end################################### ##########################set poison text module start################################### DBid = 3 all_poison_list = utils.load_poison_info(searched_cid, DBid) ### related to poison grid ### if not self.species_all.isChecked() \ and not self.species_btn1.isChecked() \ and not self.species_btn2.isChecked() \ and not self.species_btn3.isChecked() \ and not self.species_btn4.isChecked() \ and not self.species_others.isChecked(): self.species_all.setChecked(True) if not self.ep_all.isChecked() \ and not self.ep_lc_btn.isChecked() \ and not self.ep_ec_btn.isChecked() \ and not self.ep_others.isChecked(): self.ep_all.setChecked(True) filtered_poison_list = [] if self.species_all.isChecked() and self.ep_all.isChecked(): filtered_poison_list = all_poison_list elif self.species_all.isChecked() and not self.ep_all.isChecked(): if self.ep_lc_btn.isChecked(): filtered_poison_list += [ p for p in all_poison_list if 'LC50' in p ] if self.ep_ec_btn.isChecked(): filtered_poison_list += [ p for p in all_poison_list if 'EC50' in p ] if self.ep_others.isChecked(): filtered_poison_list += [ p for p in all_poison_list if not 'LC50' in p and not 'EC50' in p ] elif not self.species_all.isChecked() and self.ep_all.isChecked(): if self.species_btn1.isChecked(): filtered_poison_list += [p for p in all_poison_list if 'zebra fish' in p.lower() or \ 'zebrafish' in p.lower() or \ 'danio rerio' in p.lower()] if self.species_btn2.isChecked(): filtered_poison_list += [p for p in all_poison_list if 'fathead minnow' in p.lower() or \ 'pimephales promelas' in p.lower()] if self.species_btn3.isChecked(): filtered_poison_list += [p for p in all_poison_list if 'medaka' in p.lower() or \ 'oryzias latipes' in p.lower()] if self.species_btn4.isChecked(): filtered_poison_list += [ p for p in all_poison_list if 'daphnia' in p.lower() ] if self.species_others.isChecked(): filtered_poison_list += [p for p in all_poison_list if 'zebra fish' not in p.lower() and \ 'zebrafish' not in p.lower() and \ 'danio rerio' not in p.lower() and \ 'fathead minnow' not in p.lower() and \ 'pimephales promelas' not in p.lower() and \ 'medaka' not in p.lower() and \ 'oryzias latipes' not in p.lower() and \ 'daphnia' not in p.lower()] else: ep_filtered_poison_list = [] if self.ep_lc_btn.isChecked(): ep_filtered_poison_list += [ p for p in all_poison_list if 'LC50' in p ] if self.ep_ec_btn.isChecked(): ep_filtered_poison_list += [ p for p in all_poison_list if 'EC50' in p ] if self.ep_others.isChecked(): ep_filtered_poison_list += [ p for p in all_poison_list if not 'LC50' in p and not 'EC50' in p ] if self.species_btn1.isChecked(): filtered_poison_list += [p for p in ep_filtered_poison_list if 'zebra fish' in p.lower() or \ 'zebrafish' in p.lower() or \ 'danio rerio' in p.lower()] if self.species_btn2.isChecked(): filtered_poison_list += [p for p in ep_filtered_poison_list if 'fathead minnow' in p.lower() or \ 'pimephales promelas' in p.lower()] if self.species_btn3.isChecked(): filtered_poison_list += [p for p in ep_filtered_poison_list if 'medaka' in p.lower() or \ 'oryzias latipes' in p.lower()] if self.species_btn4.isChecked(): filtered_poison_list += [ p for p in ep_filtered_poison_list if 'daphnia' in p.lower() ] if self.species_others.isChecked(): filtered_poison_list += [p for p in ep_filtered_poison_list if 'zebra fish' not in p.lower() and \ 'zebrafish' not in p.lower() and \ 'danio rerio' not in p.lower() and \ 'fathead minnow' not in p.lower() and \ 'pimephales promelas' not in p.lower() and \ 'medaka' not in p.lower() and \ 'oryzias latipes' not in p.lower() and \ 'daphnia' not in p.lower()] filtered_poison_list = [ ' ▶︎ ' + f for f in filtered_poison_list ] poison_text = poison_text + '<br><br>' + '<p style="font-size: 40px"><b>Ecotoxicity data from experiments 안전성평가연구소 </b></p>' + '<br>' + '<br><br>'.join( filtered_poison_list) ##########################set poison text module end################################### self.poison_text.setText(poison_text) ### related to mass grid ### try: self.mass_fig.clear() self.MS_data = utils.load_ms_info(smiles, self.msms_db) searched_msms_data = self.MS_data[smiles][0]['spectrum'] self.mz_array = [ float(d.split(':')[0]) for d in searched_msms_data.split(' ') ] self.intensity_array = [ float(d.split(':')[1]) for d in searched_msms_data.split(' ') ] ax = self.mass_fig.add_subplot(111) # ax = utils.plot_mass(ax, self.mz_array, self.intensity_array) utils.plot_mass(ax, self.mz_array, self.intensity_array) self.mass_canvas.draw() reference = self.MS_data[smiles][0]['library']['link'] self.reference_line.setText(reference) # (Added) Set Item and Label of msinfo_table idx_ms = 0 self.msinfo_table.setRowCount( len(self.MS_data[smiles][0]['metaData'])) meta_n = [] meta_v = [] for ms_dict in self.MS_data[smiles][0]['metaData']: self.header_list.append(ms_dict['name']) meta_n.append(ms_dict['name']) self.msinfo_table.setItem( idx_ms, 0, QTableWidgetItem(str(ms_dict['value']))) meta_v.append(ms_dict['value']) idx_ms += 1 # meta=str() # meta_all=str() meta_all = "[MS spectrum metadata]\n\n" for i in range(0, len(meta_n)): meta = "►{} \n : {}".format(meta_n[i], meta_v[i]) meta_all += '{}\n'.format(meta) # print(meta_all) self.meta_all.setText(meta_all) # print("up", meta_n) # print("up", meta_v) self.msinfo_table.setVerticalHeaderLabels(self.header_list) self.msinfo_table.setStyleSheet("Color : black") self.msinfo_table.resizeColumnsToContents() # self.mass_canvas.draw() self.mass_layout.addWidget(self.mass_canvas) self.mass_layout.addWidget(self.reference_line) # self.mass_layout.addWidget(self.mass_info_group) self.mass_grid.setLayout(self.mass_layout) self.mass_canvas.show() except: self.mass_fig.clear() ax = self.mass_fig.add_subplot(111) ax.set_yticks([0, 20, 40, 60, 80, 100]) ax.set_xlabel('m/z') ax.set_ylabel('Intensity') plt.tight_layout() self.mass_canvas.draw() # (Added) Clear Table self.msinfo_table.clear() self.msinfo_table.setRowCount(20) self.msinfo_table.setVerticalHeaderLabels([ " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " " ]) self.msinfo_table.setColumnWidth(0, 3000) # self.msinfo_table.setVerticalHeaderLabels([" ", " ", " ", " "]) self.reference_line.setText('') # self.mass_canvas = FigureCanvas(self.mass_fig) # self.mass_canvas.draw() self.mass_layout.addWidget(self.mass_canvas) self.mass_layout.addWidget(self.reference_line) # self.mass_layout.addWidget(self.save_print_group) self.reference_line.setText('') QMessageBox.about( self, "Error", "There is no database corresponding to the {} in the mass spectrum DB" .format(smiles)) return
def search_btn_click_event(self): ### related to search grid ### df = self.toxic_db searched_type = str(self.search_type_list.currentText()) searched_input = self.search_line.text().replace(' ', '') if searched_type == 'CAS': try: searched_cid = df[list( map(lambda f: searched_input in f, df['CAS']))]['cid'].item() except: QMessageBox.about( self, "No results found.", "We do not have any datas for \"{}\"".format( searched_input)) return elif searched_type == 'IUPAC': try: searched_cid = df[df['IUPAC'] == searched_input]['cid'].item() except: QMessageBox.about( self, "No results found.", "We do not have any datas for \"{}\"".format( searched_input)) return elif searched_type == 'SMILES': try: searched_cid = df[df['SMILES'] == searched_input]['cid'].item() except: QMessageBox.about( self, "No results found.", "We do not have any datas for \"{}\"".format( searched_input)) return else: QMessageBox.about( self, "Error", "Please select search type (CAS, IUPAC, or SMILES)") return ### related to info grid ### searched_data = df[df['cid'] == searched_cid] cas = searched_data['CAS'].item() iupac_name = searched_data['IUPAC'].item() smiles = searched_data['SMILES'].item() name, all_poison_list = utils.load_poison_info(searched_cid) self.info_table.setItem(0, 0, QTableWidgetItem(name)) self.info_table.setItem(1, 0, QTableWidgetItem(iupac_name)) self.info_table.setItem(2, 0, QTableWidgetItem(', '.join(cas))) self.info_table.setItem(3, 0, QTableWidgetItem(smiles)) self.info_table.resizeColumnsToContents() ### related to poison grid ### if not self.species_all.isChecked() \ and not self.species_btn1.isChecked() \ and not self.species_btn2.isChecked() \ and not self.species_btn3.isChecked() \ and not self.species_btn4.isChecked() \ and not self.species_others.isChecked(): self.species_all.setChecked(True) if not self.ep_all.isChecked() \ and not self.ep_lc_btn.isChecked() \ and not self.ep_ec_btn.isChecked() \ and not self.ep_others.isChecked(): self.ep_all.setChecked(True) filtered_poison_list = [] if self.species_all.isChecked() and self.ep_all.isChecked(): filtered_poison_list = all_poison_list elif self.species_all.isChecked() and not self.ep_all.isChecked(): if self.ep_lc_btn.isChecked(): filtered_poison_list += [ p for p in all_poison_list if 'LC50' in p ] if self.ep_ec_btn.isChecked(): filtered_poison_list += [ p for p in all_poison_list if 'EC50' in p ] if self.ep_others.isChecked(): filtered_poison_list += [ p for p in all_poison_list if not 'LC50' in p and not 'EC50' in p ] elif not self.species_all.isChecked() and self.ep_all.isChecked(): if self.species_btn1.isChecked(): filtered_poison_list += [p for p in all_poison_list if 'zebra fish' in p.lower() or \ 'zebrafish' in p.lower() or \ 'danio rerio' in p.lower()] if self.species_btn2.isChecked(): filtered_poison_list += [p for p in all_poison_list if 'fathead minnow' in p.lower() or \ 'pimephales promelas' in p.lower()] if self.species_btn3.isChecked(): filtered_poison_list += [p for p in all_poison_list if 'medaka' in p.lower() or \ 'oryzias latipes' in p.lower()] if self.species_btn4.isChecked(): filtered_poison_list += [ p for p in all_poison_list if 'daphnia' in p.lower() ] if self.species_others.isChecked(): filtered_poison_list += [p for p in all_poison_list if 'zebra fish' not in p.lower() and \ 'zebrafish' not in p.lower() and \ 'danio rerio' not in p.lower() and \ 'fathead minnow' not in p.lower() and \ 'pimephales promelas' not in p.lower() and \ 'medaka' not in p.lower() and \ 'oryzias latipes' not in p.lower() and \ 'daphnia' not in p.lower()] else: ep_filtered_poison_list = [] if self.ep_lc_btn.isChecked(): ep_filtered_poison_list += [ p for p in all_poison_list if 'LC50' in p ] if self.ep_ec_btn.isChecked(): ep_filtered_poison_list += [ p for p in all_poison_list if 'EC50' in p ] if self.ep_others.isChecked(): ep_filtered_poison_list += [ p for p in all_poison_list if not 'LC50' in p and not 'EC50' in p ] if self.species_btn1.isChecked(): filtered_poison_list += [p for p in ep_filtered_poison_list if 'zebra fish' in p.lower() or \ 'zebrafish' in p.lower() or \ 'danio rerio' in p.lower()] if self.species_btn2.isChecked(): filtered_poison_list += [p for p in ep_filtered_poison_list if 'fathead minnow' in p.lower() or \ 'pimephales promelas' in p.lower()] if self.species_btn3.isChecked(): filtered_poison_list += [p for p in ep_filtered_poison_list if 'medaka' in p.lower() or \ 'oryzias latipes' in p.lower()] if self.species_btn4.isChecked(): filtered_poison_list += [ p for p in ep_filtered_poison_list if 'daphnia' in p.lower() ] if self.species_others.isChecked(): filtered_poison_list += [p for p in ep_filtered_poison_list if 'zebra fish' not in p.lower() and \ 'zebrafish' not in p.lower() and \ 'danio rerio' not in p.lower() and \ 'fathead minnow' not in p.lower() and \ 'pimephales promelas' not in p.lower() and \ 'medaka' not in p.lower() and \ 'oryzias latipes' not in p.lower() and \ 'daphnia' not in p.lower()] filtered_poison_list = [' ● ' + f for f in filtered_poison_list] poison_text = 'pubchem.{}'.format(searched_cid) + '\n\n' + '\n\n'.join( filtered_poison_list) self.poison_text.setText(poison_text) ### related to mass grid ### try: searched_msms_data = self.msms_db[smiles][0]['spectrum'] self.mz_array = [ float(d.split(':')[0]) for d in searched_msms_data.split(' ') ] self.intensity_array = [ float(d.split(':')[1]) for d in searched_msms_data.split(' ') ] self.mass_fig.clear() ax = self.mass_fig.add_subplot(111) ax = utils.plot_mass(ax, self.mz_array, self.intensity_array) self.mass_canvas.draw() reference = self.msms_db[smiles][0]['library']['link'] self.reference_line.setText(reference) except: self.mass_fig.clear() ax = self.mass_fig.add_subplot(111) ax.set_yticks([0, 20, 40, 60, 80, 100]) ax.set_xlabel('m/z') ax.set_ylabel('Intensity') plt.tight_layout() self.mass_canvas.draw() self.reference_line.setText('') QMessageBox.about( self, "Error", "There is no database corresponding to the {} in the mass spectrum DB" .format(smiles)) return