Question: trouble about biopython fasta file import
0
gravatar for mendel18221884
2.3 years ago by
mendel182218840 wrote:

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 • 1.5k views
ADD COMMENTlink modified 2.3 years ago by lakhujanivijay4.4k • written 2.3 years ago by mendel182218840
1
gravatar for lakhujanivijay
2.3 years ago by
lakhujanivijay4.4k
India
lakhujanivijay4.4k wrote:

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 COMMENTlink written 2.3 years ago by lakhujanivijay4.4k

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

thank you so much

ADD REPLYlink written 2.3 years ago by mendel182218840
1

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 REPLYlink written 2.3 years ago by lakhujanivijay4.4k

https://raw.githubusercontent.com/biopython/biopython/master/Doc/examples/ls_orchid.fasta

ADD REPLYlink modified 2.3 years ago • written 2.3 years ago by mendel182218840

@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 REPLYlink modified 2.3 years ago • written 2.3 years ago by cpad011211k

thank you! it helps a lot

ADD REPLYlink written 2.0 years ago by thuco.pipe0
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: 1384 users visited in the last hour