Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TB-Profiler IO #62

Merged
merged 2 commits into from
Oct 11, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)