def main(args):
    numerator_seq_files_data, denominator_seq_files_data, matrix_params, heatmap_params, filenames, max_threads = get_args(
        args)

    # Get the fold change matrix
    fold_change_matrix = get_fold_change_matrix(numerator_seq_files_data,
                                                denominator_seq_files_data,
                                                matrix_params, filenames,
                                                max_threads)

    # Now plot!
    bp_width, width, height, max_log2_fc, interval_size, minor_ticks, major_ticks = heatmap_params
    output_prefix = filenames[-1]

    output_filename = output_prefix + "_max_" + str(max_log2_fc) +  "_width_" + str(bp_width) + \
                      "bp_fold_change_TES_heatmap"

    only_heatmap_filename = generate_random_filename(".tiff")

    negative_log2_value = -1 * max_log2_fc if max_log2_fc else None

    generate_heatmap(fold_change_matrix, 'red/blue', only_heatmap_filename,
                     2.2, negative_log2_value, max_log2_fc)

    tick_params = (minor_ticks, major_ticks)

    ticks_image_filename = make_ticks_image(width, interval_size, tick_params)

    combine_images(ticks_image_filename, only_heatmap_filename,
                   output_filename)

    remove_files(fold_change_matrix, ticks_image_filename,
                 only_heatmap_filename)
def make_rgb_heatmap(fold_change_matrix_filename, heatmap_params,
                     output_filename_prefix):
    bp_width, width, height, gamma, max_fold_change, interval_size, minor_ticks_bp, major_ticks_bp = heatmap_params

    tick_params = minor_ticks_bp, major_ticks_bp

    only_heatmap_filename = generate_random_filename(extension=".tiff")

    if max_fold_change != None:
        negative_max_fold_change = -1 * max_fold_change
    else:
        negative_max_fold_change = None

    generate_heatmap(fold_change_matrix_filename,
                     'red/blue',
                     only_heatmap_filename,
                     gamma,
                     negative_max_fold_change,
                     max_fold_change,
                     ticks=None)

    ticks_image_filename = make_ticks_image(width, interval_size, tick_params)

    # Combine the two images together
    output_filename = output_filename_prefix + "_max_" + str(
        max_fold_change) + "_width_" + str(
            bp_width) + "bp_gene_body_fold_change_heatmap"

    combine_images(ticks_image_filename, only_heatmap_filename,
                   output_filename)

    remove_files(fold_change_matrix_filename, ticks_image_filename,
                 only_heatmap_filename)
def make_heatmap(matrix, heatmap_params, output_filename_prefix):
    bp_width, width, height, gamma, max_black_value, interval_size, minor_ticks_bp, major_ticks_bp = heatmap_params

    # Minor tick marks every 10 kb and major tick marks every 50 kb
    t = Ticks(minor_tick_mark_interval_size=(minor_ticks_bp / interval_size),
              major_tick_mark_interval_size=(major_ticks_bp / interval_size))

    output_filename = output_filename_prefix + "_max_" + str(
        max_black_value) + "_gamma_" + str(gamma) + "_width_" + str(
            bp_width) + "bp_TES_heatmap.tiff"

    generate_heatmap(matrix,
                     'gray',
                     output_filename,
                     gamma,
                     0,
                     max_black_value,
                     ticks=t)
Exemple #4
0
def make_heatmap(log2_matrix, max_log2_fold_change, tick_parameters, output_filename, px_per_bp):
    # Define gamma as 2.2 even though it won't be used
    gamma = 2.2
    min_value = -1 * max_log2_fold_change if max_log2_fold_change else None
    max_value = max_log2_fold_change
    red_blue_image = generate_random_filename('.tiff')

    if tick_parameters != (None, None):
        # Get the width of the matrix so we can make the ticks
        with open(log2_matrix) as file:
            width = len(file.readline().split())

        ticks_image = make_ticks_image(width, tick_parameters, px_per_bp)
        generate_heatmap(log2_matrix, 'red/blue', red_blue_image, gamma, min_value, max_value)
        combine_images(ticks_image, red_blue_image, output_filename)

    else:
        generate_heatmap(log2_matrix, 'red/blue', output_filename, gamma, min_value, max_value)
def make_heatmap(matrix_filename, output_prefix, heatmap_parameters,
                 tick_parameters):
    max_value, gamma = heatmap_parameters

    # Now make the heatmap
    min_value = None
    output_filename = output_prefix + "_max_" + str(
        max_value) + "_gamma_" + str(gamma) + "_region_heatmap.tiff"

    if tick_parameters != (None, None):
        ticks = Ticks(*tick_parameters, offset=1)
    else:
        ticks = None

    generate_heatmap(matrix_filename,
                     'gray',
                     output_filename,
                     gamma,
                     min_value,
                     max_value,
                     ticks=ticks)