Question: Biopython - Can't find file
gravatar for damonlbp
6 days ago by
damonlbp10 wrote:

Hi everyone, I'm new to Biopython and python in general so im going through the tutorials trying to get the hang of it for future job prospects in bioinformatics and for fun because why not.

I am having a few issues though, for example tutorials aren't great at telling you where to be playing with your program. I was using IDLE for a while until it turned out that i needed to use python.exe to actually install biopython. A problem at the minute is the program not finding the example stuff for this tutorial:

from Bio import SeqIO
for seq_record in SeqIO.parse("ls_orchid.fasta", "fasta"):

This just leaves the error:

Traceback (most recent call last):
  File "<pyshell#11>", line 1, in <module>
    for seq_record in SeqIO.parse("ls_orchid.fasta", "fasta"):
  File "C:\Users\dlb_p\Desktop\Python\lib\site-packages\Bio\SeqIO\", line 592, in parse
    with as_handle(handle, mode) as fp:
  File "C:\Users\dlb_p\Desktop\Python\lib\", line 81, in __enter__
    return next(self.gen)
  File "C:\Users\dlb_p\Desktop\Python\lib\site-packages\Bio\", line 87, in as_handle
    with open(handleish, mode, **kwargs) as fp:
FileNotFoundError: [Errno 2] No such file or directory: 'ls_orchid.fasta'

I have no idea where to start with this.

By the way this may be the first of many posts for help so any pointers would be greatly appreciated.

King regards,

D Pointon

ADD COMMENTlink modified 3 days ago by cpad01123.5k • written 6 days ago by damonlbp10

Have you tried hardcoding the full name of the path (including the present working directory) instead of just the filename "ls_orchid.fasta"?

ADD REPLYlink written 6 days ago by Hussain Ather440

Sorry for the late reply, doing alot of 11 hour shift ATM. How would I go about hardcoding the location?

for seq_record in SeqIO.parse ("c:\Users.. etc until I'm at the folder holding the file", "fasta"):
ADD REPLYlink written 3 days ago by damonlbp10

Yup, that's exactly how you'd do it.

ADD REPLYlink written 3 days ago by Devon Ryan73k

Awesome, I'll give it a go when I get back home. Thanks for the help.

ADD REPLYlink written 3 days ago by damonlbp10

I know error messages are scary at first, but especially with Python these usually describe very well what's going wrong. Reading error messages carefully is also an essential skill.

ADD REPLYlink written 5 days ago by WouterDeCoster24k

Sorry for the late reply. I did try reading it through but it made no sense to me, to me it looks like it found a file but the wrong one and then something on a line if that file caused it to stop working.

ADD REPLYlink written 3 days ago by damonlbp10
gravatar for Devon Ryan
6 days ago by
Devon Ryan73k
Freiburg, Germany
Devon Ryan73k wrote:

The error (just look at the list line) indicates that it can't find ls_orchid.fasta in your current directory. You need to download the file and save it in the directory in which you run that script.

ADD COMMENTlink written 6 days ago by Devon Ryan73k

Sorry for the late reply, I tried copy/pasting the file into as many directories as I could and retrying the code and still the same error.

ADD REPLYlink written 3 days ago by damonlbp10

The code won't work unless you've downloaded their file. Make sure you have the file ls_orchid.fasta in a directory before running the code in that directory.

ADD REPLYlink written 3 days ago by jrj.healey3.0k
gravatar for cpad0112
3 days ago by
cpad01123.5k wrote:
>>> import os
>>> import glob
>>> os.getcwd() ## This tells you where you are 
>>> os.chdir ("provide the file path") ## changes the working directory. This directory must be where fa file exists
>>> os.getcwd() ## rerun to know  where you are
>>> glob.glob("*.fasta") ## to check if you have .fasta files in the current directory. If your file exists, then run biopython code above
ADD COMMENTlink written 3 days ago by cpad01123.5k
Please log in to add an answer.


Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 944 users visited in the last hour