Mercurial > repos > dfornika > blast_report_basic
annotate blast_report.py @ 0:5dfd84907521 draft
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
author | dfornika |
---|---|
date | Tue, 03 Mar 2020 00:14:34 +0000 |
parents | |
children | 386a88793078 |
rev | line source |
---|---|
0
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
1 #!/usr/bin/env python |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
2 '''Report on BLAST results. |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
3 |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
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]] |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
5 ''' |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
6 import argparse |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
7 import re |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
8 import sys |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
9 |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
10 from Cheetah.Template import Template |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
11 |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
12 |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
13 def stop_err( msg ): |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
14 sys.stderr.write("%s\n" % msg) |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
15 sys.exit(1) |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
16 |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
17 |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
18 class BLASTBin: |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
19 def __init__(self, label, file): |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
20 self.label = label |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
21 self.dict = {} |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
22 |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
23 file_in = open(file) |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
24 for line in file_in: |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
25 self.dict[line.rstrip().split('.')[0]] = '' |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
26 file_in.close() |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
27 |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
28 def __str__(self): |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
29 return "label: %s dict: %s" % (self.label, str(self.dict)) |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
30 |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
31 |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
32 class BLASTQuery: |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
33 def __init__(self, query_id): |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
34 self.query_id = query_id |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
35 self.matches = [] |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
36 self.match_accessions = {} |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
37 self.bins = {} #{bin(label):[match indexes]} |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
38 self.pident_filtered = 0 |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
39 self.kw_filtered = 0 |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
40 self.kw_filtered_breakdown = {} #{kw:count} |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
41 |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
42 def __str__(self): |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
43 return "query_id: %s len(matches): %s bins (labels only): %s pident_filtered: %s kw_filtered: %s kw_filtered_breakdown: %s" \ |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
44 % (self.query_id, |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
45 str(len(self.matches)), |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
46 str([bin.label for bin in bins]), |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
47 str(self.pident_filtered), |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
48 str(self.kw_filtered), |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
49 str(self.kw_filtered_breakdown)) |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
50 |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
51 |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
52 class BLASTMatch: |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
53 def __init__(self, subject_acc, subject_descr, score, p_cov, p_ident, subject_bins): |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
54 self.subject_acc = subject_acc |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
55 self.subject_descr = subject_descr |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
56 self.score = score |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
57 self.p_cov = p_cov |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
58 self.p_ident = p_ident |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
59 self.bins = subject_bins |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
60 |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
61 def __str__(self): |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
62 return "subject_acc: %s subject_descr: %s score: %s p-cov: %s p-ident: %s" \ |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
63 % (self.subject_acc, |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
64 self.subject_descr, |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
65 str(self.score), |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
66 str(round(self.p_cov,2)), |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
67 str(round(self.p_ident, 2))) |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
68 |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
69 |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
70 |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
71 #PARSE OPTIONS AND ARGUMENTS |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
72 parser = argparse.ArgumentParser() |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
73 |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
74 parser.add_argument('-f', '--filter', |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
75 type='string', |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
76 dest='filter', |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
77 ) |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
78 parser.add_argument('-b', '--bins', |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
79 type='string', |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
80 dest='bins' |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
81 ) |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
82 parser.add_argument('-r', '--redundant', |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
83 dest='redundant', |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
84 default=False, |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
85 action='store_true' |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
86 ) |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
87 args = parser.parse_args() |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
88 |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
89 try: |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
90 input_tab, cheetah_tmpl, output_html, output_tab = args |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
91 except: |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
92 stop_err('you must supply the arguments input_tab, cheetah_tmpl and output_html.') |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
93 # print('input_tab: %s cheetah_tmpl: %s output_html: %s output_tab: %s' % (input_tab, cheetah_tmpl, output_html, output_tab)) |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
94 |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
95 |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
96 #BINS |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
97 bins=[] |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
98 if args.bins != None: |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
99 bins = list([BLASTBin(label_file.split('=')[0],label_file.split('=')[-1]) for label_file in args.bins.split(',')]) |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
100 print('database bins: %s' % str([bin.label for bin in bins])) |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
101 |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
102 #FILTERS |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
103 filter_pident = 0 |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
104 filter_kws = [] |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
105 if args.filter != None: |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
106 pident_kws = args.filter.split(':') |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
107 filter_pident = float(pident_kws[0]) |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
108 filter_kws = pident_kws[-1].split(',') |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
109 print('filter_pident: %s filter_kws: %s' % (str(filter_pident), str(filter_kws))) |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
110 |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
111 if args.redundant: |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
112 print('Throwing out redundant hits...') |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
113 |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
114 #RESULTS! |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
115 PIDENT_COL = 2 |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
116 DESCR_COL = 25 |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
117 SUBJ_ID_COL = 12 |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
118 SCORE_COL = 11 |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
119 PCOV_COL = 24 |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
120 queries = [] |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
121 current_query = '' |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
122 output_tab = open(output_tab, 'w') |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
123 |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
124 with open(input_tab) as input_tab: |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
125 for line in input_tab: |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
126 cols = line.split('\t') |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
127 if cols[0] != current_query: |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
128 current_query = cols[0] |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
129 queries.append(BLASTQuery(current_query)) |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
130 |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
131 try: |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
132 accs = cols[SUBJ_ID_COL].split('|')[1::2][1::2] |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
133 except IndexError as e: |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
134 stop_err("Problem with splitting:" + cols[SUBJ_ID_COL]) |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
135 |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
136 #hsp option: keep best (first) hit only for each query and accession id. |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
137 if args.redundant: |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
138 if accs[0] in queries[-1].match_accessions: |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
139 continue #don't save the result and skip to the next |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
140 else: |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
141 queries[-1].match_accessions[accs[0]] = '' |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
142 |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
143 |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
144 p_ident = float(cols[PIDENT_COL]) |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
145 #FILTER BY PIDENT |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
146 if p_ident < filter_pident: #if we are not filtering, filter_pident == 0 and this will never evaluate to True |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
147 queries[-1].pident_filtered += 1 |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
148 continue |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
149 |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
150 descrs = cols[DESCR_COL] |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
151 #FILTER BY KEY WORDS |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
152 filter_by_kw = False |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
153 for kw in filter_kws: |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
154 kw = kw.strip() #Fix by Damion D Nov 2013 |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
155 if kw != '' and re.search(kw, descrs, re.IGNORECASE): |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
156 filter_by_kw = True |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
157 try: |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
158 queries[-1].kw_filtered_breakdown[kw] += 1 |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
159 except: |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
160 queries[-1].kw_filtered_breakdown[kw] = 1 |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
161 if filter_by_kw: #if we are not filtering, for loop will not be entered and this will never be True |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
162 queries[-1].kw_filtered += 1 |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
163 continue |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
164 descr = descrs.split(';')[0] |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
165 |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
166 #ATTEMPT BIN |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
167 subj_bins = [] |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
168 for bin in bins: #if we are not binning, bins = [] so for loop not entered |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
169 for acc in accs: |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
170 if acc.split('.')[0] in bin.dict: |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
171 try: |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
172 queries[-1].bins[bin.label].append(len(queries[-1].matches)) |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
173 except: |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
174 queries[-1].bins[bin.label] = [len(queries[-1].matches)] |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
175 subj_bins.append(bin.label) |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
176 break #this result has been binned to this bin so break |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
177 acc = accs[0] |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
178 |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
179 score = int(float(cols[SCORE_COL])) |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
180 p_cov = float(cols[PCOV_COL]) |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
181 |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
182 #SAVE RESULT |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
183 queries[-1].matches.append( |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
184 BLASTMatch(acc, descr, score, p_cov, p_ident, subj_bins) |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
185 ) |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
186 output_tab.write(line) |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
187 input_tab.close() |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
188 output_tab.close() |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
189 |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
190 ''' |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
191 for query in queries: |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
192 print(query) |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
193 for match in query.matches: |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
194 print(' %s' % str(match)) |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
195 for bin in query.bins: |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
196 print(' bin: %s' % bin) |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
197 for x in query.bins[bin]: |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
198 print(' %s' % str(query.matches[x])) |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
199 ''' |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
200 |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
201 namespace = {'queries': queries} |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
202 html = Template(file=cheetah_tmpl, searchList=[namespace]) |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
203 out_html = open(output_html, 'w') |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
204 out_html.write(str(html)) |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
205 out_html.close() |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
206 |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
207 |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
208 if __name__ == '__main__': |
5dfd84907521
planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/blast_report_basic commit bc359460bb66db7946cc68ccbd47cd479624c4a1-dirty
dfornika
parents:
diff
changeset
|
209 main() |