1
votes

I will be very grateful for your help. I get an error message, stated below, from this part of my code, which I want to use, to elucidate differentially expressed genes in conditions of Crohn's disease and ulcerative colitis, from affymetrix microarray analysis(raw data link is https://www.ncbi.nlm.nih.gov/sites/GDSbrowser?acc=GDS1615). BUT when I run this code:

import gzip
import numpy as np

"""
Read in a SOFT format data file.  The following values can be exported:

GID : A list of gene identifiers of length d
SID : A list of sample identifiers of length n
STP : A list of sample descriptions of length d
X   : A dxn array of gene expression values
"""

fname = "../Anchang Charles/GDS1615_full.soft.gz"
with gzip.open(fname) as fid:
    SIF = {}
    for line in fid:
        if line.startswith(line, len("!dataset_table_begin")):
            break
        elif line.startswith(line, len("!subject_description")):
            subset_description = line.split("=")[1].strip()
        elif line.startswith(line, len("!subset_sample_id")):
            subset_ids = [x.strip() for x in subset_ids]
            for k in subset_ids:
                SIF[k] = subset_description
                  #.next().split("\t")
    SID = fid.next().split("\t")
    I = [i for i,x in enumerate(SID) if x.startswith("GSM")]
    SID = [SID[i] for i in I]
    STP = [SIF[k] for k in SID]

I get an error message which says

Traceback (most recent call last):

File "", line 1, in runfile('C:/Users/Anchang Charles/new affymetrix.py', wdir='C:/Users/Anchang Charles')

File "C:\Anaconda\lib\site-packages\spyder\utils\site\sitecustomize.py", line 866, in runfile execfile(filename, namespace)

File "C:\Anaconda\lib\site-packages\spyder\utils\site\sitecustomize.py", line 102, in execfile exec(compile(f.read(), filename, 'exec'), namespace)

File "C:/Users/Anchang Charles/new affymetrix.py", line 1, in from affymetrix import X,GID,STP,SID,UC,CD

File "C:\Users\Anchang Charles\affymetrix.py", line 26, in SID = fid.next().split("\t")

AttributeError: 'GzipFile' object has no attribute 'next'

1

1 Answers

3
votes

In Python 3, iterator.next() has been replaced with iterator.__next__(), but you should be calling it using the built-in next function like so:

next(iterator)

So try:

next(fid).split("\t")

Read more about it in PEP 3114

The crux of the reasoning behind the change:

The use of double underscores creates a separate namespace for names that are part of the Python language definition, so that programmers are free to create variables, attributes, and methods that start with letters, without fear of silently colliding with names that have a language-defined purpose. (Colliding with reserved keywords is still a concern, but at least this will immediately yield a syntax error.)

The naming of the next method on iterators is an exception to this convention. Code that nowhere contains an explicit call to a next method can nonetheless be silently affected by the presence of such a method. Therefore, this PEP proposes that iterators should have a __next__ method instead of a next method (with no change in semantics).