Skip to content

Commit

Permalink
Merge pull request #62 from jodyphelan/master
Browse files Browse the repository at this point in the history
TB-Profiler IO
  • Loading branch information
fmaguire authored Oct 11, 2021
2 parents 7e1a07d + dca188b commit 3c1a591
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions hAMRonization/TBProfilerIO.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/usr/bin/env python

import json
from .Interfaces import hAMRonizedResultIterator

required_metadata = ['analysis_software_version',
'reference_database_version']


class TBProfilerIterator(hAMRonizedResultIterator):

def __init__(self, source, metadata):
metadata['analysis_software_name'] = 'TBProfiler'
self.metadata = metadata

self.field_mapping = {
'filename': 'input_file_name',
'gene': 'gene_symbol',
'gene': 'gene_name',
'drug': 'drug_class',
'type': 'genetic_variation_type',
'frequency': 'variant_frequency',
'db_name': 'reference_database_id',
'db_version': 'reference_database_version',
'tbprofiler_version': 'analysis_software_version'

}

super().__init__(source, self.field_mapping, self.metadata)

def parse(self, handle):
"""
Read each and return it
"""
# skip any manually specified fields for later
json_obj = json.load(handle)
for variant in json_obj["dr_variants"]:
for drug in variant["drugs"]:
result = {
'filename': handle.name,
'gene': variant['gene'],
'gene_name': variant['gene'],
'drug': drug['drug'],
'type': 'variant',
'frequency': variant['freq'],
'db_name': json_obj['db_version']['name'],
'db_version': json_obj['db_version']['commit'],
'tbprofiler_version': json_obj['tbprofiler_version']
}
yield self.hAMRonize(result, self.metadata)

0 comments on commit 3c1a591

Please sign in to comment.