Example #1
0
 def test_database(self):
     if find_cmd("sqlite3"):
         with make_workdir() as workdir:
             arg = namedtuple('args', 'debug print_debug json ')
             args = arg(True, True, "../../data/examples/seqcluster.json")
             initialize_logger(".", args.debug, args.print_debug)
             logger = mylog.getLogger(__name__)
             logger.info(args)
             logger.info("Reading data")
             data = load_data(args.json)
             logger.info("Create database")
             make_database(data)
Example #2
0
 def test_database(self):
     if find_cmd("sqlite3"):
         with make_workdir() as workdir:
             arg = namedtuple('args', 'debug print_debug json ')
             args = arg(True, True, "../../data/examples/seqcluster.json")
             initialize_logger(".", args.debug, args.print_debug)
             logger = mylog.getLogger(__name__)
             logger.info(args)
             logger.info("Reading data")
             data = load_data(args.json)
             logger.info("Create database")
             make_database(data)
Example #3
0
 def test_databse(self):
     if find_cmd("sqlite3"):
         mod_dir = os.path.dirname(inspect.getfile(seqcluster)).replace("seqcluster/", "")
         os.chdir(os.path.join(mod_dir, "data/examples"))
         arg = namedtuple('args', 'debug print_debug json ')
         args = arg(True, True, "seqcluster.json")
         initialize_logger(".", args.debug, args.print_debug)
         logger = mylog.getLogger(__name__)
         logger.info(args)
         logger.info("Reading data")
         data = load_data(args.json)
         logger.info("Create databse")
         make_database(data)
Example #4
0
 def test_predict(self):
     if find_cmd("tRNAscan-SE"):
         mod_dir = os.path.dirname(inspect.getfile(seqcluster)).replace("seqcluster/", "")
         os.chdir(os.path.join(mod_dir, "data/examples"))
         out_dir = os.path.join(mod_dir, "data/examples/predictions")
         arg = namedtuple('args', 'debug print_debug MIN_SEQ json reference')
         args = arg(True, True, 1, "seqcluster.json", "../genomes/genome.fa")
         initialize_logger(".", args.debug, args.print_debug)
         logger = mylog.getLogger(__name__)
         logger.info(args)
         logger.info("Reading data")
         data = load_data(args.json)
         logger.info("Start prediction")
         make_predictions(data, out_dir, args)
Example #5
0
def get_loci_fasta(loci, out_fa, ref):
    """get fasta from precursor"""
    if not find_cmd("bedtools"):
        raise ValueError("Not bedtools installed")
    with make_temp_directory() as temp:
        bed_file = os.path.join(temp, "file.bed")
        for nc, loci in loci.iteritems():
            for l in loci:
                with open(bed_file, 'w') as bed_handle:
                    logger.debug("get_fasta: loci %s" % l)
                    nc, c, s, e, st = l
                    print("{0}\t{1}\t{2}\t{3}\t{3}\t{4}".format(c, s, e, nc, st), file=bed_handle)
                get_fasta(bed_file, ref, out_fa)
    return out_fa
Example #6
0
 def test_databse(self):
     if find_cmd("sqlite3"):
         mod_dir = os.path.dirname(inspect.getfile(seqcluster)).replace(
             "seqcluster/", "")
         os.chdir(os.path.join(mod_dir, "data/examples"))
         arg = namedtuple('args', 'debug print_debug json ')
         args = arg(True, True, "seqcluster.json")
         initialize_logger(".", args.debug, args.print_debug)
         logger = mylog.getLogger(__name__)
         logger.info(args)
         logger.info("Reading data")
         data = load_data(args.json)
         logger.info("Create databse")
         make_database(data)
Example #7
0
def get_loci_fasta(loci, out_fa, ref):
    """get fasta from precursor"""
    if not find_cmd("bedtools"):
        raise ValueError("Not bedtools installed")
    with make_temp_directory() as temp:
        bed_file = os.path.join(temp, "file.bed")
        for nc, loci in loci.iteritems():
            for l in loci:
                with open(bed_file, 'w') as bed_handle:
                    logger.debug("get_fasta: loci %s" % l)
                    nc, c, s, e, st = l
                    print("{0}\t{1}\t{2}\t{3}\t{3}\t{4}".format(
                        c, s, e, nc, st),
                          file=bed_handle)
                get_fasta(bed_file, ref, out_fa)
    return out_fa
