looks_like.jl 5.03 KB
Newer Older
St. Elmo's avatar
St. Elmo committed
1
2
3
4
"""
    looks_like_exchange_reaction(rxn_id::String;
        exclude_biomass = false,
        biomass_strings = _constants.biomass_strings,
St. Elmo's avatar
St. Elmo committed
5
        exchange_prefixes = _constants.exchange_prefixes,
St. Elmo's avatar
St. Elmo committed
6
7
    )

8
9
10
11
12
A predicate that matches reaction identifiers that look like
exchange or biomass reactions, given the usual naming schemes in common model
repositories. Exchange reactions are identified based on matching prefixes in
the set `exchange_prefixes` and biomass reactions are identified by looking for
occurences of `biomass_strings` in the reaction id.
St. Elmo's avatar
St. Elmo committed
13

14
Also see [`find_exchange_reactions`](@ref).
15

St. Elmo's avatar
St. Elmo committed
16
17
# Example
```
St. Elmo's avatar
St. Elmo committed
18
findall(looks_like_exchange_reaction, reactions(model)) # returns indices
19
filter(looks_like_exchange_reaction, reactions(model)) # returns Strings
St. Elmo's avatar
St. Elmo committed
20

Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
21
22
# to use the optional arguments you need to expand the function's arguments
# using an anonymous function
St. Elmo's avatar
St. Elmo committed
23
findall(x -> looks_like_exchange_reaction(x; exclude_biomass=true), reactions(model)) # returns indices
24
filter(x -> looks_like_exchange_reaction(x; exclude_biomass=true), reactions(model)) # returns Strings
St. Elmo's avatar
St. Elmo committed
25
26
```
"""
Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
27
28
function looks_like_exchange_reaction(
    rxn_id::String;
St. Elmo's avatar
St. Elmo committed
29
30
    exclude_biomass = false,
    biomass_strings = _constants.biomass_strings,
St. Elmo's avatar
St. Elmo committed
31
    exchange_prefixes = _constants.exchange_prefixes,
32
)::Bool
Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
33
34
    any(startswith(rxn_id, x) for x in exchange_prefixes) &&
        !(exclude_biomass && any(occursin(x, rxn_id) for x in biomass_strings))
St. Elmo's avatar
St. Elmo committed
35
end
36

37
38
39
40
41
42
43
44
45
46
47
48
"""
    find_exchange_reactions(m::MetabolicModel; kwargs...)

Shortcut for finding exchange reaction indexes in a model; arguments are
forwarded to [`looks_like_exchange_reaction`](@ref).
"""
find_exchange_reactions(m::MetabolicModel; kwargs...) =
    findall(id -> looks_like_exchange_reaction(id; kwargs...), reactions(m))

"""
    find_exchange_reaction_ids(m::MetabolicModel; kwargs...)

Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
49
Shortcut for finding exchange reaction identifiers in a model; arguments are
50
51
52
53
54
forwarded to [`looks_like_exchange_reaction`](@ref).
"""
find_exchange_reaction_ids(m::MetabolicModel; kwargs...) =
    filter(id -> looks_like_exchange_reaction(id, kwargs...), reactions(m))

55
56
"""
    looks_like_biomass_reaction(rxn_id::String;
St. Elmo's avatar
St. Elmo committed
57
58
        exclude_exchanges = false,
        exchange_prefixes = _constants.exchange_prefixes,
59
60
61
        biomass_strings = _constants.biomass_strings,
    )::Bool

62
63
64
65
A predicate that matches reaction identifiers that look like biomass reactions.
Biomass reactions are identified by looking for occurences of `biomass_strings`
in the reaction id. If `exclude_exchanges` is set, the strings that look like
exchanges (from [`looks_like_exchange_reaction`](@ref)) will not match.
66
67
68
69
70
71
72

# Example
```
filter(looks_like_biomass_reaction, reactions(model)) # returns strings
findall(looks_like_biomass_reaction, reactions(model)) # returns indices
```
"""
Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
73
74
function looks_like_biomass_reaction(
    rxn_id::String;
St. Elmo's avatar
St. Elmo committed
75
76
    exclude_exchanges = false,
    exchange_prefixes = _constants.exchange_prefixes,
St. Elmo's avatar
St. Elmo committed
77
    biomass_strings = _constants.biomass_strings,
78
)::Bool
Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
79
80
    any(occursin(x, rxn_id) for x in biomass_strings) &&
        !(exclude_exchanges && any(startswith(rxn_id, x) for x in exchange_prefixes))
81
end
82
83
84
85
86
87
88
89
90
91
92
93
"""
    find_biomass_reactions(m::MetabolicModel; kwargs...)

Shortcut for finding biomass reaction indexes in a model; arguments are
forwarded to [`looks_like_biomass_reaction`](@ref).
"""
find_biomass_reactions(m::MetabolicModel; kwargs...) =
    findall(id -> looks_like_biomass_reaction(id; kwargs...), reactions(m))

"""
    find_biomass_reaction_ids(m::MetabolicModel; kwargs...)

Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
94
95
Shortcut for finding biomass reaction identifiers in a model; arguments are
forwarded to [`looks_like_biomass_reaction`](@ref).
96
97
98
99
"""
find_biomass_reaction_ids(m::MetabolicModel; kwargs...) =
    filter(id -> looks_like_biomass_reaction(id, kwargs...), reactions(m))

100
101
102

"""
    looks_like_exchange_metabolite(rxn_id::String;
St. Elmo's avatar
St. Elmo committed
103
        exchange_suffixes = _constants.exchange_suffixes,
104
105
        )::Bool

106
107
108
A predicate that matches metabolite identifiers that look like involved in
exchange reactions. Exchange metabolites are identified by `exchange_suffixes`
at the end of the metabolite id.
109
110
111
112
113
114
115

# Example
```
filter(looks_like_exchange_metabolite, metabolites(model)) # returns strings
findall(looks_like_exchange_metabolite, metabolites(model)) # returns indices
```
"""
Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
116
117
function looks_like_exchange_metabolite(
    met_id::String;
St. Elmo's avatar
St. Elmo committed
118
    exchange_suffixes = _constants.exchange_suffixes,
119
)::Bool
St. Elmo's avatar
St. Elmo committed
120
    any(endswith(met_id, x) for x in exchange_suffixes)
121
end
Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138

"""
    find_exchange_metabolites(m::MetabolicModel; kwargs...)

Shortcut for finding exchange metabolite indexes in a model; arguments are
forwarded to [`looks_like_exchange_metabolite`](@ref).
"""
find_exchange_metabolites(m::MetabolicModel; kwargs...) =
    findall(id -> looks_like_exchange_metabolite(id; kwargs...), metabolites(m))
"""
    find_exchange_metabolite_ids(m::MetabolicModel; kwargs...)

Shortcut for finding exchange metabolite identifiers in a model; arguments are
forwarded to [`looks_like_exchange_metabolite`](@ref).
"""
find_exchange_metabolite_ids(m::MetabolicModel; kwargs...) =
    findall(id -> looks_like_exchange_metabolite(id; kwargs...), metabolites(m))