# Path: lib/gsample.py
# def log(msg):
# def index(reference, fastindex_path = "tools/fastindex"):
# def index_legacy(reference):
# def downsample(index, contig_filename, downsampled_filename, region_count, target_len, single_contig=False,
# 			   region_list=False, spacer_len=200):
# def csample(infile, region_size, sample_fraction, spacer_len=200, fastindex_path=""):
# def ctranslate(reference_file, sampled_index_file, sam_file, target_file, fastindex_path=""):
# 
# Path: tools/fastq2sam.py
# def encode_qname(qname, retain_petag=True):
# 	def __init__(self):
# 	def __init__(self, filename, pe):
# 	def readline(self):
# 	def next_read(self):
# 	def __init__(self):
# 	def align(read):
# 	def align(self, read, paired=False, is_read1=True):
# 	def align_pair(self, read1, read2):
# 	def align(self, read, paired=False, is_read1=True):
# 	def align_pair(self, read1, read2):
# 	def __init__(self, aligner, outfile):
# 	def write(self, what):
# 	def write_sam_header(self, reads):
# 	def write_single(self, read, to):
# 	def align_se(self, infile):
# 	def align_pe(self, infile_1, infile_2):
# class Object:
# class FASTQ:
# class Aligner:
# class DummyAligner(Aligner):
# class dwgsim(Aligner):
# class Converter:
# 
# Path: lib/sam.py
# class SAMRow:
# class SAMFile:
# class Object:
# class FASTQ:
# 	def __init__(self):
# 	def getTag(self,tag_name):
# 	def __init__(self, filename):
# 	def close(self):
# 	def hasLast(self):
# 	def getLast(self):
# 	def getCurr(self):
# 	def getHeader(self):
# 	def isSorted(self):
# 	def next(self):
# 	def __init__(self):
# 	def __init__(self, filename, write=False):
# 	def readline(self):
# 	def next_read(self):
# 	def write_read(self,read):
# 	def close(self):


import os
import shutil
import time
import yaml
import util
import simulator
	import main
from lib import gsample
from tools import fastq2sam
from lib import sam
		line_count = line_counts[0]
		if line_count % 4 != 0:
			self.mate.error("Teaser: Real data import: FASTQ file line count is not a multiple of four. This may lead to errors.")

		per_file_readcount = test["read_count"]
		if test["paired"]:
			per_file_readcount /= 2

		line_count -= line_count % 4
		import_files_readcount = line_counts[0] / 4
		if import_files_readcount < per_file_readcount:
			self.mate.warning("Teaser: Real data import: Tried to sample more reads than present in FASTQ files. Using all input instead.")
			per_file_readcount = import_files_readcount
			test["read_count"] = per_file_readcount * 2

		sample_fraction = float(per_file_readcount)/import_files_readcount
		self.log("Fraction: %f, Import file readcount: %d"%(sample_fraction,import_files_readcount))

		sampled_readcount = 0
		if test["paired"]:
			sampled_readcount += self.sampleReads(test["import_read_files"][0],test["dir"]+"/reads1.fastq",sample_fraction,"/1")
			sampled_readcount += self.sampleReads(test["import_read_files"][1],test["dir"]+"/reads2.fastq",sample_fraction,"/2")
		else:
			sampled_readcount += self.sampleReads(test["import_read_files"][0],test["dir"]+"/reads.fastq",sample_fraction)

		test["read_count"] = sampled_readcount

		self.log("Data set import successful. Total sampled reads: %d"%sampled_readcount)

	def sampleReads(self,input,output,sample_fraction=1.0,postfix=""):

# Path: lib/gsample.py
# def log(msg):
# def index(reference, fastindex_path = "tools/fastindex"):
# def index_legacy(reference):
# def downsample(index, contig_filename, downsampled_filename, region_count, target_len, single_contig=False,
# 			   region_list=False, spacer_len=200):
# def csample(infile, region_size, sample_fraction, spacer_len=200, fastindex_path=""):
# def ctranslate(reference_file, sampled_index_file, sam_file, target_file, fastindex_path=""):
# 
# Path: tools/fastq2sam.py
# def encode_qname(qname, retain_petag=True):
# 	def __init__(self):
# 	def __init__(self, filename, pe):
# 	def readline(self):
# 	def next_read(self):
# 	def __init__(self):
# 	def align(read):
# 	def align(self, read, paired=False, is_read1=True):
# 	def align_pair(self, read1, read2):
# 	def align(self, read, paired=False, is_read1=True):
# 	def align_pair(self, read1, read2):
# 	def __init__(self, aligner, outfile):
# 	def write(self, what):
# 	def write_sam_header(self, reads):
# 	def write_single(self, read, to):
# 	def align_se(self, infile):
# 	def align_pe(self, infile_1, infile_2):
# class Object:
# class FASTQ:
# class Aligner:
# class DummyAligner(Aligner):
# class dwgsim(Aligner):
# class Converter:
# 
# Path: lib/sam.py
# class SAMRow:
# class SAMFile:
# class Object:
# class FASTQ:
# 	def __init__(self):
# 	def getTag(self,tag_name):
# 	def __init__(self, filename):
# 	def close(self):
# 	def hasLast(self):
# 	def getLast(self):
# 	def getCurr(self):
# 	def getHeader(self):
# 	def isSorted(self):
# 	def next(self):
# 	def __init__(self):
# 	def __init__(self, filename, write=False):
# 	def readline(self):
# 	def next_read(self):
# 	def write_read(self,read):
# 	def close(self):


# Path: lib/teaser.py
import os
import shutil
import time
import yaml
import util
import simulator
	import main
from lib import gsample
from tools import fastq2sam
from lib import sam

		line_count = line_counts[0]
		if line_count % 4 != 0:
			self.mate.error("Teaser: Real data import: FASTQ file line count is not a multiple of four. This may lead to errors.")

		per_file_readcount = test["read_count"]
		if test["paired"]:
			per_file_readcount /= 2

		line_count -= line_count % 4
		import_files_readcount = line_counts[0] / 4
		if import_files_readcount < per_file_readcount:
			self.mate.warning("Teaser: Real data import: Tried to sample more reads than present in FASTQ files. Using all input instead.")
			per_file_readcount = import_files_readcount
			test["read_count"] = per_file_readcount * 2

		sample_fraction = float(per_file_readcount)/import_files_readcount
		self.log("Fraction: %f, Import file readcount: %d"%(sample_fraction,import_files_readcount))

		sampled_readcount = 0
		if test["paired"]:
			sampled_readcount += self.sampleReads(test["import_read_files"][0],test["dir"]+"/reads1.fastq",sample_fraction,"/1")
			sampled_readcount += self.sampleReads(test["import_read_files"][1],test["dir"]+"/reads2.fastq",sample_fraction,"/2")
		else:
			sampled_readcount += self.sampleReads(test["import_read_files"][0],test["dir"]+"/reads.fastq",sample_fraction)

		test["read_count"] = sampled_readcount

		self.log("Data set import successful. Total sampled reads: %d"%sampled_readcount)

	def sampleReads(self,input,output,sample_fraction=1.0,postfix=""):

		input=sam.FASTQ(input)