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

Support for xrefs in model_infos command

export of xrefs in csv and json formats
parent bcebc4a2
......@@ -1110,15 +1110,26 @@ def model_infos(model_file, output_dir='./',
def dump_places_to_csv(places, output_filename):
"""Write informations about places in the model to a csv."""
with open(output_filename, 'w') as csvfile:
# Get all database names
database_names = {db_name for place in places for db_name in place.get('xrefs', dict()).iterkeys()}
# Write headers
fieldnames = ("cadbiom_name", "names", "uri", "entityType",
"entityRef", "location")
writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
"entityRef", "location") + tuple(database_names)
writer = csv.DictWriter(
csvfile,
fieldnames=fieldnames,
extrasaction='ignore', # Ignore keys not found in fieldnames (xrefs)
)
writer.writeheader()
for place in places:
# Join names with a pipe...
place['names'] = "|".join(place.get('names', list()))
# Join xref ids with a pipe...
for db_name, db_ids in place.get('xrefs', dict()).iteritems():
place[db_name] = "|".join(db_ids)
writer.writerow(place)
......
......@@ -264,6 +264,7 @@ def get_places_data(places, model):
"modificationFeatures": dict(entity.modificationFeatures),
"members": list(entity.members),
"reactions": [reaction.uri for reaction in entity.reactions],
"xrefs": entity.xrefs,
}
:param arg1: Iterable of name of places.
......@@ -280,6 +281,7 @@ def get_places_data(places, model):
- entityRef
- location
- names
- xrefs
:rtype: <list <dict>>
"""
......@@ -291,6 +293,7 @@ def get_places_data(places, model):
"entityRef": '',
"location": '',
"names": list(), # Default type is 'list' for names (not '')
"xrefs": dict(),
}
# Init final dictionary
data = list()
......
Supports Markdown
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