我有一个目录data,其中有几个fastqs,如下所示:
SRR13456784_1.fastq
SRR13456784_2.fastq
SRR13456784_3.fastq
SRR13456785_1.fastq
SRR13456785_2.fastq
SRR13456785_3.fastq
SRR13456786_1.fastq
SRR13456786_2.fastq
SRR13456786_3.fastq
SRR19876543_1.fastq
SRR19876543_2.fastq
SRR19876543_3.fastq
SRR19876544_1.fastq
SRR19876544_2.fastq
SRR19876544_3.fastq我有一个details.txt分隔文件,其中有两列ID and Sample。我想将匹配样本的ID连接起来,并给出输出的示例名。
ID Sample
SRR13456784 GJK1234567
SRR13456785 GJK1234567
SRR13456786 GJK1234567
SRR19876543 GJK2444103
SRR19876544 GJK2444103对于其中一个文件,我连接如下:
cat SRR13456784_1.fastq SRR13456785_1.fastq SRR13456786_1.fastq > GSK1234567_1.fastq
cat SRR13456784_2.fastq SRR13456785_2.fastq SRR13456786_2.fastq > GSK1234567_2.fastq
cat SRR13456784_3.fastq SRR13456785_3.fastq SRR13456786_3.fastq > GSK1234567_3.fastq上面的txt文件就是一个例子,但在我的原始文件中,有300个is与50个示例匹配。
有人能告诉我如何在一个脚本中进行连接并给出输出的示例名吗?谢谢。
发布于 2023-04-27 12:18:18
你可以这样做:
$ tail -n +2 details.txt |
while read -r id sample; do
for i in {1..3}; do
cat < "${id}_${i}".fastq >> "${sample}_${i}".fastq
done
done需要tail +2来跳过头(ID Sample)。然后,我们对其余的行进行迭代,将id和样本保存在相应的变量中,然后在数字1到3上进行第二个循环,并将相关文件连接起来。将从示例输入运行的命令如下:
$ tail -n +2 details.txt | while read -r id sample; do for i in {1..3}; do echo "cat \"${id}_${i}\".fastq >> \"${sample}_${i}\".fastq"; done; done
cat "SRR13456784_1".fastq >> "GJK1234567_1".fastq
cat "SRR13456784_2".fastq >> "GJK1234567_2".fastq
cat "SRR13456784_3".fastq >> "GJK1234567_3".fastq
cat "SRR13456785_1".fastq >> "GJK1234567_1".fastq
cat "SRR13456785_2".fastq >> "GJK1234567_2".fastq
cat "SRR13456785_3".fastq >> "GJK1234567_3".fastq
cat "SRR13456786_1".fastq >> "GJK1234567_1".fastq
cat "SRR13456786_2".fastq >> "GJK1234567_2".fastq
cat "SRR13456786_3".fastq >> "GJK1234567_3".fastq
cat "SRR19876543_1".fastq >> "GJK2444103_1".fastq
cat "SRR19876543_2".fastq >> "GJK2444103_2".fastq
cat "SRR19876543_3".fastq >> "GJK2444103_3".fastq
cat "SRR19876544_1".fastq >> "GJK2444103_1".fastq
cat "SRR19876544_2".fastq >> "GJK2444103_2".fastq
cat "SRR19876544_3".fastq >> "GJK2444103_3".fastqhttps://unix.stackexchange.com/questions/744214
复制相似问题