Skip to content

Commit

Permalink
Added a fastq_merge.sh to replace the python version
Browse files Browse the repository at this point in the history
  • Loading branch information
spficklin committed Jul 13, 2024
1 parent e9a5517 commit 78dc55b
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
2 changes: 1 addition & 1 deletion bin/merge_fastq.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
if (re.match(r"^.*(_2.fastq)$", fastq_filename) and handles['_2.fastq'] is None):
handles['_2.fastq'] = open(args.out_prefix + '_2.fastq', "w")

# Now open each file and merge the records into the appropirate
# Now open each file and merge the records into the appropriate
# output file.
for fastq_filename in args.fastq_files:
fh = None
Expand Down
34 changes: 34 additions & 0 deletions bin/merge_fastq.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/bash

sample_id=$1

files_1=(`find . -maxdepth 1 -name "*_1.fastq" | grep -v $sample_id | sort`)
files_2=(`find . -maxdepth 1 -name "*_2.fastq" | grep -v $sample_id | sort`)

# Check the number of files. If there is more than one then
# combine them. If not, then just create a link with the
# sample_id as the name.
if [ ${#files_1[@]} -gt 1 ] ; then

for i in "${!files_1[@]}"; do
cat ${files_1[$i]} >> ${sample_id}_1.fastq
done;

elif [ ${#files_1[@]} -eq 1 ] ; then

ln ${files_1[0]} ${sample_id}_1.fastq

fi

# If there are paired files.
if [ ${#files_2[@]} -gt 1 ] ; then

for i in "${!files_2[@]}"; do
cat ${files_2[$i]} >> ${sample_id}_2.fastq
done;

elif [ ${#files_2[@]} -eq 1 ] ; then

ln ${files_2[0]} ${sample_id}_2.fastq
fi

3 changes: 1 addition & 2 deletions modules/local/fastq_merge.nf
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
*/
process fastq_merge {
tag { sample_id }
container "systemsgenetics/gemmaker:2.1.0"

input:
tuple val(sample_id), path(fastq_files)
Expand All @@ -14,6 +13,6 @@ process fastq_merge {

script:
"""
merge_fastq.py --fastq_files ${fastq_files.join(" ")} --out_prefix ${sample_id}
merge_fastq.sh ${sample_id}
"""
}

0 comments on commit 78dc55b

Please sign in to comment.