如何制作一个bash脚本,分别在目录中的每个文件上使用cdhit?

如何制作一个bash脚本,分别在目录中的每个文件上使用cdhit?,bash,sh,bioinformatics,Bash,Sh,Bioinformatics,我有一个目录,其中包含>500个multifasta文件。我想使用相同的程序(cd hit est)对每个文件中的序列进行聚类,然后将输出保存到另一个目录中。我希望文件的名称与原始文件中的名称相同 for file in /dir/*.fasta; do echo "$file"; cd-hit-est -i $file -o /anotherdir/${file} -c 0.98 -n 9 -d 0 -M 120000 -T 32; done 我得到部分输出,然后出现错误: ... ^M#

我有一个目录,其中包含>500个multifasta文件。我想使用相同的程序(cd hit est)对每个文件中的序列进行聚类,然后将输出保存到另一个目录中。我希望文件的名称与原始文件中的名称相同

for file in /dir/*.fasta; 
do
echo "$file";
cd-hit-est -i $file -o /anotherdir/${file} -c 0.98 -n 9 -d 0 -M 120000 -T 32;
done
我得到部分输出,然后出现错误:

...
^M# comparing sequences from      33876  to      33910
    .................---------- new table with       34 representatives
    ^M# comparing sequences from      33910  to      33943
    .................---------- new table with       33 representatives
    ^M# comparing sequences from      33943  to      33975
    ................---------- new table with       32 representatives
    ^M# comparing sequences from      33975  to      34006
    ................---------- new table with       31 representatives
    ^M# comparing sequences from      34006  to      34036
    ...............---------- new table with       30 representatives
    ^M# comparing sequences from      34036  to      34066
    ...............---------- new table with       30 representatives
    ^M# comparing sequences from      34066  to      35059
    .....................
    Fatal Error:
    file opening failed
    Program halted !!

    ---------- new table with      993 representatives

        35059  finished      34719  clusters

没有生成输出文件。有人能帮我理解我在哪里犯了错误吗?

好的,看来我现在有了答案,不管怎样,如果有人在寻找类似的答案

for file in /dir/*.fasta; 
        do
                echo "$file";
                cd-hit-est -i "$file" -o /anotherdir/$(basename "$transcriptome") -c 0.98 -n 9 -d 0 -M 120000 -T 32;
        done

用另一种方法调用输出文件就可以了。

您应该在使用它的任何地方引用
$file
cd hit est-i“$file”-o/anotherdir/“$file”
。您的命令对单个文件有效吗?示例输出中的
echo
文件名在哪里?
^M
看起来像是您允许Windows靠近您的数据,因为Linux/Unix使用换行符而不是回车符。另外,请查看GNU Parallel,以加速和简化此类操作@BenjaminW。感谢您的回复,所以我确实将所有$file放入了“$file”,并对只有一个文件的目录运行了一个测试,得到了完全相同的“致命错误”。。。我真的不明白原因是什么,因为当我运行同一个程序时。但是,如果我在一个由名称指定的文件上运行程序本身(带有cd hit est的行),那么一切都会正常工作。这意味着我在循环中做错了什么?嗨@MarkSetchell,谢谢你的评论。我对
^M
不太清楚,因为附近没有Windows操作系统,我在我的终端上看不到:)谢谢你链接到biostars!
doit() {
    file="$1"
    echo "$file";
    cd-hit-est -i "$file" -o /anotherdir/$(basename "$transcriptome") -c 0.98 -n 9 -d 0 -M 120000 -T 32;
}
env_parallel doit ::: /dir/*.fasta