src.serena.analysis.investigator

File for class for analysis stuff

  1#pylint: disable=line-too-long, too-few-public-methods, too-many-instance-attributes, too-many-locals,bare-except,invalid-name
  2"""
  3File for class for analysis stuff
  4"""
  5
  6from typing import List
  7from dataclasses import dataclass
  8import attrs
  9
 10from serena.utilities.comparison_structures import  ComparisonNucResults
 11from serena.utilities.local_minima_variation import  ComparisonLMVResponse
 12
 13@dataclass
 14class SettingsAssertionLMV():
 15    """
 16    Settings use by algortihm that determines
 17    what side of switch is asserted based on lmv_m
 18    and lmv_c comparisons
 19    """
 20    diff_limit_mfe:float = 0
 21    """ The limt that the delta of lmv_c minus lmnv_m must be greater than """
 22    diff_limit_comp:float = 1
 23    """ The limt that the delta of lmv_m minus lmnv_c must be greater than """
 24
 25#@dataclass
 26@attrs.define
 27class LMVAssertionResult():
 28    """
 29    Results from LVM comparisons
 30    """
 31    comp_compare_to_mfe:List[str] = []
 32    """ the lmv_c to lmv_m comparision as a <, >, or = symbol for each energy group"""
 33    unbouund_pronounced:List[bool] = []
 34    """ A bool that indicates if that energy group has the unbound state pronounced via lmv comparisons """
 35    bound_pronounced: List[bool] = []
 36    """ A bool that indicates if that energy group has the bound state pronounced via lmv comparisons """
 37    is_on_off_switch:List[bool] = []
 38    """ List of Bools that indicates if that energy group has indications that it is a on/off switch based on lmv comparisons in enemble
 39        A list is sued so tath the amount of on/off can be judged
 40    """
 41
 42#@dataclass
 43#class SwitchabilitySettings():
 44#    limit: float = 1.5
 45
 46#@dataclass
 47#class SwitchynessResult():
 48#    is_switchable_group:List[bool]
 49#    switchable_groups_list:List[int]
 50#    is_powerfull_switch_group:List[bool]
 51#    powerfull_groups_list:List[int]
 52
 53@dataclass
 54class RatioResults():
 55    """
 56    Ratios for the comparison structure under analysis
 57    """
 58    unbound_to_total_ratio:float = -1
 59    bound_ratio: float = -1
 60    last_unbound_ratio: float = -1
 61    last_bound_ratio: float = -1
 62    last_both_ratio: float = -1
 63    bound_to_both_ratio: float = -1
 64    bound_to_total_ratio:float = -1
 65    both_nuc_total:float = -1
 66    dot_to_total_ratio: float = -1
 67    unbound_to_both:float = -1
 68
 69@attrs.define
 70class ComparisonEvalResults():
 71    """
 72    Results from comparsion structure eval for ensemble by group
 73    """
 74    #last_count_unbound:float=0
 75    #last_count_bound:float=0
 76    #last_count_both: float = 0
 77    ratios:List[RatioResults] = []
 78    BRaise_list:List[float] =[]
 79    BUratio_list:List[float] = []
 80    bound_total_list: List[int] = []
 81    unbound_total_list: List[int] = []
 82    nuc_penatly_count:int = 0
 83    first_BUratio:float = 0
 84
 85@dataclass
 86class InvestigatorResults():
 87    """
 88    Hold the results from the investigation by the investigator
 89    this includes all the evidence so to speak that back up the
 90    claims
 91    """
 92    comparison_eval_results: ComparisonEvalResults
 93    comp_nuc_counts: ComparisonNucResults
 94    lmv_values: ComparisonLMVResponse
 95    lmv_assertions: LMVAssertionResult
 96    num_groups:int = 0
 97    total_structures_ensemble:int = 0
 98
 99class ComparisonInvestigator():
