【发布时间】:2018-09-17 16:35:56
【问题描述】:
我正在尝试做一个 bash 循环来对所有扩展名为 .sam 的文件运行一个简单的进程,这些文件可以在目录及其子目录中找到,并使用相同的名称(exc 扩展名)作为输出作为其输入,输出定向到找到输入的同一文件夹。
我得到了以下内容:
for file in $(find ~/data/finch_data/combruns_BF_genomes -name "*.sam" -type f); do
name="${file%.sam}"
dir=$(pwd $file)
samtools view -Sb "$dir"/"$name".sam > "$dir"/"$name".bam
done
但我收到了这条消息:
...
>bash:/home/madzays/qsub//home/madzays/data/finch_data/combruns_ZF_transcriptomes/ZBND81X_gff/filteredfirstZBND81X_gff.bam: No such file or directory
>bash:/home/madzays/qsub//home/madzays/data/finch_data/combruns_ZF_transcriptomes/ZBND81X_gff/filteredsecZBND81X_gff.bam: No such file or directory
>bash:/home/madzays/qsub//home/madzays/data/finch_data/combruns_ZF_transcriptomes/ZBND82V_gff/filteredfirstZBND82V_gff.bam: No such file or directory
...
可能出了什么问题? 谢谢
【问题讨论】:
-
查看路径,包含
/home/madzays/两次,应该是不正确的。 -
dir=$(pwd)不是 dir=$(pwd $file),但这不是这里的问题 -
我建议:
samtools view -Sb "$name.sam" > ...(不带 $dir) -
是的,这行得通。但为什么?我以为 find 只返回文件名,但它返回整个路径,直到文件名!