Skip to content

Commit

Permalink
MSCommunity visualization polishing
Browse files Browse the repository at this point in the history
  • Loading branch information
freiburgermsu committed Jul 19, 2023
1 parent 24f1939 commit 8bb7300
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
4 changes: 2 additions & 2 deletions modelseedpy/community/mscommscores.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,15 +328,15 @@ def calculate_scores(pairs, models_media=None, environments=None, RAST_genomes=N
del kbase_dic[f"MIP_model{modelIDs.index(models_name)+1}"]
if print_progress: print("costless_MIP done", end="\t")
if print_progress: print("MIP done", end="\t")
kbase_dic.update({"PC": f"{MSCommScores.pc(grouping, comm_model, comm_sol, community=community)[0]:.5f}"})
if print_progress: print("PC done", end="\t")
bss_values = MSCommScores.bss(None, [model_utils[model1.id], model_utils[model2.id]],
environments, models_media, anme_comm)
kbase_dic.update({f"BSS_model{modelIDs.index(name.split(' invading ')[0])+1}": f"{val:.5f}"
for name, val in bss_values.items()})
if print_progress: print("BSS done", end="\t")
kbase_dic.update({"BIT": MSCommScores.bit(grouping, comm_model, comm_sol=comm_sol, community=community)})
if print_progress: print("BIT done", end="\t")
kbase_dic.update({"PC": f"{MSCommScores.pc(grouping, comm_model, comm_sol, community=community)[0]:.5f}"})
if print_progress: print("PC done", end="\t")
# determine the growth diff content
kbase_dic.update({"GYD": f"""{list(MSCommScores.gyd(
grouping, environment=environ, community=community, anme_comm=anme_comm).values())[0]:.5f}"""})
Expand Down
8 changes: 5 additions & 3 deletions modelseedpy/community/mssteadycom.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,8 @@ def visual_interactions(cross_feeding_df, filename="cross_feeding", export_forma
metabolites_df = concat(cross_feeding_rows, axis=1).T
metabolites_df.index.name = "Metabolite ID"
display(metabolites_df)
metabolites = [msdb.compounds.get_by_id(metID.replace("_e0", "")) for metID in metabolites_df.index.tolist()]
metabolites = [msdb.compounds.get_by_id(metID.replace("_e0", "")) for metID in metabolites_df.index.tolist()
if metID not in ["cpdETCM", "cpdETCMe"]]
# define the community members that participate in cross-feeding
members = metabolites_df.loc[:, (metabolites_df != 0).any(axis=0)].columns.tolist()
members.remove("Environment")
Expand Down Expand Up @@ -268,12 +269,13 @@ def visual_interactions(cross_feeding_df, filename="cross_feeding", export_forma
# define the edges by parsing the interaction DataFrame
for met in metabolites:
row = metabolites_df.loc[met.id]
maxVal = max(list(row.to_numpy()))
for col, val in row.items():
if col == "Environment": continue
index = members.index(col)
# TODO color carbon sources red
if val > 0: dot.edge(f"S{index}", met.abbr[:3], arrowsize=f"{val / 500}", edgetooltip=str(val))
if val < 0: dot.edge(met.abbr[:3], f"S{index}", arrowsize=f"{abs(val / 500)}", edgetooltip=str(val))
if val > 0: dot.edge(f"S{index}", met.abbr[:3], arrowsize=f"{val / maxVal}", edgetooltip=str(val))
if val < 0: dot.edge(met.abbr[:3], f"S{index}", arrowsize=f"{abs(val / maxVal)}", edgetooltip=str(val))

# render and export the source
dot.render(filename, view=view_figure)
Expand Down

0 comments on commit 8bb7300

Please sign in to comment.