diff --git a/casq/celldesigner2qual.py b/casq/celldesigner2qual.py index 6caad2c0aa63133825ca1c4bbca6b924d91c56a8..c537a4996dcbf7e9151cf0ef42d721f4f646977f 100755 --- a/casq/celldesigner2qual.py +++ b/casq/celldesigner2qual.py @@ -83,6 +83,12 @@ def main(): help="""A CSV file containing input values or knock-ins/knock-outs, one per line, with name in the first column and the value in the second.""" ) + parser.add_argument( + "-n", + "--names", + action="store_true", + help="Use the names as IDs in the SBML file", + ) if sys.version_info >= (3, 8, 0): parser.add_argument( "-u", @@ -161,7 +167,7 @@ def main(): logger.disable("casq") logger.debug("parsing {fname}…", fname=args.infile.name) info, width, height = read_celldesigner(args.infile) - simplify_model(info, args.upstream, args.downstream) + simplify_model(info, args.upstream, args.downstream, args.names) if args.infile != sys.stdin and args.outfile == sys.stdout: args.outfile = os.path.splitext(args.infile.name)[0] + ".sbml" if args.bma: diff --git a/casq/simplify.py b/casq/simplify.py index 8287ba78b8c9f185155027b1a20c581c0b1fa67c..147f5072cde09122cc7d886b0df4bd4a49432e3e 100644 --- a/casq/simplify.py +++ b/casq/simplify.py @@ -26,7 +26,7 @@ import networkx as nx # type: ignore from .readCD import Transition, add_rdf -def simplify_model(info, upstream, downstream): +def simplify_model(info, upstream, downstream, names_as_ids: bool = False): """Clean the model w.r.t. some active/inactive species.""" multispecies = delete_complexes_and_store_multispecies(info) # pylint: disable=too-many-nested-blocks @@ -67,6 +67,8 @@ def simplify_model(info, upstream, downstream): ) del info[val] fix_all_names(info) + if names_as_ids: + use_names_as_ids(info) restrict_model(info, upstream, downstream) handle_phenotypes(info) @@ -290,9 +292,12 @@ def fix_all_names(info): info[other_id]["name"] = name + "_active" info[other_id]["function"] = name + "_active" else: - # FIXME don't know what to do - # print(f"active is {activity}, other was {other_activity}") - pass + newname = name + tag = 0 + while newname in namedict: + tag += 1 + newname = name + "_" + str(tag) + name = newname namedict[name] = (species, activity) data["name"] = name data["function"] = name @@ -313,3 +318,14 @@ def fix_name(name: str, ambiguous: bool, compartment: str): .replace("_super", "^") .replace("_slash_", "/") ) + + +def use_names_as_ids(info): + """Replace all ids with names.""" + newinfo = {} + for data in info.values(): + name = data["name"].replace(" ", "_") + name = ''.join(c for c in name if c.isalnum() or c == "_") + newinfo[name] = data + info.clear() + info.update(newinfo)