100    """
101    The investigator for comparison algorithm to determine if
102    the comparison structures indicate that a RNA sequence is 
103    capabale of acting as a switch
104    """
105    def __init__(self) -> None:
106        pass
107
108    def evalulate_comparison_nucs(self, comparison_nucs:ComparisonNucResults)->ComparisonEvalResults:#pylint: disable=too-many-branches,too-many-statements
109        """
110        Evaluate the results from the comparison nucs steps and return
111        the findings
112        """
113        BRaise_list:List[float] = []
114        BUratio_list:List[float] = []
115        bound_total_list: List[int] = []
116        unbound_total_list: List[int] = []
117        ratios:List[RatioResults] = []
118        nuc_penatly_count:int = 0
119        bound_hold:int = -1
120        for group_index in range(len(comparison_nucs.comparison_nuc_counts)):#pylint: disable=consider-using-enumerate
121            last_index:int = 0
122            if group_index > 0:
123                last_index = group_index -1
124            unbound:float = comparison_nucs.comparison_nuc_counts[group_index].unbound_count
125            last_unbound:float = comparison_nucs.comparison_nuc_counts[last_index].unbound_count
126
127            bound:float = comparison_nucs.comparison_nuc_counts[group_index].bound_count
128            last_bound:float = comparison_nucs.comparison_nuc_counts[last_index].bound_count
129
130            both_nuc:float = comparison_nucs.comparison_nuc_counts[group_index].both_count
131            last_both:float = comparison_nucs.comparison_nuc_counts[last_index].both_count
132
133            dot_nuc:float = comparison_nucs.comparison_nuc_counts[group_index].dot_count
134
135            nuc_count:int = comparison_nucs.comparison_nuc_counts[last_index].num_nucs
136
137            unbound_to_total_ratio:float = 0
138            bound_to_total_ratio:float = 0
139            both_nuc_total:float = 0
140            bound_ratio: float = 0
141            last_unbound_ratio = 0
142            last_bound_ratio = 0
143            last_both_ratio = 0
144            bound_to_both_ratio = 0
145            unbound_to_both_ratio = 0
146            try:
147                last_unbound_ratio = last_unbound/unbound
148            except:
149                pass
150
151            try:
152                bound_ratio = bound/unbound
153            except:
154                pass
155
156            try:
157
158                if bound_hold != -1:
159                    #do normal
160                    if bound_hold < last_bound:
161                        if bound_hold == 0:
162                            bound_hold = 1
163                        last_bound_ratio = bound/bound_hold
164                    else:
165                        last_bound_ratio = bound/last_bound
166                else:
167                    last_bound_ratio = bound/last_bound
168
169                if bound > last_bound:
170                    #its getting bigger so record that
171                    bound_hold = last_bound
172                else:
173                    bound_hold = -1
174            except:
175                pass
176
177            #added to address the ones with 0 in the first group
178            if group_index > 0:
179                if BRaise_list[group_index-1] == 0 and bound > 0:
180                    last_bound_ratio = bound
181
182
183            try:
184                last_both_ratio = both_nuc/last_both
185            except:
186                pass
187            
188            try:
189                unbound_to_both_ratio = unbound/both_nuc
190            except:
191                pass
192            
193            try:
194                bound_to_both_ratio = bound/(both_nuc - unbound)
195            except:
196                pass
197
198            unbound_to_total_ratio = unbound/nuc_count
199            bound_to_total_ratio = bound/nuc_count
200            both_nuc_total= both_nuc/nuc_count
201            dot_nuc_total= dot_nuc/nuc_count
202
203            bound_total_list.append(bound_to_total_ratio)
204            unbound_total_list.append(unbound_to_total_ratio)
205
206            #now round teh data to make it more managable
207            last_unbound_ratio = round(last_unbound_ratio,2)
208            last_bound_ratio = round(last_bound_ratio,2)
209            unbound_to_total_ratio = round(unbound_to_total_ratio,2)
210            bound_ratio = round(bound_ratio,2)
211            #bound_stats: str = f'BURatio:{round(bound_ratio,2)},both_Raise:{round(last_both_ratio,2)} BRaise:{round(last_bound_ratio,2)}, UDrop:{round(last_unbound_ratio,2)},BothTotal:{round(both_nuc_total,2)}, BoundTotal:{round(bound_to_total_ratio,2)}, UTotal:{round(unbound_to_total_ratio,2)}, bound_both:{round(bound_to_both_ratio,2)} B:{bound}, U:{unbound}. both:{both_nuc}'
212
213
214            #this is only for the fist kcal group
215            if group_index == 0:
216                nuc_penatly_count = bound
217                first_BUratio = round(bound_ratio,2)
218
219            BUratio_list.append(round(bound_ratio,2))
220            BRaise_list.append(round(bound,2))
221
222            ratio_results:RatioResults = RatioResults(unbound_to_total_ratio=unbound_to_total_ratio,
223                                                      bound_ratio=bound_ratio,
224                                                      last_unbound_ratio=last_unbound_ratio,
225                                                      last_bound_ratio=last_bound_ratio,
226                                                      last_both_ratio=last_both_ratio,
227                                                      bound_to_both_ratio=bound_to_both_ratio,
228                                                      bound_to_total_ratio=bound_to_total_ratio,
229                                                      both_nuc_total=both_nuc_total,
230                                                      dot_to_total_ratio=dot_nuc_total,
231                                                      unbound_to_both=unbound_to_both_ratio
232                                                      )
233            ratios.append(ratio_results)
234
235        comparison_eval_results: ComparisonEvalResults = ComparisonEvalResults(ratios=ratios,
236                                                                               BRaise_list=BRaise_list,
237                                                                               BUratio_list=BUratio_list,
238                                                                               bound_total_list=bound_total_list,
239                                                                               unbound_total_list=unbound_total_list,
240                                                                               nuc_penatly_count=nuc_penatly_count,
241                                                                               first_BUratio=first_BUratio)
242        return comparison_eval_results
243
244class LocalMinimaVariationInvestigator():
245    """
246    Investigators for local minima variation results and whether 
247    the lmv's of the ensemble groups indicate that the rna sequence is
248    capable of performing as a switch
249    """
250    def __init__(self) -> None:
251        pass
252
253    def evaluate_lmv_for_structure_presence(self, lmv_data:ComparisonLMVResponse, setting:SettingsAssertionLMV)->LMVAssertionResult:
254        """
255        Evalute the comparison structures lmv values and determine
256        if the enembled groups indicate a on/off switch. return the proof for
257        this determination as well for the judges to review
258        """
259        ev_comp_limit: float = 25#25
260        ev_mfe_limit:float = 30
261
262        diff_limit_mfe:float = setting.diff_limit_mfe
263        diff_limit_comp:float = setting.diff_limit_comp
264        ev_min_limit:float = 30#15
265
266        comp_pronounced:List[bool] = []
267        is_on_off_switch:List[bool] = []
268        mfe_pronounced:List[bool] = []
269
270        for group_index in range(len(lmv_data.lmv_comps)):#pylint: disable=consider-using-enumerate
271            ev_comp:float = lmv_data.lmv_comps[group_index].lmv_comp.ev_normalized
272            ev_mfe:float = lmv_data.lmv_comps[group_index].lmv_mfe.ev_normalized
273
274            comp_asserted:bool = False
275
276            mfe_asserted:bool = False
277
278            """"""
279            diff_comp:float = round(ev_mfe,2) - round(ev_comp,2)
280            if round(ev_comp,1) < round(ev_mfe,1):# and diff_comp >= diff_limit_mfe:
281                #new stuff
282                if group_index > 0:
283                    if round(ev_comp,2) < ev_comp_limit and round(ev_mfe,2) < ev_mfe_limit:
284                        mfe_asserted = True  
285                else:
286                    if round(ev_comp,2) < 15 and round(ev_mfe,2) < 15:
287                        mfe_asserted = True
288                        
289            elif round(ev_comp,1) == round(ev_mfe,1):# and diff_comp >= diff_limit_mfe:
290                #new stuff
291                if round(ev_comp,2) < ev_comp_limit and round(ev_mfe,2) < ev_mfe_limit:
292                    mfe_asserted = True
293                    comp_asserted = True
294
295            diff_mfe = round(ev_comp,2) - round(ev_mfe,2)
296            if round(ev_mfe,2) < round(ev_comp,2):# and (diff_mfe >= diff_limit_comp):
297                #new stuff
298                if round(ev_comp,2) < ev_comp_limit and round(ev_mfe,2) < ev_mfe_limit:
299                    comp_asserted = True
300                
301            if group_index > 0  and comp_asserted is True:
302                if mfe_pronounced[0] is True:
303                    is_on_off_switch.append(True)
304            else:
305                is_on_off_switch.append(False)
306
307            comp_pronounced.append(comp_asserted)
308            mfe_pronounced.append(mfe_asserted)
309
310        ev_comp_to_mfe_list:List[str] = self.comp_compared_mfe_lmv(lmv_data=lmv_data)
311
312        lmv_presence_result: LMVAssertionResult = LMVAssertionResult(comp_compare_to_mfe=ev_comp_to_mfe_list,
313                                                                        unbouund_pronounced=mfe_pronounced,
314                                                                        bound_pronounced=comp_pronounced,
315                                                                        is_on_off_switch=is_on_off_switch)
316
317        return lmv_presence_result
318
319    def comp_compared_mfe_lmv(self, lmv_data:ComparisonLMVResponse)->List[str]:
320        """
321        Determine if the lmv_c or lmv_m is asserted per group
322        """
323        ev_comp_to_mfe_list:List[str] = []
324
325        for group_index in range(len(lmv_data.lmv_comps)):#pylint: disable=consider-using-enumerate
326            ev_comp:float = lmv_data.lmv_comps[group_index].lmv_comp.ev_normalized
327            ev_mfe:float = lmv_data.lmv_comps[group_index].lmv_mfe.ev_normalized
328            if ev_comp < ev_mfe:
329                ev_comp_to_mfe_list.append('<')
330            elif ev_comp == ev_mfe:
331                ev_comp_to_mfe_list.append('=')
332            elif ev_comp > ev_mfe:
333                ev_comp_to_mfe_list.append('>')
334
335        return ev_comp_to_mfe_list
@dataclass
class SettingsAssertionLMV:
14@dataclass
15class SettingsAssertionLMV():
16    """
17    Settings use by algortihm that determines
18    what side of switch is asserted based on lmv_m
19    and lmv_c comparisons
20    """
21    diff_limit_mfe:float = 0
22    """ The limt that the delta of lmv_c minus lmnv_m must be greater than """
23    diff_limit_comp:float = 1
24    """ The limt that the delta of lmv_m minus lmnv_c must be greater than """

