我有两个文件夹,其中第一个包含19个.fa文件,第二个包含37096个.fa文件
第一个文件夹中的文件名为BF_genomea [a-s] .fa,第二个文件名为[1-37096] ZF_genome.fa
我必须运行这个过程,其中lastz filein1stfolder filein2ndfolder [arguments]> outputfile.axt,这样我就可以对第二个文件夹中的每个文件运行第一个文件夹中的每个文件。
任何类型的输出文件的命名都可以提供,只要它允许id来自哪个特定的父文件组合,并且它们具有扩展名.axt
这是我到目前为止所做的事情
for file in /tibet/madzays/finch_data/BF_genome_split/*.fa; do for otherfile in /tibet/madzays/finch_data/ZF_genome_split/*.fa; name="${file##*/}"; othername="${otherfile##*/}"; lastz $file $otherfile --step=19 --hspthresh=2200 --gappedthresh=10000 --ydrop=3400 --inner=2000 --seed=12of19 --format=axt --scores=/tibet/madzays/finch_data/BFvsZFLASTZ/HoxD55.q > /home/madzays/qsub/test/"$name""$othername".axt; done; done
答案 0 :(得分:1)
代码几乎可以直接从您的需求中翻译出来:
base=/tibet/madzays/finch_data
for b in {a..s}
do
for z in {1..37096}
do
lastz $base/BF_genome_split/${b}.fa $base/ZF_genome_split/${z}.fa --hspthresh=2200 --gappedthresh=10000 --ydrop=3400 --inner=2000 --seed=12of19 --format=axt --scores=$base/BFvsZFLASTZ/HoxD55.q > /home/madzays/qsub/test/${b}-${z}.axt
done
done
请注意,oneliner容易导致错误,例如丢失do
,这些错误很难从错误消息中找到(第1行中的错误)。
答案 1 :(得分:1)
广告我在评论中说,内部循环缺少do
关键字(for otherfile in pattern; do
< - 就在那里)。这是脚本文件的形式吗?如果是这样,你应该添加一个shebang作为告诉操作系统如何运行脚本的第一行。并将其分成多行并缩进循环的内容,以便于阅读(更容易发现丢失的do
等问题。)
在我的脑海中,我看到另外一件事我要改变:输出文件名将非常丑陋,只有两个输入文件与末端的“.atx”一起被捣碎(沿着线条) “BF_genomeac.fa14ZF_genome.fa.axt”)。我将解析输入文件名中的ID,然后使用它们来构建更合理的输出文件名约定。像这样的东西
#!/bin/bash
for file in /tibet/madzays/finch_data/BF_genome_split/*.fa; do
for otherfile in /tibet/madzays/finch_data/ZF_genome_split/*.fa; do
name="${file##*/}"
tmp="${name#BF_genomea}" # remove filename prefix
id="${tmp%.*}" # remove extension to get the ID
othername="${otherfile##*/}"
otherid="${othername%ZF_genome.fa}" # just have to remove a suffix here
lastz $file $otherfile --step=19 --hspthresh=2200 --gappedthresh=10000 --ydrop=3400 --inner=2000 --seed=12of19 --format=axt --scores=/tibet/madzays/finch_data/BFvsZFLASTZ/HoxD55.q > "/home/madzays/qsub/test/BF${id}_${otherid}ZF.axt"
done
done