You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello,
I have tried both python 3.4 and 3.7 with all of the dependencies loaded (using conda environments), but I keep getting this error in presplit_map.py:
with open_handle(init_split) as splitted, \
^
SyntaxError: invalid syntax
I tried combining this command into a single line, but still got an error. Is there a work-around for this? Or a specific version of python 3 that I need to be using? I have tried both 3.4 and 3.7.
That should be valid python. Running python3 -m py_compile ./presplit_map.py yields no syntax errors for me (Python 3.7.3, also on Python 2.7.10).
This small example works for me - make up any file and call it thing1.txt, and do the same with a gzip-compressed file to make thing2.txt.gz:
importreimportgzipis_gz=re.compile("\\.gz$")
defopen_handle(fname, write=False):
"""A function that returns a Gzip file handle or a normal file handle, depending on the file name."""if (is_gz.search(fname)):
ifwrite:
mode='wt'else:
mode='rt'returngzip.open(fname, mode)
else:
ifwrite:
mode='w'else:
mode='rU'returnopen(fname, mode)
my_file="thing1.txt"my_file2="thing2.txt.gz"withopen_handle(my_file) asf, \
open_handle(my_file2) asg:
print(f)
print(g)
Thank you for your response. I made a simple text file, thing1.txt with vim, copied and gzipped it to create thing2.txt.
The output I get when I run this script is:
When I try adding -m py_compile to run the test script you provided, as you mentioned above, it throws no error but also prints nothing.
When I try to run the code interactively with python, I get an error after the last "with" statement:
>>> with open_handle(my_file) as f, \
... open_handle(my_file2) as g:
... print(f)
... print(g)
...
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
AttributeError: __exit__
When I google this error, it seems as though "with" requires an enter and exit method and complains if it doesn't find one.
Am I running presplit_map.py incorrectly? I ran this 2 years ago on python2 with no issue with the following command:
python /home/hwick/top2b/master/interaction/scripts/presplit_map.py -G /home/reference/Human/hg19/bowtie2index/hg19 -1 $R1fastq -2 $R2fastq --sig AAGCTAGCTT -o $presplitbam= --cmd bowtie2 --cut cutadapt
If I add -m py_compile to run presplit_map.py, it tries to use python 2.6:
Traceback (most recent call last):
File "/usr/lib64/python2.6/runpy.py", line 122, in _run_module_as_main
"__main__", fname, loader, pkg_name)
File "/usr/lib64/python2.6/runpy.py", line 34, in _run_code
exec code in run_globals
File "/usr/lib64/python2.6/py_compile.py", line 168, in <module>
sys.exit(main())
File "/usr/lib64/python2.6/py_compile.py", line 160, in main
compile(filename, doraise=True)
File "/usr/lib64/python2.6/py_compile.py", line 115, in compile
f = open(file, 'U')
IOError: [Errno 2] No such file or directory: '-G'
removing -G does not solve the issue, it then claims my reference doesn't exist (it does)
The io.TextIOWrapper output is correct. The script prints the file handles, not the file contents.
Compiling won't print anything if there are no syntax errors.
Interactively running the script won't work as the open_handle function has a newline in its definition. This means that it can't be properly defined by copy-pasting.
Just force the use of Python 3 to compile presplit_map.py. This causes no problems:
Activity
LTLA commentedon Apr 5, 2019
That should be valid python. Running
python3 -m py_compile ./presplit_map.pyyields no syntax errors for me (Python 3.7.3, also on Python 2.7.10).This small example works for me - make up any file and call it
thing1.txt, and do the same with a gzip-compressed file to makething2.txt.gz:hwick commentedon Apr 5, 2019
Thank you for your response. I made a simple text file, thing1.txt with vim, copied and gzipped it to create thing2.txt.
The output I get when I run this script is:
Which is not what is in the files.
When I try adding -m py_compile to run the test script you provided, as you mentioned above, it throws no error but also prints nothing.
When I try to run the code interactively with python, I get an error after the last "with" statement:
When I google this error, it seems as though "with" requires an enter and exit method and complains if it doesn't find one.
Am I running presplit_map.py incorrectly? I ran this 2 years ago on python2 with no issue with the following command:
python /home/hwick/top2b/master/interaction/scripts/presplit_map.py -G /home/reference/Human/hg19/bowtie2index/hg19 -1 $R1fastq -2 $R2fastq --sig AAGCTAGCTT -o $presplitbam= --cmd bowtie2 --cut cutadapt
If I add -m py_compile to run presplit_map.py, it tries to use python 2.6:
removing -G does not solve the issue, it then claims my reference doesn't exist (it does)
I'm left scratching my head.
LTLA commentedon Apr 5, 2019
io.TextIOWrapperoutput is correct. The script prints the file handles, not the file contents.open_handlefunction has a newline in its definition. This means that it can't be properly defined by copy-pasting.presplit_map.py. This causes no problems: