-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild_sample_sheet.sh
More file actions
executable file
·35 lines (25 loc) · 954 Bytes
/
Copy pathbuild_sample_sheet.sh
File metadata and controls
executable file
·35 lines (25 loc) · 954 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/env bash
if [ "$#" -ne 1 ]; then
echo "Usage: $0 <path_to_data_directory>"
exit 1
fi
data_dir="$1"
[ -d "$data_dir" ] || { echo "Error: Directory '$data_dir' not found!"; exit 1; }
sample_sheet="sample_sheet.csv"
echo "SampleName,AssayName,FASTQ_R1,FASTQ_R2" > "$sample_sheet"
for sample_dir in "$data_dir"/*/; do
sample_name=$(basename "$sample_dir")
echo "Processing: $sample_name"
find "$sample_dir" -type f -regextype posix-extended \
-regex '.*(_R?1|\.R1)\.(fq|fastq)\.gz' |
while read -r fastq_r1; do
fastq_r2=$(echo "$fastq_r1" | sed -E 's/(_R?1|\.R1)\.(fq|fastq)\.gz/\1/; s/1/2/' )
fastq_r2="${fastq_r1/_R1/_R2}"
fastq_r2="${fastq_r2/_1/_2}"
fastq_r2="${fastq_r2/.R1/.R2}"
if [[ -f "$fastq_r2" ]]; then
echo "$sample_name,cutandrun,$fastq_r1,$fastq_r2" >> "$sample_sheet"
fi
done
done
echo "Sample sheet generated: $sample_sheet"