# Path: nesoni/io.py
# def find_jar(jarname, extra_help=''):    
# def symbolic_link(source, link_name):
# def _interpret_args(args, kwargs):
# def _describe_args(args, kwargs):
# def run(args, stdin=None, stdout=PIPE, stderr=None, cwd=None, no_display=False, **kwargs):
# def pipe_to(args, stdout=None, stderr=None, cores=1, **kwargs):
# def pipe_from(args, stdin=None, stderr=None, cores=1, **kwargs):
# def execute(args, stdin=None, stdout=None, stderr=None, cores=1, **kwargs):
# def get_compression_type(filename):
# def open_possibly_compressed_file(filename, compression_type=None):
# def get_file_info(filename):
# def classify_files(filenames, selectors):
# def abspath(*components):
# def copy_file(source, dest):
#     def __init__(self, filename, command):
#     def fileno(self):
#     def write(self, text):
#     def close(self):
#     def __enter__(self):
#     def __exit__(self, exc_type, exc_value, traceback):
# def open_gzip_writer(filename):
# def open_bzip2_writer(filename):    
# def open_possibly_compressed_writer(filename):
# def read_solid(filename):
# def read_illumina(filename):
# def read_illumina_with_quality(filename):
# def read_fasta(filename):
# def read_gff3_sequence(filename):
# def read_genbank_sequence(filename, genbank_callback=None):
# def read_empty(filename):
# def _filter_name(iterator, argument):
# def _filter_bar(iterator, argument):
# def _filter_rename(iterator, argument):
# def _filter_select(iterator, argument):
# def _filter_lengthatleast(iterator, argument):
# def _filter_pfilter(iterator, argument):
# def _filter_qclip(iterator, argument):
# def _filter_first(iterator, argument):
# def filter_no_qualities(iterator):
# def read_sequences(filename, qualities=False, genbank_callback=None):
# def is_sequence_file(filename):
# def is_colorspace(filename):
# def guess_quality_offset(*filenames):
# def check_name_uniqueness(read_filenames, pair_filenames=[], interleaved_filenames=[]):
# def write_fasta(f, name, sequence, qual=None):
# def write_fasta_single_line(f, name, sequence, qual=None):
# def write_fastq(f, name, sequence, qual):
# def decode_evidence(desc):
# def read_evidence_file(filename):
#     def __init__(self, values):
#     def __len__(self):
#     def __iter__(self):
#     def __getitem__(self, key):
#     def __setitem__(self, key, value):
#     def __repr__(self):
#     def value_type(self):
#     def keys(self):
#     def values(self):
#     def items(self):
#     def iterkeys(self):
#     def itervalues(self):
#     def iteritems(self):
# def named_list_type(keys, value_type=None):
# def named_list(items, value_type=None):
# def named_matrix_type(row_keys, col_keys, value_type=None):
#     def __init__(self, filename, default_group='All'):
#     def close(self):
#     def __iter__(self):
#     def next(self):
#     def __init__(self, rowname_name='Name'):
#     def write_csv(self, filename, group_line=True):
# def read_grouped_table(filename, group_cast=[], default_group='All'):
# def write_grouped_csv(filename, groups, rowname_name='Name', comments=[], group_line=True):
# def write_csv(filename, iterable, comments=[]):
# def write_csv_2(filename, iterable, comments=[], rowname_name='Name'):
# class Pipe_writer(object):
# class _Named_list(collections.Mapping):
#     class Named_list(_Named_list):
# class Table_reader(object):
# class Grouped_table(collections.OrderedDict):
# FILTERS = {
#     'name': _filter_name,
#     'bar:': _filter_bar,
#     'rename:': _filter_rename,
#     'select:': _filter_select,
#     'lengthatleast:': _filter_lengthatleast,
#     'pfilter:': _filter_pfilter,
#     'qclip:': _filter_qclip,
#     'first:': _filter_first,
# }


import sys, random
from nesoni import io



# python2.6 modify_sequence.py data/velvet_test_reference.fa >data/velvet_test_reference_modified.fa