Settings use by algortihm that determines what side of switch is asserted based on lmv_m and lmv_c comparisons

SettingsAssertionLMV(diff_limit_mfe: float = 0, diff_limit_comp: float = 1)
diff_limit_mfe: float = 0

The limt that the delta of lmv_c minus lmnv_m must be greater than

diff_limit_comp: float = 1

The limt that the delta of lmv_m minus lmnv_c must be greater than

@attrs.define
class LMVAssertionResult:
27@attrs.define
28class LMVAssertionResult():
29    """
30    Results from LVM comparisons
31    """
32    comp_compare_to_mfe:List[str] = []
33    """ the lmv_c to lmv_m comparision as a <, >, or = symbol for each energy group"""
34    unbouund_pronounced:List[bool] = []
35    """ A bool that indicates if that energy group has the unbound state pronounced via lmv comparisons """
36    bound_pronounced: List[bool] = []
37    """ A bool that indicates if that energy group has the bound state pronounced via lmv comparisons """
38    is_on_off_switch:List[bool] = []
39    """ List of Bools that indicates if that energy group has indications that it is a on/off switch based on lmv comparisons in enemble
40        A list is sued so tath the amount of on/off can be judged
41    """

Results from LVM comparisons

LMVAssertionResult( comp_compare_to_mfe: List[str] = [], unbouund_pronounced: List[bool] = [], bound_pronounced: List[bool] = [], is_on_off_switch: List[bool] = [])
2def __init__(self, comp_compare_to_mfe=attr_dict['comp_compare_to_mfe'].default, unbouund_pronounced=attr_dict['unbouund_pronounced'].default, bound_pronounced=attr_dict['bound_pronounced'].default, is_on_off_switch=attr_dict['is_on_off_switch'].default):
3    self.comp_compare_to_mfe = comp_compare_to_mfe
4    self.unbouund_pronounced = unbouund_pronounced
5    self.bound_pronounced = bound_pronounced
6    self.is_on_off_switch = is_on_off_switch

