Mercurial > repos > devteam > ncbi_blast_plus
annotate tools/ncbi_blast_plus/blastxml_to_tabular.py @ 18:577d9c12411a draft
v0.1.06, now using BLAST+ 2.2.31
author | peterjc |
---|---|
date | Mon, 07 Sep 2015 04:44:24 -0400 |
parents | c16c30e9ad5b |
children | 3034ce97dd33 |
rev | line source |
---|---|
3
643338ac83c0
Uploaded v0.0.12b, same code but moving folders around to match all my other tools and make future development simpler.
peterjc
parents:
diff
changeset
|
1 #!/usr/bin/env python |
10
70e7dcbf6573
Uploaded v0.0.20, handles dependencies via package_blast_plus_2_2_26, development moved to GitHub, RST README, MIT licence, citation information, more tests, percentage identity option to BLASTN, cElementTree to ElementTree fallback.
peterjc
parents:
3
diff
changeset
|
2 """Convert a BLAST XML file to tabular output. |
3
643338ac83c0
Uploaded v0.0.12b, same code but moving folders around to match all my other tools and make future development simpler.
peterjc
parents:
diff
changeset
|
3 |
15
c16c30e9ad5b
Uploaded v0.1.03 (internal changes); v0.1.02 (BLAST+ 2.2.30 etc)
peterjc
parents:
14
diff
changeset
|
4 Designed to convert BLAST XML files into tabular BLAST output (either |
c16c30e9ad5b
Uploaded v0.1.03 (internal changes); v0.1.02 (BLAST+ 2.2.30 etc)
peterjc
parents:
14
diff
changeset
|
5 std for standard 12 columns, or ext for the extended 25 columns offered |
c16c30e9ad5b
Uploaded v0.1.03 (internal changes); v0.1.02 (BLAST+ 2.2.30 etc)
peterjc
parents:
14
diff
changeset
|
6 in the Galaxy BLAST+ wrappers). |
3
643338ac83c0
Uploaded v0.0.12b, same code but moving folders around to match all my other tools and make future development simpler.
peterjc
parents:
diff
changeset
|
7 |
643338ac83c0
Uploaded v0.0.12b, same code but moving folders around to match all my other tools and make future development simpler.
peterjc
parents:
diff
changeset
|
8 The 12 columns output are 'qseqid sseqid pident length mismatch gapopen qstart |
643338ac83c0
Uploaded v0.0.12b, same code but moving folders around to match all my other tools and make future development simpler.
peterjc
parents:
diff
changeset
|
9 qend sstart send evalue bitscore' or 'std' at the BLAST+ command line, which |
643338ac83c0
Uploaded v0.0.12b, same code but moving folders around to match all my other tools and make future development simpler.
peterjc
parents:
diff
changeset
|
10 mean: |
643338ac83c0
Uploaded v0.0.12b, same code but moving folders around to match all my other tools and make future development simpler.
peterjc
parents:
diff
changeset
|
11 |
643338ac83c0
Uploaded v0.0.12b, same code but moving folders around to match all my other tools and make future development simpler.
peterjc
parents:
diff
changeset
|
12 ====== ========= ============================================ |
643338ac83c0
Uploaded v0.0.12b, same code but moving folders around to match all my other tools and make future development simpler.
peterjc
parents:
diff
changeset
|
13 Column NCBI name Description |
643338ac83c0
Uploaded v0.0.12b, same code but moving folders around to match all my other tools and make future development simpler.
peterjc
parents:
diff
changeset
|
14 ------ --------- -------------------------------------------- |
643338ac83c0
Uploaded v0.0.12b, same code but moving folders around to match all my other tools and make future development simpler.
peterjc
parents:
diff
changeset
|
15 1 qseqid Query Seq-id (ID of your sequence) |
643338ac83c0
Uploaded v0.0.12b, same code but moving folders around to match all my other tools and make future development simpler.
peterjc
parents:
diff
changeset
|
16 2 sseqid Subject Seq-id (ID of the database hit) |
643338ac83c0
Uploaded v0.0.12b, same code but moving folders around to match all my other tools and make future development simpler.
peterjc
parents:
diff
changeset
|
17 3 pident Percentage of identical matches |
643338ac83c0
Uploaded v0.0.12b, same code but moving folders around to match all my other tools and make future development simpler.
peterjc
parents:
diff
changeset
|
18 4 length Alignment length |
643338ac83c0
Uploaded v0.0.12b, same code but moving folders around to match all my other tools and make future development simpler.
peterjc
parents:
diff
changeset
|
19 5 mismatch Number of mismatches |
643338ac83c0
Uploaded v0.0.12b, same code but moving folders around to match all my other tools and make future development simpler.
peterjc
parents:
diff
changeset
|
20 6 gapopen Number of gap openings |
643338ac83c0
Uploaded v0.0.12b, same code but moving folders around to match all my other tools and make future development simpler.
peterjc
parents:
diff
changeset
|
21 7 qstart Start of alignment in query |
643338ac83c0
Uploaded v0.0.12b, same code but moving folders around to match all my other tools and make future development simpler.
peterjc
parents:
diff
changeset
|
22 8 qend End of alignment in query |
643338ac83c0
Uploaded v0.0.12b, same code but moving folders around to match all my other tools and make future development simpler.
peterjc
parents:
diff
changeset
|
23 9 sstart Start of alignment in subject (database hit) |
643338ac83c0
Uploaded v0.0.12b, same code but moving folders around to match all my other tools and make future development simpler.
peterjc
parents:
diff
changeset
|
24 10 send End of alignment in subject (database hit) |
643338ac83c0
Uploaded v0.0.12b, same code but moving folders around to match all my other tools and make future development simpler.
peterjc
parents:
diff
changeset
|
25 11 evalue Expectation value (E-value) |
643338ac83c0
Uploaded v0.0.12b, same code but moving folders around to match all my other tools and make future development simpler.
peterjc
parents:
diff
changeset
|
26 12 bitscore Bit score |
643338ac83c0
Uploaded v0.0.12b, same code but moving folders around to match all my other tools and make future development simpler.
peterjc
parents:
diff
changeset
|
27 ====== ========= ============================================ |
643338ac83c0
Uploaded v0.0.12b, same code but moving folders around to match all my other tools and make future development simpler.
peterjc
parents:
diff
changeset
|
28 |
643338ac83c0
Uploaded v0.0.12b, same code but moving folders around to match all my other tools and make future development simpler.
peterjc
parents:
diff
changeset
|
29 The additional columns offered in the Galaxy BLAST+ wrappers are: |
643338ac83c0
Uploaded v0.0.12b, same code but moving folders around to match all my other tools and make future development simpler.
peterjc
parents:
diff
changeset
|
30 |
643338ac83c0
Uploaded v0.0.12b, same code but moving folders around to match all my other tools and make future development simpler.
peterjc
parents:
diff
changeset
|
31 ====== ============= =========================================== |
643338ac83c0
Uploaded v0.0.12b, same code but moving folders around to match all my other tools and make future development simpler.
peterjc
parents:
diff
changeset
|
32 Column NCBI name Description |
643338ac83c0
Uploaded v0.0.12b, same code but moving folders around to match all my other tools and make future development simpler.
peterjc
parents:
diff
changeset
|
33 ------ ------------- ------------------------------------------- |
11
4c4a0da938ff
Uploaded v0.0.22, now wraps BLAST+ 2.2.28 allowing extended tabular output to include the hit descriptions as column 25.
peterjc
parents:
10
diff
changeset
|
34 13 sallseqid All subject Seq-id(s), separated by ';' |
3
643338ac83c0
Uploaded v0.0.12b, same code but moving folders around to match all my other tools and make future development simpler.
peterjc
parents:
diff
changeset
|
35 14 score Raw score |
643338ac83c0
Uploaded v0.0.12b, same code but moving folders around to match all my other tools and make future development simpler.
peterjc
parents:
diff
changeset
|
36 15 nident Number of identical matches |
643338ac83c0
Uploaded v0.0.12b, same code but moving folders around to match all my other tools and make future development simpler.
peterjc
parents:
diff
changeset
|
37 16 positive Number of positive-scoring matches |
643338ac83c0
Uploaded v0.0.12b, same code but moving folders around to match all my other tools and make future development simpler.
peterjc
parents:
diff
changeset
|
38 17 gaps Total number of gaps |
643338ac83c0
Uploaded v0.0.12b, same code but moving folders around to match all my other tools and make future development simpler.
peterjc
parents:
diff
changeset
|
39 18 ppos Percentage of positive-scoring matches |
643338ac83c0
Uploaded v0.0.12b, same code but moving folders around to match all my other tools and make future development simpler.
peterjc
parents:
diff
changeset
|
40 19 qframe Query frame |
643338ac83c0
Uploaded v0.0.12b, same code but moving folders around to match all my other tools and make future development simpler.
peterjc
parents:
diff
changeset
|
41 20 sframe Subject frame |
643338ac83c0
Uploaded v0.0.12b, same code but moving folders around to match all my other tools and make future development simpler.
peterjc
parents:
diff
changeset
|
42 21 qseq Aligned part of query sequence |
643338ac83c0
Uploaded v0.0.12b, same code but moving folders around to match all my other tools and make future development simpler.
peterjc
parents:
diff
changeset
|
43 22 sseq Aligned part of subject sequence |
643338ac83c0
Uploaded v0.0.12b, same code but moving folders around to match all my other tools and make future development simpler.
peterjc
parents:
diff
changeset
|
44 23 qlen Query sequence length |
643338ac83c0
Uploaded v0.0.12b, same code but moving folders around to match all my other tools and make future development simpler.
peterjc
parents:
diff
changeset
|
45 24 slen Subject sequence length |
11
4c4a0da938ff
Uploaded v0.0.22, now wraps BLAST+ 2.2.28 allowing extended tabular output to include the hit descriptions as column 25.
peterjc
parents:
10
diff
changeset
|
46 25 salltitles All subject titles, separated by '<>' |
3
643338ac83c0
Uploaded v0.0.12b, same code but moving folders around to match all my other tools and make future development simpler.
peterjc
parents:
diff
changeset
|
47 ====== ============= =========================================== |
643338ac83c0
Uploaded v0.0.12b, same code but moving folders around to match all my other tools and make future development simpler.
peterjc
parents:
diff
changeset
|
48 |
643338ac83c0
Uploaded v0.0.12b, same code but moving folders around to match all my other tools and make future development simpler.
peterjc
parents:
diff
changeset
|
49 Most of these fields are given explicitly in the XML file, others some like |
643338ac83c0
Uploaded v0.0.12b, same code but moving folders around to match all my other tools and make future development simpler.
peterjc
parents:
diff
changeset
|
50 the percentage identity and the number of gap openings must be calculated. |
643338ac83c0
Uploaded v0.0.12b, same code but moving folders around to match all my other tools and make future development simpler.
peterjc
parents:
diff
changeset
|
51 |
643338ac83c0
Uploaded v0.0.12b, same code but moving folders around to match all my other tools and make future development simpler.
peterjc
parents:
diff
changeset
|
52 Be aware that the sequence in the extended tabular output or XML direct from |
643338ac83c0
Uploaded v0.0.12b, same code but moving folders around to match all my other tools and make future development simpler.
peterjc
parents:
diff
changeset
|
53 BLAST+ may or may not use XXXX masking on regions of low complexity. This |
643338ac83c0
Uploaded v0.0.12b, same code but moving folders around to match all my other tools and make future development simpler.
peterjc
parents:
diff
changeset
|
54 can throw the off the calculation of percentage identity and gap openings. |
643338ac83c0
Uploaded v0.0.12b, same code but moving folders around to match all my other tools and make future development simpler.
peterjc
parents:
diff
changeset
|
55 [In fact, both BLAST 2.2.24+ and 2.2.25+ have a subtle bug in this regard, |
643338ac83c0
Uploaded v0.0.12b, same code but moving folders around to match all my other tools and make future development simpler.
peterjc
parents:
diff
changeset
|
56 with these numbers changing depending on whether or not the low complexity |
643338ac83c0
Uploaded v0.0.12b, same code but moving folders around to match all my other tools and make future development simpler.
peterjc
parents:
diff
changeset
|
57 filter is used.] |
643338ac83c0
Uploaded v0.0.12b, same code but moving folders around to match all my other tools and make future development simpler.
peterjc
parents:
diff
changeset
|
58 |
643338ac83c0
Uploaded v0.0.12b, same code but moving folders around to match all my other tools and make future development simpler.
peterjc
parents:
diff
changeset
|
59 This script attempts to produce identical output to what BLAST+ would have done. |
643338ac83c0
Uploaded v0.0.12b, same code but moving folders around to match all my other tools and make future development simpler.
peterjc
parents:
diff
changeset
|
60 However, check this with "diff -b ..." since BLAST+ sometimes includes an extra |
643338ac83c0
Uploaded v0.0.12b, same code but moving folders around to match all my other tools and make future development simpler.
peterjc
parents:
diff
changeset
|
61 space character (probably a bug). |
643338ac83c0
Uploaded v0.0.12b, same code but moving folders around to match all my other tools and make future development simpler.
peterjc
parents:
diff
changeset
|
62 """ |
643338ac83c0
Uploaded v0.0.12b, same code but moving folders around to match all my other tools and make future development simpler.
peterjc
parents:
diff
changeset
|
63 import sys |
643338ac83c0
Uploaded v0.0.12b, same code but moving folders around to match all my other tools and make future development simpler.
peterjc
parents:
diff
changeset
|
64 import re |
13
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
65 import os |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
66 from optparse import OptionParser |
3
643338ac83c0
Uploaded v0.0.12b, same code but moving folders around to match all my other tools and make future development simpler.
peterjc
parents:
diff
changeset
|
67 |
10
70e7dcbf6573
Uploaded v0.0.20, handles dependencies via package_blast_plus_2_2_26, development moved to GitHub, RST README, MIT licence, citation information, more tests, percentage identity option to BLASTN, cElementTree to ElementTree fallback.
peterjc
parents:
3
diff
changeset
|
68 if "-v" in sys.argv or "--version" in sys.argv: |
15
c16c30e9ad5b
Uploaded v0.1.03 (internal changes); v0.1.02 (BLAST+ 2.2.30 etc)
peterjc
parents:
14
diff
changeset
|
69 print "v0.1.04" |
10
70e7dcbf6573
Uploaded v0.0.20, handles dependencies via package_blast_plus_2_2_26, development moved to GitHub, RST README, MIT licence, citation information, more tests, percentage identity option to BLASTN, cElementTree to ElementTree fallback.
peterjc
parents:
3
diff
changeset
|
70 sys.exit(0) |
70e7dcbf6573
Uploaded v0.0.20, handles dependencies via package_blast_plus_2_2_26, development moved to GitHub, RST README, MIT licence, citation information, more tests, percentage identity option to BLASTN, cElementTree to ElementTree fallback.
peterjc
parents:
3
diff
changeset
|
71 |
3
643338ac83c0
Uploaded v0.0.12b, same code but moving folders around to match all my other tools and make future development simpler.
peterjc
parents:
diff
changeset
|
72 if sys.version_info[:2] >= ( 2, 5 ): |
10
70e7dcbf6573
Uploaded v0.0.20, handles dependencies via package_blast_plus_2_2_26, development moved to GitHub, RST README, MIT licence, citation information, more tests, percentage identity option to BLASTN, cElementTree to ElementTree fallback.
peterjc
parents:
3
diff
changeset
|
73 try: |
70e7dcbf6573
Uploaded v0.0.20, handles dependencies via package_blast_plus_2_2_26, development moved to GitHub, RST README, MIT licence, citation information, more tests, percentage identity option to BLASTN, cElementTree to ElementTree fallback.
peterjc
parents:
3
diff
changeset
|
74 from xml.etree import cElementTree as ElementTree |
70e7dcbf6573
Uploaded v0.0.20, handles dependencies via package_blast_plus_2_2_26, development moved to GitHub, RST README, MIT licence, citation information, more tests, percentage identity option to BLASTN, cElementTree to ElementTree fallback.
peterjc
parents:
3
diff
changeset
|
75 except ImportError: |
70e7dcbf6573
Uploaded v0.0.20, handles dependencies via package_blast_plus_2_2_26, development moved to GitHub, RST README, MIT licence, citation information, more tests, percentage identity option to BLASTN, cElementTree to ElementTree fallback.
peterjc
parents:
3
diff
changeset
|
76 from xml.etree import ElementTree as ElementTree |
3
643338ac83c0
Uploaded v0.0.12b, same code but moving folders around to match all my other tools and make future development simpler.
peterjc
parents:
diff
changeset
|
77 else: |
643338ac83c0
Uploaded v0.0.12b, same code but moving folders around to match all my other tools and make future development simpler.
peterjc
parents:
diff
changeset
|
78 from galaxy import eggs |
643338ac83c0
Uploaded v0.0.12b, same code but moving folders around to match all my other tools and make future development simpler.
peterjc
parents:
diff
changeset
|
79 import pkg_resources; pkg_resources.require( "elementtree" ) |
643338ac83c0
Uploaded v0.0.12b, same code but moving folders around to match all my other tools and make future development simpler.
peterjc
parents:
diff
changeset
|
80 from elementtree import ElementTree |
643338ac83c0
Uploaded v0.0.12b, same code but moving folders around to match all my other tools and make future development simpler.
peterjc
parents:
diff
changeset
|
81 |
643338ac83c0
Uploaded v0.0.12b, same code but moving folders around to match all my other tools and make future development simpler.
peterjc
parents:
diff
changeset
|
82 def stop_err( msg ): |
643338ac83c0
Uploaded v0.0.12b, same code but moving folders around to match all my other tools and make future development simpler.
peterjc
parents:
diff
changeset
|
83 sys.stderr.write("%s\n" % msg) |
643338ac83c0
Uploaded v0.0.12b, same code but moving folders around to match all my other tools and make future development simpler.
peterjc
parents:
diff
changeset
|
84 sys.exit(1) |
643338ac83c0
Uploaded v0.0.12b, same code but moving folders around to match all my other tools and make future development simpler.
peterjc
parents:
diff
changeset
|
85 |
13
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
86 if len(sys.argv) == 4 and sys.argv[3] in ["std", "x22", "ext"]: |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
87 #False positive if user really has a BLAST XML file called 'std' or 'ext'... |
14
2fe07f50a41e
Uploaded v0.1.01 - Requires blastdbd datatype (blast_datatypes v0.0.19). Support for makeprofiledb to create protein domain databases and use them in RPS-BLAST and RPS-TBLASTN. Tools now support GI and SeqID filters, and embed the citations.
peterjc
parents:
13
diff
changeset
|
88 stop_err("""ERROR: The script API has changed, sorry. |
2fe07f50a41e
Uploaded v0.1.01 - Requires blastdbd datatype (blast_datatypes v0.0.19). Support for makeprofiledb to create protein domain databases and use them in RPS-BLAST and RPS-TBLASTN. Tools now support GI and SeqID filters, and embed the citations.
peterjc
parents:
13
diff
changeset
|
89 |
2fe07f50a41e
Uploaded v0.1.01 - Requires blastdbd datatype (blast_datatypes v0.0.19). Support for makeprofiledb to create protein domain databases and use them in RPS-BLAST and RPS-TBLASTN. Tools now support GI and SeqID filters, and embed the citations.
peterjc
parents:
13
diff
changeset
|
90 Instead of the old style: |
2fe07f50a41e
Uploaded v0.1.01 - Requires blastdbd datatype (blast_datatypes v0.0.19). Support for makeprofiledb to create protein domain databases and use them in RPS-BLAST and RPS-TBLASTN. Tools now support GI and SeqID filters, and embed the citations.
peterjc
parents:
13
diff
changeset
|
91 |
2fe07f50a41e
Uploaded v0.1.01 - Requires blastdbd datatype (blast_datatypes v0.0.19). Support for makeprofiledb to create protein domain databases and use them in RPS-BLAST and RPS-TBLASTN. Tools now support GI and SeqID filters, and embed the citations.
peterjc
parents:
13
diff
changeset
|
92 $ python blastxml_to_tabular.py input.xml output.tabular std |
2fe07f50a41e
Uploaded v0.1.01 - Requires blastdbd datatype (blast_datatypes v0.0.19). Support for makeprofiledb to create protein domain databases and use them in RPS-BLAST and RPS-TBLASTN. Tools now support GI and SeqID filters, and embed the citations.
peterjc
parents:
13
diff
changeset
|
93 |
2fe07f50a41e
Uploaded v0.1.01 - Requires blastdbd datatype (blast_datatypes v0.0.19). Support for makeprofiledb to create protein domain databases and use them in RPS-BLAST and RPS-TBLASTN. Tools now support GI and SeqID filters, and embed the citations.
peterjc
parents:
13
diff
changeset
|
94 Please use: |
2fe07f50a41e
Uploaded v0.1.01 - Requires blastdbd datatype (blast_datatypes v0.0.19). Support for makeprofiledb to create protein domain databases and use them in RPS-BLAST and RPS-TBLASTN. Tools now support GI and SeqID filters, and embed the citations.
peterjc
parents:
13
diff
changeset
|
95 |
2fe07f50a41e
Uploaded v0.1.01 - Requires blastdbd datatype (blast_datatypes v0.0.19). Support for makeprofiledb to create protein domain databases and use them in RPS-BLAST and RPS-TBLASTN. Tools now support GI and SeqID filters, and embed the citations.
peterjc
parents:
13
diff
changeset
|
96 $ python blastxml_to_tabular.py -o output.tabular -c std input.xml |
2fe07f50a41e
Uploaded v0.1.01 - Requires blastdbd datatype (blast_datatypes v0.0.19). Support for makeprofiledb to create protein domain databases and use them in RPS-BLAST and RPS-TBLASTN. Tools now support GI and SeqID filters, and embed the citations.
peterjc
parents:
13
diff
changeset
|
97 |
2fe07f50a41e
Uploaded v0.1.01 - Requires blastdbd datatype (blast_datatypes v0.0.19). Support for makeprofiledb to create protein domain databases and use them in RPS-BLAST and RPS-TBLASTN. Tools now support GI and SeqID filters, and embed the citations.
peterjc
parents:
13
diff
changeset
|
98 For more information, use: |
2fe07f50a41e
Uploaded v0.1.01 - Requires blastdbd datatype (blast_datatypes v0.0.19). Support for makeprofiledb to create protein domain databases and use them in RPS-BLAST and RPS-TBLASTN. Tools now support GI and SeqID filters, and embed the citations.
peterjc
parents:
13
diff
changeset
|
99 |
2fe07f50a41e
Uploaded v0.1.01 - Requires blastdbd datatype (blast_datatypes v0.0.19). Support for makeprofiledb to create protein domain databases and use them in RPS-BLAST and RPS-TBLASTN. Tools now support GI and SeqID filters, and embed the citations.
peterjc
parents:
13
diff
changeset
|
100 $ python blastxml_to_tabular.py -h |
2fe07f50a41e
Uploaded v0.1.01 - Requires blastdbd datatype (blast_datatypes v0.0.19). Support for makeprofiledb to create protein domain databases and use them in RPS-BLAST and RPS-TBLASTN. Tools now support GI and SeqID filters, and embed the citations.
peterjc
parents:
13
diff
changeset
|
101 """) |
13
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
102 |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
103 usage = """usage: %prog [options] blastxml[,...] |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
104 |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
105 Convert one (or more) BLAST XML files into a single tabular file. |
3
643338ac83c0
Uploaded v0.0.12b, same code but moving folders around to match all my other tools and make future development simpler.
peterjc
parents:
diff
changeset
|
106 |
13
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
107 The columns option can be 'std' (standard 12 columns), 'ext' |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
108 (extended 25 columns), or a list of BLAST+ column names like |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
109 'qseqid,sseqid,pident' (space or comma separated). |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
110 """ |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
111 parser = OptionParser(usage=usage) |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
112 parser.add_option('-o', '--output', dest='output', default=None, help='output filename (defaults to stdout)', metavar="FILE") |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
113 parser.add_option("-c", "--columns", dest="columns", default='std', help="[std|ext|col1,col2,...] standard 12 columns, extended 25 columns, or list of column names") |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
114 (options, args) = parser.parse_args() |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
115 |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
116 colnames = 'qseqid,sseqid,pident,length,mismatch,gapopen,qstart,qend,sstart,send,evalue,bitscore,sallseqid,score,nident,positive,gaps,ppos,qframe,sframe,qseq,sseq,qlen,slen,salltitles'.split(',') |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
117 |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
118 if len(args) < 1: |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
119 stop_err("ERROR: No BLASTXML input files given; run with --help to see options.") |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
120 |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
121 out_fmt = options.columns |
3
643338ac83c0
Uploaded v0.0.12b, same code but moving folders around to match all my other tools and make future development simpler.
peterjc
parents:
diff
changeset
|
122 if out_fmt == "std": |
643338ac83c0
Uploaded v0.0.12b, same code but moving folders around to match all my other tools and make future development simpler.
peterjc
parents:
diff
changeset
|
123 extended = False |
13
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
124 cols = None |
3
643338ac83c0
Uploaded v0.0.12b, same code but moving folders around to match all my other tools and make future development simpler.
peterjc
parents:
diff
changeset
|
125 elif out_fmt == "x22": |
11
4c4a0da938ff
Uploaded v0.0.22, now wraps BLAST+ 2.2.28 allowing extended tabular output to include the hit descriptions as column 25.
peterjc
parents:
10
diff
changeset
|
126 stop_err("Format argument x22 has been replaced with ext (extended 25 columns)") |
3
643338ac83c0
Uploaded v0.0.12b, same code but moving folders around to match all my other tools and make future development simpler.
peterjc
parents:
diff
changeset
|
127 elif out_fmt == "ext": |
643338ac83c0
Uploaded v0.0.12b, same code but moving folders around to match all my other tools and make future development simpler.
peterjc
parents:
diff
changeset
|
128 extended = True |
13
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
129 cols = None |
3
643338ac83c0
Uploaded v0.0.12b, same code but moving folders around to match all my other tools and make future development simpler.
peterjc
parents:
diff
changeset
|
130 else: |
13
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
131 cols = out_fmt.replace(" ", ",").split(",") #Allow space or comma separated |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
132 #Remove any blank entries due to trailing comma, |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
133 #or annoying "None" dummy value from Galaxy if no columns |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
134 cols = [c for c in cols if c and c != "None"] |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
135 extra = set(cols).difference(colnames) |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
136 if extra: |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
137 stop_err("These are not recognised column names: %s" % ",".join(sorted(extra))) |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
138 del extra |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
139 assert set(colnames).issuperset(cols), cols |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
140 if not cols: |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
141 stop_err("No columns selected!") |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
142 extended = max(colnames.index(c) for c in cols) >= 12 #Do we need any higher columns? |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
143 del out_fmt |
3
643338ac83c0
Uploaded v0.0.12b, same code but moving folders around to match all my other tools and make future development simpler.
peterjc
parents:
diff
changeset
|
144 |
13
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
145 for in_file in args: |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
146 if not os.path.isfile(in_file): |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
147 stop_err("Input BLAST XML file not found: %s" % in_file) |
3
643338ac83c0
Uploaded v0.0.12b, same code but moving folders around to match all my other tools and make future development simpler.
peterjc
parents:
diff
changeset
|
148 |
643338ac83c0
Uploaded v0.0.12b, same code but moving folders around to match all my other tools and make future development simpler.
peterjc
parents:
diff
changeset
|
149 |
643338ac83c0
Uploaded v0.0.12b, same code but moving folders around to match all my other tools and make future development simpler.
peterjc
parents:
diff
changeset
|
150 re_default_query_id = re.compile("^Query_\d+$") |
643338ac83c0
Uploaded v0.0.12b, same code but moving folders around to match all my other tools and make future development simpler.
peterjc
parents:
diff
changeset
|
151 assert re_default_query_id.match("Query_101") |
643338ac83c0
Uploaded v0.0.12b, same code but moving folders around to match all my other tools and make future development simpler.
peterjc
parents:
diff
changeset
|
152 assert not re_default_query_id.match("Query_101a") |
643338ac83c0
Uploaded v0.0.12b, same code but moving folders around to match all my other tools and make future development simpler.
peterjc
parents:
diff
changeset
|
153 assert not re_default_query_id.match("MyQuery_101") |
643338ac83c0
Uploaded v0.0.12b, same code but moving folders around to match all my other tools and make future development simpler.
peterjc
parents:
diff
changeset
|
154 re_default_subject_id = re.compile("^Subject_\d+$") |
643338ac83c0
Uploaded v0.0.12b, same code but moving folders around to match all my other tools and make future development simpler.
peterjc
parents:
diff
changeset
|
155 assert re_default_subject_id.match("Subject_1") |
643338ac83c0
Uploaded v0.0.12b, same code but moving folders around to match all my other tools and make future development simpler.
peterjc
parents:
diff
changeset
|
156 assert not re_default_subject_id.match("Subject_") |
643338ac83c0
Uploaded v0.0.12b, same code but moving folders around to match all my other tools and make future development simpler.
peterjc
parents:
diff
changeset
|
157 assert not re_default_subject_id.match("Subject_12a") |
643338ac83c0
Uploaded v0.0.12b, same code but moving folders around to match all my other tools and make future development simpler.
peterjc
parents:
diff
changeset
|
158 assert not re_default_subject_id.match("TheSubject_1") |
643338ac83c0
Uploaded v0.0.12b, same code but moving folders around to match all my other tools and make future development simpler.
peterjc
parents:
diff
changeset
|
159 |
643338ac83c0
Uploaded v0.0.12b, same code but moving folders around to match all my other tools and make future development simpler.
peterjc
parents:
diff
changeset
|
160 |
13
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
161 def convert(blastxml_filename, output_handle): |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
162 blast_program = None |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
163 # get an iterable |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
164 try: |
15
c16c30e9ad5b
Uploaded v0.1.03 (internal changes); v0.1.02 (BLAST+ 2.2.30 etc)
peterjc
parents:
14
diff
changeset
|
165 context = ElementTree.iterparse(blastxml_filename, events=("start", "end")) |
13
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
166 except: |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
167 stop_err("Invalid data format.") |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
168 # turn it into an iterator |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
169 context = iter(context) |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
170 # get the root element |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
171 try: |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
172 event, root = context.next() |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
173 except: |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
174 stop_err( "Invalid data format." ) |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
175 for event, elem in context: |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
176 if event == "end" and elem.tag == "BlastOutput_program": |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
177 blast_program = elem.text |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
178 # for every <Iteration> tag |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
179 if event == "end" and elem.tag == "Iteration": |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
180 #Expecting either this, from BLAST 2.2.25+ using FASTA vs FASTA |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
181 # <Iteration_query-ID>sp|Q9BS26|ERP44_HUMAN</Iteration_query-ID> |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
182 # <Iteration_query-def>Endoplasmic reticulum resident protein 44 OS=Homo sapiens GN=ERP44 PE=1 SV=1</Iteration_query-def> |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
183 # <Iteration_query-len>406</Iteration_query-len> |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
184 # <Iteration_hits></Iteration_hits> |
3
643338ac83c0
Uploaded v0.0.12b, same code but moving folders around to match all my other tools and make future development simpler.
peterjc
parents:
diff
changeset
|
185 # |
13
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
186 #Or, from BLAST 2.2.24+ run online |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
187 # <Iteration_query-ID>Query_1</Iteration_query-ID> |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
188 # <Iteration_query-def>Sample</Iteration_query-def> |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
189 # <Iteration_query-len>516</Iteration_query-len> |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
190 # <Iteration_hits>... |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
191 qseqid = elem.findtext("Iteration_query-ID") |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
192 if re_default_query_id.match(qseqid): |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
193 #Place holder ID, take the first word of the query definition |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
194 qseqid = elem.findtext("Iteration_query-def").split(None,1)[0] |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
195 qlen = int(elem.findtext("Iteration_query-len")) |
3
643338ac83c0
Uploaded v0.0.12b, same code but moving folders around to match all my other tools and make future development simpler.
peterjc
parents:
diff
changeset
|
196 |
13
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
197 # for every <Hit> within <Iteration> |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
198 for hit in elem.findall("Iteration_hits/Hit"): |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
199 #Expecting either this, |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
200 # <Hit_id>gi|3024260|sp|P56514.1|OPSD_BUFBU</Hit_id> |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
201 # <Hit_def>RecName: Full=Rhodopsin</Hit_def> |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
202 # <Hit_accession>P56514</Hit_accession> |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
203 #or, |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
204 # <Hit_id>Subject_1</Hit_id> |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
205 # <Hit_def>gi|57163783|ref|NP_001009242.1| rhodopsin [Felis catus]</Hit_def> |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
206 # <Hit_accession>Subject_1</Hit_accession> |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
207 # |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
208 #apparently depending on the parse_deflines switch |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
209 # |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
210 #Or, with a local database not using -parse_seqids can get this, |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
211 # <Hit_id>gnl|BL_ORD_ID|2</Hit_id> |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
212 # <Hit_def>chrIII gi|240255695|ref|NC_003074.8| Arabidopsis thaliana chromosome 3, complete sequence</Hit_def> |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
213 # <Hit_accession>2</Hit_accession> |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
214 sseqid = hit.findtext("Hit_id").split(None,1)[0] |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
215 hit_def = sseqid + " " + hit.findtext("Hit_def") |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
216 if re_default_subject_id.match(sseqid) \ |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
217 and sseqid == hit.findtext("Hit_accession"): |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
218 #Place holder ID, take the first word of the subject definition |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
219 hit_def = hit.findtext("Hit_def") |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
220 sseqid = hit_def.split(None,1)[0] |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
221 if sseqid.startswith("gnl|BL_ORD_ID|") \ |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
222 and sseqid == "gnl|BL_ORD_ID|" + hit.findtext("Hit_accession"): |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
223 #Alternative place holder ID, again take the first word of hit_def |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
224 hit_def = hit.findtext("Hit_def") |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
225 sseqid = hit_def.split(None,1)[0] |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
226 # for every <Hsp> within <Hit> |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
227 for hsp in hit.findall("Hit_hsps/Hsp"): |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
228 nident = hsp.findtext("Hsp_identity") |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
229 length = hsp.findtext("Hsp_align-len") |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
230 pident = "%0.2f" % (100*float(nident)/float(length)) |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
231 |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
232 q_seq = hsp.findtext("Hsp_qseq") |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
233 h_seq = hsp.findtext("Hsp_hseq") |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
234 m_seq = hsp.findtext("Hsp_midline") |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
235 assert len(q_seq) == len(h_seq) == len(m_seq) == int(length) |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
236 gapopen = str(len(q_seq.replace('-', ' ').split())-1 + \ |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
237 len(h_seq.replace('-', ' ').split())-1) |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
238 |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
239 mismatch = m_seq.count(' ') + m_seq.count('+') \ |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
240 - q_seq.count('-') - h_seq.count('-') |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
241 #TODO - Remove this alternative mismatch calculation and test |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
242 #once satisifed there are no problems |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
243 expected_mismatch = len(q_seq) \ |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
244 - sum(1 for q,h in zip(q_seq, h_seq) \ |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
245 if q == h or q == "-" or h == "-") |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
246 xx = sum(1 for q,h in zip(q_seq, h_seq) if q=="X" and h=="X") |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
247 if not (expected_mismatch - q_seq.count("X") <= int(mismatch) <= expected_mismatch + xx): |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
248 stop_err("%s vs %s mismatches, expected %i <= %i <= %i" \ |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
249 % (qseqid, sseqid, expected_mismatch - q_seq.count("X"), |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
250 int(mismatch), expected_mismatch)) |
3
643338ac83c0
Uploaded v0.0.12b, same code but moving folders around to match all my other tools and make future development simpler.
peterjc
parents:
diff
changeset
|
251 |
13
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
252 #TODO - Remove this alternative identity calculation and test |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
253 #once satisifed there are no problems |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
254 expected_identity = sum(1 for q,h in zip(q_seq, h_seq) if q == h) |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
255 if not (expected_identity - xx <= int(nident) <= expected_identity + q_seq.count("X")): |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
256 stop_err("%s vs %s identities, expected %i <= %i <= %i" \ |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
257 % (qseqid, sseqid, expected_identity, int(nident), |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
258 expected_identity + q_seq.count("X"))) |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
259 |
3
643338ac83c0
Uploaded v0.0.12b, same code but moving folders around to match all my other tools and make future development simpler.
peterjc
parents:
diff
changeset
|
260 |
13
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
261 evalue = hsp.findtext("Hsp_evalue") |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
262 if evalue == "0": |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
263 evalue = "0.0" |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
264 else: |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
265 evalue = "%0.0e" % float(evalue) |
3
643338ac83c0
Uploaded v0.0.12b, same code but moving folders around to match all my other tools and make future development simpler.
peterjc
parents:
diff
changeset
|
266 |
13
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
267 bitscore = float(hsp.findtext("Hsp_bit-score")) |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
268 if bitscore < 100: |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
269 #Seems to show one decimal place for lower scores |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
270 bitscore = "%0.1f" % bitscore |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
271 else: |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
272 #Note BLAST does not round to nearest int, it truncates |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
273 bitscore = "%i" % bitscore |
3
643338ac83c0
Uploaded v0.0.12b, same code but moving folders around to match all my other tools and make future development simpler.
peterjc
parents:
diff
changeset
|
274 |
13
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
275 values = [qseqid, |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
276 sseqid, |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
277 pident, |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
278 length, #hsp.findtext("Hsp_align-len") |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
279 str(mismatch), |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
280 gapopen, |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
281 hsp.findtext("Hsp_query-from"), #qstart, |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
282 hsp.findtext("Hsp_query-to"), #qend, |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
283 hsp.findtext("Hsp_hit-from"), #sstart, |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
284 hsp.findtext("Hsp_hit-to"), #send, |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
285 evalue, #hsp.findtext("Hsp_evalue") in scientific notation |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
286 bitscore, #hsp.findtext("Hsp_bit-score") rounded |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
287 ] |
3
643338ac83c0
Uploaded v0.0.12b, same code but moving folders around to match all my other tools and make future development simpler.
peterjc
parents:
diff
changeset
|
288 |
13
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
289 if extended: |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
290 try: |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
291 sallseqid = ";".join(name.split(None,1)[0] for name in hit_def.split(" >")) |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
292 salltitles = "<>".join(name.split(None,1)[1] for name in hit_def.split(" >")) |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
293 except IndexError as e: |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
294 stop_err("Problem splitting multuple hits?\n%r\n--> %s" % (hit_def, e)) |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
295 #print hit_def, "-->", sallseqid |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
296 positive = hsp.findtext("Hsp_positive") |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
297 ppos = "%0.2f" % (100*float(positive)/float(length)) |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
298 qframe = hsp.findtext("Hsp_query-frame") |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
299 sframe = hsp.findtext("Hsp_hit-frame") |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
300 if blast_program == "blastp": |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
301 #Probably a bug in BLASTP that they use 0 or 1 depending on format |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
302 if qframe == "0": qframe = "1" |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
303 if sframe == "0": sframe = "1" |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
304 slen = int(hit.findtext("Hit_len")) |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
305 values.extend([sallseqid, |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
306 hsp.findtext("Hsp_score"), #score, |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
307 nident, |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
308 positive, |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
309 hsp.findtext("Hsp_gaps"), #gaps, |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
310 ppos, |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
311 qframe, |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
312 sframe, |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
313 #NOTE - for blastp, XML shows original seq, tabular uses XXX masking |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
314 q_seq, |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
315 h_seq, |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
316 str(qlen), |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
317 str(slen), |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
318 salltitles, |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
319 ]) |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
320 if cols: |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
321 #Only a subset of the columns are needed |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
322 values = [values[colnames.index(c)] for c in cols] |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
323 #print "\t".join(values) |
15
c16c30e9ad5b
Uploaded v0.1.03 (internal changes); v0.1.02 (BLAST+ 2.2.30 etc)
peterjc
parents:
14
diff
changeset
|
324 output_handle.write("\t".join(values) + "\n") |
13
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
325 # prevents ElementTree from growing large datastructure |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
326 root.clear() |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
327 elem.clear() |
3
643338ac83c0
Uploaded v0.0.12b, same code but moving folders around to match all my other tools and make future development simpler.
peterjc
parents:
diff
changeset
|
328 |
13
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
329 |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
330 if options.output: |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
331 outfile = open(options.output, "w") |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
332 else: |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
333 outfile = sys.stdout |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
334 |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
335 for in_file in args: |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
336 blast_program = None |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
337 convert(in_file, outfile) |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
338 |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
339 if options.output: |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
340 outfile.close() |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
341 else: |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
342 #Using stdout |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
343 pass |
623f727cdff1
Uploaded v0.1.00, uses BLAST+ 2.2.29, allows custom column selection for tabular output - including taxonomy fields.
peterjc
parents:
11
diff
changeset
|
344 |