Skip to content

Commit 994525d

Browse files
authored
Merge pull request #10 from remiolsen/master
Fix regex search
2 parents fc7edf1 + a35b89e commit 994525d

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

bin/samplesheet_gen.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,20 @@
2828
def main(in_folder, prefix_regex, out_samplesheet):
2929
# Get all fastq files in all subfolders
3030
fastq_files = os.walk(in_folder)
31-
fastq_files = [os.path.join(root, f) for root, _, files in fastq_files for f in files if f.endswith('.fastq.gz')]
31+
fastq_files = [os.path.join(root, f) for root, _, files in fastq_files for f in files if f.lower().endswith(('.fastq.gz', '.fq.gz'))]
32+
3233
# Group files by prefix
33-
prefix_re = re.compile(prefix_regex)
34+
# Find the basename first, then compile the regex and apply it to the basename.
35+
class _BasenamePrefixMatcher:
36+
def __init__(self, pattern):
37+
self._pattern = pattern
38+
39+
def search(self, path):
40+
basename = os.path.basename(path)
41+
# compile after getting the basename (pattern stays the same)
42+
return re.compile(self._pattern).search(basename)
43+
44+
prefix_re = _BasenamePrefixMatcher(prefix_regex)
3445
prefix_groups = {}
3546
for f in fastq_files:
3647
m = prefix_re.search(f)

0 commit comments

Comments
 (0)