Method generated by attrs for class LMVAssertionResult.

comp_compare_to_mfe: List[str]

the lmv_c to lmv_m comparision as a <, >, or = symbol for each energy group

unbouund_pronounced: List[bool]

A bool that indicates if that energy group has the unbound state pronounced via lmv comparisons

bound_pronounced: List[bool]

A bool that indicates if that energy group has the bound state pronounced via lmv comparisons

is_on_off_switch: List[bool]

List of Bools that indicates if that energy group has indications that it is a on/off switch based on lmv comparisons in enemble A list is sued so tath the amount of on/off can be judged

@dataclass
class RatioResults:
54@dataclass
55class RatioResults():
56    """
57    Ratios for the comparison structure under analysis
58    """
59    unbound_to_total_ratio:float = -1
60    bound_ratio: float = -1
61    last_unbound_ratio: float = -1
62    last_bound_ratio: float = -1
63    last_both_ratio: float = -1
64    bound_to_both_ratio: float = -1
65    bound_to_total_ratio:float = -1
66    both_nuc_total:float = -1
67    dot_to_total_ratio: float = -1
68    unbound_to_both:float = -1

Ratios for the comparison structure under analysis

RatioResults( unbound_to_total_ratio: float = -1, bound_ratio: float = -1, last_unbound_ratio: float = -1, last_bound_ratio: float = -1, last_both_ratio: float = -1, bound_to_both_ratio: float = -1, bound_to_total_ratio: float = -1, both_nuc_total: float = -1, dot_to_total_ratio: float = -1, unbound_to_both: float = -1)
unbound_to_total_ratio: float = -1
bound_ratio: float = -1
last_unbound_ratio: float = -1
last_bound_ratio: float = -1
last_both_ratio: float = -1
bound_to_both_ratio: float = -1
bound_to_total_ratio: float = -1
both_nuc_total: float = -1
dot_to_total_ratio: float = -1
unbound_to_both: float = -1
@attrs.define
class ComparisonEvalResults:
70@attrs.define
71class ComparisonEvalResults():
72    """
73    Results from comparsion structure eval for ensemble by group
74    """
75    #last_count_unbound:float=0
76    #last_count_bound:float=0
77    #last_count_both: float = 0
78    ratios:List[RatioResults] = []
79    BRaise_list:List[float] =[]
80    BUratio_list:List[float] = []
81    bound_total_list: List[int] = []
82    unbound_total_list: List[int] = []
83    nuc_penatly_count:int = 0
84    first_BUratio:float = 0

Results from comparsion structure eval for ensemble by group

ComparisonEvalResults( ratios: List[src.serena.analysis.investigator.RatioResults] = [], BRaise_list: List[float] = [], BUratio_list: List[float] = [], bound_total_list: List[int] = [], unbound_total_list: List[int] = [], nuc_penatly_count: int = 0, first_BUratio: float = 0)
2def __init__(self, ratios=attr_dict['ratios'].default, BRaise_list=attr_dict['BRaise_list'].default, BUratio_list=attr_dict['BUratio_list'].default, bound_total_list=attr_dict['bound_total_list'].default, unbound_total_list=attr_dict['unbound_total_list'].default, nuc_penatly_count=attr_dict['nuc_penatly_count'].default, first_BUratio=attr_dict['first_BUratio'].default):
3    self.ratios = ratios
4    self.BRaise_list = BRaise_list
5    self.BUratio_list = BUratio_list
6    self.bound_total_list = bound_total_list
7    self.unbound_total_list = unbound_total_list
8    self.nuc_penatly_count = nuc_penatly_count
9    self.first_BUratio = first_BUratio

Method generated by attrs for class ComparisonEvalResults.

BRaise_list: List[float]
BUratio_list: List[float]
bound_total_list: List[int]
unbound_total_list: List[int]
nuc_penatly_count: int
first_BUratio: float
@dataclass
class InvestigatorResults:
86@dataclass
87class InvestigatorResults():
88    """
89    Hold the results from the investigation by the investigator
90    this includes all the evidence so to speak that back up the
91    claims
92    """
93    comparison_eval_results: ComparisonEvalResults
94    comp_nuc_counts: ComparisonNucResults
95    lmv_values: ComparisonLMVResponse
96    lmv_assertions: LMVAssertionResult
97    num_groups:int = 0
98    total_structures_ensemble:int = 0

Hold the results from the investigation by the investigator this includes all the evidence so to speak that back up the claims

