# Path: seqio.py
# def iteratorFromExtension(filename):
#     '''
#     Get a sequence file iterator 
#     Based on the file's extension
#     '''
#     ext = filename.split(".")[-1]
#     if ext in ["fasta", "fa"]:
#         return fastaIterator
#     elif ext in ["fastq", "fq", "txt"]:
#         return fastqIterator
#     raise Exception, "Unknown file extension %s for file %s" % (ext,filename)
# 
# Path: nucio.py
# def fileIterator(filename, itemIterator, open_func=open):
#     '''Handles the life cyle of a file,
#        The itemIterator will be passed the 
#        opened file handle
#     '''
#     with open_func(filename) as fh:
#         for item in itemIterator(fh):
#             yield item


import sys
from seqio import iteratorFromExtension
from nucio import fileIterator
#!/usr/bin/env



if not len(sys.argv) == 2:
    sys.exit("sequencToLine.py in.{fa.fq}\n")

it = iteratorFromExtension(sys.argv[1])
for record in fileIterator(sys.argv[1], it):
    if hasattr(record, "desc"):
        print "\t".join([record.name, record.seq, record.desc, record.qual])
    else:

# Path: seqio.py
# def iteratorFromExtension(filename):
#     '''
#     Get a sequence file iterator 
#     Based on the file's extension
#     '''
#     ext = filename.split(".")[-1]
#     if ext in ["fasta", "fa"]:
#         return fastaIterator
#     elif ext in ["fastq", "fq", "txt"]:
#         return fastqIterator
#     raise Exception, "Unknown file extension %s for file %s" % (ext,filename)
# 
# Path: nucio.py
# def fileIterator(filename, itemIterator, open_func=open):
#     '''Handles the life cyle of a file,
#        The itemIterator will be passed the 
#        opened file handle
#     '''
#     with open_func(filename) as fh:
#         for item in itemIterator(fh):
#             yield item


# Path: sequenceToLine.py
import sys
from seqio import iteratorFromExtension
from nucio import fileIterator

#!/usr/bin/env



if not len(sys.argv) == 2:
    sys.exit("sequencToLine.py in.{fa.fq}\n")

it = iteratorFromExtension(sys.argv[1])
for record in fileIterator(sys.argv[1], it):
    if hasattr(record, "desc"):
        print "\t".join([record.name, record.seq, record.desc, record.qual])
    else:

        print "\t".join([record.name, record.seq])