src.serena.utilities.ensemble_structures

Sara2 api for accessing and manipulating secondary structures in dot parenthisis form copyright 2023 GrizzlyEngineer

  1"""
  2Sara2 api for accessing and manipulating secondary structures 
  3in dot parenthisis form
  4copyright 2023 GrizzlyEngineer
  5"""
  6from typing import List
  7from dataclasses import dataclass
  8
  9@dataclass
 10class KcalRanges():
 11    """
 12    Class to hold kcal ranges
 13    """
 14    start: float = 0
 15    stop: float = 0
 16
 17class Sara2SecondaryStructure():
 18    """
 19    Sara 2 Secondary Structure that is used to hold all the info for
 20    each secondary structure in ensemble
 21    """
 22
 23    def __init__(self, sequence:str = '', structure: str = '', free_energy: float = 0, stack_energy: float = 0) -> None:#pylint: disable=line-too-long
 24        self._sequence: str = sequence
 25        self._structure: str = structure
 26        self._free_energy: float = free_energy
 27        self._stack_energy: float = stack_energy
 28
 29    @property
 30    def sequence(self):
 31        """
 32        Returns the sequence as a string
 33        """
 34        return self._sequence
 35
 36    @sequence.setter
 37    def sequence(self, primary_struc: str):
 38        """
 39        Sets the sequence using string
 40        """
 41        self._sequence = primary_struc
 42
 43    @property
 44    def structure(self):
 45        """
 46        Returns the secondary strucuture in dot parens notation
 47        """
 48        return self._structure
 49
 50    @structure.setter
 51    def structure(self, dot_parens: str):
 52        """
 53        Sets the secondary structure using dot parense notation string
 54        """
 55        self._structure = dot_parens
 56
 57    @property
 58    def free_energy(self):
 59        """
 60        Returns the total free energy as float
 61        """
 62        return self._free_energy
 63
 64    @free_energy.setter
 65    def free_energy(self, energy: float):
 66        """
 67        Sets the total free energy with float
 68        """
 69        self._free_energy = energy
 70
 71    @property
 72    def stack_energy(self):
 73        """
 74        Returns the stack energy as float
 75        """
 76        return self._stack_energy
 77
 78    @stack_energy.setter
 79    def stack_energy(self, energy: float):
 80        """
 81        Sets the stack energy with float
 82        """
 83        self._stack_energy = energy
 84
 85    @property
 86    def nuc_count(self):
 87        """
 88        Returns the number of nucleotides as a int
 89        """
 90        return len(self._sequence)
 91
 92
 93class Sara2StructureList():#pylint: disable=too-many-instance-attributes
 94    """
 95    Sara2 Structure List that holds all the Sar2SecondaryStructurs
 96    that represent the ensemble in raw form
 97    """
 98    def __init__(self) -> None:
 99        self._sara_structures_list: List[Sara2SecondaryStructure] = []
