bash 中使用工具的嵌套循环
Nested loop using tool in bash
我有一个正在尝试构建的循环。那是从不同的路径中提取文件。我需要将它们循环在一起。这是我拥有的:
#!/bin/bash
#SBATCH --mem=110g
#SBATCH --cpus-per-task=12
module load java/17.0.2
for bam in /PATH1/*.sorted.dmark.bam;
do
java -Xmx110g -jar /PATHtoTOOL/fgbio-2.0.0.jar AnnotateBamWithUmis \
-i bam \
-f /PATH2/*_L001_UMI.fastq.gz \ # This is where I need the secodary loop
-o bam.UMI.bam
done
用文件填充两个数组,按索引遍历它们:
#! /bin/bash
dmarks=(/PATH1/*.sorted.dmark.bam)
fastqs=(/PATH2/*_L001_UMI.fastq.gz)
if (( ${#dmarks[@]} != ${#fastqs[@]} )) ; then
echo Different number of files >&2
exit 1
fi
for (( i=0; i<${#dmarks[@]}; ++i)) ; do
dmark=${dmarks[i]}
fastq=${fastqs[i]}
java -Xmx110g -jar /PATHtoTOOL/fgbio-2.0.0.jar AnnotateBamWithUmis \
-i "$dmark" \
-f "$fastq" \
-o bam.UMI.bam
done
我有一个正在尝试构建的循环。那是从不同的路径中提取文件。我需要将它们循环在一起。这是我拥有的:
#!/bin/bash
#SBATCH --mem=110g
#SBATCH --cpus-per-task=12
module load java/17.0.2
for bam in /PATH1/*.sorted.dmark.bam;
do
java -Xmx110g -jar /PATHtoTOOL/fgbio-2.0.0.jar AnnotateBamWithUmis \
-i bam \
-f /PATH2/*_L001_UMI.fastq.gz \ # This is where I need the secodary loop
-o bam.UMI.bam
done
用文件填充两个数组,按索引遍历它们:
#! /bin/bash
dmarks=(/PATH1/*.sorted.dmark.bam)
fastqs=(/PATH2/*_L001_UMI.fastq.gz)
if (( ${#dmarks[@]} != ${#fastqs[@]} )) ; then
echo Different number of files >&2
exit 1
fi
for (( i=0; i<${#dmarks[@]}; ++i)) ; do
dmark=${dmarks[i]}
fastq=${fastqs[i]}
java -Xmx110g -jar /PATHtoTOOL/fgbio-2.0.0.jar AnnotateBamWithUmis \
-i "$dmark" \
-f "$fastq" \
-o bam.UMI.bam
done