comparison resistance.py @ 0:1e0389317446 draft

"planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/micall-lite commit 9c3ab5825c19a7c400a46f727975edb480a91c09"
author public-health-bioinformatics
date Mon, 06 Jan 2020 19:11:48 -0500
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:1e0389317446
1 #!/usr/bin/env python
2
3 from __future__ import print_function
4
5
6 import argparse
7 from pprint import pprint
8
9
10 import yaml
11
12
13 HCV_RULES_VERSION = "1.8"
14
15
16 def load_rules_config(rules_config, genotype, backup_genotype=None):
17 rules = {
18 'drug_class': {},
19 'drugs': {}
20 }
21 rules['alg_name'] = 'HCV_RULES'
22 rules['alg_version'] = HCV_RULES_VERSION
23 rules['level_def'] = {
24 '-1': 'Resistance Interpretation Not Available',
25 '0': 'Sequence does not meet quality-control standards',
26 '1': 'Likely Susceptible',
27 '2': 'Not Indicated',
28 '3': 'Mutations Detected; Effect Unknown',
29 '4': 'Resistance Possible',
30 '5': 'Resistance Likely'
31 }
32 rules['global_range'] = [('-INF', '3', '1'), ('4', '7', '4'), ('8', 'INF', '5')]
33 for drug in rules_config:
34 drug_code = drug['code']
35 drug_rules = []
36 region = None
37 for genotype_config in drug['genotypes']:
38 region = genotype_config['region']
39 rule_text = genotype_config['rules']
40 if genotype_config['genotype'] == genotype:
41 rules['gene_def'][genotype_config['reference']] = [region]
42 break
43 elif genotype_config['genotype'] == backup_genotype:
44 rules['gene_def'].setdefault(genotype_config['reference'], [region])
45 break
46 else:
47 rule_text = 'SCORE FROM ( TRUE => "Not available" )'
48 drug_rules.append((rule_text, [('scorerange', 'useglobalrange')]))
49 try:
50 rules['drug_class'][region].append(drug_code)
51 except KeyError:
52 rules['drug_class'][region] = [drug_code]
53 rules['drugs'][drug_code] = (drug['name'], drug_rules)
54 return rules
55
56
57 def main(args):
58 with open(args.rules) as f:
59 rules = load_rules_config(yaml.safe_load(f), None)
60 pprint(rules)
61
62
63 if __name__ == '__main__':
64 parser = argparse.ArgumentParser()
65 parser.add_argument("consensus", help="Consensus fasta")
66 parser.add_argument("--rules", help="Rules file (yaml)")
67 args = parser.parse_args()
68 main(args)