I am trying to automate the running of a program, using and expect script, but I am doing something wrong. I have a bunch of files in my current directory that follow this naming convention:
file_name-hereROI.txt
file_name-hereFR.txt
file1_name-hereROI.txt
file1_name-hereFR.txt
file_name1-hereROI.txt
file_name1-hereFR.txt
file_name-here1ROI.txt
file_name-here1FR.txt
What I would like to do is to run a program on every pair. So if the string before "ROI" or "FR" is the same, it should be compared by water. I have written:
1 #/usr/bin/expect
2 for f in *ROI.fasta
3 do
4 for f2 in *FR.fasta
5 do
6 fROI=$(echo $f | cut -d'ROI' -f 1)
7 f2ROI=$(echo $f2 | cut -d'FR' -f 1)
8 if [$fROI == $f2ROI]
9 then
10 spawn water f f2
11 expect "Gap opening penalty [10.0]:"
12 send "\n"
13 expect "Gap extension penalty [0.5]:"
14 send "\n"
15 expect "Output alignment"
16 send "\n"
17 close
18 fi
19 done < ls
20 done < ls
But I am not getting very far at all. I have this error:
$ expect water.sh
wrong # args: should be "for start test next command"
while executing
"for f in *ROI.fasta"
(file "water.sh" line 2)
I think you're getting mixed up between bash and Tcl/Expect notation.
Expect is an extension of Tcl, so if you're going to have your script interpreted by Expect you need to use Tcl's constructs.
For starters, you will need to use Tcl's "for" loop, documented here .
Refer to the rest of the Tcl documentation for the other conditionals needed (if, while, etc).
foreach f [glob *ROI.txt] {
set f2 "[string range $f 0 [expr {[string length $f] - 8}]]FR.txt"
if {[file exists $f2]} {
spawn water $f $f2
# ...
}
}
To avoid hardcoding the number "8"
set suffix "ROI.txt"
set new_suffix "FR.txt"
foreach f [glob *$suffix] {
set prefix [regsub "$suffix\$" $f ""]
# or
set idx [string last $suffix $f]
set prefix [string range $f 0 [incr idx -1]]
set f2 $prefix$new_suffix
# ...
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.