Python Help!!!

  • Thread starter Elfine Peterson Tjio
  • Start date
E

Elfine Peterson Tjio

I'm trying to make a program that reads Fasta file and print it out. I used the SeqIO module and the results is:

'ATGGTCAT....SingleAlphabet()'

For this purpose, should I use SeqIO or Fasta?

for example:

from Bio import SeqIO

or

from Bio import Fasta

I want it to print every letter. Can anyone point me to the right direction. The newest biopython tutorial or book recommendation will be appreciated, too.
 
K

kyosohma

I'm trying to make a program that reads Fasta file and print it out. I used the SeqIO module and the results is:

'ATGGTCAT....SingleAlphabet()'

For this purpose, should I use SeqIO or Fasta?

for example:

from Bio import SeqIO

or

from Bio import Fasta

I want it to print every letter. Can anyone point me to the right direction. The newest biopython tutorial or book recommendation will be appreciated, too.

As I understand it, a "Fasta" file is a text file, correct? If so,
this should be trivial with Python.

I created a file with the following data from http://en.wikipedia.org/wiki/Fasta_format:
gi|5524211|gb|AAD44166.1| cytochrome b [Elephas maximus maximus]
LCLYTHIGRNIYYGSYLYSETWNTGIMLLLITMATAFMGYVLPWGQMSFWGATVITNLFSAIPYIGTNLV
EWIWGGFSVDKATLNRFFAFHFILPFTMVALAGVHLTFLHETGSNNPLGLTSDSDKIPFHPYYTIKDFLG
LLILILLLLLLALLSPDMLGDPDNHMPADPLNTPLHIKPEWYFLFAYAILRSVPNKLGGVLALFLSIVIL
GLMPFLHTSKHRSMMLRPLSQALFWTLTMDLLTLTWIGSQPVEYPYTIIGQMASILYFSIILAFLPIAGX
IENY

Then I did the following to read it:
if '>' in f:
print f
else:
for letter in f:
print letter

That seemed to work for me. You probably don't want to print the first
line, but that's easily fixed.

Hope that helps.

Mike
 
J

James Stroud

Elfine said:
I'm trying to make a program that reads Fasta file and print it out. I used the SeqIO module and the results is:

'ATGGTCAT....SingleAlphabet()'

For this purpose, should I use SeqIO or Fasta?

for example:

from Bio import SeqIO

or

from Bio import Fasta

I want it to print every letter. Can anyone point me to the right direction. The newest biopython tutorial or book recommendation will be appreciated, too.

This question is better for the biopython list. Also, your subject line
should be more specific with respect to your actual question.



James
 
N

Nathan Harmston

Hi, you could try this:

def parse(self, ifile):
id=""
seq=""
for line in open(ifile, 'r'):
if '>'==line[0]:
if id!="" and len(seq)>0:
yield id,seq
seq = ""
id=line[1:].strip("\n")
elif id!="":
for word in line.split():
seq += word
if id!="" and len(seq)>0:
yield id,seq

for id, seq in parse("some.fa"):
print "%s \n %s" %(id, seq)

Its adapted from the fasta parser in PyGr.
From what I understand biopython isnt very active and I think theres a
re-factor of it going on at the moment in the form of corebio.

Hope this helps;

Thanks

Nathan
 
C

Christof Winter

Elfine said:
I'm trying to make a program that reads Fasta file and print it out. I used
the SeqIO module and the results is:

'ATGGTCAT....SingleAlphabet()'

For this purpose, should I use SeqIO or Fasta?

for example:

from Bio import SeqIO

or

from Bio import Fasta

I want it to print every letter. Can anyone point me to the right direction.
The newest biopython tutorial or book recommendation will be appreciated,
too.

Dear Elfine:

The correct place for such a question is the BioPython discussion list at
(e-mail address removed)-bio.org

You can subscribe to it here:
http://lists.open-bio.org/mailman/listinfo/biopython/

The newest BioPython tutorial (last updated 16 March 2007) can be found at
http://biopython.org/DIST/docs/tutorial/Tutorial.pdf

SeqIO and Fasta should both work fine. You could also try

after your import for some further information.

Cheers,
Christof
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top