Mercurial > repos > peterjc > tmhmm_and_signalp
comparison tools/protein_analysis/promoter2.py @ 21:238eae32483c draft
"Check this is up to date with all 2020 changes (black etc)"
author | peterjc |
---|---|
date | Thu, 17 Jun 2021 08:21:06 +0000 |
parents | a19b3ded8f33 |
children |
comparison
equal
deleted
inserted
replaced
20:a19b3ded8f33 | 21:238eae32483c |
---|---|
39 | 39 |
40 if "-v" in sys.argv or "--version" in sys.argv: | 40 if "-v" in sys.argv or "--version" in sys.argv: |
41 sys.exit(os.system("promoter -V")) | 41 sys.exit(os.system("promoter -V")) |
42 | 42 |
43 if len(sys.argv) != 4: | 43 if len(sys.argv) != 4: |
44 sys.exit("Require three arguments, number of threads (int), input DNA FASTA file & output tabular file. " | 44 sys.exit( |
45 "Got %i arguments." % (len(sys.argv) - 1)) | 45 "Require three arguments, number of threads (int), input DNA FASTA " |
46 "file & output tabular file. Got %i arguments." % (len(sys.argv) - 1) | |
47 ) | |
46 | 48 |
47 num_threads = thread_count(sys.argv[3], default=4) | 49 num_threads = thread_count(sys.argv[3], default=4) |
48 fasta_file = os.path.abspath(sys.argv[2]) | 50 fasta_file = os.path.abspath(sys.argv[2]) |
49 tabular_file = os.path.abspath(sys.argv[3]) | 51 tabular_file = os.path.abspath(sys.argv[3]) |
50 | 52 |
94 position, score, likelihood = line.strip().split(None, 2) | 96 position, score, likelihood = line.strip().split(None, 2) |
95 except ValueError: | 97 except ValueError: |
96 print("WARNING: Problem with line: %r" % line) | 98 print("WARNING: Problem with line: %r" % line) |
97 continue | 99 continue |
98 # sys.exit("ERROR: Problem with line: %r" % line) | 100 # sys.exit("ERROR: Problem with line: %r" % line) |
99 if likelihood not in ["ignored", | 101 if likelihood not in [ |
100 "Marginal prediction", | 102 "ignored", |
101 "Medium likely prediction", | 103 "Marginal prediction", |
102 "Highly likely prediction"]: | 104 "Medium likely prediction", |
105 "Highly likely prediction", | |
106 ]: | |
103 sys.exit("ERROR: Problem with line: %r" % line) | 107 sys.exit("ERROR: Problem with line: %r" % line) |
104 out_handle.write("%s\t%s\t%s\t%s\n" % (identifier, position, score, likelihood)) | 108 out_handle.write( |
109 "%s\t%s\t%s\t%s\n" % (identifier, position, score, likelihood) | |
110 ) | |
105 return queries | 111 return queries |
106 | 112 |
107 | 113 |
108 working_dir, bin = get_path_and_binary() | 114 working_dir, bin = get_path_and_binary() |
109 | 115 |
112 | 118 |
113 # Note that if the input FASTA file contains no sequences, | 119 # Note that if the input FASTA file contains no sequences, |
114 # split_fasta returns an empty list (i.e. zero temp files). | 120 # split_fasta returns an empty list (i.e. zero temp files). |
115 # We deliberately omit the FASTA descriptions to avoid a | 121 # We deliberately omit the FASTA descriptions to avoid a |
116 # bug in promoter2 with descriptions over 200 characters. | 122 # bug in promoter2 with descriptions over 200 characters. |
117 fasta_files = split_fasta(fasta_file, os.path.join(tmp_dir, "promoter"), FASTA_CHUNK, keep_descr=False) | 123 fasta_files = split_fasta( |
124 fasta_file, os.path.join(tmp_dir, "promoter"), FASTA_CHUNK, keep_descr=False | |
125 ) | |
118 temp_files = [f + ".out" for f in fasta_files] | 126 temp_files = [f + ".out" for f in fasta_files] |
119 jobs = ["%s %s > %s" % (bin, fasta, temp) | 127 jobs = [ |
120 for fasta, temp in zip(fasta_files, temp_files)] | 128 "%s %s > %s" % (bin, fasta, temp) for fasta, temp in zip(fasta_files, temp_files) |
129 ] | |
121 | 130 |
122 | 131 |
123 def clean_up(file_list): | 132 def clean_up(file_list): |
124 for f in file_list: | 133 for f in file_list: |
125 if os.path.isfile(f): | 134 if os.path.isfile(f): |
143 try: | 152 try: |
144 output = open(temp).readline() | 153 output = open(temp).readline() |
145 except IOError: | 154 except IOError: |
146 output = "" | 155 output = "" |
147 clean_up(fasta_files + temp_files) | 156 clean_up(fasta_files + temp_files) |
148 sys.exit("One or more tasks failed, e.g. %i from %r gave:\n%s" % (error_level, cmd, output), | 157 sys.exit( |
149 error_level) | 158 "One or more tasks failed, e.g. %i from %r gave:\n%s" |
159 % (error_level, cmd, output), | |
160 error_level, | |
161 ) | |
150 | 162 |
151 del results | 163 del results |
152 del jobs | 164 del jobs |
153 | 165 |
154 out_handle = open(tabular_file, "w") | 166 out_handle = open(tabular_file, "w") |