Mercurial > repos > dfornika > micall_lite
comparison amino2consensus.py @ 23:033e0a3674bc draft
"planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/micall-lite commit d5fd8bc70d31d99c2354f1e8ec2e34d147cfa048-dirty"
author | dfornika |
---|---|
date | Mon, 06 Jan 2020 23:49:32 +0000 |
parents | b5df889acab3 |
children |
comparison
equal
deleted
inserted
replaced
22:b5df889acab3 | 23:033e0a3674bc |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 | 2 |
3 from __future__ import print_function | 3 from __future__ import print_function |
4 | 4 |
5 import argparse | |
5 import csv | 6 import csv |
6 import argparse | |
7 | 7 |
8 AMINO_ACIDS = ['A','C','D','E','F','G','H','I','K','L','M','N','P','Q','R','S','T','V','W','Y','*'] | 8 |
9 AMINO_ACIDS = ['A', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'K', 'L', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'V', 'W', 'Y', '*'] | |
10 | |
9 | 11 |
10 def determine_amino(amino_counts, threshold): | 12 def determine_amino(amino_counts, threshold): |
11 amino = "" | 13 amino = "" |
12 total_count = sum(amino_counts.values()) | 14 total_count = sum(amino_counts.values()) |
13 amino_with_max_counts = sorted(amino_counts, key=amino_counts.get, reverse=True)[0] | 15 amino_with_max_counts = sorted(amino_counts, key=amino_counts.get, reverse=True)[0] |
17 amino = amino_with_max_counts | 19 amino = amino_with_max_counts |
18 else: | 20 else: |
19 amino = "@" | 21 amino = "@" |
20 return amino | 22 return amino |
21 | 23 |
24 | |
22 def determine_first_region(amino_file): | 25 def determine_first_region(amino_file): |
23 with open(amino_file) as f: | 26 with open(amino_file) as f: |
24 reader = csv.DictReader(f) | 27 reader = csv.DictReader(f) |
25 row = next(reader) | 28 row = next(reader) |
26 region = row['region'] | 29 region = row['region'] |
27 return region | 30 return region |
31 | |
28 | 32 |
29 def main(args): | 33 def main(args): |
30 current_region = determine_first_region(args.amino) | 34 current_region = determine_first_region(args.amino) |
31 seq = [] | 35 seq = [] |
32 with open(args.amino) as f: | 36 with open(args.amino) as f: |
48 amino_counts[amino_acid] = int(row[amino_acid]) | 52 amino_counts[amino_acid] = int(row[amino_acid]) |
49 amino = determine_amino(amino_counts, args.threshold) | 53 amino = determine_amino(amino_counts, args.threshold) |
50 seq.append(amino) | 54 seq.append(amino) |
51 print(">" + current_region) | 55 print(">" + current_region) |
52 print(''.join(seq)) | 56 print(''.join(seq)) |
53 | 57 |
54 | 58 |
55 if __name__ == '__main__': | 59 if __name__ == '__main__': |
56 parser = argparse.ArgumentParser() | 60 parser = argparse.ArgumentParser() |
57 parser.add_argument("amino", help="MiCall amino.csv output file") | 61 parser.add_argument("amino", help="MiCall amino.csv output file") |
58 parser.add_argument("--threshold", default=0.15, type=float, help="Threshold for calling") | 62 parser.add_argument("--threshold", default=0.15, type=float, help="Threshold for calling") |
59 args = parser.parse_args() | 63 args = parser.parse_args() |