@@ -60,42 +60,42 @@ def build_default_params(workdir, targets):
60
60
defaultParams ['assembly_extensions' ] = list (set (assembly_extensions ))
61
61
return defaultParams
62
62
63
+
63
64
def build_dirs (ep_dir , params ):
65
+ ''' function to build full paths for all directories '''
64
66
# build main eelpond dir info
65
- rules_dir = params ['eelpond_directories' ]['rules' ]
66
67
params ['eelpond_directories' ]['base_dir' ] = ep_dir
67
- params ['eelpond_directories' ]['rules' ] = os .path .join (ep_dir , rules_dir )
68
- animals_dir = params ['eelpond_directories' ]['animals' ]
69
- params ['eelpond_directories' ]['animals' ] = os .path .join (ep_dir , 'ep_utils' , animals_dir )
70
-
68
+ params ['eelpond_directories' ]['rules' ] = os .path .join (ep_dir , params ['eelpond_directories' ]['rules' ])
69
+ params ['eelpond_directories' ]['animals' ] = os .path .join (ep_dir , params ['eelpond_directories' ]['animals' ])
71
70
# if desired, user can also provide out_path, and all dirs will be built under there
72
- # outdirectory, build all directories relative to that path
73
71
out_path = params .get ('out_path' , ep_dir )
74
- # if user inputs an absolute path:
75
- if os .path .isabs (out_path ): # if not absolute, just assume subdirectory of eelpond.
72
+ out_path = os . path . expanduser ( out_path ) # expand any `~` on unix
73
+ if os .path .isabs (out_path ): # if user inputs an absolute path, check that it exists!
76
74
assert os .path .exists (out_path ) and os .path .isdir (out_path ), f"Error: provided output path { out_path } is not an existing directory. Please fix.\n \n "
77
-
75
+ else : # if not absolute, assume subdirectory of base eelpond dir
76
+ out_path = os .path .join (ep_dir , out_path )
78
77
# allow user to define basename, and experiment, build outdir name
79
78
basename = params ['basename' ]
80
79
expt = params .get ('experiment' , '' )
81
80
if expt and not expt .startswith ('_' ):
82
81
expt = '_' + expt
83
82
outdir = basename + "_out" + expt
84
-
85
83
# Now join out_path, outdir name
84
+ out_path = os .path .realpath (out_path )
86
85
outdir = os .path .join (out_path , outdir )
87
-
88
- params ['eelpond_directories' ]['out_dir' ] = outdir # outdir NAME
89
- # if we want logs to be *within* individual outdirs, change logsdir here (else logs in eelpond dir)
90
- params ['eelpond_directories' ]['logs' ] = join (outdir , os .path .basename (params ['eelpond_directories' ]['logs' ]))
86
+ # when using out_path, need to manually build the outdir (snakemake will not automatically create it)
87
+ if not os .path .exists (outdir ):
88
+ os .makedirs (outdir )
89
+ # add full path info to the config
90
+ params ['eelpond_directories' ]['out_dir' ] = outdir
91
+ params ['eelpond_directories' ]['logs' ] = join (outdir , params ['eelpond_directories' ]['logs' ])
91
92
# build dirs for main eelpond output directories
92
93
outDirs = params ['eelpond_directories' ]['outdirs' ]
93
94
for targ , outD in outDirs .items ():
94
95
outDirs [targ ] = os .path .join (outdir , outD )
95
96
# put joined paths back in params file
96
97
params ['eelpond_directories' ]['outdirs' ] = outDirs
97
98
# build dirs for included rules
98
-
99
99
included_rules = params ['include_rules' ]
100
100
for rule in included_rules :
101
101
prog = os .path .basename (rule ).split ('.rule' )[0 ]
@@ -104,28 +104,6 @@ def build_dirs(ep_dir, params):
104
104
params [prog ]['eelpond_params' ]['outdir' ] = os .path .join (outdir , prog_dir )
105
105
return params
106
106
107
- def handle_assemblyInput (assembInput , config ):
108
- # find files
109
- program_params = config ['assemblyinput' ].get ('program_params' )
110
- assemblyfile = program_params .get ('assembly' , None )
111
- assert os .path .exists (assemblyfile ), 'Error: cannot find input assembly at {}\n ' .format (assemblyfile )
112
- sys .stderr .write ('\t Found input assembly at {}\n ' .format (assemblyfile ))
113
- gtmap = program_params .get ('gene_trans_map' , '' )
114
- extensions = {}
115
- if gtmap :
116
- assert os .path .exists (gtmap ), 'Error: cannot find assembly gene_trans_map at {}\n ' .format (gtmap )
117
- sys .stderr .write ('\t Found input assembly gene-transcript map at {}\n ' .format (gtmap ))
118
- extensions = {'base' : ['.fasta' , '.fasta.gene_trans_map' ]} # kinda hacky. do this better
119
- else :
120
- program_params ['gene_trans_map' ] = ''
121
- # grab user-input assembly extension
122
- input_assembly_extension = program_params .get ('assembly_extension' , '' )
123
- config ['assemblyinput' ] = {}
124
- config ['assemblyinput' ]['program_params' ] = program_params
125
- extensions ['assembly_extensions' ] = [input_assembly_extension ]
126
- config ['assemblyinput' ]['eelpond_params' ] = {'extensions' : extensions }
127
- return config , input_assembly_extension
128
-
129
107
def main (args ):
130
108
131
109
thisdir = os .path .abspath (os .path .dirname (__file__ ))
@@ -188,7 +166,7 @@ def main(args):
188
166
assembInput = configD .get ('assemblyinput' , None )
189
167
if assembInput :
190
168
targs += ['assemblyinput' ]
191
- configD , assemblyinput_ext = handle_assemblyInput (assembInput , configD )
169
+ configD , assemblyinput_ext = handle_assemblyinput (assembInput , configD )
192
170
else :
193
171
assemblyinput_ext = None
194
172
if 'assemblyinput' in targs and not assembInput :
@@ -225,6 +203,12 @@ def main(args):
225
203
# add extension to overall assembly_extensions info
226
204
if assemblyinput_ext : # note, need to do it here to prevent override with defaults
227
205
paramsD ['assembly_extensions' ] = list (set (paramsD .get ('assembly_extensions' , []) + [assemblyinput_ext ]))
206
+
207
+ # NOTE: I think this should be moved from here into an `input_checks` function that checks all appropriate inputs/outputs are specified for the rules in use, and provides appropriate links to docs to help guide the user.
208
+ if paramsD .get ('no_gene_trans_map' , False ):
209
+ if paramsD .get ('deseq2' ):
210
+ paramsD ['deseq2' ]['program_params' ]['gene_trans_map' ] = False
211
+ sys .stderr .write ("\t You're using `assemblyinput` without specifying a gene-trans-map. Setting differential expression to transcript-level only. See https://dib-lab.github.io/eelpond/deseq2/for details.\n " )
228
212
229
213
# use params to build directory structure
230
214
paramsD = build_dirs (thisdir , paramsD )
@@ -247,6 +231,7 @@ def main(args):
247
231
print ('\t config: {}' .format (configfile ))
248
232
print ('\t params: {}' .format (paramsfile ))
249
233
print ('\t targets: {}' .format (repr (targs )))
234
+ print ('\t output: {}' .format (repr (paramsD ['eelpond_directories' ]['out_dir' ])))
250
235
print ('\t report: {}' .format (repr (reportfile )))
251
236
print ('--------' )
252
237
0 commit comments