# Path: lib/util.py
# STATUS_NORMAL=1
# STATUS_MAX_MEMORY_EXCEEDED=2
# STATUS_MAX_RUNTIME_EXCEEDED=3
# MAX_LEN_OUT = 10000
# def runAndMeasure(command,detailed=True,maxtime=0,maxmem=0):
# def runSimple(command):
# def runAndMeasureInternal(return_queue,command,maxtime=0,maxmem=0):
# def runInternal(control_queue,command,max_memory):
# def measureProcess(queue, initial_pids, command, measurement_interval=1, max_runtime=0, max_memory=0, debug=False):
# 	def extendTargets(targets, proc):
# 	def killTargets(targets):
# 	def updateTargets(targets, metrics):
# 	def updateMetrics(target, metrics):
# def loadConfig(name, parent_dir="", already_included=[]):
# def setCallDir(d):
# def setRootDir(d):
# def enterCallDir():
# def enterRootDir():
# def getRootDir():
# def nl2br(text):
# def msg(text="", level=1):
# def yes_no(b):
# def md5(text):
# def merge(x, y):
# def formatFilesize(n):
# def percent(val, base, offset=0):
# def abs_path(path):
# def get_sam_header_line_count(filename):
# def is_sam_sorted(filename):
# def sort_sam(filename,threads=1):
# def sort_sam_picard(filename,threads=-1):
# def line_count(filename):
# def sanitize_string(s):
# def makeExportDropdown(plot_id,csv_filename):
# def parseMD(md,seq):
# 
# Path: lib/stats.py
# class ReferenceMappingStatistics:
# class MappingRow:
# 	def __init__(self):
# 	def to_string(self):
# 	def to_csv(self):
# 	def computeMeasures(self):
# 	def diff(self, other):
# 	def __init__(self, alignment=None):


import os
import csv
from lib import util
from lib import stats

	try:
		generator.set_testee(self._("output:sorted_testee_path"))
	except Exception as e:
		self.error("Failed to open output file for comparison - mapping might have failed, see subprocess logs (" + str(
			e) + ")", sam_testee_sorted_path, None)
		raise SystemExit

	try:
		generator.set_comparison(actual_comparison_path)
	except Exception as e:
		self.error("Failed to open comparison file for comparison (" + str(e) + ")", actual_comparison_path, None)
		raise SystemExit

	if self.mate.export_reads:
		generator.set_export(True)
		_,reads_csv_path=self.getCSVPath(self.getMapper().getName()+"_reads")
		generator.set_export_file(reads_csv_path)
		self.dbg("Exporting reads to %s"%reads_csv_path)

	generator.compute()
	stats_out = generator.get_stats()

	#total_count = self._("input_info:read_count")
	#if total_count == None:
	#	total_count = 0
	#stats_out.total = total_count
	#stats_out.not_found = total_count - stats_out.correct - stats_out.wrong - stats_out.not_mapped
	self.log(stats_out.to_string())


# Path: lib/util.py
# STATUS_NORMAL=1
# STATUS_MAX_MEMORY_EXCEEDED=2
# STATUS_MAX_RUNTIME_EXCEEDED=3
# MAX_LEN_OUT = 10000
# def runAndMeasure(command,detailed=True,maxtime=0,maxmem=0):
# def runSimple(command):
# def runAndMeasureInternal(return_queue,command,maxtime=0,maxmem=0):
# def runInternal(control_queue,command,max_memory):
# def measureProcess(queue, initial_pids, command, measurement_interval=1, max_runtime=0, max_memory=0, debug=False):
# 	def extendTargets(targets, proc):
# 	def killTargets(targets):
# 	def updateTargets(targets, metrics):
# 	def updateMetrics(target, metrics):
# def loadConfig(name, parent_dir="", already_included=[]):
# def setCallDir(d):
# def setRootDir(d):
# def enterCallDir():
# def enterRootDir():
# def getRootDir():
# def nl2br(text):
# def msg(text="", level=1):
# def yes_no(b):
# def md5(text):
# def merge(x, y):
# def formatFilesize(n):
# def percent(val, base, offset=0):
# def abs_path(path):
# def get_sam_header_line_count(filename):
# def is_sam_sorted(filename):
# def sort_sam(filename,threads=1):
# def sort_sam_picard(filename,threads=-1):
# def line_count(filename):
# def sanitize_string(s):
# def makeExportDropdown(plot_id,csv_filename):
# def parseMD(md,seq):
# 
# Path: lib/stats.py
# class ReferenceMappingStatistics:
# class MappingRow:
# 	def __init__(self):
# 	def to_string(self):
# 	def to_csv(self):
# 	def computeMeasures(self):
# 	def diff(self, other):
# 	def __init__(self, alignment=None):


# Path: tests_base/base_mapping_real/calc_stats.py
import os
import csv
from lib import util
from lib import stats


	try:
		generator.set_testee(self._("output:sorted_testee_path"))
	except Exception as e:
		self.error("Failed to open output file for comparison - mapping might have failed, see subprocess logs (" + str(
			e) + ")", sam_testee_sorted_path, None)
		raise SystemExit

	try:
		generator.set_comparison(actual_comparison_path)
	except Exception as e:
		self.error("Failed to open comparison file for comparison (" + str(e) + ")", actual_comparison_path, None)
		raise SystemExit

	if self.mate.export_reads:
		generator.set_export(True)
		_,reads_csv_path=self.getCSVPath(self.getMapper().getName()+"_reads")
		generator.set_export_file(reads_csv_path)
		self.dbg("Exporting reads to %s"%reads_csv_path)

	generator.compute()
	stats_out = generator.get_stats()

	#total_count = self._("input_info:read_count")
	#if total_count == None:
	#	total_count = 0
	#stats_out.total = total_count
	#stats_out.not_found = total_count - stats_out.correct - stats_out.wrong - stats_out.not_mapped
	self.log(stats_out.to_string())


	for msg, file, pos in generator.get_warnings():