File tree Expand file tree Collapse file tree 3 files changed +26
-1
lines changed Expand file tree Collapse file tree 3 files changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -41,6 +41,8 @@ Minor enhancements:
41
41
42
42
- the help message for BED has been improved to highlight the fact that the extension needs to be part of the output.
43
43
44
+ - if the directory of the output file does not exists, it is created.
45
+
44
46
Drop support for python 3.6
45
47
^^^^^^^^^^^^^^^^^^^^^^^^^^^
46
48
Original file line number Diff line number Diff line change 142
142
"""
143
143
144
144
import sys
145
+ import os
145
146
import argparse
146
147
import warnings
147
148
@@ -275,6 +276,10 @@ def main(args=None):
275
276
track_label_width = args .trackLabelFraction ,
276
277
plot_regions = regions , plot_width = args .plotWidth )
277
278
279
+ # Create dir if dir does not exists:
280
+ # Modified from https://stackoverflow.com/questions/12517451/automatically-creating-directories-with-file-output
281
+ os .makedirs (os .path .dirname (os .path .abspath (args .outFileName )), exist_ok = True )
282
+
278
283
# Plot them
279
284
if args .BED :
280
285
name = args .outFileName .split ("." )
Original file line number Diff line number Diff line change 1
1
# -*- coding: utf-8 -*-
2
2
import matplotlib as mpl
3
3
from matplotlib .testing .compare import compare_images
4
- from tempfile import NamedTemporaryFile
4
+ from tempfile import NamedTemporaryFile , TemporaryDirectory
5
5
import os .path
6
6
import pygenometracks .plotTracks
7
7
mpl .use ('agg' )
@@ -148,3 +148,21 @@ def test_fixed_height():
148
148
assert res is None , res
149
149
150
150
os .remove (outfile .name )
151
+
152
+
153
+ def test_non_existing_dir ():
154
+
155
+ outdir = TemporaryDirectory ()
156
+ output_file = os .path .join (outdir .name , "pGT_test" , "test.png" )
157
+ ini_file = os .path .join (ROOT , "title.ini" )
158
+ region = "X:3000000-3500000"
159
+ expected_file = os .path .join (ROOT , 'master_title_0.2.png' )
160
+ args = f"--tracks { ini_file } --region { region } " \
161
+ "--trackLabelFraction 0.2 --width 38 --dpi 130 " \
162
+ f"--outFileName { output_file } " .split ()
163
+ pygenometracks .plotTracks .main (args )
164
+ res = compare_images (expected_file ,
165
+ output_file , tolerance )
166
+ assert res is None , res
167
+
168
+ outdir .cleanup ()
You can’t perform that action at this time.
0 commit comments