InvestigatorResults( comparison_eval_results: src.serena.analysis.investigator.ComparisonEvalResults, comp_nuc_counts: serena.utilities.comparison_structures.ComparisonNucResults, lmv_values: serena.utilities.local_minima_variation.ComparisonLMVResponse, lmv_assertions: src.serena.analysis.investigator.LMVAssertionResult, num_groups: int = 0, total_structures_ensemble: int = 0)
comp_nuc_counts: serena.utilities.comparison_structures.ComparisonNucResults
lmv_values: serena.utilities.local_minima_variation.ComparisonLMVResponse
num_groups: int = 0
total_structures_ensemble: int = 0
class ComparisonInvestigator:
100class ComparisonInvestigator():
101    """
102    The investigator for comparison algorithm to determine if
103    the comparison structures indicate that a RNA sequence is 
104    capabale of acting as a switch
105    """
106    def __init__(self) -> None:
107        pass
108
109    def evalulate_comparison_nucs(self, comparison_nucs:ComparisonNucResults)->ComparisonEvalResults:#pylint: disable=too-many-branches,too-many-statements
110        """
111        Evaluate the results from the comparison nucs steps and return
112        the findings
113        """
114        BRaise_list:List[float] = []
115        BUratio_list:List[float] = []
116        bound_total_list: List[int] = []
117        unbound_total_list: List[int] = []
118        ratios:List[RatioResults] = []
119        nuc_penatly_count:int = 0
120        bound_hold:int = -1
121        for group_index in range(len(comparison_nucs.comparison_nuc_counts)):#pylint: disable=consider-using-enumerate
122            last_index:int = 0
123            if group_index > 0:
124                last_index = group_index -1
125            unbound:float = comparison_nucs.comparison_nuc_counts[group_index].unbound_count
126            last_unbound:float = comparison_nucs.comparison_nuc_counts[last_index].unbound_count
127
128            bound:float = comparison_nucs.comparison_nuc_counts[group_index].bound_count
129            last_bound:float = comparison_nucs.comparison_nuc_counts[last_index].bound_count
130
131            both_nuc:float = comparison_nucs.comparison_nuc_counts[group_index].both_count
132            last_both:float = comparison_nucs.comparison_nuc_counts[last_index].both_count
133
134            dot_nuc:float = comparison_nucs.comparison_nuc_counts[group_index].dot_count
135
136            nuc_count:int = comparison_nucs.comparison_nuc_counts[last_index].num_nucs
137
138            unbound_to_total_ratio:float = 0
139            bound_to_total_ratio:float = 0
140            both_nuc_total:float = 0
141            bound_ratio: float = 0
142            last_unbound_ratio = 0
143            last_bound_ratio = 0
144            last_both_ratio = 0
145            bound_to_both_ratio = 0
146            unbound_to_both_ratio = 0
147            try:
148                last_unbound_ratio = last_unbound/unbound
149            except:
150                pass
151
152            try:
153                bound_ratio = bound/unbound
154            except:
155                pass
156
157            try:
158
159                if bound_hold != -1:
160                    #do normal
161                    if bound_hold < last_bound:
162                        if bound_hold == 0:
163                            bound_hold = 1
164                        last_bound_ratio = bound/bound_hold
165                    else:
166                        last_bound_ratio = bound/last_bound
167                else:
168                    last_bound_ratio = bound/last_bound
169
170                if bound > last_bound:
171                    #its getting bigger so record that
172                    bound_hold = last_bound
173                else:
174                    bound_hold = -1
175            except:
176                pass
177
178            #added to address the ones with 0 in the first group
179            if group_index > 0:
180                if BRaise_list[group_index-1] == 0 and bound > 0:
181                    last_bound_ratio = bound
182
183
184            try:
185                last_both_ratio = both_nuc/last_both
186            except:
187                pass
188            
189            try:
190                unbound_to_both_ratio = unbound/both_nuc
191            except:
192                pass
193            
194            try:
195                bound_to_both_ratio = bound/(both_nuc - unbound)
196            except:
197                pass
198
199            unbound_to_total_ratio = unbound/nuc_count
200            bound_to_total_ratio = bound/nuc_count
201            both_nuc_total= both_nuc/nuc_count
202            dot_nuc_total= dot_nuc/nuc_count
203
204            bound_total_list.append(bound_to_total_ratio)
205            unbound_total_list.append(unbound_to_total_ratio)
206
207            #now round teh data to make it more managable
208            last_unbound_ratio = round(last_unbound_ratio,2)
209            last_bound_ratio = round(last_bound_ratio,2)
210            unbound_to_total_ratio = round(unbound_to_total_ratio,2)
211            bound_ratio = round(bound_ratio,2)
212            #bound_stats: str = f'BURatio:{round(bound_ratio,2)},both_Raise:{round(last_both_ratio,2)} BRaise:{round(last_bound_ratio,2)}, UDrop:{round(last_unbound_ratio,2)},BothTotal:{round(both_nuc_total,2)}, BoundTotal:{round(bound_to_total_ratio,2)}, UTotal:{round(unbound_to_total_ratio,2)}, bound_both:{round(bound_to_both_ratio,2)} B:{bound}, U:{unbound}. both:{both_nuc}'
213
214
215            #this is only for the fist kcal group
216            if group_index == 0:
217                nuc_penatly_count = bound
218                first_BUratio = round(bound_ratio,2)
219
220            BUratio_list.append(round(bound_ratio,2))
221            BRaise_list.append(round(bound,2))
222
223            ratio_results:RatioResults = RatioResults(unbound_to_total_ratio=unbound_to_total_ratio,
224                                                      bound_ratio=bound_ratio,
225                                                      last_unbound_ratio=last_unbound_ratio,
226                                                      last_bound_ratio=last_bound_ratio,
227                                                      last_both_ratio=last_both_ratio,
228                                                      bound_to_both_ratio=bound_to_both_ratio,
229                                                      bound_to_total_ratio=bound_to_total_ratio,
230                                                      both_nuc_total=both_nuc_total,
231                                                      dot_to_total_ratio=dot_nuc_total,
232                                                      unbound_to_both=unbound_to_both_ratio
233                                                      )
234            ratios.append(ratio_results)
235
236        comparison_eval_results: ComparisonEvalResults = ComparisonEvalResults(ratios=ratios,
237                                                                               BRaise_list=BRaise_list,
238                                                                               BUratio_list=BUratio_list,
239                                                                               bound_total_list=bound_total_list,
240                                                                               unbound_total_list=unbound_total_list,
241                                                                               nuc_penatly_count=nuc_penatly_count,
242                                                                               first_BUratio=first_BUratio)
243        return comparison_eval_results

