changeset 7:445a1923bb97 draft

Uploaded
author dfornika
date Tue, 03 Mar 2020 05:34:11 +0000
parents b8a3578b6445
children c4e67d856c19
files blast_report.py
diffstat 1 files changed, 20 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/blast_report.py	Tue Mar 03 05:33:55 2020 +0000
+++ b/blast_report.py	Tue Mar 03 05:34:11 2020 +0000
@@ -71,12 +71,14 @@
                str(round(self.p_ident, 2)))
 
 
-
 #PARSE OPTIONS AND ARGUMENTS
 parser = argparse.ArgumentParser()
 
-parser.add_argument('-f', '--filter',
-                    dest='filter',
+parser.add_argument('-f', '--filter-keywords',
+                    dest='filter_keywords',
+                    )
+parser.add_argument('-i', '--min-identity',
+                    dest='min_identity',
                     )
 parser.add_argument('-b', '--bins',
                     dest='bins'
@@ -86,13 +88,17 @@
                     default=False,
                     action='store_true'
                     )
+parser.add_argument('input_tab')
+parser.add_argument('cheetah_tmpl')
+parser.add_argument('output_html')
+parser.add_argument('output_tab')
 args = parser.parse_args()
 
 try:
     input_tab, cheetah_tmpl, output_html, output_tab = args
 except:
     stop_err('you must supply the arguments input_tab, cheetah_tmpl and output_html.')
-# print('input_tab: %s    cheetah_tmpl: %s    output_html: %s    output_tab: %s' % (input_tab, cheetah_tmpl, output_html, output_tab))
+print('input_tab: %s    cheetah_tmpl: %s    output_html: %s    output_tab: %s' % (args.input_tab, args.cheetah_tmpl, args.output_html, args.output_tab))
 
 
 #BINS
@@ -101,19 +107,17 @@
     bins = list([BLASTBin(label_file.split('=')[0],label_file.split('=')[-1]) for label_file in args.bins.split(',')])
 print('database bins: %s' % str([bin.label for bin in bins]))
 
-    #FILTERS
+#FILTERS
 filter_pident = 0
 filter_kws = []
-if args.filter != None:
-    pident_kws = args.filter.split(':')
-    filter_pident = float(pident_kws[0])
-    filter_kws = pident_kws[-1].split(',')
-print('filter_pident: %s    filter_kws: %s' % (str(filter_pident), str(filter_kws)))
+if args.keyword_filter:
+    filter_kws = args.keyword_filter.split(',')
+print('minimum percent identity: %s    filter_kws: %s' % (str(args.min_identity), str(filter_kws)))
 
 if args.discard_redundant:
     print('Throwing out redundant hits...')
 
-#RESULTS!
+
 PIDENT_COL = 2
 DESCR_COL = 25
 SUBJ_ID_COL = 12
@@ -121,9 +125,9 @@
 PCOV_COL = 24
 queries = []
 current_query = ''
-output_tab = open(output_tab, 'w')
+output_tab = open(args.output_tab, 'w')
     
-with open(input_tab) as input_tab:
+with open(args.input_tab) as input_tab:
     for line in input_tab:
         cols = line.split('\t')
         if cols[0] != current_query:
@@ -153,7 +157,7 @@
         #FILTER BY KEY WORDS
         filter_by_kw = False
         for kw in filter_kws:
-            kw = kw.strip() #Fix by Damion D Nov 2013
+            kw = kw.strip()
             if kw != '' and re.search(kw, descrs, re.IGNORECASE):
                 filter_by_kw = True
                 try:
@@ -201,8 +205,8 @@
 '''
 
 namespace = {'queries': queries}
-html = Template(file=cheetah_tmpl, searchList=[namespace])
-out_html = open(output_html, 'w')
+html = Template(file=args.cheetah_tmpl, searchList=[namespace])
+out_html = open(args.output_html, 'w')
 out_html.write(str(html))
 out_html.close()