for name, seq in io.read_sequences(sys.argv[1]):
    j = 0    
    for i in xrange(0,len(seq)-100,100):
        original = seq[i]
        if j%3 == 0:
            while True:
                new = random.choice('ACGT')
                if new != original: break
            seq = seq[:i] + new + seq[i+1:]
        elif j%3 == 1:
            n = (j // 3) % 9 + 1
            seq = seq[:i] + seq[i+n:]
        else:
            n = (j // 3) % 9 + 1
            seq = seq[:i] + ''.join( random.choice('ACGT') for k in xrange(n) ) + seq[i:]
        j += 1

# Path: nesoni/io.py
# def find_jar(jarname, extra_help=''):    
# def symbolic_link(source, link_name):
# def _interpret_args(args, kwargs):
# def _describe_args(args, kwargs):
# def run(args, stdin=None, stdout=PIPE, stderr=None, cwd=None, no_display=False, **kwargs):
# def pipe_to(args, stdout=None, stderr=None, cores=1, **kwargs):
# def pipe_from(args, stdin=None, stderr=None, cores=1, **kwargs):
# def execute(args, stdin=None, stdout=None, stderr=None, cores=1, **kwargs):
# def get_compression_type(filename):
# def open_possibly_compressed_file(filename, compression_type=None):
# def get_file_info(filename):
# def classify_files(filenames, selectors):
# def abspath(*components):
# def copy_file(source, dest):
#     def __init__(self, filename, command):
#     def fileno(self):
#     def write(self, text):
#     def close(self):
#     def __enter__(self):
#     def __exit__(self, exc_type, exc_value, traceback):
# def open_gzip_writer(filename):
# def open_bzip2_writer(filename):    
# def open_possibly_compressed_writer(filename):
# def read_solid(filename):
# def read_illumina(filename):
# def read_illumina_with_quality(filename):
# def read_fasta(filename):
# def read_gff3_sequence(filename):
# def read_genbank_sequence(filename, genbank_callback=None):
# def read_empty(filename):
# def _filter_name(iterator, argument):
# def _filter_bar(iterator, argument):
# def _filter_rename(iterator, argument):
# def _filter_select(iterator, argument):
# def _filter_lengthatleast(iterator, argument):
# def _filter_pfilter(iterator, argument):
# def _filter_qclip(iterator, argument):
# def _filter_first(iterator, argument):
# def filter_no_qualities(iterator):
# def read_sequences(filename, qualities=False, genbank_callback=None):
# def is_sequence_file(filename):
# def is_colorspace(filename):
# def guess_quality_offset(*filenames):
# def check_name_uniqueness(read_filenames, pair_filenames=[], interleaved_filenames=[]):
# def write_fasta(f, name, sequence, qual=None):
# def write_fasta_single_line(f, name, sequence, qual=None):
# def write_fastq(f, name, sequence, qual):
# def decode_evidence(desc):
# def read_evidence_file(filename):
#     def __init__(self, values):
#     def __len__(self):
#     def __iter__(self):
#     def __getitem__(self, key):
#     def __setitem__(self, key, value):
#     def __repr__(self):
#     def value_type(self):
#     def keys(self):
#     def values(self):
#     def items(self):
#     def iterkeys(self):
#     def itervalues(self):
#     def iteritems(self):
# def named_list_type(keys, value_type=None):
# def named_list(items, value_type=None):
# def named_matrix_type(row_keys, col_keys, value_type=None):
#     def __init__(self, filename, default_group='All'):
#     def close(self):
#     def __iter__(self):
#     def next(self):
#     def __init__(self, rowname_name='Name'):
#     def write_csv(self, filename, group_line=True):
# def read_grouped_table(filename, group_cast=[], default_group='All'):
# def write_grouped_csv(filename, groups, rowname_name='Name', comments=[], group_line=True):
# def write_csv(filename, iterable, comments=[]):
# def write_csv_2(filename, iterable, comments=[], rowname_name='Name'):
# class Pipe_writer(object):
# class _Named_list(collections.Mapping):
#     class Named_list(_Named_list):
# class Table_reader(object):
# class Grouped_table(collections.OrderedDict):
# FILTERS = {
#     'name': _filter_name,
#     'bar:': _filter_bar,
#     'rename:': _filter_rename,
#     'select:': _filter_select,
#     'lengthatleast:': _filter_lengthatleast,
#     'pfilter:': _filter_pfilter,
#     'qclip:': _filter_qclip,
#     'first:': _filter_first,
# }


# Path: test/modify_sequence.py
import sys, random
from nesoni import io




# python2.6 modify_sequence.py data/velvet_test_reference.fa >data/velvet_test_reference_modified.fa



for name, seq in io.read_sequences(sys.argv[1]):
    j = 0    
    for i in xrange(0,len(seq)-100,100):
        original = seq[i]
        if j%3 == 0:
            while True:
                new = random.choice('ACGT')
                if new != original: break
            seq = seq[:i] + new + seq[i+1:]
        elif j%3 == 1:
            n = (j // 3) % 9 + 1
            seq = seq[:i] + seq[i+n:]
        else:
            n = (j // 3) % 9 + 1
            seq = seq[:i] + ''.join( random.choice('ACGT') for k in xrange(n) ) + seq[i:]
        j += 1

    io.write_fasta(sys.stdout, name, seq)