Skip to content

Commit

Permalink
Merge pull request #79 from Rohan-cod/0based-1based
Browse files Browse the repository at this point in the history
Fixed base conversion for Conversion Region Disctionary
  • Loading branch information
rhdolin authored Jun 21, 2021
2 parents ff35e57 + ef5d07d commit 73e3a1d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 17 deletions.
15 changes: 2 additions & 13 deletions vcf2fhir/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ class Converter(object):
file (conv_region_filename):
**conv_region_dict** : Array of regions (e.g. '{"Chromosome":
["X", "X", "M"],"Start": [50001, 55001, 50001],"End": [52001,
60601, 60026]}'). Values for Chromosome must align with values in
["X", "X", "M"],"Start": [50000, 55000, 50000],"End": [52000,
60600, 60025]}'). Values for Chromosome must align with values in
VCF #CHROM field. Ranges must be `0-based \
<https://www.biostars.org/p/84686/>`_
(or 0-start, half-open) and based on GRCh37 or GRCh38 \
Expand Down Expand Up @@ -141,7 +141,6 @@ def __init__(
"Please provide valid 'conv_region_filename'")
elif conv_region_dict:
try:
self._fix_conv_region_zero_based(conv_region_dict)
self.conversion_region = pyranges.from_dict(conv_region_dict)
except FileNotFoundError:
raise
Expand Down Expand Up @@ -199,16 +198,6 @@ def convert(self, output_filename='fhir.json'):
output_filename)
general_logger.info("Completed VCF to FHIR Conversion")

def _fix_conv_region_zero_based(self, conv_region_dict):
i = 0
for start in conv_region_dict["Start"]:
conv_region_dict["Start"][i] = start - 1
i += 1
i = 0
for end in conv_region_dict["End"]:
conv_region_dict["End"][i] = end - 1
i += 1

def _generate_exception(self, msg):
general_logger.error(msg, exc_info=True)
raise Exception(msg, sys.exc_info)
8 changes: 4 additions & 4 deletions vcf2fhir/test/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ def test_conv_region_only(self):
def test_conv_region_dict(self):
conv_region_dict = {
"Chromosome": ["X", "X", "M"],
"Start": [50001, 55001, 50001],
"End": [52001, 60601, 60026]
"Start": [50000, 55000, 50000],
"End": [52000, 60600, 60025]
}
o_vcf_2_fhir = vcf2fhir.Converter(
os.path.join(
Expand Down Expand Up @@ -281,8 +281,8 @@ def test_region_studied(self):
def test_region_studied_dict(self):
conv_region_dict = {
"Chromosome": ["X", "X", "M"],
"Start": [50001, 55001, 50001],
"End": [52001, 60601, 60026]
"Start": [50000, 55000, 50000],
"End": [52000, 60600, 60025]
}
self.maxDiff = None
region_studied_filename = os.path.join(
Expand Down

0 comments on commit 73e3a1d

Please sign in to comment.