Пример #1
0
def create_housekeeping_file(chr_lengths, max_points, root_dir, output_dir, logger):
    max_ideograms = len(chr_lengths.keys())
    template_fpath = None
    circos_bin_fpath = get_path_to_program('circos')
    if circos_bin_fpath:
        circos_dirpath = dirname(realpath(get_path_to_program('circos')))
        template_fpath = join(circos_dirpath, '..', 'libexec', 'etc', 'housekeeping.conf')
        if not is_non_empty_file(template_fpath):
            template_fpath = join(circos_dirpath, '..', 'etc', 'housekeeping.conf')

    if not is_non_empty_file(template_fpath):
        if not get_path_to_program('circos'):
            msg = 'Circos is not found.'
        else:
            msg = 'File etc/housekeeping.conf is not found.'
        logger.warning(msg + ' You will have to manually edit etc/housekeeping.conf: '
                       'set max_points_per_track to ' + str(max_points) + ' and max_ideograms to ' + str(max_ideograms))
        return '<<include %s>>\n' % join('etc', 'housekeeping.conf')

    housekeeping_fpath = join(output_dir, 'housekeeping.conf')
    with open(template_fpath) as f:
        with open(housekeeping_fpath, 'w') as out_f:
            for line in f:
                if 'max_points_per_track' in line:
                    out_f.write('max_points_per_track = %d\n' % max_points)
                elif 'max_ideograms' in line:
                    out_f.write('max_ideograms = %d\n' % max_ideograms)
                else:
                    out_f.write(line)
    return '<<include %s>>\n' % relpath(housekeeping_fpath, root_dir)
Пример #2
0
def compile_glimmer(logger, only_clean=False):
    tool_dirpath = os.path.join(qconfig.LIBS_LOCATION, 'glimmer')
    tool_src_dirpath = os.path.join(tool_dirpath, 'src')

    if not get_path_to_program('glimmerhmm', tool_dirpath):
        compile_tool('GlimmerHMM', tool_src_dirpath, ['../glimmerhmm'], logger=logger, only_clean=only_clean)
    return get_path_to_program('glimmerhmm', tool_dirpath)
Пример #3
0
def create_housekeeping_file(chr_lengths, max_points, root_dir, output_dir, logger):
    max_ideograms = len(chr_lengths.keys())
    template_fpath = None
    circos_bin_fpath = get_path_to_program('circos')
    if circos_bin_fpath:
        circos_dirpath = dirname(realpath(get_path_to_program('circos')))
        template_fpath = join(circos_dirpath, '..', 'libexec', 'etc', 'housekeeping.conf')
        if not is_non_empty_file(template_fpath):
            template_fpath = join(circos_dirpath, '..', 'etc', 'housekeeping.conf')

    if not is_non_empty_file(template_fpath):
        if not get_path_to_program('circos'):
            msg = 'Circos is not found.'
        else:
            msg = 'File etc/housekeeping.conf is not found.'
        logger.warning(msg + ' You will have to manually edit etc/housekeeping.conf: '
                       'set max_points_per_track to ' + str(max_points) + ' and max_ideograms to ' + str(max_ideograms))
        return '<<include %s>>\n' % join('etc', 'housekeeping.conf')

    housekeeping_fpath = join(output_dir, 'housekeeping.conf')
    with open(template_fpath) as f:
        with open(housekeeping_fpath, 'w') as out_f:
            for line in f:
                if 'max_points_per_track' in line:
                    out_f.write('max_points_per_track = %d\n' % max_points)
                elif 'max_ideograms' in line:
                    out_f.write('max_ideograms = %d\n' % max_ideograms)
                else:
                    out_f.write(line)
    return '<<include %s>>\n' % relpath(housekeeping_fpath, root_dir)
