Commit 171d47d8 authored by hmueller's avatar hmueller
Browse files

Fix loss of last fasta entry. Solves #31

parent ebb26a4a
#!/usr/bin/python3
import sys
import json
import argparse
parser = argparse.ArgumentParser(description='Convert a fasta file into a json document')
parser.add_argument('--result', '-r', required=True, help='The fasta file result directory')
parser.add_argument('--result', '-r', required=True, help='The fasta file')
parser.add_argument('--output', '-o', required=True, help='The json file')
args = parser.parse_args()
documents = {}
with open(args.result) as f:
# second scan for data
entry = None
id = None
for line in f:
if line.startswith(">"):
id = line.split()[0][1:]
if entry is not None:
documents[entry['id']] = entry
entry = {'id': id, 'sequence': ''}
else:
entry['sequence'] = entry['sequence'] + line.strip()
id = line.split()[0][1:]
documents[id] = {'id': id, 'sequence': ''}
elif id is not None:
documents[id]['sequence'] += line.strip()
output_filename = args.output
with open(output_filename, 'w') as o:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment