示例#1
0
 def test_region_studied_dict(self):
     conv_region_dict = {
         "Chromosome": ["X", "X", "M"],
         "Start": [50001, 55001, 50001],
         "End": [52001, 60601, 60026]
     }
     self.maxDiff = None
     region_studied_filename = os.path.join(
         os.path.dirname(__file__), 'RegionsStudied_example3.bed')
     nocall_filename = os.path.join(os.path.dirname(
         __file__), 'NoncallableRegions_example3.bed')
     output_filename = os.path.join(os.path.dirname(
         __file__), self.TEST_RESULT_DIR, 'fhir_example3_dict.json')
     expected_output_filename = os.path.join(
         os.path.dirname(__file__), 'expected_example3.json')
     o_vcf_2_fhir = vcf2fhir.Converter(
         os.path.join(
             os.path.dirname(__file__),
             'vcf_example3.vcf'),
         'GRCh38',
         'HG00628',
         conv_region_dict=conv_region_dict,
         region_studied_filename=region_studied_filename,
         nocall_filename=nocall_filename)
     o_vcf_2_fhir.convert(output_filename)
     _compare_actual_and_expected_fhir_json(
         self,
         output_filename=output_filename,
         expected_output_filename=expected_output_filename,
         dict={7: [2, 3], 8: [3, 4]})
 def test_region_studied_dict(self):        
     conv_region_dict =  {
         "Chromosome": ["X", "X", "M"],
         "Start": [50001, 55001, 50001],
         "End": [52001, 60601, 60026]
     }
     self.maxDiff = None
     region_studied_filename = os.path.join(os.path.dirname(__file__),'RegionsStudied_example3.bed')
     nocall_filename = os.path.join(os.path.dirname(__file__),'NoncallableRegions_example3.bed')               
     output_filename = os.path.join(os.path.dirname(__file__), self.TEST_RESULT_DIR, 'fhir_example3_dict.json')
     expected_outfult_filename = os.path.join(os.path.dirname(__file__),'expected_example3.json')
     oVcf2Fhir = vcf2fhir.Converter(os.path.join(os.path.dirname(__file__), 'vcf_example3.vcf'), 'GRCh38', 'HG00628', conv_region_dict= conv_region_dict, region_studied_filename=region_studied_filename, nocall_filename=nocall_filename)
     bDone = oVcf2Fhir.convert(output_filename)
     # check if translation was completed
     self.assertEqual(bDone, True)
     actual_fhir_json = json.load(open(output_filename))
     # Validate the pased sequence relationship
     self.assertEqual(_validate_phase_rel(actual_fhir_json, {7: [2, 3], 8 : [3, 4]}), True)
     # Validate: list of observation uids and list of result uids same.
     # Also set the uids to '' to avoid guid comparison in next step
     map_ids = _get_uids_map(actual_fhir_json)
     self.assertEqual(map_ids['obv_ids'], map_ids['result_ids'])
     actual_fhir_json['issued'] = ''
     # Finally, check if the acutal json after removing all uids is same as exppected json        
     expected_fhir_json = json.load(open(expected_outfult_filename))
     self.assertEqual(actual_fhir_json, expected_fhir_json)
示例#3
0
 def test_region_studied(self):
     self.maxDiff = None
     region_studied_filename = os.path.join(
         os.path.dirname(__file__), 'RegionsStudied_example3.bed')
     conv_region_filename = os.path.join(os.path.dirname(
         __file__), 'RegionsToConvert_example3.bed')
     nocall_filename = os.path.join(os.path.dirname(
         __file__), 'NoncallableRegions_example3.bed')
     output_filename = os.path.join(os.path.dirname(
         __file__), self.TEST_RESULT_DIR, 'fhir_example3.json')
     expected_output_filename = os.path.join(
         os.path.dirname(__file__), 'expected_example3.json')
     o_vcf_2_fhir = vcf2fhir.Converter(
         os.path.join(
             os.path.dirname(__file__),
             'vcf_example3.vcf'),
         'GRCh38',
         'HG00628',
         conv_region_filename=conv_region_filename,
         region_studied_filename=region_studied_filename,
         nocall_filename=nocall_filename)
     o_vcf_2_fhir.convert(output_filename)
     _compare_actual_and_expected_fhir_json(
         self,
         output_filename=output_filename,
         expected_output_filename=expected_output_filename,
         dict={7: [2, 3], 8: [3, 4]})
 def test_logger_forks(self):
     region_studied_filename = os.path.join(os.path.dirname(__file__),
                                            'RegionsStudied_example3.bed')
     conv_region_filename = os.path.join(os.path.dirname(__file__),
                                         'RegionsToConvert_example3.bed')
     nocall_filename = os.path.join(os.path.dirname(__file__),
                                    'NoncallableRegions_example3.bed')
     output_filename = os.path.join(os.path.dirname(__file__), self.LOG_DIR,
                                    'logging_fhir.json')
     # create logger
     general_logger = logging.getLogger('vcf2fhir.general')
     invalid_record_logger = logging.getLogger('vcf2fhir.invalidrecord')
     general_logger.setLevel(logging.DEBUG)
     invalid_record_logger.setLevel(logging.DEBUG)
     # add ch to logger
     general_logger.addHandler(self.genearl_fh)
     invalid_record_logger.addHandler(self.invalid_record_fh)
     o_vcf_2_fhir = vcf2fhir.Converter(
         os.path.join(os.path.dirname(__file__), 'vcf_example3.vcf'),
         'GRCh38',
         'HG00628',
         conv_region_filename=conv_region_filename,
         region_studied_filename=region_studied_filename,
         nocall_filename=nocall_filename)
     o_vcf_2_fhir.convert(output_filename)
     self.assertEqual(os.path.exists(self.log_general_filename), True)
     self.assertEqual(os.path.exists(self.log_invalid_record_filename),
                      True)
 def test_empty_fhir_json(self):
     conv_region_filename = os.path.join(os.path.dirname(__file__),'RegionsToConvert_empty_example4.bed')             
     output_filename = os.path.join(os.path.dirname(__file__), self.TEST_RESULT_DIR, 'fhir_example4_test.json')
     oVcf2Fhir = vcf2fhir.Converter(os.path.join(os.path.dirname(__file__), 'vcf_example4.vcf'), 'GRCh38', 'HG00628', conv_region_filename=conv_region_filename)
     bDone = oVcf2Fhir.convert(output_filename)
     # check if translation was completed
     self.assertEqual(bDone, True)
 def test_required_ref_build(self):
     with self.assertRaises(Exception) as context:
         vcf2fhir.Converter(
             os.path.join(os.path.dirname(__file__), 'vcf_example1.vcf'))
     self.assertEqual(
         'You must provide build number ("GRCh37" or "GRCh38")',
         str(context.exception))
 def test_annotation(self):
     self.maxDiff = None
     region_studied_filename = os.path.join(
         os.path.dirname(__file__), 'NB6TK328_region_studied.bed')
     conv_region_filename = os.path.join(os.path.dirname(
         __file__), 'NB6TK328_conversion_region.bed')
     annotation_filename = os.path.join(os.path.dirname(
         __file__), 'NB6TK328_annotations.txt')
     output_filename = os.path.join(os.path.dirname(
         __file__), self.TEST_RESULT_DIR, 'fhir_annotation.json')
     expected_output_filename = os.path.join(
         os.path.dirname(__file__), 'expected_annotation.json')
     o_vcf_2_fhir = vcf2fhir.Converter(
         os.path.join(
             os.path.dirname(__file__),
             'NB6TK328_filtered.vcf'),
         'GRCh38',
         'NB6TK328',
         conv_region_filename=conv_region_filename,
         region_studied_filename=region_studied_filename,
         ratio_ad_dp=0.95,
         genomic_source_class='germline',
         annotation_filename=annotation_filename)
     o_vcf_2_fhir.convert(output_filename)
     _compare_actual_and_expected_fhir_json(
         self,
         output_filename=output_filename,
         expected_output_filename=expected_output_filename,
         dict={18: [11, 12], 19: [12, 13]})
