Here is the main function:
WIDTH = 221
HEIGHT = 100;
def create_pileup_images(candidate_variants):
for candidate in candidate_variants:
for biallelic_variant in split_into_biallelics(candidate):
start = biallelic_variant.start - (WIDTH-1) / 2
end = WIDTH - span_start
ref_bases = reference.get_bases(start, end)
image = Image(WIDTH, HEIGHT)
row_i = fill_reference_pixels(ref, image)
for read in reads.get_overlapping(start, end):
if row_i < HEIGHT and is_usable_read(read):
add_read(image, read, row_i)
row_i += 1
yield image
def fill_reference_pixels(ref, image):
for row in range(5):
for col in range(WIDTH):
alpha = 0.4
ref_base = ref[col]
red = get_base_color(ref_base)
green = get_quality_color(60) # The reference is high quality
blue = get_strand_color(True) # The reference is on the positive strand
image[row, col] = make_pixel(red, green, blue, alpha)
return 5
WIDTH = 221
HEIGHT = 100
def create_pileup_images(candidate_variants):
for candidate in candidate_variants:
for biallelic_variant in split_into_biallelics(candidate):
start = biallelic_variant.start - (WIDTH - 1) / 2
end = WIDTH - span_start
ref_bases = reference.get_bases(start, end)
image = Image(WIDTH, HEIGHT)
row_i = fill_reference_pixels(ref_bases, image)
for read in reads.get_overlapping(start, end):
if row_i < HEIGHT and is_usable_read(read):
add_read(image, read, row_i)
row_i += 1
yield image
def fill_reference_pixels(ref, image):
for row in range(5):
for col in range(WIDTH):
alpha = 0.4
ref_base = ref[col]
red = get_base_color(ref_base)
green = get_quality_color(60) # The reference is high quality
blue = get_strand_color(True) # The reference is on the positive strand
image[row, col] = make_pixel(red, green, blue, alpha)
return 5