100        self._structures: List[str] = []
101        self._free_energy_list: list[float] = []
102        self._stack_energy_list: list[float] = []
103        self._min_free_energy: float = 0
104        self._max_free_energy: float = 0
105        self._min_stack_energy: float = 0
106        self._max_stack_energy: float = 0
107        self._num_structures: int = 0
108        self._free_energy_span:float = 0
109        self._stack_energy_span:float = 0
110        self._weighted_structure:str = ''
111
112    def process_energy(self):
113        """
114        Process min and max energies in list as well
115        as populate counts. It always ran after adding 
116        structure
117        """
118            #now populate min and max
119        #do free energy
120        if len(self._free_energy_list) == 0:
121            self._min_free_energy = 0
122            self._max_free_energy = 0
123        else:
124            self._min_free_energy = min(self._free_energy_list)
125            self._max_free_energy = max(self._free_energy_list)
126
127        self._free_energy_span = self._max_free_energy - self._min_free_energy
128        #do stack energy
129
130        if len(self._stack_energy_list) == 0:
131            self._min_stack_energy = 0
132            self._max_stack_energy = 0
133        else:
134            self._min_stack_energy = min(self._stack_energy_list)
135            self._max_stack_energy = max(self._stack_energy_list)
136        self._stack_energy_span = self._max_stack_energy - self._min_stack_energy
137
138        #now count
139        self._num_structures = len(self._sara_structures_list)
140
141    def add_structure(self, structure: Sara2SecondaryStructure):
142        """
143        main way to add a structure to the list
144        """
145        self._sara_structures_list.append(structure)
146        #self._structures.append(structure.structure)
147        self._free_energy_list.append(structure.free_energy)
148        self._stack_energy_list.append(structure.stack_energy)
149        #self.process_energy()
150
151    def remove_structure(self, index:int):
152        """
153        remove a structure from memory
154        """
155        del self._structures[index]
156        del self._free_energy_list[index]
157        del self._stack_energy_list[index]
158        #self.process_energy()
159
160    @property
161    def mfe_structure(self):
162        """
163        Returns the mfe secibdary structure as a string
164        """
165        structure:str = ''
166        if len(self.sara_stuctures) > 0:
167            structure = self.sara_stuctures[0].structure
168        return structure
169
170    @property
171    def mfe_free_energy(self):
172        """
173        Returns the mfe total free energy as float
174        """
175        self.process_energy()
176        energy: float = 0
177        if len(self.sara_stuctures) > 0:
178            energy = self.sara_stuctures[0].free_energy
179        return energy
180
181    @property
182    def mfe_stack_energy(self):
183        """
184        Returns the mfe stack energy as float
185        """
186        self.process_energy()
187        energy: float = 0
188        if len(self.sara_stuctures) > 0:
189            energy = self.sara_stuctures[0].stack_energy
190        return energy
191
192    @property
193    def nuc_count(self):
194        """
195        Returns the total number of nucleotides as int
196        """
197        count: int = 0
198        if len(self.sara_stuctures) > 0:
199            count = self.sara_stuctures[0].nuc_count
200        return count
201
202    @property
203    def sara_stuctures(self):
204        """
205        Returns the sara structures that make up list
206        """
207        return self._sara_structures_list
208
209    @sara_stuctures.setter
210    def sara_stuctures(self, structs_list: List[Sara2SecondaryStructure]):
211        """
212        Sets the sara structures list using a List of Sara2Structures
213        """
214        #reset list
215        self._sara_structures_list=[]
216        #fill it in now
217        for struc in structs_list:
218            self.add_structure(struc)
219
220    @property
221    def max_free_energy(self):
222        """
223        Returns the maximum free energy of the structures in the list
224        """
225        self.process_energy()
226        return self._max_free_energy
227
228    @property
229    def min_free_energy(self):
230        """
231        Returns the minimum free energy of the structures in the list
232        """
233        self.process_energy()
234        return self._min_free_energy
235
236    @property
237    def max_stack_energy(self):
238        """
239        Returns the maximum stack energy of the structures in the list
240        """
241        self.process_energy()
242        return self._max_stack_energy
243
244    @property
245    def min_stack_energy(self):
246        """
247        Returns the minimum stack energy of the structures in the list
248        """
249        self.process_energy()
250        return self._min_stack_energy
251
252    @property
253    def num_structures(self):
254        """
255        Returns the number of structures in the list
256        """
257        self.process_energy()
258        return self._num_structures
259
260    @property
261    def free_energy_span(self):
262        """
263        Returns the span of the free energy of the structures in the list
264        """
265        self.process_energy()
266        return self._free_energy_span
267
268    @property
269    def stack_energy_span(self):
270        """
271        Returns the span of the stack energy of the structures in the list
272        """
273        self.process_energy()
274        return self._stack_energy_span
275
276    @property
277    def weighted_structure(self):
278        """
279        Returns the weighted structure as a string
280        """
281        return self._weighted_structure
282
283    @weighted_structure.setter
284    def weighted_structure(self, structure: str):
285        """
286        sets the weigthed structure
287        """
288        self._weighted_structure = structure
289
290class MakeSecondaryStructures():
291    """
292    Class to genereate the secondary structure
293    framework used by serena and sara
294    """
295    def make_secondary_structure(self, primary_structure:str, secondary_structure:str, free_energy:float, stack_free_energy:float)->Sara2SecondaryStructure:#pylint: disable=line-too-long
296        """
297        Function to make a secondary structue
298        """
299        return Sara2SecondaryStructure(sequence=primary_structure,
300                                       structure=secondary_structure,
301                                       free_energy=free_energy,
302                                       stack_energy=stack_free_energy
303                                       )
304
305    def make_secondary_strucuture_list(self, secondary_structures_list: List[Sara2SecondaryStructure])->Sara2StructureList:#pylint: disable=line-too-long
306        """
307        Function to make a secondary structure list
308        """
309        structure_list:Sara2StructureList = Sara2StructureList()
310        for structure in secondary_structures_list:
311            structure_list.add_structure(structure)
312        return structure_list
@dataclass
class KcalRanges:
10@dataclass
11class KcalRanges():
12    """
13    Class to hold kcal ranges
14    """
15    start: float = 0
16    stop: float = 0

