FilePatterns.jl finds the files in a directory whose names match a regular
expression or a simple template, and returns one NamedTuple per file holding
the file name, its directory, and the value of every named capture. The result
is a Tables.jl row table, ready for
DataFrame. Options let you keep only some combinations of capture values
(select), check that every expected combination is present (require), and
catch files that share the same capture values (distinct). Building sample
sheets for sequencing data is the motivating use, but nothing in the package is
specific to it.
See the documentation for the manual and API reference.
using Pkg
Pkg.add(url = "https://github.com/kescobo/FilePatterns.jl")Given a directory fastqs containing
A0001_L001_R1.fastq.gz
A0001_L001_R2.fastq.gz
A0002_L001_R1.fastq.gz
A0002_L001_R2.fastq.gz
README.txt
julia> using FilePatterns
julia> filesearch(r"(?<sample>[A-Z0-9]+)_L001_R(?<R>1|2)\.fastq\.gz", "fastqs")
4-element Vector{@NamedTuple{filename::String, directory::String, sample::String, R::String}}:
(filename = "A0001_L001_R1.fastq.gz", directory = "fastqs", sample = "A0001", R = "1")
(filename = "A0001_L001_R2.fastq.gz", directory = "fastqs", sample = "A0001", R = "2")
(filename = "A0002_L001_R1.fastq.gz", directory = "fastqs", sample = "A0002", R = "1")
(filename = "A0002_L001_R2.fastq.gz", directory = "fastqs", sample = "A0002", R = "2")The same search, written as a template, and checked against a sample sheet:
julia> pat = Pattern("<sample>_L001_R<R>.fastq.gz"; R = r"1|2")
Pattern("<sample>_L001_R<R>.fastq.gz"; R = r"1|2")
julia> filesearch(pat, "fastqs"; require = (sample = ["A0001", "A0002", "A0003"], R = 1:2))
ERROR: MissingMatchesError: 2 expected combinations have no matching file in "fastqs" for pattern Pattern("<sample>_L001_R<R>.fastq.gz"; R = r"1|2"):
(sample = "A0003", R = "1")
(sample = "A0003", R = "2")Run the tests, including the Aqua, JET and ExplicitImports checks, with
using Pkg
Pkg.test("FilePatterns")Build the documentation, which also runs its doctests, with
julia --project=docs -e 'using Pkg; Pkg.instantiate()'
julia --project=docs docs/make.jlCode is formatted with Runic.
Install it as an app with Pkg.Apps.add("Runic") (Julia 1.12+), then format
and check with
runic --inplace .
runic --check --diff .The README examples are run in test/test_readme.jl.