Dear colleagues,
Could you please help to finish my code:
I take each file in the certain one folder and make from .fna file .json so that the name of .fna become the same name but as .json , in the same folder.
for example, was:
GCF_000783815.1_ASM78381v1_genomic.fna
become:
GCF_000783815.1_ASM78381v1_genomic.json
from Bio import SeqIO
import json
my_dict = {}
import os
_file = os.listdir("data/")
print(_file)
for EL in _file:
with open(EL, 'r') as new_fasta:
for x in SeqIO.parse(new_fasta, 'fasta'):
my_dict = {
"dataset": x.id,
"sequence": str(x.seq)
}
with open('my_dict????.json', 'w') as f:
json.dump(my_dict???, f)
Check this out: How to rename multiple files on Linux. It would be something like:
@ Buffo It is not as simple as that. From python code, OP intention seems to generate a dictionary from id and sequence and then dump dictionary as json. Only part that has some problem is last two lines in python code. Appending items to dictionary is also confusing.
This is a xy problem. OP needs to clarify the objective of the python code and expected output.
thks, but I'm in Win working, could you pls advise if knows for this part:
with open('my_dict????.json', 'w') as f: json.dump(my_dict???, f)