Skip to content

Create dingo-walk PyPi package #111

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ volestipy.egg-info
venv
lp_solve_5.5/
.devcontainer/
.github/dependabot.yml
.github/dependabot.yml
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<p align="center"><img src="doc/logo/dingo.jpg" width="260" height="260"></p>
<p align="center"><img src="https://raw.githubusercontent.com/GeomScale/dingo/refs/heads/develop/doc/logo/dingo.jpg" width="260" height="260"></p>

**dingo** is a Python package that analyzes metabolic networks.
It relies on high dimensional sampling with Markov Chain Monte Carlo (MCMC)
Expand Down Expand Up @@ -290,7 +290,7 @@ plot_histogram(

The default number of bins is 60. dingo uses the package `matplotlib` for plotting.

![histogram](./doc/e_coli_aconta.png)
![histogram](https://raw.githubusercontent.com/GeomScale/dingo/refs/heads/develop/doc/e_coli_aconta.png)

### Plot a copula between two fluxes

Expand All @@ -314,6 +314,6 @@ plot_copula(data_flux1, data_flux2, n=10)

The default number of cells is 5x5=25. dingo uses the package `plotly` for plotting.

![histogram](./doc/aconta_ppc_copula.png)
![histogram](https://raw.githubusercontent.com/GeomScale/dingo/refs/heads/develop/doc/aconta_ppc_copula.png)


8 changes: 4 additions & 4 deletions dingo/MetabolicNetwork.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,18 +250,18 @@ def set_active_bound(reaction: str, reac_index: int, bound: float) -> None:
# Turn off reactions not present in media
for rxn_id in exchange_rxns - frozen_media_rxns:
"""
is_export for us, needs to check on the S
order reactions to their lb and ub
is_export for us, needs to check on the S
order reactions to their lb and ub
"""
# is_export = rxn.reactants and not rxn.products
reac_index = self._reactions.index(rxn_id)
products = np.any(self._S[:,reac_index] > 0)
products = np.any(self._S[:,reac_index] > 0)
reactants_exist = np.any(self._S[:,reac_index] < 0)
is_export = True if not products and reactants_exist else False
set_active_bound(
rxn_id, reac_index, min(0.0, -self._lb[reac_index] if is_export else self._ub[reac_index])
)

def set_solver(self, solver: str):
self._parameters["solver"] = solver

Expand Down
6 changes: 3 additions & 3 deletions dingo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def dingo_main():

# Move to the output directory
os.chdir(output_path_dir)

set_default_solver(args.solver)

if args.model_name is None:
Expand Down Expand Up @@ -133,7 +133,7 @@ def dingo_main():
raise Exception("An unknown format file given.")

model.set_solver(args.solver)

result_obj = model.fva()

with open("dingo_fva_" + name + ".pckl", "wb") as dingo_fva_file:
Expand All @@ -147,7 +147,7 @@ def dingo_main():
model = MetabolicNetwork.fom_mat(args.metabolic_network)
else:
raise Exception("An unknown format file given.")

model.set_solver(args.solver)

result_obj = model.fba()
Expand Down
2 changes: 1 addition & 1 deletion dingo/bindings/bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ void HPolytopeCPP::apply_rounding(int rounding_method, double* new_A, double* ne

// run the rounding method
if (rounding_method == 1) { // max ellipsoid
round_res = inscribed_ellipsoid_rounding<MT, VT, NT>(P, CheBall.first);
round_res = inscribed_ellipsoid_rounding<MT, VT, NT, decltype(P), Point, 2>(P, CheBall.first);

} else if (rounding_method == 2) { // isotropization
round_res = svd_rounding<AcceleratedBilliardWalk, MT, VT>(P, CheBall, 1, rng);
Expand Down
48 changes: 24 additions & 24 deletions dingo/illustrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def plot_copula(data_flux1, data_flux2, n = 5, width = 900 , height = 600, expor
fig = go.Figure(
data = [go.Surface(z=copula)],
layout = go.Layout(
height = height,
height = height,
width = width,
)
)
Expand All @@ -48,7 +48,7 @@ def plot_copula(data_flux1, data_flux2, n = 5, width = 900 , height = 600, expor
margin=dict(r=30, b=30, l=30, t=50))

fig.layout.template = None

fig.show()
fig_name = data_flux1[1] + "_" + data_flux2[1] + "_copula." + export_format

Expand Down Expand Up @@ -97,7 +97,7 @@ def plot_corr_matrix(corr_matrix, reactions, removed_reactions=[], format="svg")
removed_reactions -- A list with the removed reactions in case of a preprocess.
If provided removed reactions are not plotted.
"""

sns_colormap = [[0.0, '#3f7f93'],
[0.1, '#6397a7'],
[0.2, '#88b1bd'],
Expand All @@ -109,26 +109,26 @@ def plot_corr_matrix(corr_matrix, reactions, removed_reactions=[], format="svg")
[0.8, '#e8848b'],
[0.9, '#e15e68'],
[1.0, '#da3b46']]

if removed_reactions != 0:
for reaction in reactions:
index = reactions.index(reaction)
if reaction in removed_reactions:
reactions[index] = None
fig = px.imshow(corr_matrix,

fig = px.imshow(corr_matrix,
color_continuous_scale = sns_colormap,
x = reactions, y = reactions, origin="upper")

fig.update_layout(
xaxis=dict(tickfont=dict(size=5)),
yaxis=dict(tickfont=dict(size=5)),
width=900, height=900, plot_bgcolor="rgba(0,0,0,0)")

fig.update_traces(xgap=1, ygap=1, hoverongaps=False)

fig.show()

fig_name = "CorrelationMatrix." + format
pio.write_image(fig, fig_name, scale=2)

Expand All @@ -141,18 +141,18 @@ def plot_dendrogram(dissimilarity_matrix, reactions , plot_labels=False, t=2.0,
dissimilarity_matrix -- A matrix produced from the "cluster_corr_reactions" function
reactions -- A list with the model's reactions
plot_labels -- A boolean variable that if True plots the reactions labels in the dendrogram
t -- A threshold that defines a threshold that cuts the dendrogram
t -- A threshold that defines a threshold that cuts the dendrogram
at a specific height and colors the occuring clusters accordingly
linkage -- linkage defines the type of linkage.
linkage -- linkage defines the type of linkage.
Available linkage types are: single, average, complete, ward.
"""

fig = ff.create_dendrogram(dissimilarity_matrix,
labels=reactions,
linkagefun=lambda x: hierarchy.linkage(x, linkage),
linkagefun=lambda x: hierarchy.linkage(x, linkage),
color_threshold=t)
fig.update_layout(width=800, height=800)

if plot_labels == False:
fig.update_layout(
xaxis=dict(
Expand All @@ -166,9 +166,9 @@ def plot_dendrogram(dissimilarity_matrix, reactions , plot_labels=False, t=2.0,
yaxis=dict(
title_font=dict(size=10),
tickfont=dict(size=8) ) )

fig.show()



def plot_graph(G, pos):
Expand All @@ -184,24 +184,24 @@ def plot_graph(G, pos):
for u, v, data in G.edges(data=True):
x0, y0 = pos[u]
x1, y1 = pos[v]

edge_color = 'blue' if data['weight'] > 0 else 'red'
fig.add_trace(go.Scatter(x=[x0, x1], y=[y0, y1], mode='lines',
line=dict(width=abs(data['weight']) * 1,

fig.add_trace(go.Scatter(x=[x0, x1], y=[y0, y1], mode='lines',
line=dict(width=abs(data['weight']) * 1,
color=edge_color), hoverinfo='none',
showlegend=False))

for node in G.nodes():
x, y = pos[node]
node_name = G.nodes[node].get('name', f'Node {node}')
fig.add_trace(go.Scatter(x=[x], y=[y], mode='markers',

fig.add_trace(go.Scatter(x=[x], y=[y], mode='markers',
marker=dict(size=10),
text=[node_name],
textposition='top center',
name = node_name,
showlegend=False))

fig.update_layout(width=800, height=800)
fig.show()
fig.show()
12 changes: 6 additions & 6 deletions dingo/loading_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def read_json_file(input_file):
input_file -- a json file that contains the information about a mettabolic network, for example see http://bigg.ucsd.edu/models
"""

try:
try:
cobra.io.load_matlab_model( input_file )
except:
cobra_config = cobra.Configuration()
Expand All @@ -45,7 +45,7 @@ def read_mat_file(input_file):
Keyword arguments:
input_file -- a mat file that contains a MATLAB structure with the information about a mettabolic network, for example see http://bigg.ucsd.edu/models
"""
try:
try:
cobra.io.load_matlab_model( input_file )
except:
cobra_config = cobra.Configuration()
Expand All @@ -56,8 +56,8 @@ def read_mat_file(input_file):
return (parse_cobra_model( model ))

def read_sbml_file(input_file):
"""A Python function, based on the cobra.io.read_sbml_model() function of cabrapy
and the extract_polytope() function of PolyRound
"""A Python function, based on the cobra.io.read_sbml_model() function of cabrapy
and the extract_polytope() function of PolyRound
(https://gitlab.com/csb.ethz/PolyRound/-/blob/master/PolyRound/static_classes/parse_sbml_stoichiometry.py)
to read an SBML file (.xml) and return:
(a) lower/upper flux bounds
Expand All @@ -68,10 +68,10 @@ def read_sbml_file(input_file):
(f) the objective function to maximize the biomass pseudoreaction

Keyword arguments:
input_file -- a xml file that contains an SBML model with the information about a mettabolic network, for example see:
input_file -- a xml file that contains an SBML model with the information about a mettabolic network, for example see:
https://github.com/VirtualMetabolicHuman/AGORA/blob/master/CurrentVersion/AGORA_1_03/AGORA_1_03_sbml/Abiotrophia_defectiva_ATCC_49176.xml
"""
try:
try:
cobra.io.read_sbml_model( input_file )
except:
cobra_config = cobra.Configuration()
Expand Down
Loading