Mercurial > repos > dfornika > blast_report_basic
comparison blast_report.py @ 3:386a88793078 draft
Uploaded
author | dfornika |
---|---|
date | Tue, 03 Mar 2020 01:09:56 +0000 |
parents | 5dfd84907521 |
children | c7ce2cd96546 |
comparison
equal
deleted
inserted
replaced
2:0dbaa4e68866 | 3:386a88793078 |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 | |
3 from __future__ import print_function | |
4 | |
2 '''Report on BLAST results. | 5 '''Report on BLAST results. |
3 | 6 |
4 python blast_report.py input_tab cheetah_tmpl output_html output_tab [-f [filter_pident]:[filterkw1,...,filterkwN]] [-b bin1_label=bin1_path[,...binN_label=binN_path]] | 7 python blast_report.py input_tab cheetah_tmpl output_html output_tab [-f [filter_pident]:[filterkw1,...,filterkwN]] [-b bin1_label=bin1_path[,...binN_label=binN_path]] |
5 ''' | 8 ''' |
9 | |
6 import argparse | 10 import argparse |
7 import re | 11 import re |
8 import sys | 12 import sys |
9 | 13 |
10 from Cheetah.Template import Template | 14 from Cheetah.Template import Template |
70 | 74 |
71 #PARSE OPTIONS AND ARGUMENTS | 75 #PARSE OPTIONS AND ARGUMENTS |
72 parser = argparse.ArgumentParser() | 76 parser = argparse.ArgumentParser() |
73 | 77 |
74 parser.add_argument('-f', '--filter', | 78 parser.add_argument('-f', '--filter', |
75 type='string', | |
76 dest='filter', | 79 dest='filter', |
77 ) | 80 ) |
78 parser.add_argument('-b', '--bins', | 81 parser.add_argument('-b', '--bins', |
79 type='string', | |
80 dest='bins' | 82 dest='bins' |
81 ) | 83 ) |
82 parser.add_argument('-r', '--redundant', | 84 parser.add_argument('-r', '--discard-redundant', |
83 dest='redundant', | 85 dest='discard_redundant', |
86 type=bool, | |
84 default=False, | 87 default=False, |
85 action='store_true' | 88 action='store_true' |
86 ) | 89 ) |
87 args = parser.parse_args() | 90 args = parser.parse_args() |
88 | 91 |
106 pident_kws = args.filter.split(':') | 109 pident_kws = args.filter.split(':') |
107 filter_pident = float(pident_kws[0]) | 110 filter_pident = float(pident_kws[0]) |
108 filter_kws = pident_kws[-1].split(',') | 111 filter_kws = pident_kws[-1].split(',') |
109 print('filter_pident: %s filter_kws: %s' % (str(filter_pident), str(filter_kws))) | 112 print('filter_pident: %s filter_kws: %s' % (str(filter_pident), str(filter_kws))) |
110 | 113 |
111 if args.redundant: | 114 if args.discard_redundant: |
112 print('Throwing out redundant hits...') | 115 print('Throwing out redundant hits...') |
113 | 116 |
114 #RESULTS! | 117 #RESULTS! |
115 PIDENT_COL = 2 | 118 PIDENT_COL = 2 |
116 DESCR_COL = 25 | 119 DESCR_COL = 25 |
132 accs = cols[SUBJ_ID_COL].split('|')[1::2][1::2] | 135 accs = cols[SUBJ_ID_COL].split('|')[1::2][1::2] |
133 except IndexError as e: | 136 except IndexError as e: |
134 stop_err("Problem with splitting:" + cols[SUBJ_ID_COL]) | 137 stop_err("Problem with splitting:" + cols[SUBJ_ID_COL]) |
135 | 138 |
136 #hsp option: keep best (first) hit only for each query and accession id. | 139 #hsp option: keep best (first) hit only for each query and accession id. |
137 if args.redundant: | 140 if args.discard_redundant: |
138 if accs[0] in queries[-1].match_accessions: | 141 if accs[0] in queries[-1].match_accessions: |
139 continue #don't save the result and skip to the next | 142 continue #don't save the result and skip to the next |
140 else: | 143 else: |
141 queries[-1].match_accessions[accs[0]] = '' | 144 queries[-1].match_accessions[accs[0]] = '' |
142 | 145 |