import sys import os import time import requests # from PyQt5.QtWidgets import QApplication, QMainWindow, QWidget, QVBoxLayout, QLabel, QPushButton, QComboBox, QTableWidget, QTableWidgetItem, QLineEdit, QPlainTextEdit # from PyQt5.QtGui import QPixmap # from PyQt5 import QtCore # from PyQt5 import QtGui, QtWidgets # from PyQt5.QtWidgets import * # import openpyxl import warnings import sys import numpy as np import json import pickle import tensorflow as tf from tensorflow.keras.models import load_model import os from Bio.Blast import NCBIWWW from Bio.Blast import NCBIXML from Bio.SeqUtils import IsoelectricPoint as IP from rdkit import Chem from rdkit.Chem import rdMolDescriptors from rdkit.Chem import Descriptors # from rdkit.Chem.rdMolDescriptors import CalcMolFormula from Bio.SeqUtils.ProtParam import ProteinAnalysis import numpy as np from scipy.constants import e, epsilon_0 from scipy.constants import Boltzmann import datetime import random import string from rdkit.Chem import AllChem from rdkit import Chem from rdkit.Chem import Descriptors from scipy.constants import e import pandas as pd from rdkit.Chem import rdMolTransforms # from collections import Counter # from qiskit.algorithms.optimizers import COBYLA # from qiskit.circuit.library import TwoLocal, ZZFeatureMap # from qiskit.utils import algorithm_globals # from qiskit import BasicAer # from qiskit.utils import QuantumInstance from qiskit_machine_learning.algorithms import VQC, VQR # import qiskit import urllib # from qiskit_ibm_runtime import QiskitRuntimeService, Sampler, Estimator, Session # algorithm_globals.random_seed = 42 warnings.filterwarnings('ignore') asset_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'asset') image_dir = os.path.join(asset_dir, 'img') model_dir = os.path.join(asset_dir, 'model') qmodel_dir = os.path.join(model_dir, 'Quantum Model') label_dir = os.path.join(asset_dir, 'label') data_dir = os.path.join(asset_dir, 'data') json_dir = os.path.join(asset_dir, 'json') icon_img = os.path.join(image_dir, 'kaede_kayano.jpg') def get_base_path(): return os.path.dirname(os.path.abspath(__file__)) def ml_dock(data): # Load model with open(os.path.join(model_dir, 'Linear_Regression_Model.pkl'), "rb") as f: model = pickle.load(f) # Make predictions predictions = model.predict([data]) return predictions[0] def qml_dock(data, sampler=None): try: if sampler == None: #load model vqr = VQR.load(os.path.join(qmodel_dir, "VQR_quantum regression-based scoring function")) prediction = vqr.predict([data]) return prediction[0][0] else: #load model vqr = VQR.load(os.path.join(qmodel_dir, "VQR_quantum regression-based scoring function")) # vqr.neural_network.sampler = sampler prediction = vqr.predict([data]) return prediction[0][0] except: return None def generate_random_code(length): characters = string.ascii_letters + string.digits return ''.join(random.choice(characters) for i in range(length)) def generate_filename_with_timestamp_and_random(condition="classic"): # Dapatkan tanggal dan jam sekarang now = datetime.datetime.now() # Format tanggal dan jam date_time_str = now.strftime("%d%m%Y_%H%M%S") # Generate kode acak random_code = generate_random_code(15) # Ubah panjang kode acak sesuai kebutuhan if condition == "classic": # Gabungkan hasilnya filename = f"{date_time_str}_{random_code}" return filename else: # Gabungkan hasilnya filename = f"{date_time_str}_{random_code}_quantum" return filename def create_folder(folder_path): try: os.makedirs(folder_path) print(f"Folder '{folder_path}' created successfully.") except FileExistsError: print(f"Folder '{folder_path}' already exists.") def minmaxint(val, max_val): if isinstance(val, int): if val < 0: return 1 elif val > max_val: return max_val else: return val else: return 1 def download_file(url, save_as): response = requests.get(url, stream=True, verify=False, timeout=6000) with open(save_as, 'wb') as f: for chunk in response.iter_content(chunk_size=1024000): if chunk: f.write(chunk) f.flush() return save_as def process_text_for_url(text_input): """ Fungsi untuk mengubah teks input agar sesuai dengan format URL. Args: text_input (str): Teks yang ingin diubah. Returns: str: Teks yang telah diubah menjadi format URL yang sesuai. """ # Ganti spasi dengan tanda plus (+) processed_text = text_input.replace(" ", "%20") # URL encode teks processed_text = urllib.parse.quote_plus(processed_text) return processed_text def request_url(url_input, text_input): """ Fungsi untuk melakukan request URL dengan parameter teks. Args: url_input (str): URL yang ingin diakses. text_input (str): Teks yang akan digunakan sebagai request. Returns: Response: Objek respons dari request URL. """ # Ubah teks input sesuai dengan format URL processed_text = process_text_for_url(text_input) # Buat URL lengkap dengan parameter teks full_url = url_input + "?string_input="+ processed_text print(full_url) # Lakukan request URL response = requests.get(full_url) if response.status_code == 200: result = response.text return result else: return "Gagal" def export_string_to_text_file(string, filename): """Exports a string to a text file. Args: string: The string to export. filename: The filename to save the string to. """ with open(filename, 'w') as text_file: text_file.write(string) print("Starting App...") class ReVa: def preprocessing_begin(seq): seq = str(seq).upper() delete_char = "BJOUXZ\n\t 1234567890*&^%$#@!~()[];:',.<> 0.5 else 0 predicted_label = self.reverse_label_mapping_allergen[predicted_label_index] return predicted_label, prediction except: print("Error") # # QMessageBox.warning(self, "Error", f"Gagal Prediksi Allergenisitas") def predict_label_and_probability_toxin(self, sequence): try: model_path = 'toxin.h5' model = load_model(os.path.join(model_dir, model_path)) except: print("Error") # QMessageBox.warning(self, "Error", f"Error on load model toxin") sequence = sequence[:self.seq_length_toxin] sequence = [ReVa.one_hot_encoding(self, seq) for seq in [sequence]] sequence = [seq + [[0] * self.num_features] * (self.seq_length_toxin - len(seq)) for seq in sequence] sequence = np.array(sequence) try: prediction = model.predict(sequence)[0] predicted_label_index = 1 if prediction > 0.5 else 0 predicted_label = self.reverse_label_mapping_toxin[predicted_label_index] return predicted_label, prediction except: print("Error") # QMessageBox.warning(self, "Error", f"Error on predict toxin") def predict_label_and_probability_antigenicity(self, sequence): try: model_path = 'antigenicity.h5' model = load_model(os.path.join(model_dir, model_path)) except: print("Error") # QMessageBox.warning(self, "Error", f"Error on load model antigenisitas") sequence = sequence[:self.seq_length_antigen] sequence = [ReVa.one_hot_encoding(self, seq) for seq in [sequence]] sequence = [seq + [[0] * self.num_features] * (self.seq_length_antigen - len(seq)) for seq in sequence] sequence = np.array(sequence) try: prediction = model.predict(sequence)[0] predicted_label_index = 1 if prediction > 0.5 else 0 predicted_label = self.reverse_label_mapping_antigen[predicted_label_index] return predicted_label, prediction except: print("Error") # # QMessageBox.warning(self, "Error", f"Error on prediksi antigenisitas") def invert_dict(dictionary): inverted_dict = {value: key for key, value in dictionary.items()} return inverted_dict def process_epitope(input_list): output_list = [] current_group = [] for item in input_list: if item == 'E': current_group.append(item) else: if current_group: output_list.append(''.join(current_group)) current_group = [] output_list.append(item) if current_group: output_list.append(''.join(current_group)) return output_list def filter_epitope(data): filtered_seq = [] filtered_label = [] for i in range(len(data['seq'])): if data['label'][i] != '.': filtered_seq.append(data['seq'][i]) filtered_label.append(data['label'][i]) filtered_data = {'seq': filtered_seq, 'label': filtered_label} return filtered_data def string_to_list(input_string): return list(input_string) def calculate_hydrophobicity(sequence): hydrophobic_residues = ['A', 'I', 'L', 'M', 'F', 'V', 'W', 'Y'] hydrophilic_residues = ['R', 'N', 'C', 'Q', 'E', 'G', 'H', 'K', 'S', 'T', 'D'] hydrophobicity_scores = { 'A': 0.62, 'R': -2.53, 'N': -0.78, 'D': -0.90, 'C': 0.29, 'Q': -0.85, 'E': -0.74, 'G': 0.48, 'H': -0.40, 'I': 1.38, 'L': 1.06, 'K': -1.50, 'M': 0.64, 'F': 1.19, 'P': 0.12, 'S': -0.18, 'T': -0.05, 'W': 0.81, 'Y': 0.26, 'V': 1.08 } hydrophobicity = 0 for residue in sequence: if residue in hydrophobic_residues: hydrophobicity += hydrophobicity_scores[residue] elif residue in hydrophilic_residues: hydrophobicity -= hydrophobicity_scores[residue] else: hydrophobicity -= 0.5 # penalty for unknown residues return hydrophobicity / len(sequence) def antigenicity(sequence, window_size=7): antigenicity_scores = [] for i in range(len(sequence) - window_size + 1): window = sequence[i:i+window_size] antigenicity_score = sum([1 if window[j] == 'A' or window[j] == 'G' else 0 for j in range(window_size)]) antigenicity_scores.append(antigenicity_score) return antigenicity_scores def emini_surface_accessibility(sequence, window_size=9): surface_accessibility_scores = [] for i in range(len(sequence) - window_size + 1): window = sequence[i:i+window_size] surface_accessibility_score = sum([1 if window[j] in ['S', 'T', 'N', 'Q'] else 0 for j in range(window_size)]) surface_accessibility_scores.append(surface_accessibility_score) return surface_accessibility_scores def perform_blastp(query_sequence, self): # return "N/A" # Lakukan BLASTp if self.blast_activate == True: start = time.time() try: result_handle = NCBIWWW.qblast("blastp", "nr", query_sequence) except Exception as e: # return str(e) print("BLASTp failed to connect") return "Skip because any error" # Analisis hasil BLASTp print("BLASTp Starting...") blast_records = NCBIXML.parse(result_handle) for blast_record in blast_records: for alignment in blast_record.alignments: # Anda dapat menyesuaikan kriteria kesamaan sesuai kebutuhan # Misalnya, jika Anda ingin mengembalikan hasil jika similarity > 90% for hsp in alignment.hsps: similarity = (hsp.positives / hsp.align_length) * 100 if similarity > 80: return similarity print("BLASTp Finisihing...") end = time.time() time_blast = end-start print(f"Time for BLASTp : {time_blast} s") # Jika tidak ada protein yang cocok ditemukan return "Non-similarity" else: return "Not Activated" def predict_epitope(self): seq = self.sequence seq_extra = ReVa.extraction_feature(seq) try: pred_res_B = [self.Blabel[self.loaded_Bmodel.predict([seq_extra[i]])[0]] for i in range(len(seq_extra))] pred_res_T = [self.Tlabel[self.loaded_Tmodel.predict([seq_extra[i]])[0]] for i in range(len(seq_extra))] pred_proba_B = [np.max(self.loaded_Bmodel.predict_proba([seq_extra[i]])[0]) for i in range(len(seq_extra))] pred_proba_T = [np.max(self.loaded_Tmodel.predict_proba([seq_extra[i]])[0]) for i in range(len(seq_extra))] except: print("Error on epitope predict") # # QMessageBox.warning(self, "Error", f"Error on prediksi epitope") seq_B = ReVa.combine_lists(seq, pred_res_B) pred_B = ReVa.process_epitope(pred_res_B) seq_T = ReVa.combine_lists(seq, pred_res_T) pred_T = ReVa.process_epitope(pred_res_T) pred_res1 = { 'B': {'amino acid': ReVa.string_to_list(seq), 'predictions': pred_res_B, 'probabilities': pred_proba_B}, 'T': {'amino acid': ReVa.string_to_list(seq), 'predictions': pred_res_T, 'probabilities': pred_proba_T} } pred_res2 = { 'B': {'seq': seq_B, 'label': pred_B}, 'T': {'seq': seq_T, 'label': pred_T} } return pred_res1, pred_res2 def predict_eval(self, Bpred, Tpred): BCell = ReVa.filter_epitope(Bpred)['seq'] TCell = ReVa.filter_epitope(Tpred)['seq'] Ballergen = [] BallergenProb = [] for i in range(len(BCell)): baller, ballerprob = ReVa.predict_label_and_probability_allergenicity(self, BCell[i]) Ballergen.append(baller) BallergenProb.append(ballerprob[0]) Tallergen = [] TallergenProb = [] for i in range(len(TCell)): baller, ballerprob = ReVa.predict_label_and_probability_allergenicity(self, TCell[i]) Tallergen.append(baller) TallergenProb.append(ballerprob[0]) Btoxin = [] BtoxinProb = [] Ttoxin = [] TtoxinProb = [] for i in range(len(BCell)): baller, ballerprob = ReVa.predict_label_and_probability_toxin(self, BCell[i]) Btoxin.append(baller) BtoxinProb.append(ballerprob[0]) for i in range(len(TCell)): baller, ballerprob = ReVa.predict_label_and_probability_toxin(self, TCell[i]) Ttoxin.append(baller) TtoxinProb.append(ballerprob[0]) BAntigen = [] BAntigenProb = [] TAntigen = [] TAntigenProb = [] for i in range(len(BCell)): baller, ballerprob = ReVa.predict_label_and_probability_antigenicity(self, BCell[i]) BAntigen.append(baller) BAntigenProb.append(ballerprob[0]) for i in range(len(TCell)): baller, ballerprob = ReVa.predict_label_and_probability_antigenicity(self, TCell[i]) TAntigen.append(baller) TAntigenProb.append(ballerprob[0]) Bhydrophobicity = [] Bkolaskar = [] Btangonkar = [] Bemini = [] Bsimilar = [] BPhysicochemical = [] for i in range(len(BCell)): Bhydrophobicity.append(ReVa.calculate_hydrophobicity(BCell[i])) Bkolaskar.append(ReVa.antigenicity(BCell[i])) Btangonkar.append(ReVa.antigenicity(BCell[i], window_size=5)) Bemini.append(ReVa.emini_surface_accessibility(BCell[i])) Bsimilar.append(ReVa.perform_blastp(BCell[i], self)) BPhysicochemical.append(ProtParamClone(BCell[i]).calculate()) Thydrophobicity = [] Tkolaskar = [] Ttangonkar = [] Temini = [] Tsimilar = [] TPhysicochemical = [] for i in range(len(TCell)): Thydrophobicity.append(ReVa.calculate_hydrophobicity(TCell[i])) Tkolaskar.append(ReVa.antigenicity(TCell[i])) Ttangonkar.append(ReVa.antigenicity(TCell[i], window_size=5)) Temini.append(ReVa.emini_surface_accessibility(TCell[i])) Tsimilar.append(ReVa.perform_blastp(TCell[i], self)) TPhysicochemical.append(ProtParamClone(TCell[i]).calculate()) classical_dock1B, classical_dock1T = ClassicalDocking(BCell, TCell, self.base_path, self.target_path, self.n_receptor).ForceField1() classical_dock1BAdjuvant, classical_dock1TAdjuvant = ClassicalDockingWithAdjuvant(BCell, TCell, self.base_path, self.target_path, self.n_receptor, self.n_adjuvant).ForceField1() dock1B, dock1T = MLDocking(BCell, TCell, self.base_path, self.target_path, self.n_receptor).MLDock1() dock1BAdjuvant, dock1TAdjuvant = MLDockingWithAdjuvant(BCell, TCell, self.base_path, self.target_path, self.n_receptor, self.n_adjuvant).MLDock1() pred = { 'seq': { 'B':BCell, 'T':TCell }, 'allergenicity' : { 'B' : Ballergen, 'T' : Tallergen, 'B_proba' : BallergenProb, 'T_proba' : TallergenProb }, 'toxin' : { 'B' : Btoxin, 'T' : Ttoxin, 'B_proba' : BtoxinProb, 'T_proba' : TtoxinProb }, 'antigenicity' : { 'B' : BAntigen, 'T' : TAntigen, 'B_proba' : BAntigenProb, 'T_proba' : TAntigenProb }, 'hydrophobicity' : { 'B' : Bhydrophobicity, 'T' : Thydrophobicity }, 'kolaskar' : { 'B' : Bkolaskar, 'T' : Tkolaskar }, 'tangonkar' : { 'B' : Btangonkar, 'T' : Ttangonkar }, 'emini' : { 'B' : Bemini, 'T' : Temini }, 'similarity' : { 'B' : Bsimilar, 'T' : Tsimilar }, 'physicochemical' : { 'B' : BPhysicochemical, 'T' : TPhysicochemical }, 'classical dock(Force Field)' : { 'B' : classical_dock1B, 'T' : classical_dock1T }, 'classical dock(Force Field) With Adjuvant' : { 'B' : classical_dock1BAdjuvant, 'T' : classical_dock1TAdjuvant }, 'Machine Learning based dock' : { 'B' : dock1B, 'T' : dock1T }, 'Machine Learning based dock With Adjuvant' : { 'B' : dock1BAdjuvant, 'T' : dock1TAdjuvant }, } # file_path = f'{self.target_path}/{generate_filename_with_timestamp_and_random()}_eval_res.json' sliced_pred = {key: pred[key] for key in list(pred.keys())[:9]} # Extract data for B and T cells B_data = {key: sliced_pred[key]['B'] for key in sliced_pred.keys() if key != 'seq'} T_data = {key: sliced_pred[key]['T'] for key in sliced_pred.keys() if key != 'seq'} # Create DataFrames B_result = pd.DataFrame(B_data) T_result = pd.DataFrame(T_data) print("DataFrames exported to B_result.xlsx and T_result.xlsx") file_path = f'{self.target_path}/{generate_filename_with_timestamp_and_random()}_eval_res_quantum.json' # Export to Excel files B_result.to_csv(f"{self.target_path}/B_result.csv", index=False) T_result.to_csv(f"{self.target_path}/T_result.csv", index=False) try: url = self.llm_url B_res_review = requests.post(url, files = {"uploaded_file": open(f'{self.target_path}/B_result.csv', 'rb')}, verify=False, timeout=6000)#.content.decode('utf8').replace("'", '"') T_res_review = requests.post(url, files = {"uploaded_file": open(f'{self.target_path}/T_result.csv', 'rb')}, verify=False, timeout=6000)#.content.decode('utf8').replace("'", '"') # print(B_res_review) # print(T_res_review) # B_res_review = json.loads(B_res_review) # T_res_review = json.loads(T_res_review) export_string_to_text_file(B_res_review.text, f'{self.target_path}/B_res_review.txt') export_string_to_text_file(T_res_review.text, f'{self.target_path}/T_res_review.txt') except: pass try: alphafold_res_dir = f'{self.target_path}/Alphafold Modelling Result' create_folder(alphafold_res_dir) create_folder(f'{alphafold_res_dir}/B') create_folder(f'{alphafold_res_dir}/T') url = self.alphafold_url if url[-1] == '/': pass else: url += '/' for epitope_type in list(['B', 'T']): for i, seq in enumerate(pred['seq'][epitope_type]): # response = requests.post(url, data = {"protein_sequence": seq, "jobname":f"{epitope_type}_{i}_3D_{seq}"}, verify=False, timeout=6000) response = requests.get(url+ "?protein_sequence="+seq+"&jobname="+f"{epitope_type}_{i}_3D_{seq}", verify=False, timeout=6000) if response.status_code == 200: response_res = json.loads(response.text) print(response_res) try: download_file(url + response_res['result'],f"{alphafold_res_dir}/{epitope_type}/{epitope_type}_{i}_3D_{seq}.zip") except: print("Error/gagal download") else: print("Failed Protein Modelling") continue except: pass # Export dictionary ke file JSON with open(file_path, 'w') as json_file: json.dump(str(pred), json_file) return pred def predict(self): print("Starting Predict Epitope...") pred1, pred2 = self.predict_epitope() print("Starting Predict Evalution For Epitope...") pred_eval = self.predict_eval(pred2['B'], pred2['T']) print("Finished Predict") return pred1, pred2, pred_eval class QReVa: def preprocessing_begin(seq): seq = str(seq).upper() delete_char = "BJOUXZ\n\t 1234567890*&^%$#@!~()[];:',.<> 90% for hsp in alignment.hsps: similarity = (hsp.positives / hsp.align_length) * 100 if similarity > 80: return similarity print("BLASTp Finisihing..") end = time.time() time_blast = end-start print(f"Time for BLASTp : {time_blast} s") # Jika tidak ada protein yang cocok ditemukan return "Non-similarity" else: return "Not Activated" def predict_epitope(self): seq = self.sequence seq_extra = QReVa.extraction_feature(seq) # print(seq_extra) # try: # print([int(self.loaded_Bmodel.predict([seq_extra[i]])) for i in range(len(seq_extra))]) # except Exception as e: # print(e) # print(self.loaded_Bmodel.predict([seq_extra[0]])) print("pass test") # try: pred_res_B = [self.Blabel[int(self.loaded_Bmodel.predict([seq_extra[i]]))] for i in range(len(seq_extra))] print("Prediction B epitope pass") pred_res_T = [self.Tlabel[int(self.loaded_Tmodel.predict([seq_extra[i]]))] for i in range(len(seq_extra))] print("Prediction T epitope pass") seq_B = QReVa.combine_lists(seq, pred_res_B) pred_B = QReVa.process_epitope(pred_res_B) seq_T = QReVa.combine_lists(seq, pred_res_T) pred_T = QReVa.process_epitope(pred_res_T) pred_res1 = { 'B': {'amino acid': QReVa.string_to_list(seq), 'predictions': pred_res_B}, 'T': {'amino acid': QReVa.string_to_list(seq), 'predictions': pred_res_T} } pred_res2 = { 'B': {'seq': seq_B, 'label': pred_B}, 'T': {'seq': seq_T, 'label': pred_T} } return pred_res1, pred_res2 # pred_proba_B = [np.max(self.loaded_Bmodel.predict_proba([seq_extra[i]])[0]) for i in range(len(seq_extra))] # pred_proba_T = [np.max(self.loaded_Tmodel.predict_proba([seq_extra[i]])[0]) for i in range(len(seq_extra))] # except: # print("Error on epitope predict") # # QMessageBox.warning(self, "Error", f"Error on prediksi epitope") def predict_eval(self, Bpred, Tpred): BCell = QReVa.filter_epitope(Bpred)['seq'] TCell = QReVa.filter_epitope(Tpred)['seq'] Ballergen = [] for i in range(len(BCell)): baller = QReVa.predict_label_and_probability_allergenicity(self, BCell[i]) Ballergen.append(baller) Tallergen = [] for i in range(len(TCell)): baller = QReVa.predict_label_and_probability_allergenicity(self, TCell[i]) Tallergen.append(baller) Btoxin = [] Ttoxin = [] for i in range(len(BCell)): baller = QReVa.predict_label_and_probability_toxin(self, BCell[i]) Btoxin.append(baller) for i in range(len(TCell)): baller = QReVa.predict_label_and_probability_toxin(self, TCell[i]) Ttoxin.append(baller) BAntigen = [] TAntigen = [] for i in range(len(BCell)): baller = QReVa.predict_label_and_probability_antigenicity(self, BCell[i]) BAntigen.append(baller) for i in range(len(TCell)): baller = QReVa.predict_label_and_probability_antigenicity(self, TCell[i]) TAntigen.append(baller) Bhydrophobicity = [] Bkolaskar = [] Btangonkar = [] Bemini = [] Bsimilar = [] BPhysicochemical = [] for i in range(len(BCell)): Bhydrophobicity.append(QReVa.calculate_hydrophobicity(BCell[i])) Bkolaskar.append(QReVa.antigenicity(BCell[i])) Btangonkar.append(QReVa.antigenicity(BCell[i], window_size=5)) Bemini.append(QReVa.emini_surface_accessibility(BCell[i])) Bsimilar.append(QReVa.perform_blastp(BCell[i], self)) BPhysicochemical.append(ProtParamClone(BCell[i]).calculate()) Thydrophobicity = [] Tkolaskar = [] Ttangonkar = [] Temini = [] Tsimilar = [] TPhysicochemical = [] for i in range(len(TCell)): Thydrophobicity.append(QReVa.calculate_hydrophobicity(TCell[i])) Tkolaskar.append(QReVa.antigenicity(TCell[i])) Ttangonkar.append(QReVa.antigenicity(TCell[i], window_size=5)) Temini.append(QReVa.emini_surface_accessibility(TCell[i])) Tsimilar.append(QReVa.perform_blastp(TCell[i], self)) TPhysicochemical.append(ProtParamClone(TCell[i]).calculate()) # print(BCell) classical_dock1B, classical_dock1T = ClassicalDocking(BCell, TCell, self.base_path, self.target_path, self.n_receptor).ForceField1() # print(classical_dock1B, classical_dock1T) classical_dock1BAdjuvant, classical_dock1TAdjuvant = ClassicalDockingWithAdjuvant(BCell, TCell, self.base_path, self.target_path, self.n_receptor, self.n_adjuvant).ForceField1() dock1B, dock1T = QMLDocking(BCell, TCell, self.base_path, self.target_path, self.n_receptor, self.sampler).MLDock1() dock1BAdjuvant, dock1TAdjuvant = QMLDockingWithAdjuvant(BCell, TCell, self.base_path, self.target_path, self.n_receptor, self.n_adjuvant, self.sampler).MLDock1() # print(dock1B, dock1T) pred = { 'seq': { 'B':BCell, 'T':TCell }, 'allergenicity' : { 'B' : Ballergen, 'T' : Tallergen }, 'toxin' : { 'B' : Btoxin, 'T' : Ttoxin }, 'antigenicity' : { 'B' : BAntigen, 'T' : TAntigen }, 'hydrophobicity' : { 'B' : Bhydrophobicity, 'T' : Thydrophobicity }, 'kolaskar' : { 'B' : Bkolaskar, 'T' : Tkolaskar }, 'tangonkar' : { 'B' : Btangonkar, 'T' : Ttangonkar }, 'emini' : { 'B' : Bemini, 'T' : Temini }, 'similarity' : { 'B' : Bsimilar, 'T' : Tsimilar }, 'physicochemical' : { 'B' : BPhysicochemical, 'T' : TPhysicochemical }, 'classical dock(Force Field)' : { 'B' : classical_dock1B, 'T' : classical_dock1T }, 'classical dock(Force Field) With Adjuvant' : { 'B' : classical_dock1BAdjuvant, 'T' : classical_dock1TAdjuvant }, 'Machine Learning based dock' : { 'B' : dock1B, 'T' : dock1T }, 'Machine Learning based dock With Adjuvant' : { 'B' : dock1BAdjuvant, 'T' : dock1TAdjuvant }, } sliced_pred = {key: pred[key] for key in list(pred.keys())[:9]} # Extract data for B and T cells B_data = {key: sliced_pred[key]['B'] for key in sliced_pred.keys() if key != 'seq'} T_data = {key: sliced_pred[key]['T'] for key in sliced_pred.keys() if key != 'seq'} # Create DataFrames B_result = pd.DataFrame(B_data) T_result = pd.DataFrame(T_data) print("DataFrames exported to B_result.xlsx and T_result.xlsx") file_path = f'{self.target_path}/{generate_filename_with_timestamp_and_random()}_eval_res_quantum.json' # Export to Excel files B_result.to_csv(f"{self.target_path}/B_result.csv", index=False) T_result.to_csv(f"{self.target_path}/T_result.csv", index=False) try: url = self.llm_url B_res_review = requests.post(url, files = {"uploaded_file": open(f'{self.target_path}/B_result.csv', 'rb')}, verify=False, timeout=6000)#.content.decode('utf8').replace("'", '"') T_res_review = requests.post(url, files = {"uploaded_file": open(f'{self.target_path}/T_result.csv', 'rb')}, verify=False, timeout=6000)#.content.decode('utf8').replace("'", '"') # print(B_res_review) # print(T_res_review) # B_res_review = json.loads(B_res_review) # T_res_review = json.loads(T_res_review) export_string_to_text_file(B_res_review.text, f'{self.target_path}/B_res_review.txt') export_string_to_text_file(T_res_review.text, f'{self.target_path}/T_res_review.txt') except: pass try: alphafold_res_dir = f'{self.target_path}/Alphafold Modelling Result' create_folder(alphafold_res_dir) create_folder(f'{alphafold_res_dir}/B') create_folder(f'{alphafold_res_dir}/T') url = self.alphafold_url if url[-1] == '/': pass else: url += '/' for epitope_type in list(['B', 'T']): for i, seq in enumerate(pred['seq'][epitope_type]): # response = requests.post(url, data = {"protein_sequence": seq, "jobname":f"{epitope_type}_{i}_3D_{seq}"}, verify=False, timeout=6000) response = requests.get(url+ "?protein_sequence="+seq+"&jobname="+f"{epitope_type}_{i}_3D_{seq}", verify=False, timeout=6000) if response.status_code == 200: response_res = json.loads(response.text) print(response_res) try: download_file(url + response_res['result'],f"{alphafold_res_dir}/{epitope_type}/{epitope_type}_{i}_3D_{seq}.zip") except: print("Error/gagal download") else: print("Failed Protein Modelling") continue except: pass # try: # create_folder(f'{self.target_path}/Alphafold Modelling Result') # except: # pass # Export dictionary ke file JSON with open(file_path, 'w') as json_file: json.dump(str(pred), json_file) return pred def predict(self): print("Starting Predict Epitope..") pred1, pred2 = self.predict_epitope() print("Starting Predict Evalution For Epitope..") pred_eval = self.predict_eval(pred2['B'], pred2['T']) print("Finished Predict") return pred1, pred2, pred_eval class ProtParamClone: def preprocessing_begin(seq): seq = str(seq).upper() delete_char = "BJOUXZ\n\t 1234567890*&^%$#@!~()[];:',.<>