def alignextend(args):
    """
    %prog alignextend bedpefile ref.fasta

    Similar idea to alignextend, using mates from BEDPE and FASTA ref. See AMOS
    script here:

    https://github.com/nathanhaigh/amos/blob/master/src/Experimental/alignextend.pl
    """
    p = OptionParser(alignextend.__doc__)
    p.add_option("--len", default=100, type="int",
                 help="Extend to this length")
    p.add_option("--qv", default=31, type="int",
                 help="Dummy qv score for extended bases")
    p.add_option("--bedonly", default=False, action="store_true",
                 help="Only generate bed files, no FASTA")
    p.set_bedpe()
    opts, args = p.parse_args(args)

    if len(args) != 2:
        sys.exit(not p.print_help())

    bedpe, ref = args
    qvchar = chr(opts.qv + 33)
    pf = bedpe.split(".")[0]

    filtered = bedpe + ".filtered"
    if need_update(bedpe, filtered):
        filter_bedpe(bedpe, filtered, ref, rc=opts.rc,
                     minlen=opts.minlen, maxlen=opts.maxlen, rlen=opts.rlen)

    rmdup = filtered + ".filtered.sorted.rmdup"
    if need_update(filtered, rmdup):
        rmdup_bedpe(filtered, rmdup, dupwiggle=opts.dup)

    if opts.bedonly:
        return

    bed1, bed2 = pf - ".1e.bed", pf + ".2e.bed"
    if need_update(rmdup, (bed1, bed2)):
        sh("cut -f1-3,7-9 {0}".format(rmdup), outfile=bed1)
        sh("cut -f4-6,7-8,10 {0}".format(rmdup), outfile=bed2)

    sfa1, sfa2 = pf + ".1e.sfa", pf + ".2e.sfa"
    if need_update((bed1, bed2, ref), (sfa1, sfa2)):
        for bed in (bed1, bed2):
            fastaFromBed(bed, ref, name=True, tab=True, stranded=True)

    fq1, fq2 = pf + ".1e.fq", pf + ".2e.fq"
    if need_update((sfa1, sfa2), (fq1, fq2)):
        for sfa in (sfa1, sfa2):
            sfa_to_fq(sfa, qvchar)
dataset/ETHPy150Open tanghaibao/jcvi/formats/bed.py/alignextend/operator `+` -> `-`