Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def get_source_files(source_files) -> List[str]:
"""Get list of all available source files."""
if not source_files:
source_files = [f[1][0] for f in snakemake.utils.listfiles(
Path(get_source_path(), "{file}." + sparv_config.get("import.source_type", "xml")))]
return source_files
def find_samples(data_fp, filename_fmt):
"""
Build a list of samples from a data filepath and filename format.
:param data_fp: a Path to data files
:param filename_fmt: a string giving wildcards for {sample} and (optionally)
{rp}, for read pair (e.g. R1 or R2).
:returns: A dictionary of samples, with sample names as keys:
Samples = {
'sample1': {
'1': 'path/to/sample1_R1.fastq.gz',
'2': 'path/to/sample1_R2.fastq.gz', #optional
}, ...
}
"""
files = list(listfiles(str(data_fp/filename_fmt)))
Samples = {t[1]['sample']: {} for t in files}
for f in files:
fpath = f[0]
wcards = f[1]
rp = wcards.get('rp')
if rp:
if not rp in ['1', '2']:
raise ValueError(
"'{rp}' should capture just '1' or '2' in filename, nothing else")
Samples[wcards['sample']][rp] = fpath
else:
Samples[wcards['sample']]['1'] = fpath
return Samples