Class to hold kcal ranges

KcalRanges(start: float = 0, stop: float = 0)
start: float = 0
stop: float = 0
class Sara2SecondaryStructure:
18class Sara2SecondaryStructure():
19    """
20    Sara 2 Secondary Structure that is used to hold all the info for
21    each secondary structure in ensemble
22    """
23
24    def __init__(self, sequence:str = '', structure: str = '', free_energy: float = 0, stack_energy: float = 0) -> None:#pylint: disable=line-too-long
25        self._sequence: str = sequence
26        self._structure: str = structure
27        self._free_energy: float = free_energy
28        self._stack_energy: float = stack_energy
29
30    @property
31    def sequence(self):
32        """
33        Returns the sequence as a string
34        """
35        return self._sequence
36
37    @sequence.setter
38    def sequence(self, primary_struc: str):
39        """
40        Sets the sequence using string
41        """
42        self._sequence = primary_struc
43
44    @property
45    def structure(self):
46        """
47        Returns the secondary strucuture in dot parens notation
48        """
49        return self._structure
50
51    @structure.setter
52    def structure(self, dot_parens: str):
53        """
54        Sets the secondary structure using dot parense notation string
55        """
56        self._structure = dot_parens
57
58    @property
59    def free_energy(self):
60        """
61        Returns the total free energy as float
62        """
63        return self._free_energy
64
65    @free_energy.setter
66    def free_energy(self, energy: float):
67        """
68        Sets the total free energy with float
69        """
70        self._free_energy = energy
71
72    @property
73    def stack_energy(self):
74        """
75        Returns the stack energy as float
76        """
77        return self._stack_energy
78
79    @stack_energy.setter
80    def stack_energy(self, energy: float):
81        """
82        Sets the stack energy with float
83        """
84        self._stack_energy = energy
85
86    @property
87    def nuc_count(self):
88        """
89        Returns the number of nucleotides as a int
90        """
91        return len(self._sequence)

Sara 2 Secondary Structure that is used to hold all the info for each secondary structure in ensemble

Sara2SecondaryStructure( sequence: str = '', structure: str = '', free_energy: float = 0, stack_energy: float = 0)
24    def __init__(self, sequence:str = '', structure: str = '', free_energy: float = 0, stack_energy: float = 0) -> None:#pylint: disable=line-too-long
25        self._sequence: str = sequence
26        self._structure: str = structure
27        self._free_energy: float = free_energy
28        self._stack_energy: float = stack_energy
sequence

Returns the sequence as a string

structure

Returns the secondary strucuture in dot parens notation

free_energy

Returns the total free energy as float

stack_energy

Returns the stack energy as float

nuc_count

Returns the number of nucleotides as a int

class Sara2StructureList:
 94class Sara2StructureList():#pylint: disable=too-many-instance-attributes
 95    """
 96    Sara2 Structure List that holds all the Sar2SecondaryStructurs
 97    that represent the ensemble in raw form
 98    """
 99    def __init__(self) -> None:
