Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6079933
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:00:13+00:00 2026-05-23T11:00:13+00:00

I’m new to python and bioinformatics field. I’m using python-2.6. Now I’m trying to

  • 0

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.

The following is my 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

But I got some errors:

Traceback (most recent call last):
  File "fastqfilter.py", line 9, in <module>
    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'

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.

Hope give me some clues, and any point out any other errors in the script.

THanks a lot.

Edit: thx everyone. I followed Dan’s suggestion. And I tried on ONE fastq file first. My script goes like:

#!/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'

Then errors are:

Traceback (most recent call last):
  File "try2.py", line 8, in <module>
    list(itertools.islice(text.xreadlines(),10))
AttributeError: GzipFiles instance has no attribute 'xreadlines'

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:

#!/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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T11:00:14+00:00Added an answer on May 23, 2026 at 11:00 am

    on this line:

    text = gzip.open(file,'r').read()
    

    file is a filename not a full path so

    fullpath = os.path.join(path, file)
    text = gzip.open(fullpath,'r').read()
    

    about F.readlines()[:10] will read the whole file in to a list of lines and then take the first 10

    import itertools
    list(itertools.islice(F.xreadlines(),10))
    

    this will not read the whole file into memory and will only read the first 10 lines into a list


    but as gzip.open returns an object that doesn’t have .xreadlines() and but as files are iterable on their lines just:

    list(itertools.islice(F,10))
    

    would work as this test shows:

    >>> import gzip,itertools
    >>> list(itertools.islice(gzip.open("/home/dan/Desktop/rp718.ps.gz"),10))
    ['%!PS-Adobe-2.0\n', '%%Creator: dvips 5.528 Copyright 1986, 1994 Radical Eye Software\n', '%%Title: WLP-94-int.dvi\n', '%%CreationDate: Mon Jan 16 16:24:41 1995\n', '%%Pages: 6\n', '%%PageOrder: Ascend\n', '%%BoundingBox: 0 0 596 842\n', '%%EndComments\n', '%DVIPSCommandLine: dvips -f WLP-94-int.dvi\n', '%DVIPSParameters: dpi=300, comments removed\n']
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have thousands of HTML files to process using Groovy/Java and I need to
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am trying to understand how to use SyndicationItem to display feed which is
this is what i have right now Drawing an RSS feed into the php,
I want use html5's new tag to play a wav file (currently only supported
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.