Commit 29590252 authored by hmueller's avatar hmueller
Browse files

Add TargetP to json converter.

parent 3c3f0eb1
import sys
import json
import argparse
parser = argparse.ArgumentParser(description = 'Convert targetp results to json documents')
parser.add_argument('--result', '-r', required = True, help = 'The targetp result file')
parser.add_argument('--output', '-o', required = True, help = 'The converted results json file')
args = parser.parse_args()
filename = args.result
documents = {}
with open(filename) as f:
tool = None
field_index = {"Name": None, "cTP": None, "mTP": None, "SP": None, "Loc": None}
is_datasection = False
for line in f:
if line.startswith("---------"):
is_datasection = not is_datasection
elif is_datasection:
split = line.split()
if not split[0] in documents:
documents[split[0]] = {"id": split[0], "computations": [{'tool': tool, 'results':[{}]}]}
results = documents[split[0]]['computations'][0]["results"][0]
for field in field_index:
if field_index[field] is not None:
if field in ["cTP", "mTP", "SP"]:
results[field.lower()] = float(split[field_index[field]])
results[field.lower()] = split[field_index[field]]
if line.startswith('Name '):
split = line.split()
for field in field_index:
field_index[field] = split.index(field)
except ValueError:
print('TargetP Converter: No column "' + field + '" found in table!')
elif line.startswith('### targetp '):
split = line.split()
tool = {'name': 'TargetP',
'version': split[2].replace("v", ""),
'plantmode': True}
elif ' NON-PLANT ' in line:
tool['plantmode'] = False
output_filename = args.output
with open(output_filename, 'w') as o:
json.dump(documents, 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