I mod the script so it'll do DNA lookup in a repeat loop. What it does:
1) Prompt for location of folder that holds DNA files. --> DNA
2) Prompt for Genome.
3) Create a new folder for results. --> DNA_results
4) For each DNA file, create sub folder in DNA_results folder --> DNA
results/DNAfile
5) Output top rank sequences to DNA_file folder --> DNA
results/DNA_file/1_DNAfile, 2
DNAfile, etc...
Here it is, give it a try:
-- begin
on run
-- locate DNA files folder
set DNA_folder to choose folder with prompt "Please locate DNA files folder"
tell application "Finder"
-- get files in DNA files folder
set DNA_list to items of DNA_folder
-- make results folder base on DNA files folder
set folder_name to name of DNA_folder
set folder_container to container of DNA_folder
if not (exists item ((folder_container as string) & folder_name & "_results")) then
set result_folder to make new folder at folder_container with properties {name:(folder_name & "_results")}
else
set result_folder to item ((folder_container as string) & folder_name & "_results")
end if
end tell
with timeout of (8 * hours) seconds -- change this if need more time
return my DNA
query(DNAlist, result_folder)
end timeout
end run
on DNA
query(DNAlist, result_folder)
set AppleScript's text item delimiters to {""}
set base_URL to "http://genome.ucsc.edu"
-- this is Genome pick list, you can add more into this list
set genome_list to {"Human", "Chimp", "Rhesus"}
set _genome to (choose from list genome_list without multiple selections allowed) as string
repeat with DNA_file in DNA_list
-- make sub folder in results folder for result files
tell application "Finder"
-- get filename for subfolder and result files, base on this file name
set file_name to name of DNA_file
if not (exists (item file_name) of result_folder) then
set sub_folder to make new folder at result_folder with properties {name:file_name}
else
set sub_folder to item file_name of result_folder
end if
end tell
set DNA_text to read file (DNA_file as string)
set DNA_seq to ""
-- get rid of return
repeat with _paragraph in paragraphs of DNA_text
set DNA_seq to (DNA_seq & _paragraph) as string
end repeat
-- return {_genome, DNA_seq}
-- download the result links, any of these parameters can be change manually
do shell script "/usr/bin/curl 'http://genome.ucsc.edu/cgi-bin/hgBlat' -d hgsid=74425287 -d sort='query,score' -d output=hyperlink -d type=\"BLAT's guess\" -d hg18=\"Mar. 2006\" -d org=" & _genome & " -d userSeq=" & quoted form of DNA_seq & " -o /tmp/results_source.txt"
-- get result links in the result page
set _links to do shell script "/usr/local/bin/links
file:///tmp/results_source.txt"
set result_links to {}
set result_count to 0
-- stop parsing links when hit the limit, this determin how results you want to get
set result_limit to 5 -- change if you want more/less results
-- start parsing for hgc? links
repeat with _paragraph in paragraphs of _links
if _paragraph contains "hgc?" then
set result_count to result_count + 1
set AppleScript's text item delimiters to {"file:///"}
copy {(base_URL & last text item of _paragraph) as string} to end of result_links
set AppleScript's text item delimiters to {""}
if result_count is equal to result_limit then exit repeat
end if
end repeat
set AppleScript's text item delimiters to {""}
-- this last part open the result pages in Safari
-- but you can also use curl to direct save the files
set i to 1
tell application "Safari"
repeat with result_link in result_links
make new document
set (URL of document 1) to (result_link as string)
set wait_flag to ""
repeat until wait_flag is "complete"
delay 1
set wait_flag to do JavaScript "document.readyState" in document 1
end repeat
set text_result to text of document 1
delay 2
-- write to result file
do shell script "/bin/echo " & quoted form of text_result & " > " & quoted form of (POSIX path of ((sub_folder as string) & i & "_" & file_name))
set i to i + 1
close window 1
end repeat
end tell
end repeat
end DNA_query
--end