7
7
from .._models .sample import Sample
8
8
9
9
10
- def _get_samples_from_paths (sample_paths ):
10
+ def _get_samples_from_paths (sample_paths , filename_as_id = False ):
11
11
"""
12
12
Load multiple Sample instances from a list of file paths
13
13
14
14
:param sample_paths: list of file paths containing FCS files
15
+ :param filename_as_id: Boolean option for using the file name (as it exists on the
16
+ filesystem) for the Sample's ID, default is False.
15
17
:return: list of Sample instances
16
18
"""
17
19
samples = []
18
20
for path in sample_paths :
19
- samples .append (Sample (path ))
21
+ samples .append (Sample (path , filename_as_id = filename_as_id ))
20
22
21
23
return samples
22
24
23
25
24
- def load_samples (fcs_samples ):
26
+ def load_samples (fcs_samples , filename_as_id = False ):
25
27
"""
26
28
Returns a list of Sample instances from a variety of input types (fcs_samples), such as file or
27
29
directory paths, a Sample instance, or lists of the previous types.
@@ -30,6 +32,9 @@ def load_samples(fcs_samples):
30
32
a directory or file path, or a list of directory or file paths. If a directory, any .fcs
31
33
files in the directory will be loaded. If a list, then it must be a list of file paths or a
32
34
list of Sample instances. Lists of mixed types are not supported.
35
+ :param filename_as_id: Boolean option for using the file name (as it exists on the
36
+ filesystem) for the Sample's ID, default is False. Only applies to file paths given to the
37
+ 'fcs_samples' argument.
33
38
:return: list of Sample instances
34
39
"""
35
40
sample_list = []
@@ -43,13 +48,14 @@ def load_samples(fcs_samples):
43
48
44
49
if len (sample_types ) > 1 :
45
50
raise ValueError (
46
- "Each item in 'fcs_sample' list must be a FCS file path or Sample instance"
51
+ "Found multiple object types for 'fcs_samples' option. "
52
+ "Each item in 'fcs_samples' list must be of the same type (FCS file path or Sample instance)."
47
53
)
48
54
49
55
if Sample in sample_types :
50
56
sample_list = fcs_samples
51
57
elif str in sample_types :
52
- sample_list = _get_samples_from_paths (fcs_samples )
58
+ sample_list = _get_samples_from_paths (fcs_samples , filename_as_id = filename_as_id )
53
59
elif isinstance (fcs_samples , Sample ):
54
60
# 'fcs_samples' is a single Sample instance
55
61
sample_list = [fcs_samples ]
@@ -59,10 +65,10 @@ def load_samples(fcs_samples):
59
65
if os .path .isdir (fcs_samples ):
60
66
fcs_paths = glob (os .path .join (fcs_samples , '*.fcs' ))
61
67
if len (fcs_paths ) > 0 :
62
- sample_list = _get_samples_from_paths (fcs_paths )
68
+ sample_list = _get_samples_from_paths (fcs_paths , filename_as_id = filename_as_id )
63
69
else :
64
70
# assume a path to a single FCS file
65
- sample_list = _get_samples_from_paths ([fcs_samples ])
71
+ sample_list = _get_samples_from_paths ([fcs_samples ], filename_as_id = filename_as_id )
66
72
67
73
return sorted (sample_list )
68
74
0 commit comments