Question: Biopython - Can't find file
0
gravatar for damonlbp
2.1 years ago by
damonlbp20
damonlbp20 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: http://biopython.org/DIST/docs/tutorial/Tutorial.html#htoc10

from Bio import SeqIO
for seq_record in SeqIO.parse("ls_orchid.fasta", "fasta"):
    printseq_record.id)
    print(repr(seq_record.seq))
    print(len(seq_record))

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\__init__.py", line 592, in parse
    with as_handle(handle, mode) as fp:
  File "C:\Users\dlb_p\Desktop\Python\lib\contextlib.py", line 81, in __enter__
    return next(self.gen)
  File "C:\Users\dlb_p\Desktop\Python\lib\site-packages\Bio\File.py", 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

programming biopython sequence • 1.6k views
ADD COMMENTlink modified 2.1 years ago by cpad011212k • written 2.1 years ago by damonlbp20

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 2.1 years ago by Hussain Ather940
1

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 2.1 years ago by damonlbp20

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

ADD REPLYlink written 2.1 years ago by Devon Ryan93k

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

ADD REPLYlink written 2.1 years ago by damonlbp20

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 2.1 years ago by WouterDeCoster42k

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 2.1 years ago by damonlbp20
1
gravatar for Devon Ryan
2.1 years ago by
Devon Ryan93k
Freiburg, Germany
Devon Ryan93k 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 2.1 years ago by Devon Ryan93k

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 2.1 years ago by damonlbp20
1

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 2.1 years ago by Joe16k
1
gravatar for cpad0112
2.1 years ago by
cpad011212k
India
cpad011212k 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 2.1 years ago by cpad011212k
Please log in to add an answer.

Help
Access

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