trouble about biopython fasta file import
1
0
Entering edit mode
6.9 years ago

recently, i am leaning biopython for job. However, I got some problem at first step I followed the biopython cookbook and their example did not work.

(python 3.4.2 and version 1.69)

according to cookbook

It contains 94 records, each has a line starting with “>” (greater-than symbol) followed by the sequence on one or more lines. Now try this in Python:

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))

You shouldget something like this on your screen:

gi|2765658|emb|Z78533.1|CIZ78533
Seq('CGTAACAAGGTTTCCGTAGGTGAACCTGCGGAAGGATCATTGATGAGACCGTGG...CGC', SingleLetterAlphabet())
740

...
gi|2765564|emb|Z78439.1|PBZ78439
Seq('CATTGTTGAGATCACATAATAATTGATCGAGTTAATCTGGAGGATCTGTTTACT...GCC', SingleLetterAlphabet())
592

.

However, after i followed, I got this

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))


Traceback (most recent call last):
  File "<pyshell#27>", line 1, in <module>
    for seq_record in SeqIO.parse("ls_orchid.fasta", "fasta"):
  File "C:\Python34\lib\site-packages\Bio\SeqIO\__init__.py", line 590, in parse
    with as_handle(handle, mode) as fp:
  File "C:\Python34\lib\contextlib.py", line 59, in __enter__
    return next(self.gen)
  File "C:\Python34\lib\site-packages\Bio\File.py", line 88, in as_handle
    with open(handleish, mode, **kwargs) as fp:
FileNotFoundError: [Errno 2] No such file or directory: 'ls_orchid.fasta'

Could anyone give some suggestions to solve this problem?

thanks a lot

software error • 5.1k views
ADD COMMENT
1
Entering edit mode
6.9 years ago

FileNotFoundError: [Errno 2] No such file or directory: 'ls_orchid.fasta'

This error is self explanatory; isn't it? You forgot to have a dummy fasta file with the name "ls_orchid.fasta" in the same directory from where you executed the script.

ADD COMMENT
0
Entering edit mode

Can you demonstrate the step or line ?Because, I am just beginner. I need more help.

thank you so much

ADD REPLY
1
Entering edit mode

As a beginner, do not jump to Biopython. Learn the basics of Python first! The error is not specific to biopython, but is pointing to a rather very basic stuff i.e for your program to read a file, there must be a file (you must give it); which you forgot.

So your program is screaming loud- buddy, i will read a fasta file for sure but where is that, I can't find it!!

Solution - Your program.py file and the 'ls_orchid.fasta' should be in the same folder from where you are executing the python program.

I hope was able to explain in the most easy way.

ADD REPLY
0
Entering edit mode

@mendel

  1. Down load the fasta file (https://raw.githubusercontent.com/biopython/biopython/master/Doc/examples/ls_orchid.fasta) onto your computer. Save it on your Desktop or home folder (assuming that you are using linux)
  2. Open a terminal and go to the directory wherever you saved the file:ls_orchid.fasta (for eg. home folder/Desktop/downloads)
  3. Run biopyhon script.

However, Vijay is right that one should not jump into biopython without knowing python

ADD REPLY
0
Entering edit mode

thank you! it helps a lot

ADD REPLY

Login before adding your answer.

Traffic: 1882 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