From b4ed18af1808b4f02369d5a7688e0e38b04de351 Mon Sep 17 00:00:00 2001 From: unknown <david.hoksza@gmail.com> Date: Wed, 30 Oct 2019 12:20:29 +0100 Subject: [PATCH] updated command line parameters; correct naming of output file; updated mrm scripts --- talent/graph_utils.py | 3 ++- talent/layout_merge.py | 2 +- talent/utils/transfer.py | 40 +++++++++++++++++++++++---------- talent_gui.py | 1 + tests/mrm/scripts/report_ins.py | 2 +- tests/mrm/scripts/run_insert.sh | 7 ++++-- 6 files changed, 38 insertions(+), 17 deletions(-) diff --git a/talent/graph_utils.py b/talent/graph_utils.py index 522745a..22102a6 100644 --- a/talent/graph_utils.py +++ b/talent/graph_utils.py @@ -665,7 +665,8 @@ def get_all_reaction_ids(g) -> List[str]: def get_all_species_ids(g, filterFunctions = []) -> List[str]: return get_filtered_nodes(g, {'type': be.TYPE.SPECIES}, filterFunctions) -def get_first_species(g: nx.MultiGraph) -> be.Species: + +def get_first_species(g: nx.MultiGraph) -> 'be.Species': for id in g.nodes(): entity = get_node_data(id, g) if entity.is_species(): diff --git a/talent/layout_merge.py b/talent/layout_merge.py index ab9477a..eed74df 100644 --- a/talent/layout_merge.py +++ b/talent/layout_merge.py @@ -14,7 +14,7 @@ from . import layout as lt from . import settings from . import bioentity as be -import forcelayout as fl +# import forcelayout as fl class CompartmentCCNodeSpecies(NamedTuple): diff --git a/talent/utils/transfer.py b/talent/utils/transfer.py index d1355ad..33197c8 100644 --- a/talent/utils/transfer.py +++ b/talent/utils/transfer.py @@ -152,7 +152,8 @@ def process_db(tmps_path, fmt, split_by_cmprtmnt, ddup, cc_before_ddup) -> List[ cnt_cmprtments += 1 gc = gu.extract_comparment(gu.removeOneComponents(g), cmprtmentName) gc_rg = gu.get_reaction_graph(gc) - tmps += process(gc, gc_rg, ddup, cc_before_ddup, cmprtmentName) + name = "{}-{}".format(common.extract_target_from_fn(fn), cmprtmentName) + tmps += process(gc, gc_rg, ddup, cc_before_ddup, name) else: cnt_cmprtments += 1 g_rg = gu.get_reaction_graph(gu.removeOneComponents(g)) @@ -208,8 +209,11 @@ def load_mapping(name, ged_params, cache_path): return pickle.load(open(file_name, "rb")) if os.path.isfile(file_name) else None -def get_tgt_tmp_name(tgt, tmp): - return "{}--from--{}".format(tgt.get_name(), tmp.get_name()) +def get_tgt_tmp_name(tgt: ReactionGraph or str, tmp: ReactionGraph or str): + tgt_name = tgt.get_name() if isinstance(tgt, ReactionGraph) else tgt + tmp_name = tmp.get_name() if isinstance(tmp, ReactionGraph) else tmp + return "{}--from--{}".format(tgt_name, tmp_name) + def obtain_ed(tgt, tmp, costs, cache_path, ed_settings={}, load_map=True, store_map=True, min_mapped_ratio=0): if (len(tmp.get_reaction_graph())/len(tgt.get_reaction_graph()) < min_mapped_ratio): @@ -333,7 +337,7 @@ def map_transfer_store(tgt:ReactionGraph, tmps: List[ReactionGraph], cache_path: for mtr in mtrs: tmp = mtr.tmp bc = mtr.bc - fname = "{}/{}-tmp_order_{}-tgt-ddup_{}_tmp-ddup_{}.pkl".format(output_path, common.sanitize_string(get_tgt_tmp_name(tgt, tmp)), i, + fname = "{}{}-tmp_order_{}-tgt-ddup_{}_tmp-ddup_{}.pkl".format(output_path, common.sanitize_string(get_tgt_tmp_name(tgt, tmp)), i, tgt.is_ddup(), tmp.is_ddup()) i += 1 rv_fnames.append(fname) @@ -358,10 +362,10 @@ def group_gs_by_compartment(gs: List[nx.MultiGraph]) -> Dict[str, List[nx.MultiG def transfer(tgt_name, tgt_fname, tgt_fmt, split_by_cmprtmnt, tmps_path, tmp_fmt, - output_path, + output_path, separate_cmprtmnt, ddup_tgt=False, ddup_tmp=False, cache_path=None, tgt_sbml_source=None, tmp_cc_before_ddup=True, - separate_cmprtmnt=True): + ): """ :param tgt_name: @@ -399,6 +403,7 @@ def transfer(tgt_name, tgt_fname, tgt_fmt, split_by_cmprtmnt, tmps_path, tmp_fmt # Extract best mapping from each transfer result list g_ress = [mtrs[0].bc.g for mtrs in mtrss] + # tmps_ress = [mtrs[0].tmp for mtrs in mtrss] # Each graph is shifted to the beginning of the coordinate frame because we then need to reposition them relative to each other for g_res in g_ress: @@ -410,11 +415,14 @@ def transfer(tgt_name, tgt_fname, tgt_fmt, split_by_cmprtmnt, tmps_path, tmp_fmt g_tgt_complete: nx.MultiGraph = gu.load_graph(tgt_fname, tgt_fmt) g_res = ltm.merge_compartments(cmp_gs=cmp_gs, g_tgt=g_tgt_complete) bc = BeautificationChain(g_res) - fname = "{}/{}.pkl".format(output_path, "test", i) + + # tmp_name = "".join([tmp_res.get_name() for tmp_res in tmps_ress if tmp_res is not None]) #single-species components do not have a template + tmp_name = "multiple" + fname = "{}{}-tgt-ddup_{}_tmp-ddup_{}.pkl".format(output_path, common.sanitize_string(get_tgt_tmp_name(tgt_name, tmp_name)), ddup_tgt, ddup_tmp) bc.save(fname) - export.export(input_path=fname, format="svg", minerva_instance=settings.minerva_instance, output_path=fname + ".svg") - export.export(input_path=fname, format="celldesigner", minerva_instance=settings.minerva_instance, output_path=fname + ".xml") - export.export(input_path=fname, format="sbgn", minerva_instance=settings.minerva_instance, output_path=fname + ".sbgn") + # export.export(input_path=fname, format="svg", minerva_instance=settings.minerva_instance, output_path=fname + ".svg") + # export.export(input_path=fname, format="celldesigner", minerva_instance=settings.minerva_instance, output_path=fname + ".xml") + # export.export(input_path=fname, format="sbgn", minerva_instance=settings.minerva_instance, output_path=fname + ".sbgn") @@ -482,10 +490,16 @@ if __name__ == '__main__': required=False, type=common.str2bool, default=True) + parser.add_argument("-sep-cmp", "--separate-compartments", + required=False, + type=common.str2bool, + help="The target is split by compartments into multiple connected components, each of which is laid out separately, possibly using different templates, and the result is then assembled into a single resulting layout", + default = True) parser.add_argument("-split-cmp", "--split-by-compartments", required=False, type=common.str2bool, - default=True) + help="Splits target into compartments and each of them having a separate layout (this option is not considered if --sep-cmp=True)", + default=False) parser.add_argument("-tmp-split-by-cc-before-ddup", "--tmp-split-by-cc-before-ddup", required=False, type=common.str2bool, @@ -508,5 +522,7 @@ if __name__ == '__main__': tgt_name=name, tgt_fname=args.target, tgt_fmt=args.target_format, ddup_tgt=args.ddup_tgt, tmps_path=args.template_path, tmp_fmt=args.template_format, ddup_tmp=args.ddup_tmp, output_path=args.output, - split_by_cmprtmnt=args.split_by_compartments, tmp_cc_before_ddup=args.tmp_split_by_cc_before_ddup, + separate_cmprtmnt=args.separate_compartments, + split_by_cmprtmnt=args.split_by_compartments, + tmp_cc_before_ddup=args.tmp_split_by_cc_before_ddup, cache_path=args.cache) \ No newline at end of file diff --git a/talent_gui.py b/talent_gui.py index 14245a0..fd1c207 100644 --- a/talent_gui.py +++ b/talent_gui.py @@ -262,6 +262,7 @@ class InputWidget(QGroupBox): transfer.transfer(tgt_name="{}".format(tgt_name), tgt_fname=tgt_path, tgt_fmt=tgt_type, tmps_path=tmp_path, tmp_fmt=tmp_type, output_path=output_path, + separate_cmprtmnt=True, split_by_cmprtmnt=False, ddup_tgt=False, ddup_tmp=False, cache_path=None, tmp_cc_before_ddup=False) diff --git a/tests/mrm/scripts/report_ins.py b/tests/mrm/scripts/report_ins.py index b9f7437..b78d770 100644 --- a/tests/mrm/scripts/report_ins.py +++ b/tests/mrm/scripts/report_ins.py @@ -17,7 +17,7 @@ def main(dir_name: str): for f_path in glob.glob("{}/*.svg".format(dir_name)): f_name = os.path.basename(f_path) - tmp_name = re.match(r'.*from--(.*)-c.*', f_name).group(1) + tmp_name = re.match(r'.*---(.*)---.*', f_name).group(1) tmp_path = "{}/{}.svg".format(tmptgt_path, tmp_name) f.write('<div class="group">' '<div class="group-header">{}</div>' diff --git a/tests/mrm/scripts/run_insert.sh b/tests/mrm/scripts/run_insert.sh index 8b95d84..95c42c0 100644 --- a/tests/mrm/scripts/run_insert.sh +++ b/tests/mrm/scripts/run_insert.sh @@ -19,14 +19,17 @@ for dir in `ls -d ${TEST_ROOT}/sbml/*`; do for template_path in `ls -1 ${dir}/${target}_*`; do template=${template_path##*/} + template=${template/.sbml/} echo "Laying out target " $target "against template " $template - echo ${PYTHON} ${TALENT_UTILS}/transfer.py -tgt ${target_path} -tmp ${template_path} -o ${out_dir} -ddup-tmp false -ddup-tgt false -s settings_insert.json -cache cache - ${PYTHON} ${TALENT_UTILS}/transfer.py -tgt ${target_path} -tmp ${template_path} -o ${out_dir} -ddup-tmp false -ddup-tgt false -s settings_insert.json -cache cache + echo ${PYTHON} ${TALENT_UTILS}/transfer.py -tgt ${target_path} -tmp ${template_path} -o ${out_dir}${target}---${template}--- -ddup-tmp false -ddup-tgt false -s settings_insert.json -cache cache + ${PYTHON} ${TALENT_UTILS}/transfer.py -tgt ${target_path} -tmp ${template_path} -o ${out_dir}/${target}---${template}--- -ddup-tmp false -ddup-tgt false -s settings_insert.json -cache cache # ${PYTHON} ${TALENT_UTILS}/transfer.py -tgt ${target_path} -tmp ${template_path} -o ${out_dir} -ddup-tmp true -ddup-tgt true -s settings_insert.json -cache cache done for pkl in `ls -1 ${out_dir}/*.pkl`; do echo "Exporting " $pkl + echo "${PYTHON} ${TALENT_UTILS}/export.py -i $pkl -f svg > ${pkl}.svg" + ${PYTHON} ${TALENT_UTILS}/export.py -i $pkl -f svg > ${pkl}.svg done -- GitLab