def fasta(args):
    """
    %prog fasta fastqfiles

    Convert fastq to fasta and qual file.
    """
    p = OptionParser(fasta.__doc__)
    p.add_option("--seqtk", default=False, action="store_true",
                 help="Use seqtk to convert")
    p.set_outdir()
    p.set_outfile(outfile=None)
    opts, args = p.parse_args(args)

    if len(args) < 1:
        sys.exit(not p.print_help())

    fastqfiles = args
    outdir = opts.outdir
    if outdir and outdir != ".":
        mkdir(outdir)

    fastqfile = fastqfiles[0]
    pf = op.basename(fastqfile)
    gzinput = pf.endswith(".gz")
    if gzinput:
        pf = pf.rsplit(".", 1)[0]

    pf, sf = pf.rsplit(".", 1)
    if sf not in ("fq", "fastq"):
        logging.debug("Assumed FASTA: suffix not `fq` or `fastq`")
        return fastqfile, None

    fastafile, qualfile = pf + ".fasta", pf + ".qual"
    outfile = opts.outfile or fastafile
    outfile = op.join(outdir, outfile)
    if opts.seqtk:
        if need_update(fastqfiles, outfile):
            for i, fastqfile in enumerate(fastqfiles):
                cmd = "seqtk seq -A {0} -L 30 -l 70".format(fastqfile)
                # First one creates file, following ones append to it
                sh(cmd, outfile=outfile, append=i)
        else:
            logging.debug("Outfile `{0}` already exists.".format(outfile))
        return outfile, None

    for fastqfile in fastqfiles:
        SeqIO.convert(fastqfile, "fastq", fastafile, "fasta")
        SeqIO.convert(fastqfile, "fastq", qualfile, "qual")

    return fastafile, qualfile
def fasta ( args ) : p = OptionParser ( fasta . __doc__ ) p . add_option ( "--seqtk" , default = False , action = "store_true" , help = "Use seqtk to convert" ) p . set_outdir ( ) p . set_outfile ( outfile = None ) opts , args = p . parse_args ( args ) if len ( args ) < 1 : sys . exit ( not p . print_help ( ) ) fastqfiles = args outdir = opts . outdir if outdir and outdir != "." : mkdir ( outdir ) fastqfile = fastqfiles [ 0 ] pf = op . basename ( fastqfile ) gzinput = pf . endswith ( ".gz" ) if gzinput : pf = pf . rsplit ( "." , 1 ) [ 0 ] pf , sf = pf . rsplit ( "." , 1 ) if sf not in ( "fq" , "fastq" ) : logging . debug ( "Assumed FASTA: suffix not `fq` or `fastq`" ) return fastqfile , None fastafile , qualfile = pf + ".fasta" , pf + ".qual" outfile = opts . outfile or fastafile outfile = op . join ( outdir , outfile ) if opts . seqtk : if need_update ( fastqfiles , outfile ) : for i , fastqfile in enumerate ( fastqfiles ) : cmd = "seqtk seq -A {0} -L 30 -l 70" . format ( fastqfile ) sh ( cmd , outfile = outfile , append = i ) else : logging . debug ( "Outfile `{0}` already exists." . format ( outfile ) ) return outfile , None for fastqfile in fastqfiles : SeqIO . convert ( fastqfile , "fastq" , fastafile , "fasta" ) SeqIO . convert ( fastqfile , "fastq" , qualfile , "qual" ) return fastafile , qualfile
%prog fasta fastqfiles

    Convert fastq to fasta and qual file.