Entering edit mode
5 months ago
QX
▴
60
Hi all,
I try to write a bash to merge all input bam files; however, I found it difficult to concatenate a path to the files.
What I would like to receive is that if i put an A_barcode, B_barcode, C_barcode.bam files, and a path: ${bam_dir}='user/bam_merge/', I would like the command to run:
samtools merge barcode.sorted.merge.bam user/bam_merge/A_barcode.bam user/bam_merge/B_barcode.bam user/bam_merge/C_barcode.bam
I try this but not working.
./merge.sh *bam
#!/bin/bash
input_bams=$@
output_bam=$(echo $input_bams | awk -F'_' '{print $2}' | uniq).sorted.merge.bam
echo "Input: $input_bams"
echo "Output: $output_bam"
# add path to input:
input=($(awk -v base="${bam_dir}" '{for (i=1; i<=NF; i++) print base"/"$i}' <<< "${input_bams[@]}"))
# add path to output:
output=${bam_dir}$output_bam
echo "### RUNNING merge job --------------------------------------------------"
$samtools merge $output $input
also, do I need to sort again the merged file after I merge all these sorted files?
Best,
looks complicated , is it worth a shell script ?, how about 'just' using the option -b of samtools merge ?
I try to parallel job on slurm with many files, this is just example. I find a way to do this by loop, despite it look quite wordy:
QX : Don't use the
"
for highlighting code. Use101010
to post code in monospaced font.