Note that there are some explanatory texts on larger screens.

plurals
  1. POGzip problem,traceback and IOError: [Errno 2] No such file or directory
    primarykey
    data
    text
    <p>I'm new to python and bioinformatics field. I'm using python-2.6. Now I'm trying to select all fastq.gz files, then gzip.open(just a few lines because it's too huge and time-wasting), then count 'J' , then pick out those files with 'J' count NOT equal to 0.</p> <p>The following is my code:</p> <pre><code>#!/usr/bin/python import os,sys,re,gzip path = "/home/XXX/nearline" for file in os.listdir(path): if re.match('.*\.recal.fastq.gz', file): text = gzip.open(file,'r').readlines()[:10] word_list = text.split() number = word_list.count('J') + 1 if number !== 0: print file </code></pre> <p>But I got some errors:</p> <pre><code>Traceback (most recent call last): File "fastqfilter.py", line 9, in &lt;module&gt; text = gzip.open(file,'r').readlines()[:10] File "/share/lib/python2.6/gzip.py", line 33, in open return GzipFile(filename, mode, compresslevel) File "/share/lib/python2.6/gzip.py", line 79, in __init__ fileobj = self.myfileobj = __builtin__.open(filename, mode or 'rb') IOError: [Errno 2] No such file or directory: 'ERR001268_1.recal.fastq.gz' </code></pre> <p>What's this traceback: File...... Is there anything wrong with gzip here? And why can't it find ERR001268_1.recal.fastq.gz? It's the first fastq file in the list, and DOES exist there.</p> <p>Hope give me some clues, and any point out any other errors in the script.</p> <p>THanks a lot.</p> <p>Edit: thx everyone. I followed Dan's suggestion. And I tried on ONE fastq file first. My script goes like:</p> <pre><code>#!/usr/bin/python import os,sys import gzip import itertools file = gzip.open('/home/xug/nearline/ERR001274_1.recal.fastq.gz','r') list(itertools.islice(file.xreadlines(),10)) word_list = list.split() number = word_list.count('J') + 1 if number != 0: print 'ERR001274_1.recal.fastq.gz' </code></pre> <p>Then errors are:</p> <pre><code>Traceback (most recent call last): File "try2.py", line 8, in &lt;module&gt; list(itertools.islice(text.xreadlines(),10)) AttributeError: GzipFiles instance has no attribute 'xreadlines' </code></pre> <p>Edit again: Thx Dan, I've solved the problem yesterday. Seems GzipFiles don't support xreadlines. So I tried the similar way as you suggested later. And it works. See below:</p> <pre><code>#!/usr/bin/python import os,sys,re import gzip from itertools import islice path = "/home/XXXX/nearline" for file in os.listdir(path): if re.match('.*\.recal.fastq.gz', file): fullpath = os.path.join(path, file) myfile = gzip.open(fullpath,'r') head = list(islice(myfile,1000)) word_str = ";".join(str(x) for x in head) number = word_str.count('J') if number != 0: print file </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload