mgalardini / pyseer

SEER, reimplemented in python 🐍🔮
http://pyseer.readthedocs.io
Apache License 2.0
109 stars 27 forks source link

UnboundLocalError: local variable 'lineage_clusters_full' referenced before assignment #160

Closed jpaganini closed 3 years ago

jpaganini commented 3 years ago

Hi guys,

I'm experiencing an issue for running the whole genome prediction model, only when using the --lineage-clusters option. I'm runnning the following code:

pyseer --kmers ../../2021_06_08_unitig_calling/results/test_pyseer.txt.gz --phenotypes ../data/test.pheno --wg enet --save-vars ../results/test_unitigs --save-model ../results/test_ecoli --lineage-clusters ../data/lineages.txt --cpu 4 --alpha 1 > ../results/test_unitigs.txt

The error obtained is as follows:

/home/dla_mm/jpaganini/data/miniconda3/envs/pyseer_mmbioit/lib/python3.9/site-packages/pyseer/__main__.py

Traceback (most recent call last):
  File "/home/dla_mm/jpaganini/data/miniconda3/envs/pyseer_mmbioit/bin/pyseer", line 10, in <module>
    sys.exit(main())
  File "/home/dla_mm/jpaganini/data/miniconda3/envs/pyseer_mmbioit/lib/python3.9/site-packages/pyseer/__main__.py", line 637, in main
    clus_totals = np.sum(lineage_clusters_full, axis=0)
UnboundLocalError: local variable 'lineage_clusters_full' referenced before assignment

I "fixed" the error by adding the following code at line 135 of pyseer/main.py : lineage_clusters_full=lineage_clusters

However, I'm not entirely sure that this is the correct solution.

I hope this info helps!

Cheers,

mgalardini commented 3 years ago

Thanks for reporting this issue! I think you should add --lineage to your command line to resolve the issue. We should check for its presence when the software starts so that it does not happen.

Can you try and let me know if that resolves the issue? Thanks!

jpaganini commented 3 years ago

Hi Marco,

Thanks for your prompt reply. I tried using the --lineage option as well. Find below the output. command: pyseer --kmers ../../2021_06_08_unitig_calling/results/test_pyseer.txt.gz --phenotypes ../data/test.pheno --wg enet --save-vars ../results/test_unitigs --save-model ../results/test_ecoli --lineage --lineage-clusters ../data/lineages.txt --cpu 4 --alpha 1 > ../results/test_unitigs.txt output: Using sequence reweighting requires clusters to weight with. Provide these with --lineage-clusters. Incompatible with --lineage.

johnlees commented 3 years ago

Looking through the code I think we've got the logic wrong at some point. I believe these lines: https://github.com/mgalardini/pyseer/blob/master/pyseer/__main__.py#L408-L409 Should be in the preceding if options.lineage_clusters block, not the if options.lineage block.

Also, I don't think we have a test for this case, so should add one.

johnlees commented 3 years ago

(I will make a fix for this now)

jpaganini commented 3 years ago

Hey guys,

Thanks for taking a look at this so quickly. I'll give a try to the new version soon.

Cheers,