Skip to content

Commit

Permalink
Modify 'makeSpeciesGlyphsVisible' function to receive a list of speci…
Browse files Browse the repository at this point in the history
…es id, reaction id, and reaction glyph index as its input
  • Loading branch information
adelhpour committed Nov 11, 2024
1 parent ecc1865 commit 6371ec6
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 61 deletions.
35 changes: 25 additions & 10 deletions src/bindings/python/ctypes/libsbmlnetwork.py.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -490,29 +490,44 @@ class LibSBMLNetwork:
"""
return lib.c_api_makeSpeciesGlyphVisible(self.sbml_object, str(species_id).encode(), str(reaction_id).encode(), visible, reaction_glyph_index, layout_index)

def makeSpeciesGlyphsVisible(self, species_ids=None, visible=True, layout_index=0):
def makeSpeciesGlyphsVisible(self, species=None, visible=True, layout_index=0):
"""
Makes the SpeciesGlyphs of Species with the given species_ids in the Layout object with the given index in the given SBMLDocument visible or invisible

:Parameters:

- species_ids (list of strings): a list of strings that determines the ids of the Species
- species = (list of lists or list of strings, optional): a list (default: None) that determines the list of Species. The list contains:
- a list of lists where each list includes:
- 'id' (str): the ID of the Species
- 'reaction_id' (str): the ID of the Reaction
- 'reaction_glyph_index' (int, optional): the index (default: 0) of the ReactionGlyph in the given SBMLDocument
- visible = (boolean, optional): a boolean (default: True) that determines whether to make the SpeciesGlyphs visible or invisible
- layout_index (int, optional): an integer (default: 0) that determines the index of the Layout object in the given SBMLDocument

:Returns:

true on success and false if the SpeciesGlyphs could not be hidden
"""
species_ids_ptr = None
species_ids_len = 0
if species_ids is not None:
species_ids_len = len(species_ids)
species_ids_ptr = (ctypes.c_char_p * len(species_ids))()
for i in range(len(species_ids)):
species_ids_ptr[i] = ctypes.c_char_p(species_ids[i].encode())
species_ptr = None
if species is not None:
species_ptr = (ctypes.POINTER(ctypes.c_char_p) * len(species))()
for i in range(len(species)):
a_species_ptr = (ctypes.c_char_p * 3)()
if isinstance(species[i], list):
if len(species[i]) == 3:
print(species[i])
a_species_ptr[0] = ctypes.c_char_p(str(species[i][0]).encode())
a_species_ptr[1] = ctypes.c_char_p(str(species[i][1]).encode())
a_species_ptr[2] = ctypes.c_char_p(str(species[i][2]).encode())
elif len(species[i]) == 2:
a_species_ptr[0] = ctypes.c_char_p(str(species[i][0]).encode())
a_species_ptr[1] = ctypes.c_char_p(str(species[i][1]).encode())
a_species_ptr[2] = ctypes.c_char_p(str(0).encode())
else:
raise Exception("The species parameter should be a list of lists with species id, reaction id, and reaction glyph index or a list of lists with species id and reaction id.")
species_ptr[i] = a_species_ptr

return lib.c_api_makeSpeciesGlyphsVisible(self.sbml_object, species_ids_ptr, species_ids_len, visible, layout_index)
return lib.c_api_makeSpeciesGlyphsVisible(self.sbml_object, species_ptr, len(species_ptr), visible, layout_index)

def getCanvasWidth(self, layout_index=0):
"""
Expand Down
17 changes: 12 additions & 5 deletions src/c_api/libsbmlnetwork_c_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,19 @@ namespace LIBSBMLNETWORK_CPP_NAMESPACE {
return makeSpeciesGlyphVisible(document, layoutIndex, speciesId, reactionId, reactionGlyphIndex, visible);
}

