Commit c2185fba authored by Roman Sarrazin-Gendron's avatar Roman Sarrazin-Gendron
Browse files

preserved rotations

parent 4b75446c
......@@ -420,6 +420,25 @@ def adjust_aln(best_struct,positions,better_positions):
new_best_struct = (full_sample,new_nucs_for_each_nodes,best_of_sample)
return new_best_struct
def preserve_rotation(position_subsets):
print(position_subsets)
if len(position_subsets)<3:
#print("not a junction")
permutations = list(itertools.permutations(position_subsets))
return permutations
current_permutations = []
is_first = position_subsets[0]
current_p = position_subsets.copy()
for i in range(len(position_subsets)):
moved = current_p[0]
current_p.append(moved)
current_p.pop(0)
#print("current_p",current_p)
current_permutations.append(current_p.copy())
#print("current_perm",current_permutations)
return current_permutations
def get_position_permutations(position_subsets,component_distance):
final_position_permutations = []
to_permute = []
......@@ -437,7 +456,10 @@ def get_position_permutations(position_subsets,component_distance):
for position in range(len(component_distance)+1):
if position not in set(permuted):
not_permuted.append(position)
permutations = list(itertools.permutations(to_permute))
#permutations = list(itertools.permutations(to_permute))
permutations = preserve_rotation(to_permute)
#print("PERMUTATIONS",permutations)
# print(preserve_rotation(to_permute))
for perm in permutations:
this_perm = []
perm_counter = 0
......@@ -565,6 +587,7 @@ def seq_to_struct(
g_distance=[]
h_distance = []
j_distance = []
k_distance = []
for junc in component_distance:
a=junc[0]
b=junc[1]
......@@ -574,6 +597,8 @@ def seq_to_struct(
f= max(int((a+b)/6),c+0)
h= int(1.5*b)
j = int(1.2*b)
k = max(a,len(seq))
reduced_component_distance.append([a,c])
halfway_component_distance.append([a,d])
......@@ -582,6 +607,7 @@ def seq_to_struct(
g_distance.append([a,c])
h_distance.append([a,h])
j_distance.append([a,j])
k_distance.append([a,k])
permutations = get_permutations(position_subsets,component_distance,iii)
regex_list = []
for perm in permutations:
......@@ -596,6 +622,7 @@ def seq_to_struct(
res6 = build_regex(position_subsets,g_distance, node_dict, convert, positions, mc)
res7 = build_regex(position_subsets,h_distance, node_dict, convert, positions, mc)
res8 = build_regex(position_subsets,j_distance, node_dict, convert, positions, mc)
res9 = build_regex(position_subsets,k_distance, node_dict, convert, positions, mc)
regex_list.append([res,position_subsets,node_dict])
regex_list.append([res2,position_subsets,node_dict])
......@@ -605,6 +632,7 @@ def seq_to_struct(
regex_list.append([res6,position_subsets,node_dict])
regex_list.append([res7,position_subsets,node_dict])
regex_list.append([res8,position_subsets,node_dict])
regex_list.append([res9,position_subsets,node_dict])
output = []
final_model = {}
......
......@@ -9,25 +9,25 @@ import argparse
import time as timer
def run_BP(seq, ss, modules_to_parse, dataset, left_out, m=8, n=5, sm=0.8, mc=3, p=25000, k=1,sscons=2):
def run_BP(seq, ss, modules_to_parse, dataset, left_out, m=8, n=5, sm=0.8, mc=3, p=25000, sw=1,sscons=2):
#print("excuting bayespairing with secondary structure:",ss)
return_dict= BayesPairing.parse_sequence(seq, modules_to_parse, "", dataset, left_out, sm, mc, p)
#print(return_dict)
#print("now returning")
maxs = BayesPairing.returner(return_dict, seq, ss, m, n, k, int(sscons))
maxs = BayesPairing.returner(return_dict, seq, ss, m, n, sw, int(sscons))
#print(maxs)
#end = timer.time()
#print("TIME USED:", end - time, "\n")
return maxs
def parse_sequences(input,modules_to_check=[],dataset="",ss="",m=4,n=3,sm=0.3,mc=3,p=25000,k=1,t=15.7,w=200,s=100,sscons=2):
def parse_sequences(input,modules_to_check=[],dataset="",ss="",m=4,n=3,sm=0.3,mc=3,p=25000,sw=1,t=15.7,w=200,s=100,sscons=2):
if dataset=="":
dataset="rna3dmotif"
graphs = pickle.load(open("../models/" + dataset + "_one_of_each_graph.cPickle", "rb"))
if len(modules_to_check) == 0:
modules_to_check = range(len(graphs))
argum = {"m":m, "n":n, "sm":sm,"mc":mc,"p":p,"k":k,"t":t,"w":w,"s":s,"sscons":2}
argum = {"m":m, "n":n, "sm":sm,"mc":mc,"p":p,"sw":sw,"t":t,"w":w,"s":s,"sscons":2}
this_output = run_fasta(input,modules_to_check,dataset,ss,argum)
return this_output
......@@ -354,7 +354,7 @@ if __name__ == "__main__":
parser.add_argument("-t", help="Score threshold for a module to be called. [0 to 35]. Default:25 ")
parser.add_argument("-w", help="Window Length [50 to 300]. Default:200 ")
parser.add_argument("-s", help="Step size between windows [10 to 200]. Default:100 ")
parser.add_argument("-k", help="weight of the secondary structure analysis [0.8 to 2]. Default:1 ")
parser.add_argument("-sw", help="weight of the secondary structure analysis [0.8 to 2]. Default:1 ")
parser.add_argument("-o", help="Name of the output file. Default: output ")
parser.add_argument("-sscons", help="Constraint level of the module-secondary structure match. Integer from 0 to 5, 0 being most constrained")
......@@ -369,8 +369,8 @@ if __name__ == "__main__":
arguments["m"] = args.m
if args.n != None:
arguments["n"] = args.n
if args.k != None:
arguments["k"] = args.k
if args.sw != None:
arguments["sw"] = args.sw
if args.t != None:
arguments["t"] = args.t
if args.w != None:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment