#!/usr/local/bin/julia

using ArgParse

function translate(RNAString)
	CodonTable = Dict("UUU" => 'F', "CUU" => 'L', "AUU" => 'I', "GUU" => 'V',
					"UUC" => 'F', "CUC" => 'L', "AUC" => 'I', "GUC" => 'V',
					"UUA" => 'L', "CUA" => 'L', "AUA" => 'I', "GUA" => 'V',
					"UUG" => 'L', "CUG" => 'L', "AUG" => 'M', "GUG" => 'V',
					"UCU" => 'S', "CCU" => 'P', "ACU" => 'T', "GCU" => 'A',
					"UCC" => 'S', "CCC" => 'P', "ACC" => 'T', "GCC" => 'A',
					"UCA" => 'S', "CCA" => 'P', "ACA" => 'T', "GCA" => 'A',
					"UCG" => 'S', "CCG" => 'P', "ACG" => 'T', "GCG" => 'A',
					"UAU" => 'Y', "CAU" => 'H', "AAU" => 'N', "GAU" => 'D',
					"UAC" => 'Y', "CAC" => 'H', "AAC" => 'N', "GAC" => 'D',
					"UAA" => ' ', "CAA" => 'Q', "AAA" => 'K', "GAA" => 'E',
					"UAG" => ' ', "CAG" => 'Q', "AAG" => 'K', "GAG" => 'E',
					"UGU" => 'C', "CGU" => 'R', "AGU" => 'S', "GGU" => 'G',
					"UGC" => 'C', "CGC" => 'R', "AGC" => 'S', "GGC" => 'G',
					"UGA" => ' ', "CGA" => 'R', "AGA" => 'R', "GGA" => 'G',
					"UGG" => 'W', "CGG" => 'R', "AGG" => 'R', "GGG" => 'G')

	Codons = [RNAString[idx:idx+2] for idx in 1:3:length(RNAString)]
	Protein = strip(join([CodonTable[Codon] for Codon in Codons]))

end

function main(args)
	# Argument parsing
	configs = ArgParseSettings()

	add_arg_group!(configs, "Options:")
	@add_arg_table! configs begin
		"--input", "-i"
			help	 = "Input filename"
			action	 = :store_arg
			arg_type = String
		"--output", "-o"
			help	 = "Output filename"
			action	 = :store_arg
			arg_type = String
		end
	# Store arguments to variables
	parsed_args = parse_args(args, configs)
	infile      = parsed_args["input"]
	outfile     = parsed_args["output"]

	# Read file and compute problem via function
	RNAString = chomp(open(f->read(f, String), infile))
	@show ProteinString = translate(RNAString)
	open(f->write(f, "$ProteinString"), outfile, "w+")
	
end

main(ARGS)
