def Calculate_Foldability_NFE(seq, dp_str, scaler, clf): print '*Calculate Foldability NFE' print 'seq:',seq print 'dp_str:', dp_str foldability_WOMFE = entrna_main(seq, dp_str, scaler, clf) #foldability = entrna_main(seq1,dp_str,scaler, clf) #print('foldability',foldability) return foldability_WOMFE
def UpdateBestWholeChainEverInMemory(BestWholeChainEverInMemory, GlobalPossibleActionSet, OriginalRNAChain, scaler, clf, scaler_ori, clf_ori): temp = 0 append_list = [] for item in GlobalPossibleActionSet: position_of_nucleotide = item.PositionOfNucleotide reward = item.rewards #print 'rewards', reward, 'vs', BestWholeChainEverInMemory.rewards if reward >= BestWholeChainEverInMemory.rewards and item.WholeChainBP != [0 for i in range(0, len(OriginalRNAChain))]: #print 'FLAG*****BestWC changed', 'new reward:', reward, 'old reward:', BestWholeChainEverInMemory.rewards BestWholeChainEverInMemory.rewards = reward BestWholeChainEverInMemory.ChainItself = item.WholeChainBP BestWholeChainEverInMemory.Parent = item.PartialChain_parent BestWholeChainEverInMemory.ori_WC = item.ori_WC temp = temp + 1 elif item.WholeChainBP == [0 for i in range(0, len(OriginalRNAChain))]: pass else: pass if temp == 0: print "Sorry, there are no matching partial chain as parent" #Here we replace the whole chain and scores of the corresponding next step as fortified's. temp_1 =0 for item in GlobalPossibleActionSet: position_of_nucleotide = item.PositionOfNucleotide temp_nuc = BestWholeChainEverInMemory.ChainItself[position_of_nucleotide] if BestWholeChainEverInMemory.ChainItself[position_of_nucleotide] == 2.5: temp_nuc = 2 elif BestWholeChainEverInMemory.ChainItself[position_of_nucleotide] == 1.5: temp_nuc = 1 #print 'item.BasePair', item.BasePair #print 'BestWholeChainEverInMemory.ChainItself[position_of_nucleotide]', BestWholeChainEverInMemory.ChainItself[position_of_nucleotide] #print 'temp_nuc', temp_nuc #print 'item.WholeChainBP[:(position_of_nucleotide-1)]', item.WholeChainBP[:(position_of_nucleotide-1)] #print 'BestWholeChainEverInMemory.ChainItself[:(position_of_nucleotide-1)]', BestWholeChainEverInMemory.ChainItself[:(position_of_nucleotide-1)] if item.BasePair == temp_nuc and item.WholeChainBP[:(position_of_nucleotide-1)] == BestWholeChainEverInMemory.ChainItself[:(position_of_nucleotide-1)]: temp_1 = temp_1 +1 new_item = deepcopy(item) new_item.WholeChainBP = BestWholeChainEverInMemory.ChainItself new_item.ori_WC = BestWholeChainEverInMemory.ChainItself #print 'item.Parent', item.PartialChain_parent.ChainItself, 'VVVSSS', 'new_item.PartialChain_parent', new_item.PartialChain_parent.ChainItself BestWholeChainEverInMemory.Parent = new_item.PartialChain_parent new_rewards_1 = entrna_main(''.join(map(str, OriginalRNAChain)), ''.join(map(str, BP_to_DP(BestWholeChainEverInMemory.ChainItself))), scaler, clf) new_rewards_2 = entrna_main_ori(''.join(map(str, OriginalRNAChain)), ''.join(map(str, BP_to_DP(BestWholeChainEverInMemory.ChainItself))), scaler_ori, clf_ori) new_rewards_3 = abs(new_rewards_1 - new_rewards_2) new_item.rewards = new_rewards_1 append_list.append(new_item) #print 'append_list' for itera in append_list: #print 'New_action_deepcopy', itera.Nucleotide, itera.BasePair, itera.rewards, itera.PartialChain_parent, itera.WholeChainBP GlobalPossibleActionSet.append(itera) if temp_1 == 0: raise Exception("Sorry, there's no corresponding action to fortified solution.") return GlobalPossibleActionSet,BestWholeChainEverInMemory
def GetRewards(WholeChain,OriginalRNAChain,scaler, clf): """ In this function we plug in ENTRNA as rewards. """ seq = OriginalRNAChain dp = SeqAttRollOut_RNAfold.TransferIntoDP(WholeChain) seq_str = ''.join(map(str, seq)) dp_str = ''.join(map(str, dp)) #bp = dp_to_bp(dp) #print('*Get Rewards:*') #print('seq_str is:',seq_str) #print('dp_str is:',dp_str) foldability = entrna_main(seq_str, dp_str, scaler, clf) rewards = foldability #print('Now the rewards is',rewards) #rewards = random.randrange(0,5) return rewards
def Calculate_Foldability_NFE(seq, dp_str, scaler, clf): foldability_WOMFE = entrna_main(seq, dp_str, scaler, clf) #foldability = entrna_main(seq1,dp_str,scaler, clf) #print('foldability',foldability) return foldability_WOMFE