The investigator for comparison algorithm to determine if the comparison structures indicate that a RNA sequence is capabale of acting as a switch

def evalulate_comparison_nucs( self, comparison_nucs: serena.utilities.comparison_structures.ComparisonNucResults) -> src.serena.analysis.investigator.ComparisonEvalResults:
109    def evalulate_comparison_nucs(self, comparison_nucs:ComparisonNucResults)->ComparisonEvalResults:#pylint: disable=too-many-branches,too-many-statements
110        """
111        Evaluate the results from the comparison nucs steps and return
112        the findings
113        """
114        BRaise_list:List[float] = []
115        BUratio_list:List[float] = []
116        bound_total_list: List[int] = []
117        unbound_total_list: List[int] = []
118        ratios:List[RatioResults] = []
119        nuc_penatly_count:int = 0
120        bound_hold:int = -1
121        for group_index in range(len(comparison_nucs.comparison_nuc_counts)):#pylint: disable=consider-using-enumerate
122            last_index:int = 0
123            if group_index > 0:
124                last_index = group_index -1
125            unbound:float = comparison_nucs.comparison_nuc_counts[group_index].unbound_count
126            last_unbound:float = comparison_nucs.comparison_nuc_counts[last_index].unbound_count
127
128            bound:float = comparison_nucs.comparison_nuc_counts[group_index].bound_count
129            last_bound:float = comparison_nucs.comparison_nuc_counts[last_index].bound_count
130
131            both_nuc:float = comparison_nucs.comparison_nuc_counts[group_index].both_count
132            last_both:float = comparison_nucs.comparison_nuc_counts[last_index].both_count
133
134            dot_nuc:float = comparison_nucs.comparison_nuc_counts[group_index].dot_count
135
136            nuc_count:int = comparison_nucs.comparison_nuc_counts[last_index].num_nucs
137
138            unbound_to_total_ratio:float = 0
139            bound_to_total_ratio:float = 0
140            both_nuc_total:float = 0
141            bound_ratio: float = 0
142            last_unbound_ratio = 0
143            last_bound_ratio = 0
144            last_both_ratio = 0
145            bound_to_both_ratio = 0
146            unbound_to_both_ratio = 0
147            try:
148                last_unbound_ratio = last_unbound/unbound
149            except:
150                pass
151
152            try:
153                bound_ratio = bound/unbound
154            except:
155                pass
156
157            try:
158
159                if bound_hold != -1:
160                    #do normal
161                    if bound_hold < last_bound:
162                        if bound_hold == 0:
163                            bound_hold = 1
164                        last_bound_ratio = bound/bound_hold
165                    else:
166                        last_bound_ratio = bound/last_bound
167                else:
168                    last_bound_ratio = bound/last_bound
169
170                if bound > last_bound:
171                    #its getting bigger so record that
172                    bound_hold = last_bound
173                else:
174                    bound_hold = -1
175            except:
176                pass
177
178            #added to address the ones with 0 in the first group
179            if group_index > 0:
180                if BRaise_list[group_index-1] == 0 and bound > 0:
181                    last_bound_ratio = bound
182
183
184            try:
185                last_both_ratio = both_nuc/last_both
186            except:
187                pass
188            
189            try:
190                unbound_to_both_ratio = unbound/both_nuc
191            except:
192                pass
193            
194            try:
195                bound_to_both_ratio = bound/(both_nuc - unbound)
196            except:
197                pass
198
199            unbound_to_total_ratio = unbound/nuc_count
200            bound_to_total_ratio = bound/nuc_count
201            both_nuc_total= both_nuc/nuc_count
202            dot_nuc_total= dot_nuc/nuc_count
203
204            bound_total_list.append(bound_to_total_ratio)
205            unbound_total_list.append(unbound_to_total_ratio)
206
207            #now round teh data to make it more managable
208            last_unbound_ratio = round(last_unbound_ratio,2)
209            last_bound_ratio = round(last_bound_ratio,2)
210            unbound_to_total_ratio = round(unbound_to_total_ratio,2)
211            bound_ratio = round(bound_ratio,2)
212            #bound_stats: str = f'BURatio:{round(bound_ratio,2)},both_Raise:{round(last_both_ratio,2)} BRaise:{round(last_bound_ratio,2)}, UDrop:{round(last_unbound_ratio,2)},BothTotal:{round(both_nuc_total,2)}, BoundTotal:{round(bound_to_total_ratio,2)}, UTotal:{round(unbound_to_total_ratio,2)}, bound_both:{round(bound_to_both_ratio,2)} B:{bound}, U:{unbound}. both:{both_nuc}'
213
214
215            #this is only for the fist kcal group
216            if group_index == 0:
217                nuc_penatly_count = bound
218                first_BUratio = round(bound_ratio,2)
219
220            BUratio_list.append(round(bound_ratio,2))
221            BRaise_list.append(round(bound,2))
222
223            ratio_results:RatioResults = RatioResults(unbound_to_total_ratio=unbound_to_total_ratio,
224                                                      bound_ratio=bound_ratio,
225                                                      last_unbound_ratio=last_unbound_ratio,
226                                                      last_bound_ratio=last_bound_ratio,
227                                                      last_both_ratio=last_both_ratio,
228                                                      bound_to_both_ratio=bound_to_both_ratio,
229                                                      bound_to_total_ratio=bound_to_total_ratio,
230                                                      both_nuc_total=both_nuc_total,
231                                                      dot_to_total_ratio=dot_nuc_total,
232                                                      unbound_to_both=unbound_to_both_ratio
233                                                      )
234            ratios.append(ratio_results)
235
236        comparison_eval_results: ComparisonEvalResults = ComparisonEvalResults(ratios=ratios,
237                                                                               BRaise_list=BRaise_list,
238                                                                               BUratio_list=BUratio_list,
239                                                                               bound_total_list=bound_total_list,
240                                                                               unbound_total_list=unbound_total_list,
241                                                                               nuc_penatly_count=nuc_penatly_count,
242                                                                               first_BUratio=first_BUratio)
243        return comparison_eval_results

