#!/usr/bin/env ruby

require_relative "params_reader.rb"

def parse_ARGV()
	pars = {}
	ARGV.each do |a|
		pars[a.split("=")[0]] = a.split("=")[1]
	end
	return pars
end
pars = parse_ARGV()

# example value: input_fasta_file=/nfs/labs/compbio/sgeorg/motif_analysis/cluster_files/Ago/data/seq_PARalyzer_3UTR_FilterType_NA_minConversionLocationCount_2
if(pars["params_file"] == nil)
  	print "ERROR: need to specify params_file\n"
  	print "command FORMAT: ./copy_files.rb params_file=<file_name>\n"
	exit
end

def run(params_file)
	# defined inside: 'params_reader.rb'
	pars = ParamsReader.read_params_file(params_file)
	
#	split_suff = pars["clusters_file"].scan(/_[^_]*.csv/)[0]
#	out_dir=pars["clusters_file"].split(split_suff)[0]

	out_dir=File.dirname(pars["clusters_file"]) + "/" + File.basename(pars["clusters_file"]).split(".csv")[0]

	print "copying files to #{out_dir}\n"
	
	command = "cp generate_logo.R #{out_dir}/generate_logo.R"
	system(command)
	
	if(pars["clusters_file"].scan("AGO") != [])
		command = "cp mEAT #{out_dir}/mEAT"
		print "mEAT\n"
		system(command)
	
		command = "cp miRbase_sorted #{out_dir}/miRbase_sorted"
		print "miRbase_sorted\n"
		system(command)
		command = "cp miRs_experessed #{out_dir}/miRs_experessed"
		print "miRs_experessed\n"
		system(command)
	
		command = "cp run_mEAT_analysis #{out_dir}/run_mEAT_analysis"
		print "run_mEAT_analysis\n"
		system(command)
	
	else
		command = "cp cERMIT #{out_dir}/cERMIT"
		print "cERMIT\n"
		system(command)
	
		command = "cp oligos_size_* #{out_dir}"
		print "oligos_size_* \n"
		system(command)
	
		command = "cp run_cERMIT_analysis #{out_dir}/run_cERMIT_analysis"
		print "run_cERMIT_analysis\n"
		system(command)

		command = "cp covariates_file_list #{out_dir}/covariates_file_list"
		print "covariates_file_list\n"
		system(command)
	end
	
	if(pars["clusters_file"].scan("QKI") != [])
		command = "cp pssm_QKI #{out_dir}/data/pssm_QKI"
		print "pssm_QKI\n"
		system(command)
	end

end

#############
# run command
#############
run(pars["params_file"])
#############
# run command
#############


