Commit f999dcbb authored by VIGNET Pierre's avatar VIGNET Pierre
Browse files

[model_info] Ability to extract smallmolecules; json files carry the type of...

[model_info] Ability to extract smallmolecules; json files carry the type of entities queried; fix typos
parent c2f7d9d1
......@@ -509,6 +509,8 @@ def main():
help="Retrieve data only for the frontier places/boundaries of the model.")
group.add_argument('--genes', action='store_true',
help="Retrieve data only for the genes in the model.")
group.add_argument('--smallmolecules', action='store_true',
help="Retrieve data only for the smallmolecules in the model.")
# Outputs
parser_model_info.add_argument('--csv', action='store_true',
help="Create a CSV file containing data about previously filtered "
......
......@@ -447,22 +447,25 @@ def low_graph_info(model_file, centralities):
def low_model_info(model_file,
all_entities=False, boundaries=False, genes=False):
all_entities=False, boundaries=False, genes=False, smallmolecules=False):
"""Low level function for :meth:`~cadbiom_cmd.solution_repr.model_info`.
Get JSON data with information about the model and its entities.
:param arg1: File for the model.
:param arg2: If True, data for all places of the model are returned
:param model_file: File for the model.
:key all_entities: If True, data for all places of the model are returned
(optional).
:param arg3: If True, only data for the frontier places of the model
:key boundaries: If True, only data for the frontier places of the model
are returned (optional).
:param arg4: If True, only data for the genes of the model are returned
:key genes: If True, only data for the genes of the model are returned
(optional).
:type arg1: <str>
:type arg2: <boolean>
:type arg3: <boolean>
:type arg4: <boolean>
:key smallmolecules: If True, only data for the smallmolecules of the model
are returned (optional).
:type model_file: <str>
:type all_entities: <boolean>
:type boundaries: <boolean>
:type genes: <boolean>
:type smallmolecules: <boolean>
:return: Dictionary with informations about the model and the queried nodes.
:Example:
......@@ -538,7 +541,7 @@ def low_model_info(model_file,
# from cadbiom_gui.gt_gui.utils.reporter import CompilReporter
static_analyser = StaticAnalyzer(Reporter())
static_analyser.build_from_chart_model(model)
info['entitiesLocations'], info['entitesTypes'] = \
info['entitiesLocations'], info['entitiesTypes'] = \
static_analyser.get_stats_entities_data()
# Filter places
......@@ -552,6 +555,12 @@ def low_model_info(model_file,
g = (place_name for place_name in all_places_1 if '_gene' in place_name)
info['entitiesData'] = get_places_data(g, model)
if smallmolecules:
# Filter on entityTypes
info['entitiesData'] = \
[data for data in get_places_data(all_places_1, model)
if data["entityType"] == "SmallMolecule"]
return info
......@@ -641,28 +650,31 @@ def model_graph(model_file, output_dir='./graphs/',
def model_info(model_file, output_dir='./',
all_entities=False, boundaries=False,
genes=False, default=True, **kwargs):
genes=False, smallmolecules=False, default=True, **kwargs):
"""Get quick and full informations about the model structure and places.
:param model_file: File for the '.bcx' model.
:param output_dir: Output directory.
:param all_entities: If True, data for all places of the model are returned
:key output_dir: Output directory.
:key all_entities: If True, data for all places of the model are returned
(optional).
:param boundaries: If True, only data for the frontier places of the model
:key boundaries: If True, only data for the frontier places of the model
are returned (optional).
:param genes: If True, only data for the genes of the model are returned
:key genes: If True, only data for the genes of the model are returned
(optional).
:param default: Display quick description of the model
:key smallmolecules: If True, only data for the smallmolecules of the model
are returned (optional).
:key default: Display quick description of the model
(Number of places, transitions, entities types, entities locations).
:keyword json: If True, make a JSON dump of results in output path(optional).
:keyword csv: If True, make a csv dump of informations about filtered places.
:key json: If True, make a JSON dump of results in output path(optional).
:key csv: If True, make a csv dump of informations about filtered places.
:type model_file: <str>
:type output_dir: <str>
:type all_entities: <boolean>
:type boundaries: <boolean>
:type genes: <boolean>
:type smallmolecules: <boolean>
:type default: <boolean>
:type json: <boolean>
:type csv: <boolean>
......@@ -704,14 +716,16 @@ def model_info(model_file, output_dir='./',
writer.writerow(temp_place)
def get_csv_filename():
"""Return the csv filename according to the given filters."""
def get_output_filename(filetype="csv"):
"""Return the filename according to the given filters and filetype."""
if all_entities:
return output_dir + "all_entities.csv"
return "all_entities." + filetype
if boundaries:
return output_dir + "boundaries.csv"
return "boundaries." + filetype
if genes:
return output_dir + "genes.csv"
return "genes." + filetype
if smallmolecules:
return "smallmolecules." + filetype
if default:
......@@ -724,16 +738,16 @@ def model_info(model_file, output_dir='./',
model_info = low_model_info(
model_file,
all_entities, boundaries, genes
all_entities, boundaries, genes, smallmolecules
)
# Export to csv file
if make_csv:
dump_places_to_csv(model_info['entitiesData'], get_csv_filename())
dump_places_to_csv(model_info['entitiesData'], output_dir + get_output_filename())
# Export to json file
if make_json:
with open(output_dir + "model_summary.json", 'w') as f_d:
with open(output_dir + "model_summary_" + get_output_filename("json"), 'w') as f_d:
# Handle escaped unicode characters in model
# Ex: \u03b2-catenin => β-Catenin
f_d.write(
......
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