Mercurial > repos > peterjc > tmhmm_and_signalp
annotate tools/protein_analysis/psortb.py @ 17:e6cc27d182a8 draft
Uploaded v0.2.6, embedded citations and uses $GALAXY_SLOTS
author | peterjc |
---|---|
date | Fri, 21 Nov 2014 08:19:09 -0500 |
parents | 99b82a2b1272 |
children | eb6ac44d4b8e |
rev | line source |
---|---|
11
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
1 #!/usr/bin/env python |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
2 """Wrapper for psortb for use in Galaxy. |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
3 |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
4 This script takes exactly six command line arguments - which includes the |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
5 number of threads, and the input protein FASTA filename and output |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
6 tabular filename. It then splits up the FASTA input and calls multiple |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
7 copies of the standalone psortb v3 program, then collates the output. |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
8 e.g. Rather than this, |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
9 |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
10 psort $type -c $cutoff -d $divergent -o long $sequence > $outfile |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
11 |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
12 Call this: |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
13 |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
14 psort $threads $type $cutoff $divergent $sequence $outfile |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
15 |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
16 If ommitting -c or -d options, set $cutoff and $divergent to zero or blank. |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
17 |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
18 Note that this is somewhat redundant with job-splitting available in Galaxy |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
19 itself (see the SignalP XML file for settings), but both can be applied. |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
20 |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
21 Additionally it ensures the header line (with the column names) starts |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
22 with a # character as used elsewhere in Galaxy. |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
23 """ |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
24 import sys |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
25 import os |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
26 import tempfile |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
27 from seq_analysis_utils import stop_err, split_fasta, run_jobs, thread_count |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
28 |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
29 FASTA_CHUNK = 500 |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
30 |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
31 if "-v" in sys.argv or "--version" in sys.argv: |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
32 """Return underlying PSORTb's version""" |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
33 sys.exit(os.system("psort --version")) |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
34 |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
35 if len(sys.argv) != 8: |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
36 stop_err("Require 7 arguments, number of threads (int), type (e.g. archaea), " |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
37 "output (e.g. terse/normal/long), cutoff, divergent, input protein " |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
38 "FASTA file & output tabular file") |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
39 |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
40 num_threads = thread_count(sys.argv[1], default=4) |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
41 org_type = sys.argv[2] |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
42 out_type = sys.argv[3] |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
43 cutoff = sys.argv[4] |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
44 if cutoff.strip() and float(cutoff.strip()) != 0.0: |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
45 cutoff = "-c %s" % cutoff |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
46 else: |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
47 cutoff = "" |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
48 divergent = sys.argv[5] |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
49 if divergent.strip() and float(divergent.strip()) != 0.0: |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
50 divergent = "-d %s" % divergent |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
51 else: |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
52 divergent = "" |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
53 fasta_file = sys.argv[6] |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
54 tabular_file = sys.argv[7] |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
55 |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
56 if out_type == "terse": |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
57 header = ['SeqID', 'Localization', 'Score'] |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
58 elif out_type == "normal": |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
59 stop_err("Normal output not implemented yet, sorry.") |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
60 elif out_type == "long": |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
61 if org_type == "-n": |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
62 #Gram negative bacteria |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
63 header = ['SeqID', 'CMSVM-_Localization', 'CMSVM-_Details', 'CytoSVM-_Localization', 'CytoSVM-_Details', |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
64 'ECSVM-_Localization', 'ECSVM-_Details', 'ModHMM-_Localization', 'ModHMM-_Details', |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
65 'Motif-_Localization', 'Motif-_Details', 'OMPMotif-_Localization', 'OMPMotif-_Details', |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
66 'OMSVM-_Localization', 'OMSVM-_Details', 'PPSVM-_Localization', 'PPSVM-_Details', |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
67 'Profile-_Localization', 'Profile-_Details', |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
68 'SCL-BLAST-_Localization', 'SCL-BLAST-_Details', 'SCL-BLASTe-_Localization', 'SCL-BLASTe-_Details', |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
69 'Signal-_Localization', 'Signal-_Details', |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
70 'Cytoplasmic_Score', 'CytoplasmicMembrane_Score', 'Periplasmic_Score', 'OuterMembrane_Score', |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
71 'Extracellular_Score', 'Final_Localization', 'Final_Localization_Details', 'Final_Score', |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
72 'Secondary_Localization', 'PSortb_Version'] |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
73 elif org_type == "-p": |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
74 #Gram positive bacteria |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
75 header = ['SeqID', 'CMSVM+_Localization', 'CMSVM+_Details', 'CWSVM+_Localization', 'CWSVM+_Details', |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
76 'CytoSVM+_Localization', 'CytoSVM+_Details', 'ECSVM+_Localization', 'ECSVM+_Details', |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
77 'ModHMM+_Localization', 'ModHMM+_Details', 'Motif+_Localization', 'Motif+_Details', |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
78 'Profile+_Localization', 'Profile+_Details', |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
79 'SCL-BLAST+_Localization', 'SCL-BLAST+_Details', 'SCL-BLASTe+_Localization', 'SCL-BLASTe+_Details', |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
80 'Signal+_Localization', 'Signal+_Details', |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
81 'Cytoplasmic_Score', 'CytoplasmicMembrane_Score', 'Cellwall_Score', |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
82 'Extracellular_Score', 'Final_Localization', 'Final_Localization_Details', 'Final_Score', |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
83 'Secondary_Localization', 'PSortb_Version'] |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
84 elif org_type == "-a": |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
85 #Archaea |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
86 header = ['SeqID', 'CMSVM_a_Localization', 'CMSVM_a_Details', 'CWSVM_a_Localization', 'CWSVM_a_Details', |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
87 'CytoSVM_a_Localization', 'CytoSVM_a_Details', 'ECSVM_a_Localization', 'ECSVM_a_Details', |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
88 'ModHMM_a_Localization', 'ModHMM_a_Details', 'Motif_a_Localization', 'Motif_a_Details', |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
89 'Profile_a_Localization', 'Profile_a_Details', |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
90 'SCL-BLAST_a_Localization', 'SCL-BLAST_a_Details', 'SCL-BLASTe_a_Localization', 'SCL-BLASTe_a_Details', |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
91 'Signal_a_Localization', 'Signal_a_Details', |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
92 'Cytoplasmic_Score', 'CytoplasmicMembrane_Score', 'Cellwall_Score', |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
93 'Extracellular_Score', 'Final_Localization', 'Final_Localization_Details', 'Final_Score', |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
94 'Secondary_Localization', 'PSortb_Version'] |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
95 else: |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
96 stop_err("Expected -n, -p or -a for the organism type, not %r" % org_type) |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
97 else: |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
98 stop_err("Expected terse, normal or long for the output type, not %r" % out_type) |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
99 |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
100 tmp_dir = tempfile.mkdtemp() |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
101 |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
102 def clean_tabular(raw_handle, out_handle): |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
103 """Clean up tabular TMHMM output, returns output line count.""" |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
104 global header |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
105 count = 0 |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
106 for line in raw_handle: |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
107 if not line.strip() or line.startswith("#"): |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
108 #Ignore any blank lines or comment lines |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
109 continue |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
110 parts = [x.strip() for x in line.rstrip("\r\n").split("\t")] |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
111 if parts == header: |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
112 #Ignore the header line |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
113 continue |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
114 if not parts[-1] and len(parts) == len(header) + 1: |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
115 #Ignore dummy blank extra column, e.g. |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
116 #"...2.0\t\tPSORTb version 3.0\t\n" |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
117 parts = parts[:-1] |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
118 assert len(parts) == len(header), \ |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
119 "%i fields, not %i, in line:\n%r" % (len(line), len(header), line) |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
120 out_handle.write(line) |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
121 count += 1 |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
122 return count |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
123 |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
124 #Note that if the input FASTA file contains no sequences, |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
125 #split_fasta returns an empty list (i.e. zero temp files). |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
126 fasta_files = split_fasta(fasta_file, os.path.join(tmp_dir, "tmhmm"), FASTA_CHUNK) |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
127 temp_files = [f+".out" for f in fasta_files] |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
128 jobs = ["psort %s %s %s -o %s %s > %s" % (org_type, cutoff, divergent, out_type, fasta, temp) |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
129 for fasta, temp in zip(fasta_files, temp_files)] |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
130 |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
131 def clean_up(file_list): |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
132 for f in file_list: |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
133 if os.path.isfile(f): |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
134 os.remove(f) |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
135 try: |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
136 os.rmdir(tmp_dir) |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
137 except: |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
138 pass |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
139 |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
140 if len(jobs) > 1 and num_threads > 1: |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
141 #A small "info" message for Galaxy to show the user. |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
142 print "Using %i threads for %i tasks" % (min(num_threads, len(jobs)), len(jobs)) |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
143 results = run_jobs(jobs, num_threads) |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
144 for fasta, temp, cmd in zip(fasta_files, temp_files, jobs): |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
145 error_level = results[cmd] |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
146 if error_level: |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
147 try: |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
148 output = open(temp).readline() |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
149 except IOError: |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
150 output = "" |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
151 clean_up(fasta_files + temp_files) |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
152 stop_err("One or more tasks failed, e.g. %i from %r gave:\n%s" % (error_level, cmd, output), |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
153 error_level) |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
154 del results |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
155 del jobs |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
156 |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
157 out_handle = open(tabular_file, "w") |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
158 out_handle.write("#%s\n" % "\t".join(header)) |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
159 count = 0 |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
160 for temp in temp_files: |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
161 data_handle = open(temp) |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
162 count += clean_tabular(data_handle, out_handle) |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
163 data_handle.close() |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
164 if not count: |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
165 clean_up(fasta_files + temp_files) |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
166 stop_err("No output from psortb") |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
167 out_handle.close() |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
168 print "%i records" % count |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
169 |
99b82a2b1272
Uploaded v0.2.0 which added PSORTb wrapper (written with Konrad Paszkiewicz)
peterjc
parents:
diff
changeset
|
170 clean_up(fasta_files + temp_files) |