# Path: mirtop/libs/read.py
# def get_fasta(bed_file, ref, out_fa):
#     """Run bedtools to get fasta from bed file"""
#     cmd = "bedtools getfasta -s -fi {ref} -bed {bed_file} -fo {out_fa}"
#     run(cmd.format(**locals()))


import random
from mirtop.libs.read import get_fasta
        p = random.uniform(0, 0.1)
        counts = int(p * total) + 1
        seen += counts
        name = "seq_%s_%s_%s_x%s" % (c, s, e, counts)
        reads[name] = (seq[s:e], counts)
    return reads


def _write_reads(reads, prefix):
    """
    Write fasta file, ma file and real position
    """
    out_ma = prefix + ".ma"
    out_fasta = prefix + ".fasta"
    out_real = prefix + ".txt"
    with open(out_ma, 'w') as ma_handle:
        print("id\tseq\tsample", file=ma_handle)
        with open(out_fasta, 'w') as fa_handle:
            with open(out_real, 'w') as read_handle:
                for idx, r in enumerate(reads):
                    info = r.split("_")
                    print("seq_%s\t%s\t%s" % (idx, reads[r][0], reads[r][1]), file=ma_handle)
                    print(">seq_%s\n%s" % (idx, reads[r][0]), file=fa_handle)
                    print("%s\t%s\t%s\t%s\t%s\t%s\t%s" % (idx, r, reads[r][0], reads[r][1], info[1], info[2], info[3]), file=read_handle)


def _get_precursor(bed_file, reference, out_fa):
    """
    get sequence precursor from position
    """

# Path: mirtop/libs/read.py
# def get_fasta(bed_file, ref, out_fa):
#     """Run bedtools to get fasta from bed file"""
#     cmd = "bedtools getfasta -s -fi {ref} -bed {bed_file} -fo {out_fa}"
#     run(cmd.format(**locals()))


# Path: mirtop/libs/simulator.py
import random
from mirtop.libs.read import get_fasta

        p = random.uniform(0, 0.1)
        counts = int(p * total) + 1
        seen += counts
        name = "seq_%s_%s_%s_x%s" % (c, s, e, counts)
        reads[name] = (seq[s:e], counts)
    return reads


def _write_reads(reads, prefix):
    """
    Write fasta file, ma file and real position
    """
    out_ma = prefix + ".ma"
    out_fasta = prefix + ".fasta"
    out_real = prefix + ".txt"
    with open(out_ma, 'w') as ma_handle:
        print("id\tseq\tsample", file=ma_handle)
        with open(out_fasta, 'w') as fa_handle:
            with open(out_real, 'w') as read_handle:
                for idx, r in enumerate(reads):
                    info = r.split("_")
                    print("seq_%s\t%s\t%s" % (idx, reads[r][0], reads[r][1]), file=ma_handle)
                    print(">seq_%s\n%s" % (idx, reads[r][0]), file=fa_handle)
                    print("%s\t%s\t%s\t%s\t%s\t%s\t%s" % (idx, r, reads[r][0], reads[r][1], info[1], info[2], info[3]), file=read_handle)


def _get_precursor(bed_file, reference, out_fa):
    """
    get sequence precursor from position
    """

    get_fasta(bed_file, reference, out_fa)