100        self._sara_structures_list: List[Sara2SecondaryStructure] = []
101        self._structures: List[str] = []
102        self._free_energy_list: list[float] = []
103        self._stack_energy_list: list[float] = []
104        self._min_free_energy: float = 0
105        self._max_free_energy: float = 0
106        self._min_stack_energy: float = 0
107        self._max_stack_energy: float = 0
108        self._num_structures: int = 0
109        self._free_energy_span:float = 0
110        self._stack_energy_span:float = 0
111        self._weighted_structure:str = ''
112
113    def process_energy(self):
114        """
115        Process min and max energies in list as well
116        as populate counts. It always ran after adding 
117        structure
118        """
119            #now populate min and max
120        #do free energy
121        if len(self._free_energy_list) == 0:
122            self._min_free_energy = 0
123            self._max_free_energy = 0
124        else:
125            self._min_free_energy = min(self._free_energy_list)
126            self._max_free_energy = max(self._free_energy_list)
127
128        self._free_energy_span = self._max_free_energy - self._min_free_energy
129        #do stack energy
130
131        if len(self._stack_energy_list) == 0:
132            self._min_stack_energy = 0
133            self._max_stack_energy = 0
134        else:
135            self._min_stack_energy = min(self._stack_energy_list)
136            self._max_stack_energy = max(self._stack_energy_list)
137        self._stack_energy_span = self._max_stack_energy - self._min_stack_energy
138
139        #now count
140        self._num_structures = len(self._sara_structures_list)
141
142    def add_structure(self, structure: Sara2SecondaryStructure):
143        """
144        main way to add a structure to the list
145        """
146        self._sara_structures_list.append(structure)
147        #self._structures.append(structure.structure)
148        self._free_energy_list.append(structure.free_energy)
149        self._stack_energy_list.append(structure.stack_energy)
150        #self.process_energy()
151
152    def remove_structure(self, index:int):
153        """
154        remove a structure from memory
155        """
156        del self._structures[index]
157        del self._free_energy_list[index]
158        del self._stack_energy_list[index]
159        #self.process_energy()
160
161    @property
162    def mfe_structure(self):
163        """
164        Returns the mfe secibdary structure as a string
165        """
166        structure:str = ''
167        if len(self.sara_stuctures) > 0:
168            structure = self.sara_stuctures[0].structure
169        return structure
170
171    @property
172    def mfe_free_energy(self):
173        """
174        Returns the mfe total free energy as float
175        """
176        self.process_energy()
177        energy: float = 0
178        if len(self.sara_stuctures) > 0:
179            energy = self.sara_stuctures[0].free_energy
180        return energy
181
182    @property
183    def mfe_stack_energy(self):
184        """
185        Returns the mfe stack energy as float
186        """
187        self.process_energy()
188        energy: float = 0
189        if len(self.sara_stuctures) > 0:
190            energy = self.sara_stuctures[0].stack_energy
191        return energy
192
193    @property
194    def nuc_count(self):
195        """
196        Returns the total number of nucleotides as int
197        """
198        count: int = 0
199        if len(self.sara_stuctures) > 0:
200            count = self.sara_stuctures[0].nuc_count
201        return count
202
203    @property
204    def sara_stuctures(self):
205        """
206        Returns the sara structures that make up list
207        """
208        return self._sara_structures_list
209
210    @sara_stuctures.setter
211    def sara_stuctures(self, structs_list: List[Sara2SecondaryStructure]):
212        """
213        Sets the sara structures list using a List of Sara2Structures
214        """
215        #reset list
216        self._sara_structures_list=[]
217        #fill it in now
218        for struc in structs_list:
219            self.add_structure(struc)
220
221    @property
222    def max_free_energy(self):
223        """
224        Returns the maximum free energy of the structures in the list
225        """
226        self.process_energy()
227        return self._max_free_energy
228
229    @property
230    def min_free_energy(self):
231        """
232        Returns the minimum free energy of the structures in the list
233        """
234        self.process_energy()
235        return self._min_free_energy
236
237    @property
238    def max_stack_energy(self):
239        """
240        Returns the maximum stack energy of the structures in the list
241        """
242        self.process_energy()
243        return self._max_stack_energy
244
245    @property
246    def min_stack_energy(self):
247        """
248        Returns the minimum stack energy of the structures in the list
249        """
250        self.process_energy()
251        return self._min_stack_energy
252
253    @property
254    def num_structures(self):
255        """
256        Returns the number of structures in the list
257        """
258        self.process_energy()
259        return self._num_structures
260
261    @property
262    def free_energy_span(self):
263        """
264        Returns the span of the free energy of the structures in the list
265        """
266        self.process_energy()
267        return self._free_energy_span
268
269    @property
270    def stack_energy_span(self):
271        """
272        Returns the span of the stack energy of the structures in the list
273        """
274        self.process_energy()
275        return self._stack_energy_span
276
277    @property
278    def weighted_structure(self):
279        """
280        Returns the weighted structure as a string
281        """
282        return self._weighted_structure
283
284    @weighted_structure.setter
285    def weighted_structure(self, structure: str):
286        """
287        sets the weigthed structure
288        """
289        self._weighted_structure = structure

Sara2 Structure List that holds all the Sar2SecondaryStructurs that represent the ensemble in raw form

