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