Evaluate the results from the comparison nucs steps and return the findings

class LocalMinimaVariationInvestigator:
245class LocalMinimaVariationInvestigator():
246    """
247    Investigators for local minima variation results and whether 
248    the lmv's of the ensemble groups indicate that the rna sequence is
249    capable of performing as a switch
250    """
251    def __init__(self) -> None:
252        pass
253
254    def evaluate_lmv_for_structure_presence(self, lmv_data:ComparisonLMVResponse, setting:SettingsAssertionLMV)->LMVAssertionResult:
255        """
256        Evalute the comparison structures lmv values and determine
257        if the enembled groups indicate a on/off switch. return the proof for
258        this determination as well for the judges to review
259        """
260        ev_comp_limit: float = 25#25
261        ev_mfe_limit:float = 30
262
263        diff_limit_mfe:float = setting.diff_limit_mfe
264        diff_limit_comp:float = setting.diff_limit_comp
265        ev_min_limit:float = 30#15
266
267        comp_pronounced:List[bool] = []
268        is_on_off_switch:List[bool] = []
269        mfe_pronounced:List[bool] = []
270
271        for group_index in range(len(lmv_data.lmv_comps)):#pylint: disable=consider-using-enumerate
272            ev_comp:float = lmv_data.lmv_comps[group_index].lmv_comp.ev_normalized
273            ev_mfe:float = lmv_data.lmv_comps[group_index].lmv_mfe.ev_normalized
274
275            comp_asserted:bool = False
276
277            mfe_asserted:bool = False
278
279            """"""
280            diff_comp:float = round(ev_mfe,2) - round(ev_comp,2)
281            if round(ev_comp,1) < round(ev_mfe,1):# and diff_comp >= diff_limit_mfe:
282                #new stuff
283                if group_index > 0:
284                    if round(ev_comp,2) < ev_comp_limit and round(ev_mfe,2) < ev_mfe_limit:
285                        mfe_asserted = True  
286                else:
287                    if round(ev_comp,2) < 15 and round(ev_mfe,2) < 15:
288                        mfe_asserted = True
289                        
290            elif round(ev_comp,1) == round(ev_mfe,1):# and diff_comp >= diff_limit_mfe:
291                #new stuff
292                if round(ev_comp,2) < ev_comp_limit and round(ev_mfe,2) < ev_mfe_limit:
293                    mfe_asserted = True
294                    comp_asserted = True
295
296            diff_mfe = round(ev_comp,2) - round(ev_mfe,2)
297            if round(ev_mfe,2) < round(ev_comp,2):# and (diff_mfe >= diff_limit_comp):
298                #new stuff
299                if round(ev_comp,2) < ev_comp_limit and round(ev_mfe,2) < ev_mfe_limit:
300                    comp_asserted = True
301                
302            if group_index > 0  and comp_asserted is True:
303                if mfe_pronounced[0] is True:
304                    is_on_off_switch.append(True)
305            else:
306                is_on_off_switch.append(False)
307
308            comp_pronounced.append(comp_asserted)
309            mfe_pronounced.append(mfe_asserted)
310
311        ev_comp_to_mfe_list:List[str] = self.comp_compared_mfe_lmv(lmv_data=lmv_data)
312
313        lmv_presence_result: LMVAssertionResult = LMVAssertionResult(comp_compare_to_mfe=ev_comp_to_mfe_list,
314                                                                        unbouund_pronounced=mfe_pronounced,
315                                                                        bound_pronounced=comp_pronounced,
316                                                                        is_on_off_switch=is_on_off_switch)
317
318        return lmv_presence_result
319
320    def comp_compared_mfe_lmv(self, lmv_data:ComparisonLMVResponse)->List[str]:
321        """
322        Determine if the lmv_c or lmv_m is asserted per group
323        """
324        ev_comp_to_mfe_list:List[str] = []
325
326        for group_index in range(len(lmv_data.lmv_comps)):#pylint: disable=consider-using-enumerate
327            ev_comp:float = lmv_data.lmv_comps[group_index].lmv_comp.ev_normalized
328            ev_mfe:float = lmv_data.lmv_comps[group_index].lmv_mfe.ev_normalized
329            if ev_comp < ev_mfe:
330                ev_comp_to_mfe_list.append('<')
331            elif ev_comp == ev_mfe:
332                ev_comp_to_mfe_list.append('=')
333            elif ev_comp > ev_mfe:
334                ev_comp_to_mfe_list.append('>')
335
336        return ev_comp_to_mfe_list

