#!/opt/conda/conda-bld/albatradis_1758427780971/_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/bin/python
import argparse
import sys
import os
import pkg_resources
sys.path.append('../')
sys.path.append('./')
from albatradis.AlbaTraDIS import AlbaTraDIS


version = ''
try:
	version = pkg_resources.get_distribution("albatradis").version
except pkg_resources.DistributionNotFound:
	version = 'x.y.z'

parser = argparse.ArgumentParser(
	description = 'Tradis analysis',
	usage = 'albatradis [options] EMBLfile condition_plotfiles control_plotfiles', formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('emblfile', help='Annotation file in EMBL format', type=str)
parser.add_argument('plotfiles', help='Input plot files (optionally gzipped). There must be an equal number of condition and control files', nargs='+', type=str)

parser.add_argument('--span_gaps',             '-s', help='Span a gap if it is this multiple of a window size', type=int, default=1)
parser.add_argument('--iterations',            '-i', help='No. of times to rescan', type=int, default=1)
parser.add_argument('--minimum_block',         '-b', help='Minimum number of reads which must be in 1 block in comparison', type=int, default=100)
parser.add_argument('--minimum_logfc',         '-f', help='Minimum log fold change +/-', type=float, default=1)
parser.add_argument('--minimum_logcpm',        '-c', help='Minimum log counts per million +/-', type=float, default=8.0)
parser.add_argument('--minimum_threshold',     '-m', help='Only include insert sites with this number or greater insertions', type=int, default=5)
parser.add_argument('--minimum_proportion_insertions', '-d', help='If the proportion of insertions is too low compared to control, dont call decreased insertions below this level', type=float, default=0.1)
parser.add_argument('--dont_normalise_plots',  '-n', action='store_true', help='Dont normalise input plots', default = False)
parser.add_argument('--prefix',                '-o',  help='Output directory prefix', type=str, default='output')
parser.add_argument('--pvalue',                '-p',  help='Dont report anything above this p-value', type=float, default=0.05)
parser.add_argument('--qvalue',                '-q',  help='Dont report anything above this q-value', type=float, default=0.05)
parser.add_argument('--strict_signal',         '-g', action='store_true', help='A result must be present in the combined plots to be returned', default = False)
parser.add_argument('--use_annotation',        '-a',  help='Use the reference annotation rather than a sliding window', action='store_true', default = False)
parser.add_argument('--prime_feature_size',    '-z', help='Feature size when adding 5/3 prime block when --use_annotation', type=int, default=198)
parser.add_argument('--window_interval',       '-l',  help='Window interval', type=int, default=25)
parser.add_argument('--window_size',	       '-w', help='Window size', type=int, default= 100)
parser.add_argument('--verbose',               '-v', action='store_true', help='Print out more information about the analysis while it runs', default = False)
parser.add_argument('--debug', action='store_true', help='Turn on debugging', default = False)
parser.add_argument('--version', action='version', version=str(version))


options = parser.parse_args()

if options.debug:
	options.verbose = True
	import cProfile, pstats, io
	pr = cProfile.Profile()
	pr.enable()
		
	albatradis = AlbaTraDIS(options)
	albatradis.run()
		
	pr.disable()
	s = io.StringIO()
	sortby = 'cumulative'
	ps = pstats.Stats(pr, stream=s).sort_stats(sortby)
	ps.print_stats()
	print(s.getvalue())
else:
	albatradis = AlbaTraDIS(options)
	albatradis.run()