示例#8
0
 def test_tabix(self):
     self.maxDiff = None
     region_studied_filename = os.path.join(
         os.path.dirname(__file__), 'RegionsStudied_example4.bed')
     conv_region_filename = os.path.join(os.path.dirname(
         __file__), 'RegionsToConvert_example4.bed')
     nocall_filename = os.path.join(os.path.dirname(
         __file__), 'NoncallableRegions_example4.bed')
     output_filename = os.path.join(os.path.dirname(
         __file__), self.TEST_RESULT_DIR, 'fhir_example4_tabix.json')
     expected_outfult_filename = os.path.join(
         os.path.dirname(__file__), 'expected_example4.json')
     oVcf2Fhir = vcf2fhir.Converter(os.path.join(os.path.dirname(__file__), 'vcf_example4.vcf.gz'), 'GRCh38', 'HG00628', has_tabix=True,
                                    conv_region_filename=conv_region_filename, region_studied_filename=region_studied_filename, nocall_filename=nocall_filename)
     oVcf2Fhir.convert(output_filename)
     actual_fhir_json = json.load(open(output_filename))
     # Validate the pased sequence relationship
     self.assertEqual(_validate_phase_rel(
         actual_fhir_json, {31: [24, 25], 32: [25, 26]}), True)
     # Validate: list of observation uids and list of result uids same.
     # Also set the uids to '' to avoid guid comparison in next step
     map_ids = _get_uids_map(actual_fhir_json)
     self.assertEqual(map_ids['obv_ids'], map_ids['result_ids'])
     actual_fhir_json['issued'] = ''
     # Finally, check if the acutal json after removing all uids is same as exppected json
     expected_fhir_json = json.load(open(expected_outfult_filename))
     self.assertEqual(actual_fhir_json, expected_fhir_json)
示例#9
0
 def test_tabix(self):
     self.maxDiff = None
     region_studied_filename = os.path.join(
         os.path.dirname(__file__), 'RegionsStudied_example4.bed')
     conv_region_filename = os.path.join(os.path.dirname(
         __file__), 'RegionsToConvert_example4.bed')
     nocall_filename = os.path.join(os.path.dirname(
         __file__), 'NoncallableRegions_example4.bed')
     output_filename = os.path.join(os.path.dirname(
         __file__), self.TEST_RESULT_DIR, 'fhir_example4_tabix.json')
     expected_output_filename = os.path.join(
         os.path.dirname(__file__), 'expected_example4.json')
     o_vcf_2_fhir = vcf2fhir.Converter(
         os.path.join(
             os.path.dirname(__file__),
             'vcf_example4.vcf.gz'),
         'GRCh38',
         'HG00628',
         has_tabix=True,
         conv_region_filename=conv_region_filename,
         region_studied_filename=region_studied_filename,
         nocall_filename=nocall_filename)
     o_vcf_2_fhir.convert(output_filename)
     _compare_actual_and_expected_fhir_json(
         self,
         output_filename=output_filename,
         expected_output_filename=expected_output_filename,
         dict={31: [24, 25], 32: [25, 26]})
示例#10
0
 def test_conv_region_region_studied(self):
     region_studied_filename = os.path.join(
         os.path.dirname(__file__), 'RegionsStudied_example3.bed')
     conv_region_filename = os.path.join(os.path.dirname(
         __file__), 'RegionsToConvert_example3.bed')
     oVcf2Fhir = vcf2fhir.Converter(os.path.join(os.path.dirname(__file__), 'vcf_example3.vcf'), 'GRCh37',
                                    'abc', conv_region_filename=conv_region_filename, region_studied_filename=region_studied_filename)
     self.assertEqual(type(oVcf2Fhir), vcf2fhir.Converter)
示例#11
0
 def test_empty_fhir_json(self):
     conv_region_filename = os.path.join(os.path.dirname(
         __file__), 'RegionsToConvert_empty_example4.bed')
     output_filename = os.path.join(os.path.dirname(
         __file__), self.TEST_RESULT_DIR, 'fhir_example4_test.json')
     oVcf2Fhir = vcf2fhir.Converter(os.path.join(os.path.dirname(
         __file__), 'vcf_example4.vcf'), 'GRCh38', 'HG00628', conv_region_filename=conv_region_filename)
     oVcf2Fhir.convert(output_filename)
