I have to make a generic parser for parsing fasta files using Python.
The format is like:
>gi|348686675|gb|JH159151.1| Phytophthora sojae unplaced genomic scaffold PHYSOscaffold_1, whole genome shotgun sequence
TACGAGAATAATTTCTCATCATCCAGCTTTAACACAAAATTCGCA
>gi|348686675|gb|JH159151.1| Phytophthora sojae unplaced genomic scaffold PHYSOscaffold_2, whole genome shotgun sequence
CAGTTTTCGTTAAGAGAACTTAACATTTTCTTATGACGTAAATGA
AGTTTATATATAAATTTCCTTTTTATTGGA
>gi|348686675|gb|JH159151.1| Phytophthora sojae unplaced genomic scaffold PHYSOscaffold_3, whole genome shotgun sequence
GAACTTAACATTTTCTTATGACGTAAATGAAGTTTATATATAAATTTCCTTTTTATTGGA
TAATATGCCTATGCCGCATAATTTTTATATCTTTCTCCTAACAAAACATTCGCTTGTAAA
I have to retrieve each title and sequence separately and insert the values in my created MySQL database.
eg: title1 = PHYSOscaffold_1
sequence2 = TACGAGAATAATTTCTCATCATCCAGCTTTAACACAAAATTCGCA
title2 = PHYSOscaffold_2
sequence1 = CAGTTTTCGTTAAGAGAACTTAACATTTTCTTATGACGTAAATGA AGTTTATATATAAATTTCCTTTTTATTGGA
and so on... I the insert these values into a MySQL table.
The output of my parse should be like:
name1 \t sequence1 \t length_of_sequence \t a_count \t t_count \t g_count \t c_count
name2 \t sequence2 \t length_of_sequence \t a_count \t t_count \t g_count \t c_count
So far, I have written a very basic script like this:
infile = open("simple.fasta")
line = infile.readline()
if not line.startswith(">"):
raise TypeError("Not a FASTA file: %r" % line)
title = line
sequence_lines = []
while 1:
line = infile.readline().rstrip()
if line == "":
break
sequence_lines.append(line)
I am only getting my first sequence and title.
I am a novice and need expert help.