30
30
31
31
def shorten_output (s ):
32
32
# return pprint.pformat(s)
33
- if len (s )> 40 :
34
- s = s [:40 ]+ "..."
33
+ if len (s ) > 40 :
34
+ s = s [:40 ] + "..."
35
35
return s
36
36
37
+
37
38
def error (* msg , error_code = 1 ):
38
39
"""
39
40
Prints an error message to stderr and exits the program with the specified error code.
@@ -103,7 +104,7 @@ def run_safe(command, output_fn=None, output_fo=None, err_msg=None, thr_exc=True
103
104
command_str_nice = shorten_output (command_str )
104
105
105
106
if not silent :
106
- message ("Shell command:" , command_str_nice )
107
+ message (f "Shell command: ' { command_str_nice } '" )
107
108
108
109
if output_fn is None :
109
110
if output_fo is None :
@@ -130,9 +131,9 @@ def run_safe(command, output_fn=None, output_fo=None, err_msg=None, thr_exc=True
130
131
131
132
if error_code == 0 or error_code == 141 :
132
133
if not silent :
133
- message ("Finished: {}" . format ( command_str_nice ) )
134
+ message (f "Finished: ' { command_str_nice } '" )
134
135
else :
135
- message ("Unfinished, an error occurred (error code {}): {}" . format ( error_code , command_str ) )
136
+ message (f "Unfinished, an error occurred (error code { error_code } ): ' { command_str } '" )
136
137
137
138
if err_msg is not None :
138
139
print ('Error: {}' .format (err_msg ), file = sys .stderr )
@@ -161,7 +162,7 @@ def mash_triangle(inp_fns, phylip_fn, k, s, t, fof, verbose):
161
162
Raises:
162
163
None
163
164
"""
164
- message ("Running mash " )
165
+ message ("Running Mash " )
165
166
cmd = f"mash triangle -s { s } -k { k } -p { t } " .split ()
166
167
if fof :
167
168
cmd += ["-l" ]
@@ -203,11 +204,11 @@ def postprocess_mash_phylip(phylip_in_fn, phylip_out_fn, verbose):
203
204
for i , x in enumerate (f ):
204
205
x = x .strip ()
205
206
if i != 0 :
206
- print (x , file = sys .stderr )
207
207
l , sep , r = x .partition ("\t " )
208
208
l = fn_to_node_name (l )
209
209
x = l + sep + r
210
- message (x )
210
+ if verbose :
211
+ message ("Mash output:" , x )
211
212
print (x , file = g )
212
213
#basename_components = os.path.basename(p[0]).split(".")
213
214
#if len(basename_components) == 1:
@@ -283,7 +284,7 @@ def attotree(fns, newick_fo, k, s, t, phylogeny_algorithm, fof, verbose):
283
284
None
284
285
"""
285
286
with tempfile .TemporaryDirectory () as d :
286
- message ('created a temporary directory' , d )
287
+ message ('Created a temporary directory' , d )
287
288
phylip1_fn = os .path .join (d , "distances.phylip0" )
288
289
phylip2_fn = os .path .join (d , "distances.phylip" )
289
290
newick1_fn = os .path .join (d , "tree.nw" )
0 commit comments