示例#12
0
 def test_region_studied_only(self):
     region_studied_filename = os.path.join(
         os.path.dirname(__file__), 'RegionsStudied_example4.bed')
     output_filename = os.path.join(os.path.dirname(
         __file__), self.TEST_RESULT_DIR, 'fhir_example4_test.json')
     oVcf2Fhir = vcf2fhir.Converter(os.path.join(os.path.dirname(
         __file__), 'vcf_example4.vcf'), 'GRCh38', 'HG00628', region_studied_filename=region_studied_filename)
     oVcf2Fhir.convert(output_filename)
示例#13
0
 def test_no_conv_region_nocall(self):
     nocall_filename = os.path.join(os.path.dirname(
         __file__), 'NoncallableRegions_example3.bed')
     with self.assertRaises(Exception) as context:
         vcf2fhir.Converter(os.path.join(os.path.dirname(
             __file__), 'vcf_example3.vcf'), 'GRCh37', 'abc', nocall_filename=nocall_filename)
     self.assertEqual(
         'Please also provide region_studied_filename when nocall_filename is provided', str(context.exception))
 def test_conv_region_dict(self):
     conv_region_dict =  {
         "Chromosome": ["X", "X", "M"],
         "Start": [50001, 55001, 50001],
         "End": [52001, 60601, 60026]
     }
     oVcf2Fhir = vcf2fhir.Converter(os.path.join(os.path.dirname(__file__), 'vcf_example3.vcf'), 'GRCh37', 'abc', conv_region_dict=conv_region_dict)
     self.assertEqual(type(oVcf2Fhir), vcf2fhir.Converter)
示例#15
0
 def test_conv_region_only(self):
     conv_region_filename = os.path.join(os.path.dirname(__file__),
                                         'RegionsToConvert_example3.bed')
     o_vcf_2_fhir = vcf2fhir.Converter(
         os.path.join(os.path.dirname(__file__), 'vcf_example3.vcf'),
         'GRCh37',
         'abc',
         conv_region_filename=conv_region_filename)
     self.assertEqual(type(o_vcf_2_fhir), vcf2fhir.Converter)
