import os, egglib, sys, unittest, random, re, gc, time
from collections import Iterable
import string, random

"""
starts=[1472,1017,971,465,1184,633,344,305,236,1445,1284,551]
ends=  [1446,972,634,345,1018,552,306,237,75,1285,1185,466]
diff=[]

for i,k in zip(starts,ends):
		diff.append(i-k)
	
sequence="ATGGACCCCCTTGGGGACACGCTGCGGCGACTGCGGGAGGCCTTCCACGCGGGGCGCACGCGGCCAGCTGAGTTCCGGGCTGCGCAGCTCCAAGGCCTGGGCCGCTTCCTGCAAGAAAACAAGCAGCTTCTGCACGACGCACTGGCCCAGGACCTGCACAAGTCAGCCTTCGAGTCGGAGGTGTCTGAGGTTGCCATCAGCCAGGGCGAGGTCACCCTGGCCCTCAGGAACCGGGCCTGGATGAAGGACGAGCGTGTGCCCAAGAACCTGGCCACGCAGCTGGACTCCGCCTTCATCCGGAAGGAGCCCTTTGGCCTGGTCCTCATCATTGCGCCCTGGAACTATCCGCTGAACCTGACGCTGGTGCCCCTCGTGGGAGCCCTCGCTGCAGGGAACTGTGTGGTGCTGAAGCCATCGGAGATTAGCAAGAACGTCGAGAAGATCCTGGCCGAGGTGCTGCCCCAATACGTGGACCAGAGCTGCTTTGCTGTGGTGCTGGGCGGGCCCCAGGAGACGGGGCAGCTGCTAGAGCACAGGTTCGACTACATCTTCTTCACAGGGAGCCCTCGTGTGGGCAAGATTGTTATGACTGCTGCCGCCAAGCACCTGACACCTGTCACCCTGGAGCTGGGGGGCAAGAACCCTTGCTACGTGGACGACAACTGCGACCCCCAGACCGTGGCCAACCGCGTGGCCTGGTTCCGCTACTTCAACGCCGGCCAGACCTGCGTGGCCCCCGACTACGTCCTATGCAGCCCTGAGATGCAGGAGAGGCTGCTGCCTGCCCTGCAGAGCACCATCACCCGTTTCTATGGCGACGACCCCCAGAGCTCCCCAAACCTGGGCCGCATCATCAACCAGAAACAGTTCCAGCGGCTGCGGGCATTGCTGGGCTGCCGTGTGGCCATTGGGGGCCAGAGCGATGAGAGCGATCGCTACATCGCCCCCACGGTGCTGGTGGATGTGCAGGAGATGGAGCCTGTGATGCAGGAGGAGATCTTCGGGCCCATCCTGCCCATCGTGAACGTGCAGAGCTTGGACGAGGCCATCGAGTTCATCAACCGGCGGGAGAAGCCCCTGGCCCTGTACGCCTTCTCCAACAGCAGCCAGGTGGTCAAGCGGGTGCTGACCCAGACCAGCAGCGGGGGCTTCTGTGGGAACGACGGCTTCATGCACATGACCCTGGCCAGCCTGCCTTTTGGAGGAGTGGGTGCCAGTGGGATGGGCCGGTACCATGGCAAGTTCTCCTTCGACACCTTCTCCCACCATCGCGCCTGCCTCCTGCGCAGCCCGGGGATGGAGAAGCTCAACGCCCTCCGCTACCCGCCGCAATCGCCGCGCCGCCTGAGGATGCTGCTGGTGGCCATGGAGCAAGGCTGCAGCTGCACACTGCTCTGA"

seq_split=[]
d=0
for i in diff: 
	seq_split.append(sequence[d:(d+i)])
	d=d+i

for i in seq_split:
	print i




"""
#Fonction generant n sequences nucleotidique de taille i, avec un codon start 'ATG' en debut de sequence et un des codon stop in fasta format


def seq_finish_by_stop(seq_size):
	seq_s=(seq_size-3)
	l_stop=['TAA', 'TAG', 'TGA']
	#l_start='ATG'
	string=	''.join(random.choice('ACGT-') for _ in range(seq_s))
	cd_stop=random.choice(l_stop)
	l=[]
	#l.append(l_start)
	l.append(string)
	l.append(cd_stop)
	sequence=''.join(l)
	return sequence


def seq_finish_by_random(seq_size):
	seq_s=seq_size
	#l_start='ATG'
	string=	''.join(random.choice('ACGT-') for _ in range(seq_s))
	l=[]
	#l.append(l_start)
	l.append(string)
	#l.append(cd_stop)
	sequence=''.join(l)
	return sequence


def seq_generator(fname,n_seq,seq_size):
	file_= open(fname, "a")
	for i in range(n_seq):
		choices=[0,1]		
		ch=random.choice(choices)
		if ch == 1:
			sequence= seq_finish_by_stop(seq_size)
		else:
			sequence= seq_finish_by_random(seq_size)

		file_.write('>sequence_{0}\n'.format(i))
		file_.write('{0}\n'.format(sequence))	

	file_.close()