def process_energy(self):
113    def process_energy(self):
114        """
115        Process min and max energies in list as well
116        as populate counts. It always ran after adding 
117        structure
118        """
119            #now populate min and max
120        #do free energy
121        if len(self._free_energy_list) == 0:
122            self._min_free_energy = 0
123            self._max_free_energy = 0
124        else:
125            self._min_free_energy = min(self._free_energy_list)
126            self._max_free_energy = max(self._free_energy_list)
127
128        self._free_energy_span = self._max_free_energy - self._min_free_energy
129        #do stack energy
130
131        if len(self._stack_energy_list) == 0:
132            self._min_stack_energy = 0
133            self._max_stack_energy = 0
134        else:
135            self._min_stack_energy = min(self._stack_energy_list)
136            self._max_stack_energy = max(self._stack_energy_list)
137        self._stack_energy_span = self._max_stack_energy - self._min_stack_energy
138
139        #now count
140        self._num_structures = len(self._sara_structures_list)

Process min and max energies in list as well as populate counts. It always ran after adding structure

def add_structure( self, structure: src.serena.utilities.ensemble_structures.Sara2SecondaryStructure):
142    def add_structure(self, structure: Sara2SecondaryStructure):
143        """
144        main way to add a structure to the list
145        """
146        self._sara_structures_list.append(structure)
147        #self._structures.append(structure.structure)
148        self._free_energy_list.append(structure.free_energy)
149        self._stack_energy_list.append(structure.stack_energy)
150        #self.process_energy()

main way to add a structure to the list

def remove_structure(self, index: int):
152    def remove_structure(self, index:int):
153        """
154        remove a structure from memory
155        """
156        del self._structures[index]
157        del self._free_energy_list[index]
158        del self._stack_energy_list[index]
159        #self.process_energy()

remove a structure from memory

mfe_structure

Returns the mfe secibdary structure as a string

mfe_free_energy

Returns the mfe total free energy as float

mfe_stack_energy

Returns the mfe stack energy as float

nuc_count

Returns the total number of nucleotides as int

sara_stuctures

Returns the sara structures that make up list

max_free_energy

Returns the maximum free energy of the structures in the list

min_free_energy

Returns the minimum free energy of the structures in the list

max_stack_energy

Returns the maximum stack energy of the structures in the list

min_stack_energy

Returns the minimum stack energy of the structures in the list

num_structures

Returns the number of structures in the list

free_energy_span

Returns the span of the free energy of the structures in the list

stack_energy_span

Returns the span of the stack energy of the structures in the list

weighted_structure

Returns the weighted structure as a string

class MakeSecondaryStructures:
291class MakeSecondaryStructures():
292    """
293    Class to genereate the secondary structure
294    framework used by serena and sara
295    """
296    def make_secondary_structure(self, primary_structure:str, secondary_structure:str, free_energy:float, stack_free_energy:float)->Sara2SecondaryStructure:#pylint: disable=line-too-long
297        """
298        Function to make a secondary structue
299        """
300        return Sara2SecondaryStructure(sequence=primary_structure,
301                                       structure=secondary_structure,
302                                       free_energy=free_energy,
303                                       stack_energy=stack_free_energy
304                                       )
305
306    def make_secondary_strucuture_list(self, secondary_structures_list: List[Sara2SecondaryStructure])->Sara2StructureList:#pylint: disable=line-too-long
307        """
308        Function to make a secondary structure list
309        """
310        structure_list:Sara2StructureList = Sara2StructureList()
311        for structure in secondary_structures_list:
312            structure_list.add_structure(structure)
313        return structure_list

Class to genereate the secondary structure framework used by serena and sara

def make_secondary_structure( self, primary_structure: str, secondary_structure: str, free_energy: float, stack_free_energy: float) -> src.serena.utilities.ensemble_structures.Sara2SecondaryStructure:
296    def make_secondary_structure(self, primary_structure:str, secondary_structure:str, free_energy:float, stack_free_energy:float)->Sara2SecondaryStructure:#pylint: disable=line-too-long
297        """
298        Function to make a secondary structue
299        """
300        return Sara2SecondaryStructure(sequence=primary_structure,
301                                       structure=secondary_structure,
302                                       free_energy=free_energy,
303                                       stack_energy=stack_free_energy
304                                       )

Function to make a secondary structue

def make_secondary_strucuture_list( self, secondary_structures_list: List[src.serena.utilities.ensemble_structures.Sara2SecondaryStructure]) -> src.serena.utilities.ensemble_structures.Sara2StructureList:
306    def make_secondary_strucuture_list(self, secondary_structures_list: List[Sara2SecondaryStructure])->Sara2StructureList:#pylint: disable=line-too-long
307        """
308        Function to make a secondary structure list
309        """
310        structure_list:Sara2StructureList = Sara2StructureList()
311        for structure in secondary_structures_list:
312            structure_list.add_structure(structure)
313        return structure_list

Function to make a secondary structure list