def _add_log2_depth(in_file, out_file, data):
    """Create a CNVkit cnn file with depths
    http://cnvkit.readthedocs.io/en/stable/fileformats.html?highlight=cnn#target-and-antitarget-bin-level-coverages-cnn
    """
    if not utils.file_exists(out_file):
        with file_transaction(data, out_file) as tx_out_file:
            with utils.open_gzipsafe(in_file) as in_handle:
                with open(tx_out_file, "w") as out_handle:
                    out_handle.write("chromosome\tstart\tend\tgene\tlog2\tdepth\n")
                    for line in in_handle:
                        parts = line.rstrip().split("\t")
                        if len(parts) > 4:
                            # Handle inputs unannotated with gene names
                            if len(parts) == 5:
                                chrom, start, end, orig_name, depth = parts
                                gene_name = orig_name if (orig_name in ["Antitarget", "Background"]) else "."
                            else:
                                assert len(parts) == 6, parts
                                chrom, start, end, orig_name, depth, gene_name = parts
                            depth = float(depth)
                            log2_depth = math.log(float(depth), 2) if depth else -20.0
                            out_handle.write("%s\t%s\t%s\t%s\t%.3f\t%.2f\n" %
                                             (chrom, start, end, gene_name, log2_depth, depth))
    return out_file
def _add_log2_depth ( in_file , out_file , data ) : if not utils . file_exists ( out_file ) : with file_transaction ( data , out_file ) as tx_out_file : with utils . open_gzipsafe ( in_file ) as in_handle : with open ( tx_out_file , "w" ) as out_handle : out_handle . write ( "chromosome\tstart\tend\tgene\tlog2\tdepth\n" ) for line in in_handle : parts = line . rstrip ( ) . split ( "\t" ) if len ( parts ) > 4 : if len ( parts ) == 5 : chrom , start , end , orig_name , depth = parts gene_name = orig_name if ( orig_name in [ "Antitarget" , "Background" ] ) else "." else : assert len ( parts ) == 6 , parts chrom , start , end , orig_name , depth , gene_name = parts depth = float ( depth ) log2_depth = math . log ( float ( depth ) , 2 ) if depth else - 20.0 out_handle . write ( "%s\t%s\t%s\t%s\t%.3f\t%.2f\n" % ( chrom , start , end , gene_name , log2_depth , depth ) ) return out_file
Create a CNVkit cnn file with depths
    http://cnvkit.readthedocs.io/en/stable/fileformats.html?highlight=cnn#target-and-antitarget-bin-level-coverages-cnn