1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
|
diff -Naur mafft-6.240/src/mafft-homologs.tmpl mafft-6.240.new/src/mafft-homologs.tmpl
--- mafft-6.240/src/mafft-homologs.tmpl 2006-10-01 20:31:38.000000000 -0400
+++ mafft-6.240.new/src/mafft-homologs.tmpl 2008-09-05 17:14:17.000000000 -0400
@@ -31,11 +31,22 @@
# -w entire sequences are subjected to BLAST search
# (default: well-aligned region only)
-
require 'getopts'
+require 'tempfile'
+
+# create temporary files
+temp_vf = Tempfile.new("_vf").path
+temp_if = Tempfile.new("_if").path
+temp_pf = Tempfile.new("_pf").path
+temp_af = Tempfile.new("_af").path
+temp_qf = Tempfile.new("_qf").path
+temp_bf = Tempfile.new("_bf").path
+temp_rid = Tempfile.new("_rid").path
+temp_res = Tempfile.new("_res").path
-system( mafftpath + " --help > /tmp/_vf#{$$} 2>&1" )
-pfp = File.open( "/tmp/_vf#{$$}", 'r' )
+
+system( mafftpath + " --help > #{temp_vf} 2>&1" )
+pfp = File.open( "#{temp_vf}", 'r' )
while pfp.gets
break if $_ =~ /MAFFT v/
end
@@ -114,35 +125,38 @@
mafftopt += " " + $OPT_o + " "
end
-system "cat " + ARGV.to_s + " > /tmp/_if#{$$}"
+system "cat " + ARGV.to_s + " > #{temp_if}"
ar = mafftopt.split(" ")
nar = ar.length
for i in 0..(nar-1)
if ar[i] == "--seed" then
- system "cat #{ar[i+1]} >> /tmp/_if#{$$}"
+ system "cat #{ar[i+1]} >> #{temp_if}"
end
end
nseq = 0
-ifp = File.open( "/tmp/_if#{$$}", 'r' )
+ifp = File.open( "#{temp_if}", 'r' )
while ifp.gets
nseq += 1 if $_ =~ /^>/
end
ifp.close
-STDERR.puts "Performing preliminary alignment .. "
-if nseq == 1 then
- system( "cp /tmp/_if#{$$}" + " /tmp/_pf#{$$}" )
+if nseq >= 100 then
+ STDERR.puts "The number of input sequences must be <100."
+ exit
+elsif nseq == 1 then
+ system( "cp #{temp_if}" + " #{temp_pf}" )
else
+ STDERR.puts "Performing preliminary alignment .. "
if entiresearch == 1 then
-# system( mafftpath + " --maxiterate 1000 --localpair /tmp/_if#{$$} > /tmp/_pf#{$$}" )
- system( mafftpath + " --maxiterate 0 --retree 2 /tmp/_if#{$$} > /tmp/_pf#{$$}" )
+# system( mafftpath + " --maxiterate 1000 --localpair #{temp_if} > #{temp_pf}" )
+ system( mafftpath + " --maxiterate 0 --retree 2 #{temp_if} > #{temp_pf}" )
else
- system( mafftpath + " --maxiterate 1000 --localpair --core --coreext --corethr #{corethr.to_s} --corewin #{corewin.to_s} /tmp/_if#{$$} > /tmp/_pf#{$$}" )
+ system( mafftpath + " --maxiterate 1000 --localpair --core --coreext --corethr #{corethr.to_s} --corewin #{corewin.to_s} #{temp_if} > #{temp_pf}" )
end
end
-pfp = File.open( "/tmp/_pf#{$$}", 'r' )
+pfp = File.open( "#{temp_pf}", 'r' )
inname = []
inseq = []
slen = []
@@ -155,7 +169,7 @@
end
pfp.close
-pfp = File.open( "/tmp/_if#{$$}", 'r' )
+pfp = File.open( "#{temp_if}", 'r' )
orname = []
orseq = []
nin = 0
@@ -188,7 +202,7 @@
#p act
-afp = File.open( "/tmp/_af#{$$}", 'w' )
+afp = File.open( "#{temp_af}", 'w' )
STDERR.puts "Searching .. \n"
ids = []
@@ -209,10 +223,10 @@
end
if local == 0 then
- command = "lynx -source 'http://www.ncbi.nlm.nih.gov/blast/Blast.cgi?QUERY=" + inseq[i] + "&DATABASE=swissprot&HITLIST_SIZE=" + nadd.to_s + "&FILTER=L&EXPECT='" + eval.to_s + "'&FORMAT_TYPE=TEXT&PROGRAM=blastp&SERVICE=plain&NCBI_GI=on&PAGE=Proteins&CMD=Put' > /tmp/_rid#{$$}"
+ command = "lynx -source 'http://www.ncbi.nlm.nih.gov/blast/Blast.cgi?QUERY=" + inseq[i] + "&DATABASE=swissprot&HITLIST_SIZE=" + nadd.to_s + "&FILTER=L&EXPECT='" + eval.to_s + "'&FORMAT_TYPE=TEXT&PROGRAM=blastp&SERVICE=plain&NCBI_GI=on&PAGE=Proteins&CMD=Put' > #{temp_rid}"
system command
- ridp = File.open( "/tmp/_rid#{$$}", 'r' )
+ ridp = File.open( "#{temp_rid}", 'r' )
while ridp.gets
break if $_ =~ / RID = (.*)/
end
@@ -224,9 +238,9 @@
while 1
STDERR.printf "."
sleep 10
- command = "lynx -source 'http://www.ncbi.nlm.nih.gov/blast/Blast.cgi?RID=" + rid + "&DESCRIPTIONS=500&ALIGNMENTS=" + nadd.to_s + "&ALIGNMENT_TYPE=Pairwise&OVERVIEW=no&CMD=Get&FORMAT_TYPE=XML' > /tmp/_res#{$$}"
+ command = "lynx -source 'http://www.ncbi.nlm.nih.gov/blast/Blast.cgi?RID=" + rid + "&DESCRIPTIONS=500&ALIGNMENTS=" + nadd.to_s + "&ALIGNMENT_TYPE=Pairwise&OVERVIEW=no&CMD=Get&FORMAT_TYPE=XML' > #{temp_res}"
system command
- resp = File.open( "/tmp/_res#{$$}", 'r' )
+ resp = File.open( "#{temp_res}", 'r' )
# resp.gets
# if $_ =~ /WAITING/ then
# resp.close
@@ -247,17 +261,17 @@
else
# puts "Not supported"
# exit
- qfp = File.open( "/tmp/_q#{$$}", 'w' )
+ qfp = File.open( "#{temp_qf}", 'w' )
qfp.puts "> "
qfp.puts inseq[i]
qfp.close
- command = blastpath + " -p blastp -e #{eval} -b 1000 -m 7 -i /tmp/_q#{$$} -d #{localdb} > /tmp/_res#{$$}"
+ command = blastpath + " -p blastp -e #{eval} -b 1000 -m 7 -i #{temp_qf} -d #{localdb} > #{temp_res}"
system command
- resp = File.open( "/tmp/_res#{$$}", 'r' )
+ resp = File.open( "#{temp_res}", 'r' )
end
STDERR.puts " Done.\n\n"
- resp = File.open( "/tmp/_res#{$$}", 'r' )
+ resp = File.open( "#{temp_res}", 'r' )
while 1
while resp.gets
break if $_ =~ /<Hit_id>(.*)<\/Hit_id>/ || $_ =~ /(<Iteration_stat>)/
@@ -310,17 +324,15 @@
afp.close
STDERR.puts "Performing alignment .. "
-system( mafftpath + mafftopt + " /tmp/_af#{$$} > /tmp/_bf#{$$}" )
+system( mafftpath + mafftopt + " #{temp_af} > #{temp_bf}" )
STDERR.puts "done."
-bfp = File.open( "/tmp/_bf#{$$}", 'r' )
+bfp = File.open( "#{temp_bf}", 'r' )
outseq = []
outnam = []
readfasta( bfp, outnam, outseq )
bfp.close
-
-
outseq2 = []
outnam2 = []
@@ -356,5 +368,3 @@
puts ">" + outnam2[i]
puts outseq2[i].gsub( /.{1,60}/, "\\0\n" )
end
-
-system( "rm -rf /tmp/_if#{$$} /tmp/_vf#{$$} /tmp/_af#{$$} /tmp/_bf#{$$} /tmp/_pf#{$$} /tmp/_q#{$$} /tmp/_res#{$$} /tmp/_rid#{$$}" )
diff -Naur mafft-6.240/src/mafft.tmpl mafft-6.240.new/src/mafft.tmpl
--- mafft-6.240/src/mafft.tmpl 2007-04-03 19:16:51.000000000 -0400
+++ mafft-6.240.new/src/mafft.tmpl 2008-09-05 17:18:04.000000000 -0400
@@ -240,11 +240,14 @@
shift
done;
-# TMPFILE=/tmp/`basename $0`.`whoami`.$$.`date +%y%m%d%H%M%S`
- TMPFILE=/tmp/$progname.$$
+ # create temporary directory; terminate script in case of failure
+ if ! TMPFILE=`mktemp -dt $progname.XXXXXXXXXX`; then
+ echo "Failed to create temporary directory"
+ exit 1
+ fi
+
umask 077
- mkdir $TMPFILE || er=1
- trap "rm -r $TMPFILE " 0
+ trap "rm -rf $TMPFILE " 0
if [ $# -eq 1 ]; then
if [ -r "$1" -o "$1" = - ]; then
cat "$1" | tr "\r" "\n" > $TMPFILE/infile
|