aineniamh / snipit

snipit: summarise snps relative to your reference sequence
GNU General Public License v3.0
141 stars 28 forks source link

Error about: "UnboundLocalError: local variable 'top_polygon' referenced before assignment" #8

Closed sbridgett closed 1 year ago

sbridgett commented 3 years ago

A couple of times snipit has failed with the following error:

Traceback (most recent call last):
  File "/mnt/userapps/miniconda3/bin/snipit", line 8, in <module>
    sys.exit(main())
  File "/mnt/userapps/miniconda3/lib/python3.8/site-packages/snipit/command.py", line 72, in main
    sfunks.make_graph(num_seqs,num_snps,record_ambs,record_snps,output,label_map,colours,length,args.width,args.height,args.size_option)
  File "/mnt/userapps/miniconda3/bin/snp_functions.py", line 331, in make_graph
    rect = patches.Rectangle((0,(top_polygon)), length, y_inc ,alpha=0.2, fill=True, edgecolor='none',facecolor="dimgrey")
UnboundLocalError: local variable 'top_polygon' referenced before assignment

I think this occurs when the samples in the multi-fasta input file all have the same SNP's. I can send an example fasta file containing two fasta sequences that produced this error. If this is the reason, then perhaps could just output a "No SNP's found message."

I'm using MAFFT v7.487 with the "linsi" option (eg: "mafft-linsi input_fasta > aligned_fasta"), and using miniconda with conda 4.10.3, and Python 3.8.10, and Snipit version 1.0.3:

$ pip show snipit Name: snipit Version: 1.0.3 Summary: snipit Home-page: https://github.com/aineniamh/snipit etc...

aineniamh commented 3 years ago

Hi @sbridgett, thanks for flagging this! I recently noticed that issue myself, but of course didn't flag it anywhere useful! I had been trying to figure out what would desired behaviour be- a blank plot or just an error message to handle having no SNPs to show.

sbridgett commented 3 years ago

Hi @aineniamh, That's good you've already noticed this too, and that's a good question about what is best way to deal with it - perhaps could do both - print a warning message on stderr, and on the plot could write eg: "No SNP's found" or "No SNP's to show between these samples", then users would know why no SNPs were plotted even if they hadn't checked the message written stderr.

terrycojones commented 2 years ago

I just ran into this too. I think it would be more consistent to produce a blank plot.

Thanks for the code!

aineniamh commented 1 year ago

Fixed now