PoonLab / covizu

Rapid analysis and visualization of coronavirus genome variation
https://filogeneti.ca/CoVizu/
MIT License
46 stars 20 forks source link

Circular import in gisaid_utils.py #388

Closed ArtPoon closed 2 years ago

ArtPoon commented 2 years ago
art@Wernstrom covizu % python3 covizu/utils/gisaid_utils.py -h
Traceback (most recent call last):
  File "/Users/art/git/covizu/covizu/utils/gisaid_utils.py", line 12, in <module>
    from covizu.minimap2 import minimap2, encode_diffs
  File "/usr/local/lib/python3.9/site-packages/covizu-0.3-py3.9.egg/covizu/minimap2.py", line 9, in <module>
    from covizu.utils import gisaid_utils
  File "/usr/local/lib/python3.9/site-packages/covizu-0.3-py3.9.egg/covizu/utils/gisaid_utils.py", line 12, in <module>
    from covizu.minimap2 import minimap2, encode_diffs
ImportError: cannot import name 'minimap2' from partially initialized module 'covizu.minimap2' (most likely due to a circular import) (/usr/local/lib/python3.9/site-packages/covizu-0.3-py3.9.egg/covizu/minimap2.py)
ArtPoon commented 2 years ago

Patched this with the following:

diff --git a/covizu/minimap2.py b/covizu/minimap2.py
index 9219eba..0034cc9 100644
--- a/covizu/minimap2.py
+++ b/covizu/minimap2.py
@@ -7,6 +7,7 @@ import json

 import covizu
 from covizu.utils import gisaid_utils
+#from covizu.utils.gisaid_utils import filter_problematic

 def apply_cigar(seq, rpos, cigar):
diff --git a/covizu/utils/gisaid_utils.py b/covizu/utils/gisaid_utils.py
index 5651b55..7c0b4fd 100644
--- a/covizu/utils/gisaid_utils.py
+++ b/covizu/utils/gisaid_utils.py
@@ -9,7 +9,8 @@ from datetime import datetime
 import getpass

 import covizu
-from covizu.minimap2 import minimap2, encode_diffs
+from covizu import minimap2
+#from covizu.minimap2 import minimap2, encode_diffs
 from covizu.utils.seq_utils import *
 from covizu.utils.progress_utils import Callback

@@ -132,9 +133,9 @@ def extract_features(batcher, ref_file, binpath='minimap2', nthread=3, minlen=29
         reflen = len(convert_fasta(handle)[0][1])

     for fasta, batch in batcher:
-        mm2 = minimap2(fasta, ref_file, stream=True, path=binpath, nthread=nthread,
+        mm2 = minimap2.minimap2(fasta, ref_file, stream=True, path=binpath, nthread=nthread,
                        minlen=minlen)
-        result = list(encode_diffs(mm2, reflen=reflen))
+        result = list(minimap2.encode_diffs(mm2, reflen=reflen))
         for row, record in zip(result, batch):
             # reconcile minimap2 output with GISAID record
             qname, diffs, missing = row
ArtPoon commented 2 years ago

Unit test suite should have caught this. We need to make sure this gets run with every PR. Also need to incorporate the above patch into dev.

ArtPoon commented 2 years ago

Close, deal with this when we work on #389