src.serena.interfaces.vienna2_fmn_hack_interface
1import subprocess 2from subprocess import CompletedProcess 3from dataclasses import dataclass 4 5from serena.utilities.ensemble_structures import Sara2SecondaryStructure, Sara2StructureList 6 7 8 9class Vienna2FMNInterface(): 10 """ 11 class to interface with vienna2_fmn hack by Elnando888 12 """ 13 @dataclass 14 class CommandResponse(): 15 stdout:str 16 stderr:str 17 return_code:int 18 19 def __init__(self) -> None: 20 pass 21 22 def rnafold_fmn(self,input_sequence:str,do_fmn:bool = True, fmn_amount:int = 200, fmn_delta:float = 0)-> Sara2SecondaryStructure: 23 command = [] 24 if do_fmn is True: 25 command= ["RNAfold", "--ligand", f'FMN:{fmn_amount}'] 26 else: 27 command= ["RNAfold"] 28 sequence: str = '' 29 structure:str = '' 30 energy:float = 0 31 process = subprocess.run(command, input=input_sequence, encoding="utf-8", capture_output=True) 32 raw_result = process.stdout.split('\n') 33 if len(raw_result) > 0: 34 sequence = raw_result[0] 35 raw_struct = raw_result[1].split(' ') 36 if len(raw_struct) > 0: 37 structure = raw_struct[0] 38 energy_str:str = raw_struct[1] 39 energy_str = energy_str.strip('(') 40 energy_str = energy_str.strip(')') 41 try: 42 energy = float(energy_str) 43 energy = energy - fmn_delta 44 except ValueError as error: 45 energy = 0 46 47 sara_struct: Sara2SecondaryStructure = Sara2SecondaryStructure(sequence=sequence, 48 structure=structure, 49 free_energy=energy) 50 51 return sara_struct 52 53 def rnasubopt_fmn(self, input_sequence:str, do_fmn:bool = True, fmn_amount:int = 200): 54 struct_list_response:Sara2StructureList = Sara2StructureList() 55 sequence: str = '' 56 command = [] 57 if do_fmn is True: 58 command= ["RNAsubopt", "--ligand", f'FMN:{fmn_amount}'] 59 else: 60 command= ["RNAsubopt"] 61 subopt_response = self.run_command_locally(command=command, 62 extra_input=input_sequence) 63 raw_result = subopt_response.stdout.split('\n') 64 found_sequence:bool = False 65 if len(raw_result) > 1: 66 sequence_raw = raw_result[0].split(' ') 67 if len(sequence_raw) > 1: 68 sequence = sequence_raw[0] 69 found_sequence = True 70 71 if found_sequence is True: 72 #skip first one as it is the sequence 73 for index in range(1, len(raw_result)): 74 sara_struct:Sara2SecondaryStructure = Sara2SecondaryStructure() 75 raw_struct = raw_result[index].split(' ') 76 if len(raw_struct) > 1: 77 sara_struct.sequence = sequence 78 sara_struct.structure = raw_struct[0] 79 try: 80 energy = float(raw_struct[1]) 81 sara_struct.free_energy = energy 82 except ValueError as error: 83 energy = 0 84 struct_list_response.add_structure(sara_struct) 85 86 return struct_list_response 87 88 89 90 def run_command_locally(self, command:str, extra_input:str ='/n')-> CommandResponse: 91 process = subprocess.run(command, input=extra_input, encoding="utf-8", capture_output=True) 92 response: self.CommandResponse = self.CommandResponse(stdout=process.stdout, 93 stderr=process.stderr, 94 return_code=process.returncode) 95 return response 96 97 98#new_viena: Vienna2FMNInterface = Vienna2FMNInterface() 99#seq = 'GCCAUCGCAUGAGGAUAUGCUCCCGUUUCGGGAGCAGAAGGCAUGUCAUAAGACAUGAGGAUCACCCAUGUGGUUAAGAUGGCA' 100#result = new_viena.rnasubopt_fmn(seq) 101#print(result)
class
Vienna2FMNInterface:
11class Vienna2FMNInterface(): 12 """ 13 class to interface with vienna2_fmn hack by Elnando888 14 """ 15 @dataclass 16 class CommandResponse(): 17 stdout:str 18 stderr:str 19 return_code:int 20 21 def __init__(self) -> None: 22 pass 23 24 def rnafold_fmn(self,input_sequence:str,do_fmn:bool = True, fmn_amount:int = 200, fmn_delta:float = 0)-> Sara2SecondaryStructure: 25 command = [] 26 if do_fmn is True: 27 command= ["RNAfold", "--ligand", f'FMN:{fmn_amount}'] 28 else: 29 command= ["RNAfold"] 30 sequence: str = '' 31 structure:str = '' 32 energy:float = 0 33 process = subprocess.run(command, input=input_sequence, encoding="utf-8", capture_output=True) 34 raw_result = process.stdout.split('\n') 35 if len(raw_result) > 0: 36 sequence = raw_result[0] 37 raw_struct = raw_result[1].split(' ') 38 if len(raw_struct) > 0: 39 structure = raw_struct[0] 40 energy_str:str = raw_struct[1] 41 energy_str = energy_str.strip('(') 42 energy_str = energy_str.strip(')') 43 try: 44 energy = float(energy_str) 45 energy = energy - fmn_delta 46 except ValueError as error: 47 energy = 0 48 49 sara_struct: Sara2SecondaryStructure = Sara2SecondaryStructure(sequence=sequence, 50 structure=structure, 51 free_energy=energy) 52 53 return sara_struct 54 55 def rnasubopt_fmn(self, input_sequence:str, do_fmn:bool = True, fmn_amount:int = 200): 56 struct_list_response:Sara2StructureList = Sara2StructureList() 57 sequence: str = '' 58 command = [] 59 if do_fmn is True: 60 command= ["RNAsubopt", "--ligand", f'FMN:{fmn_amount}'] 61 else: 62 command= ["RNAsubopt"] 63 subopt_response = self.run_command_locally(command=command, 64 extra_input=input_sequence) 65 raw_result = subopt_response.stdout.split('\n') 66 found_sequence:bool = False 67 if len(raw_result) > 1: 68 sequence_raw = raw_result[0].split(' ') 69 if len(sequence_raw) > 1: 70 sequence = sequence_raw[0] 71 found_sequence = True 72 73 if found_sequence is True: 74 #skip first one as it is the sequence 75 for index in range(1, len(raw_result)): 76 sara_struct:Sara2SecondaryStructure = Sara2SecondaryStructure() 77 raw_struct = raw_result[index].split(' ') 78 if len(raw_struct) > 1: 79 sara_struct.sequence = sequence 80 sara_struct.structure = raw_struct[0] 81 try: 82 energy = float(raw_struct[1]) 83 sara_struct.free_energy = energy 84 except ValueError as error: 85 energy = 0 86 struct_list_response.add_structure(sara_struct) 87 88 return struct_list_response 89 90 91 92 def run_command_locally(self, command:str, extra_input:str ='/n')-> CommandResponse: 93 process = subprocess.run(command, input=extra_input, encoding="utf-8", capture_output=True) 94 response: self.CommandResponse = self.CommandResponse(stdout=process.stdout, 95 stderr=process.stderr, 96 return_code=process.returncode) 97 return response
class to interface with vienna2_fmn hack by Elnando888
def
rnafold_fmn( self, input_sequence: str, do_fmn: bool = True, fmn_amount: int = 200, fmn_delta: float = 0) -> serena.utilities.ensemble_structures.Sara2SecondaryStructure:
24 def rnafold_fmn(self,input_sequence:str,do_fmn:bool = True, fmn_amount:int = 200, fmn_delta:float = 0)-> Sara2SecondaryStructure: 25 command = [] 26 if do_fmn is True: 27 command= ["RNAfold", "--ligand", f'FMN:{fmn_amount}'] 28 else: 29 command= ["RNAfold"] 30 sequence: str = '' 31 structure:str = '' 32 energy:float = 0 33 process = subprocess.run(command, input=input_sequence, encoding="utf-8", capture_output=True) 34 raw_result = process.stdout.split('\n') 35 if len(raw_result) > 0: 36 sequence = raw_result[0] 37 raw_struct = raw_result[1].split(' ') 38 if len(raw_struct) > 0: 39 structure = raw_struct[0] 40 energy_str:str = raw_struct[1] 41 energy_str = energy_str.strip('(') 42 energy_str = energy_str.strip(')') 43 try: 44 energy = float(energy_str) 45 energy = energy - fmn_delta 46 except ValueError as error: 47 energy = 0 48 49 sara_struct: Sara2SecondaryStructure = Sara2SecondaryStructure(sequence=sequence, 50 structure=structure, 51 free_energy=energy) 52 53 return sara_struct
def
rnasubopt_fmn( self, input_sequence: str, do_fmn: bool = True, fmn_amount: int = 200):
55 def rnasubopt_fmn(self, input_sequence:str, do_fmn:bool = True, fmn_amount:int = 200): 56 struct_list_response:Sara2StructureList = Sara2StructureList() 57 sequence: str = '' 58 command = [] 59 if do_fmn is True: 60 command= ["RNAsubopt", "--ligand", f'FMN:{fmn_amount}'] 61 else: 62 command= ["RNAsubopt"] 63 subopt_response = self.run_command_locally(command=command, 64 extra_input=input_sequence) 65 raw_result = subopt_response.stdout.split('\n') 66 found_sequence:bool = False 67 if len(raw_result) > 1: 68 sequence_raw = raw_result[0].split(' ') 69 if len(sequence_raw) > 1: 70 sequence = sequence_raw[0] 71 found_sequence = True 72 73 if found_sequence is True: 74 #skip first one as it is the sequence 75 for index in range(1, len(raw_result)): 76 sara_struct:Sara2SecondaryStructure = Sara2SecondaryStructure() 77 raw_struct = raw_result[index].split(' ') 78 if len(raw_struct) > 1: 79 sara_struct.sequence = sequence 80 sara_struct.structure = raw_struct[0] 81 try: 82 energy = float(raw_struct[1]) 83 sara_struct.free_energy = energy 84 except ValueError as error: 85 energy = 0 86 struct_list_response.add_structure(sara_struct) 87 88 return struct_list_response
def
run_command_locally( self, command: str, extra_input: str = '/n') -> src.serena.interfaces.vienna2_fmn_hack_interface.Vienna2FMNInterface.CommandResponse:
92 def run_command_locally(self, command:str, extra_input:str ='/n')-> CommandResponse: 93 process = subprocess.run(command, input=extra_input, encoding="utf-8", capture_output=True) 94 response: self.CommandResponse = self.CommandResponse(stdout=process.stdout, 95 stderr=process.stderr, 96 return_code=process.returncode) 97 return response
@dataclass
class
Vienna2FMNInterface.CommandResponse: