<commit_before>import os, sys, glob, random, itertools

'''
Inserts SNPs and 20% of SNPs as InDels
Outputs Two files for every file - reference.fasta
1. mutated reference - reference_X_percent_SNPs_Y_percent_InDels.fasta
2. mutation index for true and mutated reference - reference_X_percent_SNPs_Y_percent_InDels_Index.txt
'''

class Fastaseq():
	"""
	fasta reader
	"""
	def __init__(self):
		self.id = None
		self.seq = ''
		self.length = ''
	  
	@staticmethod 
	def readline(linein):
		seqobj = Fastaseq()
		for line in linein:
			if len(line)==0: 
				print >> sys.stderr, 'empty line'
				continue
			
			if line.startswith('>'):
				if seqobj.id is None:
					seqobj.id = line.rstrip()
					continue
				else:
					yield seqobj
					seqobj = Fastaseq()
					seqobj.id = line.rstrip()
			else:
				seqobj.seq += line.rstrip('\n\r').upper()
		yield seqobj

def MutateReference(workingDir):
	for referenceFastaFile in glob.glob(os.path.join(workingDir + "referenceFastaFiles", "*")):
		if not "percent" in referenceFastaFile and (".fa" in referenceFastaFile or ".fasta" in referenceFastaFile):
			mutation_rates = [0.2]#[0.01, 0.05, 0.10, 0.20]
			for mutation_rate in mutation_rates:
				indel_rate = 0.2 * mutation_rate # indel rate = 20% of Substitution rate
				i = mutation_rate * 100
				j = indel_rate * 100
				newreferenceFastaFile = referenceFastaFile.split(".fa")[0] + "_" + str(i) + "_percent_SNPs_" + str(j) + "_percent_InDels.fasta"
				mutationIndexFile = referenceFastaFile.split(".fa")[0] + "_" + str(i) + "_percent_SNPs_" + str(j) + "_percent_InDels_Index.txt"
				if not os.path.exists(newreferenceFastaFile):
					referenceFasta = open(referenceFastaFile, "r")
					newreferenceFasta = open(newreferenceFastaFile, "w")
<commit_msg>Now keeps index of InDels and SNPs<commit_after>import os, sys, glob, random, itertools

'''
Inserts SNPs and 20% of SNPs as InDels
Outputs Two files for every file - reference.fasta
1. mutated reference - reference_X_percent_SNPs_Y_percent_InDels.fasta
2. mutation index for true and mutated reference - reference_X_percent_SNPs_Y_percent_InDels_Index.txt
'''

class Fastaseq():
	"""
	fasta reader
	"""
	def __init__(self):
		self.id = None
		self.seq = ''
		self.length = ''
	  
	@staticmethod 
	def readline(linein):
		seqobj = Fastaseq()
		for line in linein:
			if len(line)==0: 
				print >> sys.stderr, 'empty line'
				continue
			
			if line.startswith('>'):
				if seqobj.id is None:
					seqobj.id = line.rstrip()
					continue
				else:
					yield seqobj
					seqobj = Fastaseq()
					seqobj.id = line.rstrip()
			else:
				seqobj.seq += line.rstrip('\n\r').upper()
		yield seqobj

def MutateReference(workingDir):
	for referenceFastaFile in glob.glob(os.path.join(workingDir + "referenceFastaFiles", "*")):
		if not "percent" in referenceFastaFile and (".fa" in referenceFastaFile or ".fasta" in referenceFastaFile):
			mutation_rates = [0.01, 0.05, 0.10, 0.20]
			for mutation_rate in mutation_rates:
				indel_rate = 0.2 * mutation_rate # indel rate = 20% of Substitution rate
				i = mutation_rate * 100
				j = indel_rate * 100
				newreferenceFastaFile = referenceFastaFile.split(".fa")[0] + "_" + str(i) + "_percent_SNPs_" + str(j) + "_percent_InDels.fasta"
				mutationIndexFile = referenceFastaFile.split(".fa")[0] + "_" + str(i) + "_percent_SNPs_" + str(j) + "_percent_InDels_Index.txt"
				if not os.path.exists(newreferenceFastaFile):
					referenceFasta = open(referenceFastaFile, "r")
					newreferenceFasta = open(newreferenceFastaFile, "w")

{'fraction_non_alphanumeric': 0.12432585864320182, 'fraction_numerical': 0.017030939540164634, 'mean_word_length': 3.840659340659341, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3731232', 'n_tokens_mistral': 1471, 'n_tokens_neox': 1240, 'n_words': 298}