示例#16
0
 def test_with_patient_id(self):
     self.maxDiff = None
     o_vcf_2_fhir = vcf2fhir.Converter(os.path.join(os.path.dirname(
         __file__), 'vcf_example1.vcf'), 'GRCh37', 'HG00628')
     output_filename = os.path.join(os.path.dirname(
         __file__), self.TEST_RESULT_DIR, 'fhir_with_patient_example1.json')
     expected_output_filename = os.path.join(os.path.dirname(
         __file__), 'expected_example1_with_patient.json')
     o_vcf_2_fhir.convert(output_filename)
     _compare_actual_and_expected_fhir_json(
         self,
         output_filename=output_filename,
         expected_output_filename=expected_output_filename,
         dict={8: [5, 6]})
 def test_structural_mixed(self):
     self.maxDiff = None
     o_vcf_2_fhir = vcf2fhir.Converter(os.path.join(
         os.path.dirname(__file__), 'vcf_structural_variants.vcf'),
         'GRCh37',
         genomic_source_class='mixed',)
     output_filename = os.path.join(os.path.dirname(
         __file__), self.TEST_RESULT_DIR, 'fhir_structural_mixed.json')
     expected_output_filename = os.path.join(
         os.path.dirname(__file__), 'expected_fhir_mixed_structural.json')
     o_vcf_2_fhir.convert(output_filename)
     _compare_actual_and_expected_fhir_json(
         self,
         output_filename=output_filename,
         expected_output_filename=expected_output_filename,
         dict={49: [38, 40], 48: [36, 38]})
 def test_structural_germline(self):
     self.maxDiff = None
     o_vcf_2_fhir = vcf2fhir.Converter(os.path.join(
         os.path.dirname(__file__), 'vcf_structural_variants.vcf'),
         'GRCh37',
         genomic_source_class='germline',)
     output_filename = os.path.join(os.path.dirname(
         __file__), self.TEST_RESULT_DIR, 'fhir_structural_germline.json')
     expected_output_filename = os.path.join(
         os.path.dirname(__file__),
         'expected_fhir_germline_structural.json')
     o_vcf_2_fhir.convert(output_filename)
     _compare_actual_and_expected_fhir_json(
         self,
         output_filename=output_filename,
         expected_output_filename=expected_output_filename,
         dict={45: [34, 36], 44: [32, 34]})
 def test_with_patient_id(self):
     self.maxDiff = None
     oVcf2Fhir = vcf2fhir.Converter(os.path.join(os.path.dirname(__file__), 'vcf_example1.vcf'), 'GRCh37', 'HG00628')        
     output_filename = os.path.join(os.path.dirname(__file__), self.TEST_RESULT_DIR, 'fhir_with_patient_example1.json')
     expected_outfult_filename = os.path.join(os.path.dirname(__file__),'expected_example1_with_patient.json')
     bDone = oVcf2Fhir.convert(output_filename)
     # check if translation was completed
     self.assertEqual(bDone, True)
     actual_fhir_json = json.load(open(output_filename))
     # Validate the pased sequence relationship
     self.assertEqual(_validate_phase_rel(actual_fhir_json, {8 : [5, 6]}), True)
     # Validate: list of observation uids and list of result uids same.
     # Also set the uids to '' to avoid guid comparison in next step
     map_ids = _get_uids_map(actual_fhir_json)
     self.assertEqual(map_ids['obv_ids'], map_ids['result_ids'])
     actual_fhir_json['issued'] = ''
     # Finally, check if the acutal json after removing all uids is same as exppected json        
     expected_fhir_json = json.load(open(expected_outfult_filename))
     self.assertEqual(actual_fhir_json, expected_fhir_json)
 def test_no_region_examined(self):
     self.maxDiff = None
     region_studied_filename = os.path.join(
         os.path.dirname(__file__), 'HG00403A_studied.bed')
     conv_region_filename = os.path.join(os.path.dirname(
         __file__), 'HG00403A_convert.bed')
     output_filename = os.path.join(os.path.dirname(
         __file__), self.TEST_RESULT_DIR, 'HG00403A.json')
     expected_output_filename = os.path.join(
         os.path.dirname(__file__), 'expected_HG00403A.json')
     o_vcf_2_fhir = vcf2fhir.Converter(
         os.path.join(
             os.path.dirname(__file__),
             'HG00403A.vcf.gz'),
         'GRCh37',
         has_tabix=True,
         conv_region_filename=conv_region_filename,
         region_studied_filename=region_studied_filename)
     o_vcf_2_fhir.convert(output_filename)
     _compare_actual_and_expected_fhir_json(
         self,
         output_filename=output_filename,
         expected_output_filename=expected_output_filename,
         is_null=True)
示例#21
0
 def test_valid_ref_build_38(self):
     o_vcf_2_fhir = vcf2fhir.Converter(
         os.path.join(os.path.dirname(__file__), 'vcf_example1.vcf'),
         'GRCh38')
     self.assertEqual(type(o_vcf_2_fhir), vcf2fhir.Converter)
示例#22
0
 def test_required_vcf_filename(self):
     with self.assertRaises(Exception) as context:
         vcf2fhir.Converter()
     self.assertTrue(
         'You must provide vcf_filename' in str(context.exception))
示例#23
0
 def test_anotherfile(self):
     o_vcf_2_fhir = vcf2fhir.Converter(
         os.path.join(os.path.dirname(__file__), 'vcf_example2.vcf'),
         'GRCh37', 'HG00628')
     o_vcf_2_fhir.convert(output_filename=os.path.join(
         os.path.dirname(__file__), self.TEST_RESULT_DIR, 'fhir2.json'))
 def test_anotherfile(self):
     oVcf2Fhir = vcf2fhir.Converter(os.path.join(os.path.dirname(__file__), 'vcf_example2.vcf'), 'GRCh37', 'HG00628')
     bDone = oVcf2Fhir.convert(output_filename=os.path.join(os.path.dirname(__file__), self.TEST_RESULT_DIR,'fhir2.json'))
     self.assertEqual(bDone, True)