Biopython - Can't find file
2
0
Entering edit mode
7.0 years ago
damonlbp ▴ 20

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

biopython programming sequence • 5.2k views
ADD COMMENT
0
Entering edit mode

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

ADD REPLY
1
Entering edit mode

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 REPLY
0
Entering edit mode

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

ADD REPLY
0
Entering edit mode

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

ADD REPLY
0
Entering edit mode

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 REPLY
0
Entering edit mode

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 REPLY
1
Entering edit mode
7.0 years ago

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 COMMENT
0
Entering edit mode

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 REPLY
1
Entering edit mode

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 REPLY
1
Entering edit mode
7.0 years ago
>>> 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 COMMENT

Login before adding your answer.

Traffic: 1574 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6