Example #8
0
def map_to_precursors(seqs, names, loci, out_file, args):
    """map sequences to precursors with razers3"""
    with make_temp_directory() as temp:
        pre_fasta = os.path.join(temp, "pre.fa")
        seqs_fasta = os.path.join(temp, "seqs.fa")
        out_sam = os.path.join(temp, "out.sam")
        pre_fasta = get_loci_fasta(loci, pre_fasta, args.ref)
        out_precursor_file = out_file.replace("tsv", "fa")
        seqs_fasta = get_seqs_fasta(seqs, names, seqs_fasta)

        # print(open(pre_fasta).read().split("\n")[1])
        if find_cmd("razers3"):
            cmd = "razers3 -dr 2 -i 80 -rr 90 -f -o {out_sam} {temp}/pre.fa  {seqs_fasta}"
            run(cmd.format(**locals()))
            out_file = read_alignment(out_sam, loci, seqs, out_file)
            shutil.copy(pre_fasta, out_precursor_file)
    return out_file
Example #9
0
def deprecated_map_to_precursors(seqs, names, loci, out_file, args):
    """map sequences to precursors with bowtie"""
    with make_temp_directory() as temp:
        pre_fasta = os.path.join(temp, "pre.fa")
        seqs_fasta = os.path.join(temp, "seqs.fa")
        out_sam = os.path.join(temp, "out.sam")
        pre_fasta = get_loci_fasta(loci, pre_fasta, args.ref)
        out_precursor_file = out_file.replace("tsv", "fa")
        seqs_fasta = get_seqs_fasta(seqs, names, seqs_fasta)
        if find_cmd("bowtie2-build"):
            cmd = "bowtie2-build -f {pre_fasta} {temp}/pre"
            run(cmd.format(**locals()))
            cmd = "bowtie2 -a --rdg 7,3 --mp 4 --end-to-end -D 20 -R 3 -N 0 -i S,1,0.8 -L 3 -f -x  {temp}/pre -U {seqs_fasta} -S {out_sam}"
            run(cmd.format(**locals()))
            out_file = read_alignment(out_sam, loci, seqs, out_file)
            shutil.copy(pre_fasta, out_precursor_file)
    return out_file
Example #10
0
def map_to_precursors(seqs, names, loci, out_file, args):
    """map sequences to precursors with razers3"""
    with make_temp_directory() as temp:
        pre_fasta = os.path.join(temp, "pre.fa")
        seqs_fasta = os.path.join(temp, "seqs.fa")
        out_sam = os.path.join(temp, "out.sam")
        pre_fasta = get_loci_fasta(loci, pre_fasta, args.ref)
        out_precursor_file = out_file.replace("tsv", "fa")
        seqs_fasta = get_seqs_fasta(seqs, names, seqs_fasta)

        # print(open(pre_fasta).read().split("\n")[1])
        if find_cmd("razers3"):
            cmd = "razers3 -dr 2 -i 80 -rr 90 -f -o {out_sam} {temp}/pre.fa  {seqs_fasta}"
            run(cmd.format(**locals()))
            out_file = read_alignment(out_sam, loci, seqs, out_file)
            shutil.copy(pre_fasta, out_precursor_file)
    return out_file
Example #11
0
def deprecated_map_to_precursors(seqs, names, loci, out_file, args):
    """map sequences to precursors with bowtie"""
    with make_temp_directory() as temp:
        pre_fasta = os.path.join(temp, "pre.fa")
        seqs_fasta = os.path.join(temp, "seqs.fa")
        out_sam = os.path.join(temp, "out.sam")
        pre_fasta = get_loci_fasta(loci, pre_fasta, args.ref)
        out_precursor_file = out_file.replace("tsv", "fa")
        seqs_fasta = get_seqs_fasta(seqs, names, seqs_fasta)
        if find_cmd("bowtie2-build"):
            cmd = "bowtie2-build -f {pre_fasta} {temp}/pre"
            run(cmd.format(**locals()))
            cmd = "bowtie2 -a --rdg 7,3 --mp 4 --end-to-end -D 20 -R 3 -N 0 -i S,1,0.8 -L 3 -f -x  {temp}/pre -U {seqs_fasta} -S {out_sam}"
            run(cmd.format(**locals()))
            out_file = read_alignment(out_sam, loci, seqs, out_file)
            shutil.copy(pre_fasta, out_precursor_file)
    return out_file
Example #12
0
 def test_predict(self):
     if find_cmd("tRNAscan-SE"):
         mod_dir = os.path.dirname(inspect.getfile(seqcluster)).replace(
             "seqcluster/", "")
         os.chdir(os.path.join(mod_dir, "data/examples"))
         out_dir = os.path.join(mod_dir,
                                "data/examples/test_out_predictions")
         arg = namedtuple('args',
                          'debug print_debug MIN_SEQ json reference')
         args = arg(True, True, 1, "seqcluster.json",
                    "../genomes/genome.fa")
         initialize_logger(".", args.debug, args.print_debug)
         logger = mylog.getLogger(__name__)
         logger.info(args)
         logger.info("Reading data")
         data = load_data(args.json)
         logger.info("Start prediction")
         is_tRNA(data, out_dir, args)