annotate resistance.py @ 2:ee780352368b draft

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