morrislab / metient

5 stars 1 forks source link

Graphviz error #2

Open willhooper opened 2 months ago

willhooper commented 2 months ago

Hi,

Thank you for developing this useful package! I'm running into an error when I run met.evaluate_label_clone_tree when setting visualize=True in the print config. When I set it to false and paste the output into an online graphviz renderer, I see a similar error re: line 3.

Warning: syntax ambiguity - badly delimited number '12p' in line 3 of input splits into two tokens
Error: syntax error in line 3 near ','
Traceback (most recent call last):
  File "/gpfs/commons/home/whooper/micromamba/envs/metient/lib/python3.8/site-packages/pygraphviz/agraph.py", line 1237, in read
    self.handle = gv.agread(fh, None)
  File "/gpfs/commons/home/whooper/micromamba/envs/metient/lib/python3.8/site-packages/pygraphviz/graphviz.py", line 85, in agread
    return _graphviz.agread(file, arg2)
ValueError: agread: bad input data

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/gpfs/commons/home/whooper/scripts/nepc/pm63-revisions/metient/run-metient.py", line 35, in <module>
    main()
  File "/gpfs/commons/home/whooper/scripts/nepc/pm63-revisions/metient/run-metient.py", line 25, in main
    met.evaluate_label_clone_tree(args.tree,
  File "/gpfs/commons/home/whooper/micromamba/envs/metient/lib/python3.8/site-packages/metient/metient.py", line 56, in evaluate_label_clone_tree
    return mig_hist.evaluate_label_clone_tree(tree_fn, tsv_fn, weights, print_config, output_dir, run_name, O=O, sample_size=sample_size,
  File "/gpfs/commons/home/whooper/micromamba/envs/metient/lib/python3.8/site-packages/metient/lib/migration_history_inference.py", line 164, in evaluate_label_clone_tree
    return evaluate(tree_fn, tsv_fn, weights, print_config, output_dir, run_name,
  File "/gpfs/commons/home/whooper/micromamba/envs/metient/lib/python3.8/site-packages/metient/lib/migration_history_inference.py", line 181, in evaluate
    infer_migration_history(T, pooled_tsv_fn, primary_site, weights, print_config, output_dir, f"{run_name}_{primary_site}",
  File "/gpfs/commons/home/whooper/micromamba/envs/metient/lib/python3.8/site-packages/metient/lib/migration_history_inference.py", line 443, in infer_migration_history
    edges, vert_to_site_map, mig_graph_edges, loss_info = putil.save_best_trees(final_solutions, U, O, weights,
  File "/gpfs/commons/home/whooper/micromamba/envs/metient/lib/python3.8/site-packages/metient/util/plotting_util.py", line 717, in save_best_trees
    save_outputs(figure_outputs, print_config, output_dir, run_name, pickle_outputs, weights)
  File "/gpfs/commons/home/whooper/micromamba/envs/metient/lib/python3.8/site-packages/metient/util/plotting_util.py", line 772, in save_outputs
    tree = pgv.AGraph(string=tree_dot).draw(format="png", prog="dot", args="-Glabel=\"\"")
  File "/gpfs/commons/home/whooper/micromamba/envs/metient/lib/python3.8/site-packages/pygraphviz/agraph.py", line 167, in __init__
    self.from_string(string)
  File "/gpfs/commons/home/whooper/micromamba/envs/metient/lib/python3.8/site-packages/pygraphviz/agraph.py", line 1317, in from_string
    self.read(fh)
  File "/gpfs/commons/home/whooper/micromamba/envs/metient/lib/python3.8/site-packages/pygraphviz/agraph.py", line 1239, in read
    raise DotError("Invalid Input")
pygraphviz.agraph.DotError: Invalid Input
divyakoyy commented 1 month ago

Hi Will,

I have a suspicion that this is an issue within graphviz since it can't handle some input characters in node labels (i.e., what is passed into the character_label columns of the input tsv). If you make the character_label columns something simple, like the character_index, does this problem go away? If that doesn't help, can you upload the input tsv you're using for me to diagnose further?

Best,

Divya

willhooper commented 1 month ago

Hi Divya,

Thanks for the quick response! I looked into this a little more closely, and it seems like the issue is the fontsize field in the node attributes. Either quoting the value, e.g. fontsize="12pt", or switching to fontsize=12 fixes the issue when using graphviz on the command line.

Best, Will

divyakoyy commented 1 month ago

Hi Will,

Glad to hear it's working, but still not sure what the problem is - the generated .dot files I have contain fontsize="12pt". Do the .dot files you have look different?

Thanks for the help!

Best,

Divya

willhooper commented 1 month ago

Yes, here's a sample line:

0 [xlabel=clone0, fillcolor="#6aa84fff", color="#6aa84fff", style=filled, label="", shape=circle, penwidth=3, fontname=Arial, fontsize=12pt, fixedsize=true, height=0.25];
divyakoyy commented 1 month ago

Thanks so much. Unfortunately I can't reproduce this on any machine, but I pushed a potential fix to this. If you could pip install --upgrade metient and see if this works for you, that would be awesome.

If the above doesn't work, my other suspicion is that there's something wrong with the graphviz version you're using - if so, with your conda environment activated, could you let me know what you graphvuz verison is (run dot -V on command line)?

Thanks!