@@ -143,34 +143,33 @@ def _validate_mag_ids(
143
143
144
144
145
145
class FileDictMixin :
146
- def file_dict (self , relative = False , suffixes = None ):
146
+ def file_dict (self , relative = False ):
147
147
"""
148
148
For per sample directories it returns a mapping of sample id to
149
149
another dictionary where keys represent the file name and values
150
150
correspond to the filepath for each file matching the pathspec.
151
151
For files, it returns a mapping of file name to filepath for each
152
- file matching the pathspec. The specified suffixes are removed
153
- from filenames.
152
+ file matching the pathspec. If the dir format has the attribute
153
+ 'suffixes', then these are removed from filenames.
154
154
155
155
Parameters
156
156
---------
157
157
relative : bool
158
158
Whether to return filepaths relative to the directory's location.
159
159
Returns absolute filepaths by default.
160
- suffixes : List
161
- A list of suffixes that should be removed from the filenames to
162
- generate the ID.
163
160
164
161
Returns
165
162
-------
166
163
dict
167
- Mapping of filename -> filepath as described above.
164
+ Mapping of sample id -> filepath as described above.
168
165
Or mapping of sample id -> dict {filename: filepath} as
169
166
described above.
170
167
Both levels of the dictionary are sorted alphabetically by key.
171
168
"""
169
+ suffixes = getattr (self , "suffixes" , [])
172
170
file_pattern = re .compile (self .pathspec )
173
171
ids = defaultdict (dict )
172
+
174
173
for entry in self .path .iterdir ():
175
174
if entry .is_dir ():
176
175
outer_id = entry .name
@@ -184,7 +183,7 @@ def file_dict(self, relative=False, suffixes=None):
184
183
suffixes = suffixes ,
185
184
)
186
185
187
- ids [outer_id ][inner_id ] = str ( file_path )
186
+ ids [outer_id ][inner_id ] = file_path
188
187
ids [outer_id ] = dict (sorted (ids [outer_id ].items ()))
189
188
else :
190
189
if file_pattern .match (entry .name ):
@@ -196,7 +195,7 @@ def file_dict(self, relative=False, suffixes=None):
196
195
suffixes = suffixes ,
197
196
)
198
197
199
- ids [inner_id ] = str ( file_path )
198
+ ids [inner_id ] = file_path
200
199
201
200
return dict (sorted (ids .items ()))
202
201
@@ -217,17 +216,19 @@ def _process_path(path, relative, dir_format, suffixes):
217
216
to the directory formats path or absolute.
218
217
dir_format : model.DirectoryFormat.
219
218
Any object of class model.DirectoryFormat.
219
+ suffixes : List
220
+ A list of suffixes that should be removed from the filenames to
221
+ generate the ID.
220
222
221
223
Returns:
222
224
-------
223
225
processed_path : str
224
- The full relative or absolut path to the file.
226
+ The full relative or absolute path to the file.
225
227
_id : str
226
228
The ID derived from the file name. ID will be "" if the filename
227
229
consists only of the suffix.
228
230
"""
229
231
file_name = path .stem
230
-
231
232
_id = file_name
232
233
233
234
if suffixes :
0 commit comments