Investigators for local minima variation results and whether the lmv's of the ensemble groups indicate that the rna sequence is capable of performing as a switch

def evaluate_lmv_for_structure_presence( self, lmv_data: serena.utilities.local_minima_variation.ComparisonLMVResponse, setting: src.serena.analysis.investigator.SettingsAssertionLMV) -> src.serena.analysis.investigator.LMVAssertionResult:
254    def evaluate_lmv_for_structure_presence(self, lmv_data:ComparisonLMVResponse, setting:SettingsAssertionLMV)->LMVAssertionResult:
255        """
256        Evalute the comparison structures lmv values and determine
257        if the enembled groups indicate a on/off switch. return the proof for
258        this determination as well for the judges to review
259        """
260        ev_comp_limit: float = 25#25
261        ev_mfe_limit:float = 30
262
263        diff_limit_mfe:float = setting.diff_limit_mfe
264        diff_limit_comp:float = setting.diff_limit_comp
265        ev_min_limit:float = 30#15
266
267        comp_pronounced:List[bool] = []
268        is_on_off_switch:List[bool] = []
269        mfe_pronounced:List[bool] = []
270
271        for group_index in range(len(lmv_data.lmv_comps)):#pylint: disable=consider-using-enumerate
272            ev_comp:float = lmv_data.lmv_comps[group_index].lmv_comp.ev_normalized
273            ev_mfe:float = lmv_data.lmv_comps[group_index].lmv_mfe.ev_normalized
274
275            comp_asserted:bool = False
276
277            mfe_asserted:bool = False
278
279            """"""
280            diff_comp:float = round(ev_mfe,2) - round(ev_comp,2)
281            if round(ev_comp,1) < round(ev_mfe,1):# and diff_comp >= diff_limit_mfe:
282                #new stuff
283                if group_index > 0:
284                    if round(ev_comp,2) < ev_comp_limit and round(ev_mfe,2) < ev_mfe_limit:
285                        mfe_asserted = True  
286                else:
287                    if round(ev_comp,2) < 15 and round(ev_mfe,2) < 15:
288                        mfe_asserted = True
289                        
290            elif round(ev_comp,1) == round(ev_mfe,1):# and diff_comp >= diff_limit_mfe:
291                #new stuff
292                if round(ev_comp,2) < ev_comp_limit and round(ev_mfe,2) < ev_mfe_limit:
293                    mfe_asserted = True
294                    comp_asserted = True
295
296            diff_mfe = round(ev_comp,2) - round(ev_mfe,2)
297            if round(ev_mfe,2) < round(ev_comp,2):# and (diff_mfe >= diff_limit_comp):
298                #new stuff
299                if round(ev_comp,2) < ev_comp_limit and round(ev_mfe,2) < ev_mfe_limit:
300                    comp_asserted = True
301                
302            if group_index > 0  and comp_asserted is True:
303                if mfe_pronounced[0] is True:
304                    is_on_off_switch.append(True)
305            else:
306                is_on_off_switch.append(False)
307
308            comp_pronounced.append(comp_asserted)
309            mfe_pronounced.append(mfe_asserted)
310
311        ev_comp_to_mfe_list:List[str] = self.comp_compared_mfe_lmv(lmv_data=lmv_data)
312
313        lmv_presence_result: LMVAssertionResult = LMVAssertionResult(comp_compare_to_mfe=ev_comp_to_mfe_list,
314                                                                        unbouund_pronounced=mfe_pronounced,
315                                                                        bound_pronounced=comp_pronounced,
316                                                                        is_on_off_switch=is_on_off_switch)
317
318        return lmv_presence_result

Evalute the comparison structures lmv values and determine if the enembled groups indicate a on/off switch. return the proof for this determination as well for the judges to review

def comp_compared_mfe_lmv( self, lmv_data: serena.utilities.local_minima_variation.ComparisonLMVResponse) -> List[str]:
320    def comp_compared_mfe_lmv(self, lmv_data:ComparisonLMVResponse)->List[str]:
321        """
322        Determine if the lmv_c or lmv_m is asserted per group
323        """
324        ev_comp_to_mfe_list:List[str] = []
325
326        for group_index in range(len(lmv_data.lmv_comps)):#pylint: disable=consider-using-enumerate
327            ev_comp:float = lmv_data.lmv_comps[group_index].lmv_comp.ev_normalized
328            ev_mfe:float = lmv_data.lmv_comps[group_index].lmv_mfe.ev_normalized
329            if ev_comp < ev_mfe:
330                ev_comp_to_mfe_list.append('<')
331            elif ev_comp == ev_mfe:
332                ev_comp_to_mfe_list.append('=')
333            elif ev_comp > ev_mfe:
334                ev_comp_to_mfe_list.append('>')
335
336        return ev_comp_to_mfe_list

Determine if the lmv_c or lmv_m is asserted per group