Skip to content

Commit

Permalink
Fix #472 by combining rules for HCV-6 and HCV-6e.
Browse files Browse the repository at this point in the history
  • Loading branch information
donkirkby committed Jun 18, 2019
1 parent 607acfa commit da6fa92
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
12 changes: 8 additions & 4 deletions micall/resistance/asi_algorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ def __init__(self,
file=None,
rules_yaml=None,
genotype=None,
references=None):
references=None,
backup_genotype=None):
""" Load ASI rules from a file or file object. """

if references is None:
Expand Down Expand Up @@ -108,7 +109,7 @@ def __init__(self,
if file is not None:
self.load_xml(file)
elif rules_yaml is not None:
self.load_yaml(rules_yaml, genotype)
self.load_yaml(rules_yaml, genotype, backup_genotype)

def load_xml(self, file):
dom = minidom.parse(file)
Expand Down Expand Up @@ -215,7 +216,7 @@ def load_xml(self, file):
rules.append([condition, actions]) # hrmm
self.mutation_comments.append([gene_name, rules])

def load_yaml(self, rules_config, genotype):
def load_yaml(self, rules_config, genotype, backup_genotype=None):
self.alg_name = 'HCV_RULES'
self.alg_version = HCV_RULES_VERSION
self.level_def = {'-1': 'Resistance Interpretation Not Available',
Expand All @@ -232,10 +233,13 @@ def load_yaml(self, rules_config, genotype):
region = None
for genotype_config in drug['genotypes']:
region = genotype_config['region']
rule_text = genotype_config['rules']
if genotype_config['genotype'] == genotype:
rule_text = genotype_config['rules']
self.gene_def[genotype_config['reference']] = [region]
break
elif genotype_config['genotype'] == backup_genotype:
self.gene_def.setdefault(genotype_config['reference'], [region])
break
else:
rule_text = 'SCORE FROM ( TRUE => "Not available" )'
drug_rules.append((rule_text, [('scorerange', 'useglobalrange')]))
Expand Down
8 changes: 7 additions & 1 deletion micall/resistance/resistance.py
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,13 @@ def load_asi():
for rule in hcv_rules
for genotype in rule['genotypes']}
for genotype in genotypes:
asi = AsiAlgorithm(rules_yaml=hcv_rules, genotype=genotype)
if len(genotype) > 1 and genotype[0] in genotypes:
backup_genotype = genotype[0]
else:
backup_genotype = None
asi = AsiAlgorithm(rules_yaml=hcv_rules,
genotype=genotype,
backup_genotype=backup_genotype)
algorithms[genotype] = asi

return algorithms
Expand Down
8 changes: 8 additions & 0 deletions micall/tests/test_resistance.py
Original file line number Diff line number Diff line change
Expand Up @@ -999,6 +999,14 @@ def test_read_aminos_missing_position():
assert expected_aminos == aminos


def test_genotype_6e_regions(asi_algorithms):
""" Should have rules for NS3, NS5a, and NS5b. """
asi_6e = asi_algorithms['6E']
expected_regions = {'HCV6-EUHK2-NS3', 'HCV6-EUHK2-NS5a', 'HCV6-EUHK2-NS5b'}

assert expected_regions == set(asi_6e.gene_def.keys())


def test_read_aminos_pos_55_resistant(asi_algorithms):
amino_lines = [
'seed,region,q-cutoff,query.nuc.pos,refseq.aa.pos,'
Expand Down

0 comments on commit da6fa92

Please sign in to comment.