def _run_smoove(full_bams, sr_bams, disc_bams, work_dir, items):
    """Run lumpy-sv using smoove.
    """
    batch = sshared.get_cur_batch(items)
    ext = "-%s-svs" % batch if batch else "-svs"
    name = "%s%s" % (dd.get_sample_name(items[0]), ext)
    out_file = os.path.join(work_dir, "%s-smoove.genotyped.vcf.gz" % name)
    sv_exclude_bed = sshared.prepare_exclude_file(items, out_file)
    old_out_file = os.path.join(work_dir, "%s%s-prep.vcf.gz"
                                % (os.path.splitext(os.path.basename(items[0]["align_bam"]))[0], ext))
    if utils.file_exists(old_out_file):
        return old_out_file, sv_exclude_bed
    if not utils.file_exists(out_file):
        with file_transaction(items[0], out_file) as tx_out_file:
            cores = dd.get_num_cores(items[0])
            out_dir = os.path.dirname(tx_out_file)
            ref_file = dd.get_ref_file(items[0])
            full_bams = " ".join(_prepare_smoove_bams(full_bams, sr_bams, disc_bams, items,
                                                      os.path.dirname(tx_out_file)))
            std_excludes = ["~^GL", "~^HLA", "~_random", "~^chrUn", "~alt", "~decoy"]
            def _is_std_exclude(n):
                clean_excludes = [x.replace("~", "").replace("^", "") for x in std_excludes]
                return any([n.startswith(x) or n.endswith(x) for x in clean_excludes])
            exclude_chrs = [c.name for c in ref.file_contigs(ref_file)
                            if not chromhacks.is_nonalt(c.name) and not _is_std_exclude(c.name)]
            exclude_chrs = "--excludechroms '%s'" % ",".join(std_excludes + exclude_chrs)
            exclude_bed = ("--exclude %s" % sv_exclude_bed) if utils.file_exists(sv_exclude_bed) else ""
            tempdir = os.path.dirname(tx_out_file)
            cmd = ("export TMPDIR={tempdir} && "
                   "smoove call --processes {cores} --genotype --removepr --fasta {ref_file} "
                   "--name {name} --outdir {out_dir} "
                   "{exclude_bed} {exclude_chrs} {full_bams}")
            with utils.chdir(tempdir):
                try:
                    do.run(cmd.format(**locals()), "smoove lumpy calling", items[0])
                except subprocess.CalledProcessError as msg:
                    if _allowed_errors(msg):
                        vcfutils.write_empty_vcf(tx_out_file, config=items[0]["config"],
                                                 samples=[dd.get_sample_name(d) for d in items])
                    else:
                        logger.exception()
                        raise
    vcfutils.bgzip_and_index(out_file, items[0]["config"])
    return out_file, sv_exclude_bed
def _run_smoove ( full_bams , sr_bams , disc_bams , work_dir , items ) : batch = sshared . get_cur_batch ( items ) ext = "-%s-svs" % batch if batch else "-svs" name = "%s%s" % ( dd . get_sample_name ( items [ 0 ] ) , ext ) out_file = os . path . join ( work_dir , "%s-smoove.genotyped.vcf.gz" % name ) sv_exclude_bed = sshared . prepare_exclude_file ( items , out_file ) old_out_file = os . path . join ( work_dir , "%s%s-prep.vcf.gz" % ( os . path . splitext ( os . path . basename ( items [ 0 ] [ "align_bam" ] ) ) [ 0 ] , ext ) ) if utils . file_exists ( old_out_file ) : return old_out_file , sv_exclude_bed if not utils . file_exists ( out_file ) : with file_transaction ( items [ 0 ] , out_file ) as tx_out_file : cores = dd . get_num_cores ( items [ 0 ] ) out_dir = os . path . dirname ( tx_out_file ) ref_file = dd . get_ref_file ( items [ 0 ] ) full_bams = " " . join ( _prepare_smoove_bams ( full_bams , sr_bams , disc_bams , items , os . path . dirname ( tx_out_file ) ) ) std_excludes = [ "~^GL" , "~^HLA" , "~_random" , "~^chrUn" , "~alt" , "~decoy" ] def _is_std_exclude ( n ) : clean_excludes = [ x . replace ( "~" , "" ) . replace ( "^" , "" ) for x in std_excludes ] return any ( [ n . startswith ( x ) or n . endswith ( x ) for x in clean_excludes ] ) exclude_chrs = [ c . name for c in ref . file_contigs ( ref_file ) if not chromhacks . is_nonalt ( c . name ) and not _is_std_exclude ( c . name ) ] exclude_chrs = "--excludechroms '%s'" % "," . join ( std_excludes + exclude_chrs ) exclude_bed = ( "--exclude %s" % sv_exclude_bed ) if utils . file_exists ( sv_exclude_bed ) else "" tempdir = os . path . dirname ( tx_out_file ) cmd = ( "export TMPDIR={tempdir} && " "smoove call --processes {cores} --genotype --removepr --fasta {ref_file} " "--name {name} --outdir {out_dir} " "{exclude_bed} {exclude_chrs} {full_bams}" ) with utils . chdir ( tempdir ) : try : do . run ( cmd . format ( ** locals ( ) ) , "smoove lumpy calling" , items [ 0 ] ) except subprocess . CalledProcessError as msg : if _allowed_errors ( msg ) : vcfutils . write_empty_vcf ( tx_out_file , config = items [ 0 ] [ "config" ] , samples = [ dd . get_sample_name ( d ) for d in items ] ) else : logger . exception ( ) raise vcfutils . bgzip_and_index ( out_file , items [ 0 ] [ "config" ] ) return out_file , sv_exclude_bed
Run lumpy-sv using smoove.