comparison tools/protein_analysis/tmhmm2.py @ 18:eb6ac44d4b8e draft

Suite v0.2.8, record Promoter 2 verion + misc internal updates
author peterjc
date Tue, 01 Sep 2015 09:56:36 -0400
parents 99b82a2b1272
children f3ecd80850e2
comparison
equal deleted inserted replaced
17:e6cc27d182a8 18:eb6ac44d4b8e
41 when there is no output from tmhmm2, and raise an error. 41 when there is no output from tmhmm2, and raise an error.
42 """ 42 """
43 import sys 43 import sys
44 import os 44 import os
45 import tempfile 45 import tempfile
46 from seq_analysis_utils import stop_err, split_fasta, run_jobs, thread_count 46 from seq_analysis_utils import sys_exit, split_fasta, run_jobs, thread_count
47 47
48 FASTA_CHUNK = 500 48 FASTA_CHUNK = 500
49 49
50 if len(sys.argv) != 4: 50 if len(sys.argv) != 4:
51 stop_err("Require three arguments, number of threads (int), input protein FASTA file & output tabular file") 51 sys_exit("Require three arguments, number of threads (int), input protein FASTA file & output tabular file")
52 52
53 num_threads = thread_count(sys.argv[1], default=4) 53 num_threads = thread_count(sys.argv[1], default=4)
54 fasta_file = sys.argv[2] 54 fasta_file = sys.argv[2]
55 tabular_file = sys.argv[3] 55 tabular_file = sys.argv[3]
56 56
66 parts = line.rstrip("\r\n").split("\t") 66 parts = line.rstrip("\r\n").split("\t")
67 try: 67 try:
68 identifier, length, expAA, first60, predhel, topology = parts 68 identifier, length, expAA, first60, predhel, topology = parts
69 except: 69 except:
70 assert len(parts)!=6 70 assert len(parts)!=6
71 stop_err("Bad line: %r" % line) 71 sys_exit("Bad line: %r" % line)
72 assert length.startswith("len="), line 72 assert length.startswith("len="), line
73 length = length[4:] 73 length = length[4:]
74 assert expAA.startswith("ExpAA="), line 74 assert expAA.startswith("ExpAA="), line
75 expAA = expAA[6:] 75 expAA = expAA[6:]
76 assert first60.startswith("First60="), line 76 assert first60.startswith("First60="), line
110 try: 110 try:
111 output = open(temp).readline() 111 output = open(temp).readline()
112 except IOError: 112 except IOError:
113 output = "" 113 output = ""
114 clean_up(fasta_files + temp_files) 114 clean_up(fasta_files + temp_files)
115 stop_err("One or more tasks failed, e.g. %i from %r gave:\n%s" % (error_level, cmd, output), 115 sys_exit("One or more tasks failed, e.g. %i from %r gave:\n%s" % (error_level, cmd, output),
116 error_level) 116 error_level)
117 del results 117 del results
118 del jobs 118 del jobs
119 119
120 out_handle = open(tabular_file, "w") 120 out_handle = open(tabular_file, "w")
123 data_handle = open(temp) 123 data_handle = open(temp)
124 count = clean_tabular(data_handle, out_handle) 124 count = clean_tabular(data_handle, out_handle)
125 data_handle.close() 125 data_handle.close()
126 if not count: 126 if not count:
127 clean_up(fasta_files + temp_files) 127 clean_up(fasta_files + temp_files)
128 stop_err("No output from tmhmm2") 128 sys_exit("No output from tmhmm2")
129 out_handle.close() 129 out_handle.close()
130 130
131 clean_up(fasta_files + temp_files) 131 clean_up(fasta_files + temp_files)