MacVector and Applescript

Up to MacVector 13 MacVector has had limited Applescript support. The current release (12.7.5) is able to open sequences, print them and that’s about it!

We’ve had frequent requests for MacVector to batch process files. So with the new release (coming very soon) you can batch process files. No analysis can be undertaken just yet but if you need to convert to a different format then this is easily scriptable.

This simple script will open and save all files in a folder. If you want to add extensions to all your files or convert to the latest file format then this will quickly churn through your files.

-- Open, save then close each MV file in folder
set inputFolder to (choose folder with prompt "Select Folder of MV files to open and save:")
tell application "Finder"
	set AllFiles to every file of folder inputFolder
end tell
tell application "MacVector"
	repeat with f in AllFiles
		open f
		delay 0.3
		set docRef to (a reference to the first document)
		save docRef
		close docRef
	end repeat
end tell

This Applescript will convert a folder of MacVector NA files into Genbank format

-- Batch convert all MacVector files in a folder into Genbank format in a second folder.
-- clindley@macvector.com
-- v0.2
-- 2 April  2014
-- 2 April 2014 added routine to ignore any file other than MacVector NA files.

set inputFolder to (choose folder with prompt "Select Folder of MV files to convert:")
set outputFolder to (choose folder with prompt "Select Folder to save Genbank files") as text -- we need this as text to manipulate later

tell application "Finder"
	set AllFiles to every file of folder inputFolder
end tell

repeat with f in AllFiles
	--create the output filepath and add ".gb".
	tell application "Finder"
		--get file  extension of the file
		set mvExtension to the name extension of f
		-- get file path as posix path
		set inputFilePath to name of f
		set AppleScript's text item delimiters to "."
		set outputFilePathBits to text items of inputFilePath
		set last text item of outputFilePathBits to "gb"
		set outputFileName to outputFilePathBits as text
		set outputFilePath to outputFolder & outputFileName as text
	end tell
	
	if mvExtension = "nucl" then
		tell application "MacVector"
			--Now open the file
			open f
			delay 0.3 -- wait a little bit until MV has opened the file
			--now save it as a genbank file
			set docRef to (a reference to the first document)
			save docRef in outputFilePath as GenBank
			close docRef
		end tell
	end if
end repeat

MacVector 13 is still undergoing testing but will be out very soon.

This entry was posted in Development, Releases, Tips and tagged . Bookmark the permalink. Both comments and trackbacks are currently closed.