Skip to content

Commit

Permalink
#71 WIP: Moved set_column_height to base class
Browse files Browse the repository at this point in the history
  • Loading branch information
josiahseaman committed Dec 4, 2018
1 parent 44c664e commit 6cb2ecf
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
9 changes: 0 additions & 9 deletions DDV/MultipleAlignmentLayout.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,5 @@ def initialize_image_by_sequence_dimensions(self, consensus_width=None, num_line
self.image_length = consensus_width * num_lines
self.prepare_image(self.image_length)

def contig_json(self):
return '[]' # not implemented, but must override base class


def set_column_height(self, heights):
try:
from statistics import median
average_line_count = int(median(heights))
except ImportError:
average_line_count = int(ceil(sum(heights) / len(heights)))
self.column_height = min(max(heights), average_line_count * 2)
27 changes: 18 additions & 9 deletions DDV/TransposonLayout.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def create_image_from_preprocessed_alignment(self, input_file_path, consensus_wi


def process_all_repeats(self, ref_fasta, output_folder, output_file_name, repeat_annotation_filename, chromosomes=None):
self.levels.origin[1] += self.levels[5].padding # One full Row of padding for Title
self.levels.origin = (self.levels.origin[0], self.levels.origin[1] + self.levels[5].padding) # One full Row of padding for Title
start_time = datetime.now()
self.read_all_files(ref_fasta, repeat_annotation_filename, chromosomes)

Expand Down Expand Up @@ -68,7 +68,8 @@ def initialize_image_by_sequence_dimensions(self, consensus_width=None, num_line
consensus_width = sum([x.rep_end for x in self.repeat_entries]) // len(self.repeat_entries) # rough approximation of size
num_lines = len(self.repeat_entries)
print("Average Width", consensus_width, "Entries", num_lines)
self.set_column_height()
heights = self.repeat_entries_to_heights()
self.set_column_height(heights)
else:
self.column_height = 1000

Expand Down Expand Up @@ -108,7 +109,7 @@ def layout_based_on_repeat_size(self, contig, width, height=None):
# skip to next mega row
if self.next_origin[0] + width + 1 >= self.image.width:
self.next_origin[0] = self.border_width
self.next_origin[1] += self.levels[3].thickness # self.column_height
self.next_origin[1] += self.levels[3].thickness #self.column_height #

modulos = [width, height, 9999, 9999]
padding = [0, 0, 20, 20 * 3]
Expand Down Expand Up @@ -207,13 +208,21 @@ def draw_repeat_title(self, contig, x, y):
vertical_label=False,
canvas=self.image)

def set_column_height(self):
counts = defaultdict(lambda: 0)
def set_column_height(self, heights):
try:
from statistics import median
average_line_count = int(median(heights))
except ImportError:
average_line_count = int(math.ceil(sum(heights) / len(heights)))
self.column_height = min(max(heights), average_line_count * 2)
print("Setting Column Height to %i based on Average line count per Block" % self.column_height)

def repeat_entries_to_heights(self):
rep_count = defaultdict(lambda: 0)
for x in self.repeat_entries:
counts[x.rep_name] += 1
average_line_count = int(math.ceil(sum(counts.values()) / len(counts)))
print("Setting Column Height to %i based on Average line count per Repeat Name" % (average_line_count * 2))
self.column_height = average_line_count * 2
rep_count[x.rep_name] += 1
heights = sorted([val for val in rep_count.values()])
return heights


def grab_aligned_repeat(consensus_width, contig, fragment):
Expand Down

0 comments on commit 6cb2ecf

Please sign in to comment.