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>/ || $_ =~ /()/ @@ -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