Commit 348583f5 authored by BARGAIN Orianne's avatar BARGAIN Orianne
Browse files

add detection of intermediary michaelis menten motif

parent ab5230e3
......@@ -2,8 +2,7 @@
motif,
[
% Public API
motif_reduction/1,
motif/1
motif_reduction/1
]
).
......@@ -14,18 +13,15 @@
:- doc('Function to rewrite a graph with reduced motifs (for example michaelis menten motifs).').
:- grammar(motif).
motif(michaelis_menten).
:- grammar_doc('\\emphright{Michaelis Menten motif}').
:- initial(option(motif: michaelis_menten)).
:- initial(option(michaelis_menten_complete: yes)).
:- initial(option(michaelis_menten_intermediary: yes)).
motif_reduction(Input_file) :-
biocham_command,
type(Input_file, input_file),
doc('Function to rewrite a graph with reduced motifs (for example michaelis menten motifs).'),
option(motif, motif, Motif, 'Which motif to reduce'),
option(michaelis_menten_complete, yesno, MM_complete, 'specifies if reducing michaelis menten motifs'),
option(michaelis_menten_intermediary, yesno, MM_intermediary, 'specifies if reducing intermediary michaelis menten motifs'),
debug(motif, "Debugging motif reduction", []),
once(get_graph_info(Input_file, Number_species, Edges, Number_vertex, Id)),
Graph = [Number_vertex, Number_species, Edges, Id],
......@@ -33,12 +29,18 @@ motif_reduction(Input_file) :-
atom_concat(Root, "_reduced.bc", Output_file),
open(Output_file, write, Stream),
(
Motif=michaelis_menten
MM_complete=yes
->
once(michaelis_menten_detection_dict(Graph, Stream)),
debug(motif, "Done looking for Michaelis Menten motifs", []),
write_reactions(Graph, Stream)
debug(motif, "Done looking for complete Michaelis Menten motifs", [])
),
(
MM_intermediary=yes
->
once(michaelis_menten_detection_dict_inter(Graph, Stream)),
debug(motif, "Done looking for intermediary Michaelis Menten motifs", [])
),
write_reactions(Graph, Stream),
close(Stream).
/* get_type */
......@@ -57,98 +59,6 @@ get_type(A, ID, Type):-
Type is 0
).
/* michaelis_menten_detection */
/* michaelis_menten_detection(+Graph, +Stream)
-> looks for michaelis menten motifs
+Graph: the graph
+Stream: where to write the new graph */
michaelis_menten_detection(Graph, Stream):-
Graph = [Number_vertex, _, Edges, Id],
assert(seen(Number_vertex)),
Number_vertex_1 is Number_vertex - 1,
numlist(0,Number_vertex_1,Vertex_list),
forall(
(
member(E, Vertex_list),
member(S, Vertex_list),
member(P, Vertex_list),
member(ES, Vertex_list),
member(R1, Vertex_list),
member(R_1, Vertex_list),
member(R2, Vertex_list)
),
(
(
get_type(E, Id, 0),
get_type(S, Id, 0),
get_type(P, Id, 0),
get_type(ES, Id, 0),
get_type(R1, Id, 1),
get_type(R_1, Id, 1),
get_type(R2, Id, 1),
michaelis_menten_motif(E, S, P, ES, R1, R_1, R2, Edges)
->
debug(motif, "Michaelis Menten motif with E:~w S:~w P:~w ES:~w R1:~w R-1:~w R2:~w", [E, S, P, ES, R1, R_1, R2]),
assert(seen(R1)),
assert(seen(R_1)),
assert(seen(R2)),
write_reaction([E, S], [E, P], Id, Stream)
;
true
)
)
).
/* michaelis_menten_motif */
/* michaelis_menten_motif(+E, +S, +P, +ES, +R1, +R_1, +R2, +Edges)
-> checks if the concerned species and reactions form a michaelis menten motif
+E: enzyme
+S: substrate
+P: product
+ES: catalyser
+R1: reaction 1
+R_1: reverse of reaction 1
+R2: reaction 2
+Edges: graph edges list */
michaelis_menten_motif(E, S, P, ES, R1, R_1, R2, Edges):-
Good_arc1 = (E,R1),
Good_arc2 = (S,R1),
Good_arc3 = (R1,ES),
Good_arc4 = (ES,R_1),
Good_arc5 = (R_1,E),
Good_arc6 = (R_1,S),
Good_arc7 = (ES,R2),
Good_arc8 = (R2,E),
Good_arc9 = (R2,P),
Good_arcs = [Good_arc1, Good_arc2, Good_arc3, Good_arc4, Good_arc5, Good_arc6, Good_arc7, Good_arc8, Good_arc9],
forall(
member(Arc, Good_arcs),
member(Arc, Edges)
),
Isolated_vertices = [ES, R1, R_1, R2],
forall(
member(Arc, Edges),
(
member(Arc, Good_arcs)
;
not_bad_arc(Arc, Isolated_vertices)
)
).
/* not_bad_arc */
/* not_bad_arc(+Arc, +List_vertices)
-> makes sure the arc doesn't contain an isolated vertex
+Arc: the arc
+List_vertices: list of vertices to test */
not_bad_arc(Arc, List_vertices):-
forall(
member(Vertex, List_vertices),
(
not(Arc = (_, Vertex)),
not(Arc = (Vertex, _))
)
).
/* write_reaction */
/* write_reaction(+Reactant_list, +Product_list, +Id, +Stream)
-> write a reaction in a biocham format
......@@ -254,6 +164,36 @@ find_product(R, Edges, I, Product_list):-
),
find_product(R, Edges, I_1, Product_sub_list).
/* construct_dict_arcs */
/* construct_dict_arcs(+Arcs, -Dict_direct, -Dict_indirect)
-> constructs dictionary from list of edges
+Arcs: list of edges
-Dict_direct: constructed dict of direct arcs
-Dict_indirect: constructed dict of indirect arcs */
construct_dict_arcs([Arc], Dict_direct, Dict_indirect):-
Arc = (Vertex_A, Vertex_B),
Dict_direct = arcs{}.put(Vertex_A, [Vertex_B]),
Dict_indirect = arcs{}.put(Vertex_B, [Vertex_A]).
construct_dict_arcs([Arc|Tail], New_dict_direct, New_dict_indirect):-
construct_dict_arcs(Tail, Sub_dict_direct, Sub_dict_indirect),
Arc = (Vertex_A, Vertex_B),
(
get_dict(Vertex_A, Sub_dict_direct, Goals_vertex_A)
->
append([Vertex_B], Goals_vertex_A, Updated_goals_vertex_A),
get_dict(Vertex_A, Sub_dict_direct, Goals_vertex_A, New_dict_direct, Updated_goals_vertex_A)
;
New_dict_direct = Sub_dict_direct.put(Vertex_A, [Vertex_B])
),
(
get_dict(Vertex_B, Sub_dict_indirect, Goals_vertex_B)
->
append([Vertex_A], Goals_vertex_B, Updated_goals_vertex_B),
get_dict(Vertex_B, Sub_dict_indirect, Goals_vertex_B, New_dict_indirect, Updated_goals_vertex_B)
;
New_dict_indirect = Sub_dict_indirect.put(Vertex_B, [Vertex_A])
).
/* michaelis_menten_detection_dict */
/* michaelis_menten_detection_dict(+Graph, +Stream)
-> looks for michaelis menten motifs
......@@ -289,36 +229,6 @@ michaelis_menten_detection_dict(Graph, Stream):-
peek_count(michaelis_menten_motif_count, Nb_michelis_menten),
format("Number of Michaelis Menten motifs: ~w~n", [Nb_michelis_menten]).
/* construct_dict_arcs */
/* construct_dict_arcs(+Arcs, -Dict_direct, -Dict_indirect)
-> constructs dictionary from list of edges
+Arcs: list of edges
-Dict_direct: constructed dict of direct arcs
-Dict_indirect: constructed dict of indirect arcs */
construct_dict_arcs([Arc], Dict_direct, Dict_indirect):-
Arc = (Vertex_A, Vertex_B),
Dict_direct = arcs{}.put(Vertex_A, [Vertex_B]),
Dict_indirect = arcs{}.put(Vertex_B, [Vertex_A]).
construct_dict_arcs([Arc|Tail], New_dict_direct, New_dict_indirect):-
construct_dict_arcs(Tail, Sub_dict_direct, Sub_dict_indirect),
Arc = (Vertex_A, Vertex_B),
(
get_dict(Vertex_A, Sub_dict_direct, Goals_vertex_A)
->
append([Vertex_B], Goals_vertex_A, Updated_goals_vertex_A),
get_dict(Vertex_A, Sub_dict_direct, Goals_vertex_A, New_dict_direct, Updated_goals_vertex_A)
;
New_dict_direct = Sub_dict_direct.put(Vertex_A, [Vertex_B])
),
(
get_dict(Vertex_B, Sub_dict_indirect, Goals_vertex_B)
->
append([Vertex_A], Goals_vertex_B, Updated_goals_vertex_B),
get_dict(Vertex_B, Sub_dict_indirect, Goals_vertex_B, New_dict_indirect, Updated_goals_vertex_B)
;
New_dict_indirect = Sub_dict_indirect.put(Vertex_B, [Vertex_A])
).
/* michaelis_menten_motif */
/* michaelis_menten_motif(+ES, +Dict_arcs_direct, +Dict_arcs_indirect, +E, +S, +P, +R1, +R_1, +R2)
-> checks if the concerned species and reactions form a michaelis menten motif
......@@ -340,6 +250,8 @@ michaelis_menten_motif(ES, Dict_arcs_direct, Dict_arcs_indirect, E, S, P, R1, R_
Goals_ES = [R2, R_1]
),
Targets_ES = [R1],
get_dict(R1, Dict_arcs_direct, Goals_R1),
Goals_R1 = [ES],
get_dict(R1, Dict_arcs_indirect, Targets_R1),
(
Targets_R1 = [E, S]
......@@ -352,9 +264,177 @@ michaelis_menten_motif(ES, Dict_arcs_direct, Dict_arcs_indirect, E, S, P, R1, R_
;
Goals_R_1 = [S, E]
),
get_dict(R_1, Dict_arcs_indirect, Targets_R_1),
Targets_R_1 = [ES],
get_dict(R2, Dict_arcs_direct, Goals_R2),
(
Goals_R2 = [E, P]
;
Goals_R2 = [P, E]
),
get_dict(R2, Dict_arcs_indirect, Targets_R2),
Targets_R2 = [ES].
/* michaelis_menten_detection_dict_inter */
/* michaelis_menten_detection_dict_inter(+Graph, +Stream)
-> looks for intermediate michaelis menten motifs
+Graph: the graph
+Stream: where to write the new graph */
michaelis_menten_detection_dict_inter(Graph, Stream):-
Graph = [Number_vertex, Number_species, Edges, Id],
construct_dict_arcs(Edges, Dict_arcs_direct, Dict_arcs_indirect),
debug(motif, "Dict direct: ~w ~nDict indirect: ~w", [Dict_arcs_direct, Dict_arcs_indirect]),
assert(seen(Number_vertex)),
Number_species_1 is Number_species - 1,
numlist(0, Number_species_1, Species_list),
set_counter(michaelis_menten_motif_medium_count, 0),
forall(
(
member(ES, Species_list)
),
(
(
once(michaelis_menten_motif_medium(ES, Dict_arcs_direct, Dict_arcs_indirect, E, S, P, R1, R2))
->
debug(motif, "Intermediary Michaelis Menten motif with E:~w S:~w P:~w ES:~w R1:~w R2:~w", [E, S, P, ES, R1, R2]),
assert(seen(R1)),
assert(seen(R2)),
write_reaction([E, S], [E, P], Id, Stream),
count(michaelis_menten_motif_medium_count, _)
;
true
)
)
),
peek_count(michaelis_menten_motif_medium_count, Nb_michelis_menten_medium),
format("Number of intermediary Michaelis Menten motifs: ~w~n", [Nb_michelis_menten_medium]).
/* michaelis_menten_motif_medium */
/* michaelis_menten_motif_medium(+ES, +Dict_arcs_direct, +Dict_arcs_indirect, +E, +S, +P, +R1, +R2)
-> checks if the concerned species and reactions form an intermediate michaelis menten motif
+ES: catalyser
+Dict_arcs_direct: dict of directed arcs
+Dict_arcs_indirect: dict of undirected arcs
+E: enzyme
+S: substrate
+P: product
+R1: reaction 1
+R2: reaction 2 */
michaelis_menten_motif_medium(ES, Dict_arcs_direct, Dict_arcs_indirect, E, S, P, R1, R2):-
get_dict(ES, Dict_arcs_direct, Goals_ES),
get_dict(ES, Dict_arcs_indirect, Targets_ES),
Goals_ES = [R2],
Targets_ES = [R1],
get_dict(R1, Dict_arcs_direct, Goals_R1),
Goals_R1 = [ES],
get_dict(R1, Dict_arcs_indirect, Targets_R1),
(
Targets_R1 = [E, S]
;
Targets_R1 = [S, E]
),
get_dict(R2, Dict_arcs_direct, Goals_R2),
(
Goals_R2 = [E, P]
;
Goals_R2 = [P, E]
),
get_dict(R2, Dict_arcs_indirect, Targets_R2),
Targets_R2 = [ES].
/* Old code just in case
/ michaelis_menten_detection /
/ michaelis_menten_detection(+Graph, +Stream)
-> looks for michaelis menten motifs
+Graph: the graph
+Stream: where to write the new graph /
michaelis_menten_detection(Graph, Stream):-
Graph = [Number_vertex, _, Edges, Id],
assert(seen(Number_vertex)),
Number_vertex_1 is Number_vertex - 1,
numlist(0,Number_vertex_1,Vertex_list),
forall(
(
member(E, Vertex_list),
member(S, Vertex_list),
member(P, Vertex_list),
member(ES, Vertex_list),
member(R1, Vertex_list),
member(R_1, Vertex_list),
member(R2, Vertex_list)
),
(
(
get_type(E, Id, 0),
get_type(S, Id, 0),
get_type(P, Id, 0),
get_type(ES, Id, 0),
get_type(R1, Id, 1),
get_type(R_1, Id, 1),
get_type(R2, Id, 1),
michaelis_menten_motif(E, S, P, ES, R1, R_1, R2, Edges)
->
debug(motif, "Michaelis Menten motif with E:~w S:~w P:~w ES:~w R1:~w R-1:~w R2:~w", [E, S, P, ES, R1, R_1, R2]),
assert(seen(R1)),
assert(seen(R_1)),
assert(seen(R2)),
write_reaction([E, S], [E, P], Id, Stream)
;
true
)
)
).
/ michaelis_menten_motif /
/ michaelis_menten_motif(+E, +S, +P, +ES, +R1, +R_1, +R2, +Edges)
-> checks if the concerned species and reactions form a michaelis menten motif
+E: enzyme
+S: substrate
+P: product
+ES: catalyser
+R1: reaction 1
+R_1: reverse of reaction 1
+R2: reaction 2
+Edges: graph edges list /
michaelis_menten_motif(E, S, P, ES, R1, R_1, R2, Edges):-
Good_arc1 = (E,R1),
Good_arc2 = (S,R1),
Good_arc3 = (R1,ES),
Good_arc4 = (ES,R_1),
Good_arc5 = (R_1,E),
Good_arc6 = (R_1,S),
Good_arc7 = (ES,R2),
Good_arc8 = (R2,E),
Good_arc9 = (R2,P),
Good_arcs = [Good_arc1, Good_arc2, Good_arc3, Good_arc4, Good_arc5, Good_arc6, Good_arc7, Good_arc8, Good_arc9],
forall(
member(Arc, Good_arcs),
member(Arc, Edges)
),
Isolated_vertices = [ES, R1, R_1, R2],
forall(
member(Arc, Edges),
(
member(Arc, Good_arcs)
;
not_bad_arc(Arc, Isolated_vertices)
)
).
/ not_bad_arc /
/ not_bad_arc(+Arc, +List_vertices)
-> makes sure the arc doesn't contain an isolated vertex
+Arc: the arc
+List_vertices: list of vertices to test /
not_bad_arc(Arc, List_vertices):-
forall(
member(Vertex, List_vertices),
(
not(Arc = (_, Vertex)),
not(Arc = (Vertex, _))
)
).
*/
......@@ -2,6 +2,13 @@
:- begin_tests(motif).
has_start(Start, String) :-
atom_concat(Start, _, String).
count_start(Atom, List, Count) :-
include(has_start(Atom), List, L),
length(L, Count).
test('motif_fail') :-
command('motif_reduction("library/examples/sepi/MM5.bc").'),
read_file_to_string("library/examples/sepi/MM5_reduced.bc", String, []),
......@@ -12,4 +19,40 @@ test('motif_success') :-
read_file_to_string("library/examples/sepi/MM1_reduced.bc", String, []),
String = "S+E=>P+E.\n".
test('motif_intermediary_success') :-
command('motif_reduction("library/examples/sepi/MM6.bc").'),
read_file_to_string("library/examples/sepi/MM6_reduced.bc", String, []),
String = "S+E=>P+E.\n".
test('motif_mapk1_to_mapk3') :-
command('motif_reduction("library/examples/sepi/mapk1.bc").'),
with_output_to(
atom(Result),
command('search_reduction("library:examples/sepi/mapk1_reduced.bc", "library:examples/sepi/mapk3.bc").')
),
atomic_list_concat(Split, '\n', Result),
count_start('sepi', Split, 1),
with_output_to(
atom(Result2),
command('search_reduction("library:examples/sepi/mapk3.bc", "library:examples/sepi/mapk1_reduced.bc").')
),
atomic_list_concat(Split2, '\n', Result2),
count_start('sepi', Split2, 1).
test('motif_mapk2_to_mapk3') :-
command('motif_reduction("library/examples/sepi/mapk2.bc").'),
with_output_to(
atom(Result),
command('search_reduction("library:examples/sepi/mapk2_reduced.bc", "library:examples/sepi/mapk3.bc").')
),
atomic_list_concat(Split, '\n', Result),
count_start('sepi', Split, 1),
with_output_to(
atom(Result2),
command('search_reduction("library:examples/sepi/mapk3.bc", "library:examples/sepi/mapk2_reduced.bc").')
),
atomic_list_concat(Split2, '\n', Result2),
count_start('sepi', Split2, 1).
:- end_tests(motif).
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