#!/usr/bin/env python

# Copyright (C) 2011-2012 CRS4.
#
# This file is part of Seal.
#
# Seal is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option)
# any later version.
#
# Seal is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
# for more details.
#
# You should have received a copy of the GNU General Public License along
# with Seal.  If not, see <http://www.gnu.org/licenses/>.


# Driver for the Seqal hadoop program.
# For documentation on the command line options run ./seqal --help

# Input should be the output directory of the PairReadsQSeq (PRQ) application.
#
# All paths are HDFS paths, and may be relative to your HDFS home
# (/user/<your username>);

# hadoop is expected to be either in $HADOOP_HOME/bin or in the PATH;
# if you use a non-standard Hadoop configuration directory, set
# HADOOP_CONF_DIR accordingly.

import logging
import os
import sys

import bl.lib.tools.hadut as hadut
from bl.mr.seq.seqal.seqal_run import SeqalRun
from bl.mr.seq.seqal.seqal_config import SeqalConfigError

def main():
	print >>sys.stderr, "Using hadoop executable %s" % hadut.hadoop

	retcode = 0

	run = SeqalRun()
	try:
		run.parse_cmd_line()
		retcode = run.run()
	except SeqalConfigError as e:
		logger = logging.getLogger(SeqalRun.LogName)
		logger.critical("Error in Seqal run configuration")
		logger.critical(">>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<")
		logger.critical(e)
		logger.critical(">>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<")
		retcode = 1

	if retcode != 0:
		print >>sys.stderr, "Error running Seqal"
	return retcode

if __name__ == "__main__":
  sys.exit(main())