int c_api_makeSpeciesGlyphsVisible(SBMLDocument* document, const char** speciesIds, const int speciesIdsSize, const bool visible, int layoutIndex) {
std::set<std::string> speciesIdsSet = std::set<std::string>();
for (int i = 0; i < speciesIdsSize; i++)
speciesIdsSet.insert(speciesIds[i]);
int c_api_makeSpeciesGlyphsVisible(SBMLDocument* document, const char ***species, const int speciesSize, const bool visible, int layoutIndex) {
std::set<std::tuple<std::string, std::string, int> > speciesSet = std::set<std::tuple<std::string, std::string, int> >();
if (species) {
for (int i = 0; i < speciesSize; i++) {
const char **aSpecies = species[i];
const char *speciesId = aSpecies[0];
const char *reactionId = aSpecies[1];
int reactionGlyphIndex = atoi(aSpecies[2]);
speciesSet.insert(std::make_tuple(speciesId, reactionId, reactionGlyphIndex));
}
}

return makeSpeciesGlyphsVisible(document, layoutIndex, speciesIdsSet, visible);
return makeSpeciesGlyphsVisible(document, layoutIndex, speciesSet, visible);
}

double c_api_getCanvasWidth(SBMLDocument* document, int layoutIndex) {
Expand Down
4 changes: 2 additions & 2 deletions src/c_api/libsbmlnetwork_c_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,12 @@ namespace LIBSBMLNETWORK_CPP_NAMESPACE {

/// @brief Hide the SpeciesGlyphs with the given species Ids in the Layout object with the given index in the ListOfLayouts of the SBML document.
/// @param document a pointer to the SBMLDocument object.
/// @param speciesIds an array of strings containing the ids of the species to hide the SpeciesGlyphs for.
/// @param species an array of strings containing the ids of the species, ids of the reactions, and the indices of the reaction glyphs that the species are participants of.
/// @param speciesIdsSize the size of speciesIds
/// @param visible a boolean value to determine whether make SpeciesGlyph visible or invisible.
/// @param layoutIndex the index number of the Layout to return.
/// @return integer value indicating success/failure of the function.
LIBSBMLNETWORK_EXTERN int c_api_makeSpeciesGlyphsVisible(SBMLDocument* document, const char** speciesIds, const int speciesIdsSize, bool visible = true, int layoutIndex = 0);
LIBSBMLNETWORK_EXTERN int c_api_makeSpeciesGlyphsVisible(SBMLDocument* document, const char ***species, const int speciesSize, const bool visible, int layoutIndex);

/// @brief Returns the value of the "width" attribute of the Dimensions object of the Layout object
/// with the given index in the ListOfLayouts of the SBML document.
Expand Down
35 changes: 4 additions & 31 deletions src/libsbmlnetwork_layout_helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -655,17 +655,12 @@ int setSpeciesGlyphIndexInReactionGlyph(Layout* layout, const std::string specie
return -1;
}

int makeSpeciesGlyphsVisible(Model* model, Layout* layout, std::set<std::string> speciesIds, bool visible) {
if (!speciesIds.size()) {
for (unsigned int i = 0; i < model->getNumSpecies(); i++)
speciesIds.insert(model->getSpecies(i)->getId());
int makeSpeciesGlyphsVisible(Model* model, Layout* layout, std::set<std::tuple<std::string, std::string, int> > species, bool visible) {
for (std::set<std::tuple<std::string, std::string, int> >::const_iterator speciesIt = species.cbegin(); speciesIt != species.cend(); speciesIt++) {
if (makeSpeciesGlyphVisible(getReactionGlyph(layout, std::get<1>(*speciesIt), std::get<2>(*speciesIt)), std::get<0>(*speciesIt), visible))
return -1;
}

if (!visible)
hideSpeciesGlyphs(layout, speciesIds);
else
unHideSpeciesGlyphs(layout, speciesIds);

return 0;
}

Expand All @@ -676,28 +671,6 @@ int makeSpeciesGlyphVisible(ReactionGlyph* reactionGlyph, const std::string spec
return unHideSpeciesGlyph(reactionGlyph, speciesId);
}

int hideSpeciesGlyphs(Layout* layout, std::set<std::string> speciesIds) {
for (std::set<std::string>::const_iterator speciesIdsIt = speciesIds.cbegin(); speciesIdsIt != speciesIds.cend(); speciesIdsIt++) {
if (hideSpeciesGlyph(layout, *speciesIdsIt))
return -1;
}

return 0;
}

int unHideSpeciesGlyphs(Layout* layout, std::set<std::string> speciesIds) {
for (std::set<std::string>::const_iterator speciesIdsIt = speciesIds.cbegin(); speciesIdsIt != speciesIds.cend(); speciesIdsIt++) {
if (unHideSpeciesGlyph(layout, *speciesIdsIt))
return -1;
for (unsigned int i = 0; i < layout->getNumReactionGlyphs(); i++) {
ReactionGlyph* reactionGlyph = layout->getReactionGlyph(i);
makeSpeciesGlyphVisible(reactionGlyph, *speciesIdsIt, true);
}
}

return 0;
}

int hideSpeciesGlyph(SBase* sBase, const std::string speciesId) {
if (sBase) {
std::string hiddenSpeciesIds = getUserData(sBase, "hidden_species_ids");
Expand Down
6 changes: 1 addition & 5 deletions src/libsbmlnetwork_layout_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,10 @@ SpeciesGlyph* getSpeciesGlyph(Layout* layout, const std::string& speciesId, cons

int setSpeciesGlyphIndexInReactionGlyph(Layout* layout, const std::string speciesId, ReactionGlyph* reactionGlyph, const unsigned int index);

int makeSpeciesGlyphsVisible(Model* model, Layout* layout, std::set<std::string> speciesIds, bool visible = true);
int makeSpeciesGlyphsVisible(Model* model, Layout* layout, std::set<std::tuple<std::string, std::string, int> > species, bool visible = true);

int makeSpeciesGlyphVisible(ReactionGlyph* reactionGlyph, const std::string speciesId, bool visible = true);

int hideSpeciesGlyphs(Layout* layout, std::set<std::string> speciesIds);

int unHideSpeciesGlyphs(Layout* layout, std::set<std::string> speciesIds);

int hideSpeciesGlyph(SBase* sBase, const std::string speciesId);

int unHideSpeciesGlyph(SBase* sBase, const std::string speciesId);
Expand Down
8 changes: 4 additions & 4 deletions src/libsbmlnetwork_sbmldocument_layout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,19 +190,19 @@ int makeSpeciesGlyphVisible(SBMLDocument* document, unsigned int layoutIndex, co
return -1;
}

int makeSpeciesGlyphsVisible(SBMLDocument* document, const std::set<std::string>& speciesIds, bool visible) {
int makeSpeciesGlyphsVisible(SBMLDocument* document, const std::set<std::tuple<std::string, std::string, int> >& species, bool visible) {
if (document && document->isSetModel()) {
if (!makeSpeciesGlyphsVisible(document->getModel(), getLayout(document), speciesIds, visible))
if (!makeSpeciesGlyphsVisible(document->getModel(), getLayout(document), species, visible))
return setDefaultLayoutLocations(document, getLayout(document));
}


return -1;
}

int makeSpeciesGlyphsVisible(SBMLDocument* document, unsigned int layoutIndex, const std::set<std::string>& speciesIds, bool visible) {
int makeSpeciesGlyphsVisible(SBMLDocument* document, unsigned int layoutIndex, const std::set<std::tuple<std::string, std::string, int> >& species, bool visible) {
if (document && document->isSetModel()) {
if (!makeSpeciesGlyphsVisible(document->getModel(), getLayout(document, layoutIndex), speciesIds, visible))
if (!makeSpeciesGlyphsVisible(document->getModel(), getLayout(document, layoutIndex), species, visible))
return setDefaultLayoutLocations(document, getLayout(document, layoutIndex));
}

Expand Down
8 changes: 4 additions & 4 deletions src/libsbmlnetwork_sbmldocument_layout.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,18 +167,18 @@ LIBSBMLNETWORK_EXTERN int makeSpeciesGlyphVisible(SBMLDocument* document, unsign

/// @brief Makes the Species Glyph with the given species Id which is a participant of the reaction with the given Id and index in the first Layout object in the ListOfLayouts of the SBML document visible or invisible.
/// @param document a pointer to the SBMLDocument object.
/// @param speciesIds a set of the ids of the Species to hide/show.
/// @param species a set of tuples of the ids of the Species, the id of the Reaction, and the index of the ReactionGlyph object to hide/show the SpeciesGlyph for.
/// @param visible a boolean value to determine whether to make the SpeciesGlyph visible or invisible.
/// @return integer value indicating success/failure of the function.
LIBSBMLNETWORK_EXTERN int makeSpeciesGlyphsVisible(SBMLDocument* document, const std::set<std::string>& speciesIds, bool visible);
LIBSBMLNETWORK_EXTERN int makeSpeciesGlyphsVisible(SBMLDocument* document, const std::set<std::tuple<std::string, std::string, int> >& species, bool visible);

/// @brief Makes the Species Glyph with the given species Id which is a participant of the reaction with the given Id and index in the Layout object with the given index in the ListOfLayouts of the SBML document visible or invisible.
/// @param document a pointer to the SBMLDocument object.
/// @param layoutIndex the index number of the Layout to return.
/// @param speciesIds a set of the ids of the Species to hide/show.
/// @param species a set of tuples of the ids of the Species, the id of the Reaction, and the index of the ReactionGlyph object to hide/show the SpeciesGlyph for.
/// @param visible a boolean value to determine whether to make the SpeciesGlyph visible or invisible.
/// @return integer value indicating success/failure of the function.
LIBSBMLNETWORK_EXTERN int makeSpeciesGlyphsVisible(SBMLDocument* document, unsigned int layoutIndex, const std::set<std::string>& speciesIds, bool visible);
LIBSBMLNETWORK_EXTERN int makeSpeciesGlyphsVisible(SBMLDocument* document, unsigned int layoutIndex, const std::set<std::tuple<std::string, std::string, int> >& species, bool visible);

/// @brief Returns the Dimensions object of the Layout object with the given index in the ListOfLayouts of the SBML document.
/// @param document a pointer to the SBMLDocument object.
Expand Down

0 comments on commit 6371ec6

Please sign in to comment.