How to use the snakemake.utils.listfiles function in snakemake

To help you get started, we’ve selected a few snakemake examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github spraakbanken / sparv-pipeline / sparv / core / snake_utils.py View on Github external
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
github sunbeam-labs / sunbeam / sunbeamlib / scripts / list_samples.py View on Github external
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