我正在使用一些遵循以下基本模式的软件运行 bash 脚本。
while read sample; do
software ${sample} > output.txt
done <samples.txt
对于某些示例,会打印此消息:“站点 Pf3D7_02_v3:274217 与另一个变体重叠,正在跳过...”
此消息不会停止软件运行,但会使结果为假。因此,如果给出消息,我想停止软件并继续 while 循环移动到下一个示例。samples.txt 中有很多示例,这就是我不能手动执行此操作的原因。一种表示消息用于哪个样本的方法也会有所帮助。因为它是我只是得到该消息的许多行,而不知道该消息是针对哪个循环给出的。
有没有可能帮助解决这个问题?
仅供参考,我正在使用的程序称为 bcftools 共识。如果我需要提供更多信息,请告诉我。
编辑:添加了“> output.txt”——意识到我已经把它剥离得太多了
编辑 2:这是使用下面 chepner 建议的完整脚本。抱歉有点辛苦:
mkfifo p
while IFS= read -r sample; do
bcftools consensus --fasta-ref $HOME/Pf/MSP2_3D7_I_region_ref_noprimer.fasta --sample ${sample} --missing N $EPHEMERAL/bam/Pf_eph/MSP2_I_PfC_Final/Pf_60_public_Pf3D7_02_v3.final.normalised_bcf.vcf.gz --output ${sample}_MSP2_I_consensus_seq.fasta | tee p &
grep -q -m 1 "The site Pf3D7_02_v3" p && kill $!
done <$HOME/Pf/Pf_git/BF_Mali_samples.txt
rm p