0

command.py, 将两个配对文件合并在一起,CA01_S1_R1.fastqCA01_S1_R2.fastq. 然后它将结果打印到一个新目录paired.out并命名结果文件paired.fastq。完整的命令将读取

command.py -f CA01_S1_R1.fastq -r CA01_S1_R2.fastq -o paired.out

但是,我想对许多文件执行此命令,然后将所有输出保存到同一目录中。此外,输出需要具有唯一的名称。所以,我也想发送文件 2 和 3,同时有效地运行这些命令:

command.py -f CA02_S2_R1.fastq -r CA02_S2_R2.fastq -o paired.out

command.py -f CA03_S3_R1.fastq -r CA03_S3_R2.fastq -o paired.out

但是,即使我有代码在所有样本上循环此命令,该命令也会继续覆盖最后配对的输出,因为所有输出都保存在文件夹paired.out中,文件名为paired.fastq. 有没有我可以编写的简单循环,它将通过命令发送每个文件对,然后进入文件夹并将文件输出重命名paired.fastqCA01_paired.fastq,然后对我的所有文件重复?

我知道我可以使用以下命令通过命令发送多个文件:

for f in CA*_S*_R1.fastq; do
# Replace R1 with R2 in the filename and run the command on both files.
command.py -f "$f" -r "${f/R1/R2}" -o paired.ends
done; unset -v f

我想在这个循环中添加第二条指令,只 cd 进入这个文件夹,然后重命名文件,每次递增 1。我不知道如何设置增量变量。我想它看起来像这样:

for f in CA*_S*_R1.fastq; do
# Replace R1 with R2 in the filename and run the command on both files.
command.py -f "$f" -r "${f/R1/R2}" -o paired.ends
#cd into the output folder
cd paired.ends
#create an environmental variable that keep tracks of which file number I am on
g=01
#rename the output file
mv fastqjoin.join.fastq CA$g_fastqjoin.join.fastq
#update the environmental variable that keeps track of which file number I am on
g= g + 1
#cd out of the folder where the outputs are being stored and back to the folder that contains all the files to be paired.
cd ..
done; unset -v f
4

1 回答 1

1

假设文件通过blah_R1.fastq和配对blah_R2.fastq

for f in *_R1.fastq; do
    r=${f/_R1/_R2}
    command.py -f "$f" -r "$r" -o paired.out &&
        mv paired.out/paired.fastq paired.out/"${f%%_*}_paired.fastq"
done
于 2014-10-29T19:58:04.723 回答