Question: How To Read Dna Sequences From More Than One Fasta File From A Directory?
0
gravatar for viv_bio
8.4 years ago by
viv_bio30
IIT Bombay
viv_bio30 wrote:
import os
from Bio import SeqIO
import glob
list_of_files = glob.glob( "directory path/./*.fasta")
for file_name in list_of_files:
       R = SeqIO.parse(file_name)
       for records in R:
                     print records

from this i can parse over all the files in directory but i am not able to print Sequence records in it .

python biopython • 2.5k views
ADD COMMENTlink modified 8.4 years ago by Leonor Palmeira3.7k • written 8.4 years ago by viv_bio30

Is that pseudo code? The SeqIO parse function requires a format argument as well, e.g. "fasta" or "gb".

ADD REPLYlink written 8.4 years ago by Peter5.9k
3
gravatar for Leonor Palmeira
8.4 years ago by
Leonor Palmeira3.7k
Liège, Belgium
Leonor Palmeira3.7k wrote:

SeqIO.parse() returns a SeqRecord object, and the __str__() method for this object (method implicitely called whenever you run a 'print x') will return a bunch of information and not just the sequence:

ID: Z78439.1
Name: Z78439
Description: P.barbatum 5.8S rRNA gene and ITS1 and ITS2 DNA.
Number of features: 5
/source=Paphiopedilum barbatum
/taxonomy=['Eukaryota', 'Viridiplantae', 'Streptophyta', 'Embryophyta', ..., 'Paphiopedilum']
/keywords=['5.8S ribosomal RNA', '5.8S rRNA gene', 'internal transcribed spacer', 'ITS1', 'ITS2']
/references=[<Bio.SeqFeature.Reference ...>, <Bio.SeqFeature.Reference ...>]
/data_file_division=PLN
/date=30-NOV-2006
/organism=Paphiopedilum barbatum
/gi=2765564
Seq('CATTGTTGAGATCACATAATAATTGATCGAGTTAATCTGGAGGATCTGTTTACTTTGGTC ...', IUPACAmbiguousDNA())

Have you tried rather a

print records.seq

or a

print records.format("fasta")

This is possibly what you are looking for.

ADD COMMENTlink modified 8.4 years ago • written 8.4 years ago by Leonor Palmeira3.7k
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: 2077 users visited in the last hour