Пример #4
0
def search_sv_with_gridss(main_ref_fpath, bam_fpath, meta_ref_fpaths, output_dirpath, err_fpath):
    logger.info('  Searching structural variations with GRIDSS...')
    final_bed_fpath = join(output_dirpath, qutils.name_from_fpath(main_ref_fpath) + '_' + qconfig.sv_bed_fname)
    if isfile(final_bed_fpath):
        logger.info('    Using existing file: ' + final_bed_fpath)
        return final_bed_fpath

    if not get_path_to_program('java') or not check_java_version(1.8):
        logger.warning('Java 1.8 or later is required to run GRIDSS. Please install it and rerun QUAST.')
        return None
    if not get_path_to_program('Rscript'):
        logger.warning('R is required to run GRIDSS. Please install it and rerun QUAST.')
        return None

    if meta_ref_fpaths:
        n_jobs = min(len(meta_ref_fpaths), qconfig.max_threads)
        threads_per_job = max(1, qconfig.max_threads // n_jobs)
        parallel_args = [(cur_ref_fpath, output_dirpath, err_fpath, threads_per_job) for cur_ref_fpath in meta_ref_fpaths]
        bed_fpaths = run_parallel(process_one_ref, parallel_args, n_jobs, filter_results=True)
        if bed_fpaths:
            qutils.cat_files(bed_fpaths, final_bed_fpath)
    else:
        process_one_ref(main_ref_fpath, output_dirpath, err_fpath, qconfig.max_threads, bam_fpath=bam_fpath, bed_fpath=final_bed_fpath)
    logger.info('    Saving to: ' + final_bed_fpath)
    return final_bed_fpath
Пример #5
0
def compile_glimmer(logger, only_clean=False):
    tool_dirpath = os.path.join(qconfig.LIBS_LOCATION, 'glimmer')
    tool_src_dirpath = os.path.join(tool_dirpath, 'src')

    if not get_path_to_program('glimmerhmm', tool_dirpath):
        compile_tool('GlimmerHMM', tool_src_dirpath, ['../glimmerhmm'], logger=logger, only_clean=only_clean)
    return get_path_to_program('glimmerhmm', tool_dirpath)
Пример #6
0
def search_sv_with_gridss(main_ref_fpath, bam_fpath, meta_ref_fpaths, output_dirpath, err_fpath):
    logger.info('  Searching structural variations with GRIDSS...')
    final_bed_fpath = join(output_dirpath, qutils.name_from_fpath(main_ref_fpath) + '_' + qconfig.sv_bed_fname)
    if isfile(final_bed_fpath):
        logger.info('    Using existing file: ' + final_bed_fpath)
        return final_bed_fpath

    if not get_path_to_program('java') or not check_java_version(1.8):
        logger.warning('Java 1.8 or later is required to run GRIDSS. Please install it and rerun QUAST.')
        return None
    if not get_path_to_program('Rscript'):
        logger.warning('R is required to run GRIDSS. Please install it and rerun QUAST.')
        return None

    if meta_ref_fpaths:
        n_jobs = min(len(meta_ref_fpaths), qconfig.max_threads)
        threads_per_job = max(1, qconfig.max_threads // n_jobs)
        parallel_args = [(cur_ref_fpath, output_dirpath, err_fpath, threads_per_job) for cur_ref_fpath in meta_ref_fpaths]
        bed_fpaths = run_parallel(process_one_ref, parallel_args, n_jobs, filter_results=True)
        if bed_fpaths:
            qutils.cat_files(bed_fpaths, final_bed_fpath)
    else:
        process_one_ref(main_ref_fpath, output_dirpath, err_fpath, qconfig.max_threads, bam_fpath=bam_fpath, bed_fpath=final_bed_fpath)
    logger.info('    Saving to: ' + final_bed_fpath)
    return final_bed_fpath
Пример #7
0
def do(ref_fpath, contigs_fpaths, contig_report_fpath_pattern, gc_fpath,
       features_containers, cov_fpath, output_dir, logger):
    if not exists(output_dir):
        os.makedirs(output_dir)
    conf_fpath, circos_legend_fpath = create_conf(ref_fpath, contigs_fpaths,
                                                  contig_report_fpath_pattern,
                                                  output_dir, gc_fpath,
                                                  features_containers,
                                                  cov_fpath, logger)
    circos_exec = get_path_to_program('circos')
    if not circos_exec:
        logger.warning(
            'Circos is not installed!\n'
            'If you want to create Circos plots, install Circos as described at http://circos.ca/tutorials/lessons/configuration/distribution_and_installation '
            'and run the following command:\n\tcircos -conf ' + conf_fpath +
            '\n'
            'The plot legend is saved to ' + circos_legend_fpath + '\n')
        return None, None

    cmdline = [circos_exec, '-conf', conf_fpath]
    log_fpath = join(output_dir, 'circos.log')
    err_fpath = join(output_dir, 'circos.err')
    circos_png_fpath = join(output_dir, circos_png_fname)
    return_code = qutils.call_subprocess(cmdline,
                                         stdout=open(log_fpath, 'w'),
                                         stderr=open(err_fpath, 'w'))
    if return_code == 0 and is_non_empty_file(circos_png_fpath):
        return circos_png_fpath, circos_legend_fpath
    else:
        logger.warning('  Circos diagram was not created. See ' + log_fpath +
                       ' and ' + err_fpath + ' for details')
        return None, None
Пример #8
0
def get_blast_fpath(fname):
    blast_path = os.path.join(blast_dirpath, fname)
    if os.path.exists(blast_path):
        return blast_path

    blast_path = qutils.get_path_to_program(fname)
    return blast_path
Пример #9
0
def get_blast_fpath(fname):
    blast_path = os.path.join(blast_dirpath, fname)
    if os.path.exists(blast_path):
        return blast_path

    blast_path = qutils.get_path_to_program(fname)
    return blast_path
Пример #10
0
def gnuplot_exec_fpath():
    system_gnuplot_fpath = get_path_to_program('gnuplot')
    if system_gnuplot_fpath:
        return system_gnuplot_fpath, True
    tool_dirpath = join(qconfig.LIBS_LOCATION, 'gnuplot')
    tool_src_dirpath = join(tool_dirpath, 'src')
    tool_exec_fpath = join(tool_src_dirpath, 'gnuplot')
    return tool_exec_fpath, False
Пример #11
0
def do(ref_fpath, contigs_fpaths, contig_report_fpath_pattern, gc_fpath, features_containers, cov_fpath, output_dir, logger):
    if not exists(output_dir):
        os.makedirs(output_dir)
    conf_fpath, circos_legend_fpath = create_conf(ref_fpath, contigs_fpaths, contig_report_fpath_pattern, output_dir, gc_fpath, features_containers, cov_fpath, logger)
    circos_exec = get_path_to_program('circos')
    if not circos_exec:
        logger.warning('Circos is not installed!\n'
                       'If you want to create Circos plots, install Circos as described at http://circos.ca/tutorials/lessons/configuration/distribution_and_installation '
                       'and run the following command:\n circos -conf ' + conf_fpath + '.\n '
                       'The plot annotation is saved to ' + circos_legend_fpath)
        return None, None

    cmdline = [circos_exec, '-conf', conf_fpath]
    log_fpath = join(output_dir, 'circos.log')
    err_fpath = join(output_dir, 'circos.err')
    circos_png_fpath = join(output_dir, circos_png_fname)
    return_code = qutils.call_subprocess(cmdline, stdout=open(log_fpath, 'w'), stderr=open(err_fpath, 'w'))
    if return_code == 0 and is_non_empty_file(circos_png_fpath):
        return circos_png_fpath, circos_legend_fpath
    else:
        logger.warning('  Circos diagram was not created. See ' + log_fpath + ' and ' + err_fpath + ' for details')
        return None, None
Пример #12
0
def download_augustus(logger, only_clean=False):
    def __check_preinstalled_augustus_completeness(dirpath):
        etraining_path = os.path.join(dirpath, 'bin', 'etraining')
        if not os.path.isfile(etraining_path) or not os.access(
                etraining_path, os.X_OK):
            return False
        for aux_dir in ['scripts', 'config']:
            aux_dir_path = os.path.join(dirpath, aux_dir)
            if not os.path.isdir(aux_dir_path):
                return False
        return True

    preinstalled_augustus = qutils.get_path_to_program('augustus')
    if preinstalled_augustus is not None:
        preinstalled_augustus_dirpath = os.path.dirname(
            os.path.dirname(preinstalled_augustus))
        if __check_preinstalled_augustus_completeness(
                preinstalled_augustus_dirpath):
            return preinstalled_augustus_dirpath
    return download_tool('augustus',
                         augustus_version, ['bin'],
                         logger,
                         augustus_url,
                         only_clean=only_clean)
Пример #13
0
def get_installed_emem():
    return qutils.get_path_to_program('e-mem')
Пример #14
0
def minimap_fpath():
    return get_path_to_program('minimap2', minimap_dirpath)
Пример #15
0
def bedtools_fpath(fname):
    return get_path_to_program(fname, bedtools_bin_dirpath)
Пример #16
0
def bwa_fpath(fname):
    return get_path_to_program(fname, bwa_dirpath)
Пример #17
0
def get_installed_emem():
    return qutils.get_path_to_program('e-mem')
Пример #18
0
def minimap_fpath():
    return get_path_to_program('minimap2',
                               contig_aligner_dirpath,
                               min_version='2.10')
Пример #19
0
def bedtools_fpath(fname):
    return get_path_to_program(fname, bedtools_bin_dirpath)
Пример #20
0
def bwa_fpath(fname):
    return get_path_to_program(fname, bwa_dirpath)
Пример #21
0
def minimap_fpath():
    return get_path_to_program('minimap2', contig_aligner_dirpath, min_version='2.10')