Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UnboundLocalError: local variable 'res' referenced before assignment #30

Open
hyBio opened this issue Sep 6, 2023 · 0 comments
Open

Comments

@hyBio
Copy link

hyBio commented Sep 6, 2023

hello, when I am using the --plot parameter, I get the following error, without the --plot parameter it works fine.(cmd:"singularity exec ./pcoc_latest.sif pcoc_det.py -t /data/SG.tree.nwk -aa /data/AA/OG0010882.aligned-gb.sorted.fa -o /data/pcoc_test -m "6,2,3,4,5/9/37,33,34,35,36" -f 0.95 --plot_complete_ali --plot")

2023-09-06 13:35:14,105 - INFO - 1 on 144 cpus
2023-09-06 13:35:14,114 - INFO - Profile category uses during estimation:	10	C10
2023-09-06 13:35:14,114 - INFO - Alignment: /data/AA/OG0010882.aligned-gb.sorted.fa
2023-09-06 13:35:14,174 - INFO - Alignment: 23 seqs 2837 sites
2023-09-06 13:35:14,174 - INFO - Alphabet usage:
A(5.04%), C(1.98%), E(7.26%), D(5.23%), G(4.61%), F(5.77%), I(6.20%), H(1.88%), K(5.75%), -(2.14%), M(3.53%), L(10.18%), N(2.55%), Q(4.00%), P(3.57%), S(8.06%), R(4.78%), T(4.99%), W(2.08%), V(6.57%), Y(3.85%)
2023-09-06 13:35:14,174 - INFO - alignment ok after checking
2023-09-06 13:35:14,175 - INFO - tree: /data/SG.tree.nwk
2023-09-06 13:35:14,177 - INFO - tree ok after checking
2023-09-06 13:35:14,178 - INFO - Sequence and leaf names match.
2023-09-06 13:36:22,719 - INFO - PCOC_V1 model: # filtered position: 28/2837
2023-09-06 13:36:22,743 - INFO - PC_V1 model: # filtered position: 0/2837
2023-09-06 13:36:22,767 - INFO - OC_V1 model: # filtered position: 43/2837
2023-09-06 13:36:22,790 - INFO - UNION model: # filtered position: 43/2837
Traceback (most recent call last):
  File "/usr/local/bin/pcoc_det.py", line 703, in <module>
    mk_detect(tree_filename, ali_basename, OutDirName)
  File "/usr/local/bin/pcoc_det.py", line 644, in mk_detect
    plot_data.make_tree_ali_detect_combi(g_tree, g_tree.repseq + "/" + ali_basename, prefix_out+"_plot_complete.pdf", dict_benchmark=dict_values_pcoc, hp=positions_to_highlight, title = args.plot_title)
  File "/usr/local/bin/plot_data.py", line 670, in make_tree_ali_detect_combi
    res = t.render(Out, tree_style=phylotree_style)
  File "/usr/local/lib/python2.7/dist-packages/ete3/coretype/tree.py", line 1362, in render
    units=units, dpi=dpi)
  File "/usr/local/lib/python2.7/dist-packages/ete3/treeview/drawer.py", line 104, in render_tree
    tree_item, n2i, n2f = render(t, img)
  File "/usr/local/lib/python2.7/dist-packages/ete3/treeview/qt4_render.py", line 321, in render
    aligned_region_width = render_aligned_faces(img, mainRect, parent.tree_layer, n2i, n2f)
  File "/usr/local/lib/python2.7/dist-packages/ete3/treeview/qt4_render.py", line 823, in render_aligned_faces
    fb_head = _FaceGroupItem(img.aligned_header, None)
  File "/usr/local/lib/python2.7/dist-packages/ete3/treeview/qt4_face_render.py", line 104, in __init__
    self.update_columns_size()
  File "/usr/local/lib/python2.7/dist-packages/ete3/treeview/qt4_face_render.py", line 142, in update_columns_size
    f.update_items()
  File "/usr/local/bin/plot_data.py", line 376, in update_items
    col_width=self.col_w)
  File "/usr/local/bin/plot_data.py", line 253, in draw_fun
    color = get_corr_color(val)
  File "/usr/local/bin/plot_data.py", line 391, in get_corr_color
    return(res)
UnboundLocalError: local variable 'res' referenced before assignment

I looked at line 391 of the plot_data.py script and found that if the score variable if it does not satisfy the judgment condition, it returns an empty res, causing an UnboundLocalError. Could you please take the time to help out with this, even though you may not be working on this project anymore. Deeply tks.

def get_corr_color(x):
    score = [1,0.99,0.9,0.8,0.7,0.5, 0.3, 0.1, 0]
    color = ["red", "red",  "orange", "#EFDB00", "#6BAC00","#008000", "#7174D0", "#800080", "#A3A3A3"]
    score = [1,0.99,0.9,0.8,0.7, 0.6, 0.5, 0.4, 0.3, 0.2, 0.1, 0]
    color = ["#9E0142","#9E0142","#D53E4F","#F46D43","#FDAE61","#FEE08B","#E6F598","#ABDDA4","#66C2A5","#3288BD","#5E4FA2","#A3A3A3"]

    for i in range(len(score)):
        if x >= score[i]:
            res = color[i]
            break
    return(res)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant