0

I have a tool to compare alignment. Command is

./mscore -cftit <inputFile> <inputFile2>

And the result is four lines in the console. What I try to do?

I have hundreds files:

file1.afa
resFile1.fasta
file2.afa
resFile2.fasta
file3.afa
resFile3.fasta
...

I need to put into arguments in first-row "X.afa" file and in second same name but "X.fasta" file. The result should be saved as Xfinal.txt file or something like that. So I should have hundreds of *final.txt files. (after I will cat it in python, and count).

How can i do that in bash?

I have tried something like this:

#!/bin/bash
ls *.afa | parallel "mscore -cftit {} {}.fasta >{}final.txt"

but of course, it didn't work. Bash it's not familiar to me, I need to just have fast some biological results and I want to automatize my job. I will learn it but now I need it fast. Can someone help me?

hektor102
  • 47
  • 5

1 Answers1

1

So I think you want a sequence of commands like this:

mscore -cftit file1.afa resFile1.fasta > File1final.txt
mscore -cftit file2.afa resFile2.fasta > File2final.txt
mscore -cftit file3.afa resFile3.fasta > File3final.txt
...

Try this:

ls *.afa | while read A; do B=`echo $A | sed 's/^file/resFile/;s/.afa$//'`; ./mscore -cftit $A $B.fasta > ${B}final.txt; done

Better version (thanks @tripleee):

for afafile in *.afa; do number="${afafile#file}"; number="${number%.afa}"; ./mscore -cftit "$afafile" "resFile${number}.fasta" > "file${number}final.txt"; done
jezzaaaa
  • 91
  • 4
  • 1
    You mean `for A in *.afa; do B=resFile${A#file}; B=${B%.afa}; etc`; see also https://mywiki.wooledge.org/ParsingLs and [why you need quotes](https://stackoverflow.com/questions/10067266/when-to-wrap-quotes-around-a-shell-variable/27701642) – tripleee Feb 15 '19 at 11:49
  • Works great! Thank u so much! – hektor102 Feb 15 '19 at 11:55