Good day,
Could you please help with my code: I need to convert from fasta file to json-object and I'm doing this via python dictionary. I have stock with two things:
from Bio import SeqIO
from Bio.SeqIO import parse
my_dict = {}
with open("Salm_ser_Enteritidis.fasta", 'r') as new_fasta:
for x in SeqIO.parse(new_fasta, 'fasta'):
dataset = x.id
sequence = x.seq
my_dict = {"dataset": x.id,
"sequence": x.seq}
print(my_dict)
Output is
{'dataset': 'PYJS01003085.1', 'sequence':
Seq('TCTCATCCGCCAAAACATCTTCGGCGTTGTAAGGTTAAGCCTCACGGTTCATTA...TTA')
but I need only actial sequence without word Seq for key 'sequence', so that output was:
{'dataset': 'PYJS01003085.1', 'sequence':
'TCTCATCCGCCAAAACATCTTCGGCGTTGTAAGGTTAAGCCTCACGGTTCATTA...TTA'
and the second problem:
import json
my_json = json.dumps(my_dict)
output TypeError: Object of type Seq is not JSON serializable
but via print(type(my_dict)) I have output that my_dict is <class 'dict'>, not type Seq. How to convert to dict for further # json?
Thanks in advance, Galina
please see: https://stackoverflow.com/questions/7100125/storing-python-dictionaries