This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Biopython Indentation Error

Hi,

I've been dabbling in biopython for about a year and I recently upgraded to Biopython release 1.59. I've been refreshing my skills with some tutorials (taken verbatim from the Biopython Cookbook) but I always get the error below when I run a for loop and any module from the biopython library:

IndentationError: expected an indented block

I only get this error when I call the .py file that I wrote in Komodo Edit version 7.0.2 from the command line terminal:

Priyas-iMac:~ Priya$ python /Users/priya/Documents/Python/Tutorials/BioParse.py
Traceback (most recent call last):
  File "/Users/priya/Documents/Python/Tutorials/BioParse.py", line 4, in <module>
    SeqIO.write(rc, "/Users/priya/Documents/Python/Tutorials/ls_orchid_rc.fasta", "fasta")
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Bio/SeqIO/__init__.py", line 400, in write
    from Bio import AlignIO
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Bio/AlignIO/__init__.py", line 147, in <module>
    import NexusIO
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Bio/AlignIO/NexusIO.py", line 19, in <module>
    from Bio.Nexus import Nexus
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Bio/Nexus/Nexus.py", line 15, in <module>
    import os,sys, math, random, copy
  File "/Users/Priya/Documents/Python/Tutorials/random.py", line 27
    randLowHigh(5,10)
    ^
IndentationError: expected an indented block

But when I start up python directly and type in the tutorial example line by line it works fine:

Priyas-iMac:~ Priya$ python 
Python 2.7.3 (default, Apr 19 2012, 00:55:09) 
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from Bio import SeqIO
>>> for seq_record in SeqIO.parse("/Users/priya/Documents/Python/Tutorials/ls_orchid.txt","fasta"):
...      print seq_record.id
... 
gi|2765658|emb|Z78533.1|CIZ78533
gi|2765657|emb|Z78532.1|CCZ78532

I can also still run old code that I wrote a year ago that has for loops and calls biopython modules, just not anything new that I write.

Any insight into this problem would be greatly appreciated!

Priya

biopython error

Make sure that your indentation is consistent. In most editors there is an option to change space-tabs into tabs or tabs into space tabs. Try doing that for random.py. If that doesn't work, post the code as bow suggested.

What version of Python are you using with your BioPython upgrade? Make sure they're compatible. I had some issues with indentation errors with the new Biopython 1.64 and Python 2.6.6, where the new biopython would work perfectly with 2.7.

1 answer

Hi priyasshah,

It looks like there's an error in this file: "/Users/Priya/Documents/Python/Tutorials/random.py". Could you paste the contents here: http://pastebin.com/?

Log in to answer this question.