-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconcatenate_fast1.sh
More file actions
39 lines (28 loc) · 1009 Bytes
/
Copy pathconcatenate_fast1.sh
File metadata and controls
39 lines (28 loc) · 1009 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
36
37
38
39
#!/bin/bash
# author: Patricia Agudelo-Romero, PhD
# email: p.agudeloromero@gmail.com
# Concatenate FASTQ files split by lanes (L00*) into one per sample.
# It does the same for R1 and R2
if [ $# -lt 2 ]; then
echo "Usage: $0 <input_dir> <output_dir> [jobs]"
exit 1
fi
INPUT_DIR=$1
OUTPUT_DIR=$2
JOBS=${3:-4} # default 4 parallel jobs
mkdir -p "$OUTPUT_DIR"
# Generate commands
> concat_commands.txt
for R1 in "$INPUT_DIR"/*L00*_R1_001.fastq.gz; do
SAMPLE=$(basename "$R1" | sed -E 's/_L00[0-9]_R1_001.fastq.gz//')
echo "sample: $SAMPLE"
# Output filenames
OUT_R1="${OUTPUT_DIR}/${SAMPLE}_R1_001.fastq.gz"
OUT_R2="${OUTPUT_DIR}/${SAMPLE}_R2_001.fastq.gz"
# Write commands for R1 and R2
echo "cat ${INPUT_DIR}/${SAMPLE}_L00*_R1_001.fastq.gz > ${OUT_R1}" >> concat_commands.txt
echo "cat ${INPUT_DIR}/${SAMPLE}_L00*_R2_001.fastq.gz > ${OUT_R2}" >> concat_commands.txt
done
# Run in parallel
parallel -j "$JOBS" < concat_commands.txt
#rm concat_commands.txt